@effect/schema
Advanced tools
Comparing version 0.74.0 to 0.74.1
@@ -74,2 +74,24 @@ "use strict"; | ||
}); | ||
const removeDefaultJsonSchemaAnnotations = (jsonSchemaAnnotations, ast) => { | ||
if (jsonSchemaAnnotations["title"] === ast.annotations[AST.TitleAnnotationId]) { | ||
delete jsonSchemaAnnotations["title"]; | ||
} | ||
if (jsonSchemaAnnotations["description"] === ast.annotations[AST.DescriptionAnnotationId]) { | ||
delete jsonSchemaAnnotations["description"]; | ||
} | ||
return jsonSchemaAnnotations; | ||
}; | ||
const getASTJsonSchemaAnnotations = ast => { | ||
const jsonSchemaAnnotations = getJsonSchemaAnnotations(ast); | ||
switch (ast._tag) { | ||
case "StringKeyword": | ||
return removeDefaultJsonSchemaAnnotations(jsonSchemaAnnotations, AST.stringKeyword); | ||
case "NumberKeyword": | ||
return removeDefaultJsonSchemaAnnotations(jsonSchemaAnnotations, AST.numberKeyword); | ||
case "BooleanKeyword": | ||
return removeDefaultJsonSchemaAnnotations(jsonSchemaAnnotations, AST.booleanKeyword); | ||
default: | ||
return jsonSchemaAnnotations; | ||
} | ||
}; | ||
const pruneUndefinedKeyword = ps => { | ||
@@ -120,5 +142,12 @@ const type = ps.type; | ||
try { | ||
return merge(merge(go(ast.from, $defs, true, path), getJsonSchemaAnnotations(ast)), handler); | ||
return { | ||
...go(ast.from, $defs, true, path), | ||
...getJsonSchemaAnnotations(ast), | ||
...handler | ||
}; | ||
} catch (e) { | ||
return merge(getJsonSchemaAnnotations(ast), handler); | ||
return { | ||
...getJsonSchemaAnnotations(ast), | ||
...handler | ||
}; | ||
} | ||
@@ -135,3 +164,3 @@ } else if (!isOverrideAnnotation(handler)) { | ||
} | ||
if (handleIdentifier && !AST.isTransformation(ast)) { | ||
if (handleIdentifier && !AST.isTransformation(ast) && !AST.isRefinement(ast)) { | ||
const identifier = AST.getJSONIdentifier(ast); | ||
@@ -182,22 +211,16 @@ if (Option.isSome(identifier)) { | ||
case "StringKeyword": | ||
{ | ||
const out = { | ||
type: "string" | ||
}; | ||
return ast === AST.stringKeyword ? out : merge(out, getJsonSchemaAnnotations(ast)); | ||
} | ||
return { | ||
type: "string", | ||
...getASTJsonSchemaAnnotations(ast) | ||
}; | ||
case "NumberKeyword": | ||
{ | ||
const out = { | ||
type: "number" | ||
}; | ||
return ast === AST.numberKeyword ? out : merge(out, getJsonSchemaAnnotations(ast)); | ||
} | ||
return { | ||
type: "number", | ||
...getASTJsonSchemaAnnotations(ast) | ||
}; | ||
case "BooleanKeyword": | ||
{ | ||
const out = { | ||
type: "boolean" | ||
}; | ||
return ast === AST.booleanKeyword ? out : merge(out, getJsonSchemaAnnotations(ast)); | ||
} | ||
return { | ||
type: "boolean", | ||
...getASTJsonSchemaAnnotations(ast) | ||
}; | ||
case "BigIntKeyword": | ||
@@ -367,3 +390,6 @@ throw new Error(errors_.getJSONSchemaMissingAnnotationErrorMessage(path, ast)); | ||
{ | ||
throw new Error(errors_.getJSONSchemaMissingAnnotationErrorMessage(path, ast)); | ||
if (AST.encodedBoundAST(ast) === ast) { | ||
throw new Error(errors_.getJSONSchemaMissingAnnotationErrorMessage(path, ast)); | ||
} | ||
return go(ast.from, $defs, true, path); | ||
} | ||
@@ -370,0 +396,0 @@ case "TemplateLiteral": |
@@ -64,2 +64,24 @@ /** | ||
}); | ||
const removeDefaultJsonSchemaAnnotations = (jsonSchemaAnnotations, ast) => { | ||
if (jsonSchemaAnnotations["title"] === ast.annotations[AST.TitleAnnotationId]) { | ||
delete jsonSchemaAnnotations["title"]; | ||
} | ||
if (jsonSchemaAnnotations["description"] === ast.annotations[AST.DescriptionAnnotationId]) { | ||
delete jsonSchemaAnnotations["description"]; | ||
} | ||
return jsonSchemaAnnotations; | ||
}; | ||
const getASTJsonSchemaAnnotations = ast => { | ||
const jsonSchemaAnnotations = getJsonSchemaAnnotations(ast); | ||
switch (ast._tag) { | ||
case "StringKeyword": | ||
return removeDefaultJsonSchemaAnnotations(jsonSchemaAnnotations, AST.stringKeyword); | ||
case "NumberKeyword": | ||
return removeDefaultJsonSchemaAnnotations(jsonSchemaAnnotations, AST.numberKeyword); | ||
case "BooleanKeyword": | ||
return removeDefaultJsonSchemaAnnotations(jsonSchemaAnnotations, AST.booleanKeyword); | ||
default: | ||
return jsonSchemaAnnotations; | ||
} | ||
}; | ||
const pruneUndefinedKeyword = ps => { | ||
@@ -110,5 +132,12 @@ const type = ps.type; | ||
try { | ||
return merge(merge(go(ast.from, $defs, true, path), getJsonSchemaAnnotations(ast)), handler); | ||
return { | ||
...go(ast.from, $defs, true, path), | ||
...getJsonSchemaAnnotations(ast), | ||
...handler | ||
}; | ||
} catch (e) { | ||
return merge(getJsonSchemaAnnotations(ast), handler); | ||
return { | ||
...getJsonSchemaAnnotations(ast), | ||
...handler | ||
}; | ||
} | ||
@@ -125,3 +154,3 @@ } else if (!isOverrideAnnotation(handler)) { | ||
} | ||
if (handleIdentifier && !AST.isTransformation(ast)) { | ||
if (handleIdentifier && !AST.isTransformation(ast) && !AST.isRefinement(ast)) { | ||
const identifier = AST.getJSONIdentifier(ast); | ||
@@ -172,22 +201,16 @@ if (Option.isSome(identifier)) { | ||
case "StringKeyword": | ||
{ | ||
const out = { | ||
type: "string" | ||
}; | ||
return ast === AST.stringKeyword ? out : merge(out, getJsonSchemaAnnotations(ast)); | ||
} | ||
return { | ||
type: "string", | ||
...getASTJsonSchemaAnnotations(ast) | ||
}; | ||
case "NumberKeyword": | ||
{ | ||
const out = { | ||
type: "number" | ||
}; | ||
return ast === AST.numberKeyword ? out : merge(out, getJsonSchemaAnnotations(ast)); | ||
} | ||
return { | ||
type: "number", | ||
...getASTJsonSchemaAnnotations(ast) | ||
}; | ||
case "BooleanKeyword": | ||
{ | ||
const out = { | ||
type: "boolean" | ||
}; | ||
return ast === AST.booleanKeyword ? out : merge(out, getJsonSchemaAnnotations(ast)); | ||
} | ||
return { | ||
type: "boolean", | ||
...getASTJsonSchemaAnnotations(ast) | ||
}; | ||
case "BigIntKeyword": | ||
@@ -357,3 +380,6 @@ throw new Error(errors_.getJSONSchemaMissingAnnotationErrorMessage(path, ast)); | ||
{ | ||
throw new Error(errors_.getJSONSchemaMissingAnnotationErrorMessage(path, ast)); | ||
if (AST.encodedBoundAST(ast) === ast) { | ||
throw new Error(errors_.getJSONSchemaMissingAnnotationErrorMessage(path, ast)); | ||
} | ||
return go(ast.from, $defs, true, path); | ||
} | ||
@@ -360,0 +386,0 @@ case "TemplateLiteral": |
{ | ||
"name": "@effect/schema", | ||
"version": "0.74.0", | ||
"version": "0.74.1", | ||
"description": "Modeling the schema of data structures as first-class values", | ||
@@ -16,3 +16,3 @@ "license": "MIT", | ||
"peerDependencies": { | ||
"effect": "^3.8.3" | ||
"effect": "^3.8.4" | ||
}, | ||
@@ -19,0 +19,0 @@ "publishConfig": { |
@@ -264,2 +264,29 @@ /** | ||
const removeDefaultJsonSchemaAnnotations = ( | ||
jsonSchemaAnnotations: JsonSchemaAnnotations, | ||
ast: AST.AST | ||
): JsonSchemaAnnotations => { | ||
if (jsonSchemaAnnotations["title"] === ast.annotations[AST.TitleAnnotationId]) { | ||
delete jsonSchemaAnnotations["title"] | ||
} | ||
if (jsonSchemaAnnotations["description"] === ast.annotations[AST.DescriptionAnnotationId]) { | ||
delete jsonSchemaAnnotations["description"] | ||
} | ||
return jsonSchemaAnnotations | ||
} | ||
const getASTJsonSchemaAnnotations = (ast: AST.AST): JsonSchemaAnnotations => { | ||
const jsonSchemaAnnotations = getJsonSchemaAnnotations(ast) | ||
switch (ast._tag) { | ||
case "StringKeyword": | ||
return removeDefaultJsonSchemaAnnotations(jsonSchemaAnnotations, AST.stringKeyword) | ||
case "NumberKeyword": | ||
return removeDefaultJsonSchemaAnnotations(jsonSchemaAnnotations, AST.numberKeyword) | ||
case "BooleanKeyword": | ||
return removeDefaultJsonSchemaAnnotations(jsonSchemaAnnotations, AST.booleanKeyword) | ||
default: | ||
return jsonSchemaAnnotations | ||
} | ||
} | ||
const pruneUndefinedKeyword = (ps: AST.PropertySignature): AST.AST | undefined => { | ||
@@ -323,5 +350,12 @@ const type = ps.type | ||
try { | ||
return merge(merge(go(ast.from, $defs, true, path), getJsonSchemaAnnotations(ast)), handler) | ||
return { | ||
...go(ast.from, $defs, true, path), | ||
...getJsonSchemaAnnotations(ast), | ||
...handler | ||
} | ||
} catch (e) { | ||
return merge(getJsonSchemaAnnotations(ast), handler) | ||
return { | ||
...getJsonSchemaAnnotations(ast), | ||
...handler | ||
} | ||
} | ||
@@ -338,3 +372,3 @@ } else if (!isOverrideAnnotation(handler)) { | ||
} | ||
if (handleIdentifier && !AST.isTransformation(ast)) { | ||
if (handleIdentifier && !AST.isTransformation(ast) && !AST.isRefinement(ast)) { | ||
const identifier = AST.getJSONIdentifier(ast) | ||
@@ -377,14 +411,8 @@ if (Option.isSome(identifier)) { | ||
return merge(objectJsonSchema, getJsonSchemaAnnotations(ast)) | ||
case "StringKeyword": { | ||
const out: JsonSchema7 = { type: "string" } | ||
return ast === AST.stringKeyword ? out : merge(out, getJsonSchemaAnnotations(ast)) | ||
} | ||
case "NumberKeyword": { | ||
const out: JsonSchema7 = { type: "number" } | ||
return ast === AST.numberKeyword ? out : merge(out, getJsonSchemaAnnotations(ast)) | ||
} | ||
case "BooleanKeyword": { | ||
const out: JsonSchema7 = { type: "boolean" } | ||
return ast === AST.booleanKeyword ? out : merge(out, getJsonSchemaAnnotations(ast)) | ||
} | ||
case "StringKeyword": | ||
return { type: "string", ...getASTJsonSchemaAnnotations(ast) } | ||
case "NumberKeyword": | ||
return { type: "number", ...getASTJsonSchemaAnnotations(ast) } | ||
case "BooleanKeyword": | ||
return { type: "boolean", ...getASTJsonSchemaAnnotations(ast) } | ||
case "BigIntKeyword": | ||
@@ -549,3 +577,6 @@ throw new Error(errors_.getJSONSchemaMissingAnnotationErrorMessage(path, ast)) | ||
case "Refinement": { | ||
throw new Error(errors_.getJSONSchemaMissingAnnotationErrorMessage(path, ast)) | ||
if (AST.encodedBoundAST(ast) === ast) { | ||
throw new Error(errors_.getJSONSchemaMissingAnnotationErrorMessage(path, ast)) | ||
} | ||
return go(ast.from, $defs, true, path) | ||
} | ||
@@ -552,0 +583,0 @@ case "TemplateLiteral": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2314573
43051