Skip to content

Commit

Permalink
Merge pull request #918 from samchon/features/json
Browse files Browse the repository at this point in the history
Fix bug of `IJsonSchema.default`.
  • Loading branch information
samchon committed Jan 9, 2024
2 parents b0c404c + f13acee commit 781c8e1
Show file tree
Hide file tree
Showing 61 changed files with 798 additions and 800 deletions.
2 changes: 1 addition & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@
"suppress-warnings": "^1.0.2",
"tstl": "^2.5.13",
"uuid": "^9.0.1",
"typia": "D:\\github\\samchon\\typia\\typia-5.3.8.tgz"
"typia": "D:\\github\\samchon\\typia\\typia-5.3.9.tgz"
}
}
2 changes: 1 addition & 1 deletion errors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
"typescript": "^5.3.2"
},
"dependencies": {
"typia": "D:\\github\\samchon\\typia\\typia-5.3.8.tgz"
"typia": "D:\\github\\samchon\\typia\\typia-5.3.9.tgz"
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typia",
"version": "5.3.8",
"version": "5.3.9",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions packages/typescript-json/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript-json",
"version": "5.3.8",
"version": "5.3.9",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -61,7 +61,7 @@
},
"homepage": "https://typia.io",
"dependencies": {
"typia": "5.3.8"
"typia": "5.3.9"
},
"peerDependencies": {
"typescript": ">=4.8.0 <5.4.0"
Expand Down
15 changes: 12 additions & 3 deletions src/programmers/internal/application_alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,19 @@ export const application_alias =
: undefined;
})(),
description: alias.description ?? undefined,
"x-typia-jsDocTags": alias.jsDocTags.length
? alias.jsDocTags
: undefined,
"x-typia-jsDocTags": (() => {
const filtered = alias.jsDocTags.filter(
(tag) =>
tag.name !== "title" &&
tag.name !== "deprecated" &&
tag.name !== "hidden",
);
return filtered.length ? filtered : undefined;
})(),
})!;
if (options.surplus === false && schema["x-typia-jsDocTags"]?.length)
delete (schema as any)["x-typia-jsDocTags"];

components.schemas ??= {};
components.schemas[key] = {
$id: options.purpose === "ajv" ? $id : undefined,
Expand Down
16 changes: 12 additions & 4 deletions src/programmers/internal/application_object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,25 @@ const create_object_schema =
description: property.description ?? undefined,
...(options.surplus
? {
"x-typia-jsDocTags": property.jsDocTags.length
? property.jsDocTags
: undefined,
"x-typia-required": property.value.required,
"x-typia-optional": property.value.optional,
}
: {}),
"x-typia-jsDocTags": (() => {
const filtered = property.jsDocTags.filter(
(tag) =>
tag.name !== "title" &&
tag.name !== "deprecated" &&
tag.name !== "hidden",
);
return filtered.length ? filtered : undefined;
})(),
});

if (schema === null) continue;
else if (key !== null) {
if (options.surplus === false && schema["x-typia-jsDocTags"]?.length)
delete schema["x-typia-jsDocTags"];
if (key !== null) {
properties[key] = schema;
if (property.value.isRequired() === true) required.push(key);
} else {
Expand Down
2 changes: 1 addition & 1 deletion test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@
"suppress-warnings": "^1.0.2",
"tstl": "^2.5.13",
"uuid": "^9.0.1",
"typia": "D:\\github\\samchon\\typia\\typia-5.3.8.tgz"
"typia": "D:\\github\\samchon\\typia\\typia-5.3.9.tgz"
}
}
52 changes: 37 additions & 15 deletions test/schemas/json/ajv_standard/CommentTagDefault.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,41 @@
"type": "object",
"properties": {
"boolean": {
"type": "boolean"
"default": true,
"type": "boolean",
"description": "Default tag on `boolean` typed value."
},
"number": {
"type": "number"
"type": "number",
"default": 1,
"description": "Default tag on `number` typed value."
},
"string": {
"type": "string"
"type": "string",
"default": "two",
"description": "Default tag on `string` typed value."
},
"text": {
"type": "string"
"type": "string",
"default": "Very long text, can you understand it?",
"description": "Default tag on `string` typed value with long characters."
},
"boolean_and_number_and_string": {
"oneOf": [
{
"type": "string"
"type": "string",
"default": "two"
},
{
"type": "number"
"type": "number",
"default": 1
},
{
"default": true,
"type": "boolean"
}
]
],
"description": "Default value on union typed property."
},
"union_but_boolean": {
"oneOf": [
Expand All @@ -44,40 +56,47 @@
"type": "number"
},
{
"default": true,
"type": "boolean"
}
]
],
"description": "Default value on union typed property."
},
"union_but_number": {
"oneOf": [
{
"type": "string"
},
{
"type": "number"
"type": "number",
"default": 1
},
{
"type": "boolean"
}
]
],
"description": "Default value on union typed property."
},
"union_but_string": {
"oneOf": [
{
"type": "string"
"type": "string",
"default": "two"
},
{
"type": "number"
},
{
"type": "boolean"
}
]
],
"description": "Default value on union typed property."
},
"vulnerable_range": {
"type": "number",
"maximum": 5,
"minimum": 3
"minimum": 3,
"description": "Default value on union typed property."
},
"boolean_and_number_and_template": {
"oneOf": [
Expand All @@ -86,12 +105,15 @@
"pattern": "^([+-]?\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?|true|false|(prefix_(.*)))"
},
{
"type": "number"
"type": "number",
"default": 1
},
{
"default": true,
"type": "boolean"
}
]
],
"description": "Default value on union typed property."
}
},
"required": [
Expand Down
24 changes: 12 additions & 12 deletions test/schemas/json/ajv_surplus/CommentTagArray.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
"exclusive": true
}
],
"x-typia-required": true,
"x-typia-optional": false,
"x-typia-jsDocTags": [
{
"name": "items",
Expand All @@ -63,9 +65,7 @@
}
]
}
],
"x-typia-required": true,
"x-typia-optional": false
]
},
"minItems": {
"type": "array",
Expand All @@ -83,6 +83,8 @@
"exclusive": true
}
],
"x-typia-required": true,
"x-typia-optional": false,
"x-typia-jsDocTags": [
{
"name": "minItems",
Expand All @@ -93,9 +95,7 @@
}
]
}
],
"x-typia-required": true,
"x-typia-optional": false
]
},
"both": {
"type": "array",
Expand All @@ -122,6 +122,8 @@
"exclusive": true
}
],
"x-typia-required": true,
"x-typia-optional": false,
"x-typia-jsDocTags": [
{
"name": "minItems",
Expand All @@ -141,9 +143,7 @@
}
]
}
],
"x-typia-required": true,
"x-typia-optional": false
]
},
"equal": {
"type": "array",
Expand All @@ -170,6 +170,8 @@
"exclusive": true
}
],
"x-typia-required": true,
"x-typia-optional": false,
"x-typia-jsDocTags": [
{
"name": "minItems",
Expand All @@ -189,9 +191,7 @@
}
]
}
],
"x-typia-required": true,
"x-typia-optional": false
]
}
},
"required": [
Expand Down
24 changes: 12 additions & 12 deletions test/schemas/json/ajv_surplus/CommentTagArrayUnion.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
"exclusive": true
}
],
"x-typia-required": true,
"x-typia-optional": false,
"x-typia-jsDocTags": [
{
"name": "items",
Expand All @@ -52,9 +54,7 @@
}
]
}
],
"x-typia-required": true,
"x-typia-optional": false
]
},
"minItems": {
"type": "array",
Expand All @@ -72,6 +72,8 @@
"exclusive": true
}
],
"x-typia-required": true,
"x-typia-optional": false,
"x-typia-jsDocTags": [
{
"name": "minItems",
Expand All @@ -82,9 +84,7 @@
}
]
}
],
"x-typia-required": true,
"x-typia-optional": false
]
},
"maxItems": {
"type": "array",
Expand All @@ -109,6 +109,8 @@
"exclusive": true
}
],
"x-typia-required": true,
"x-typia-optional": false,
"x-typia-jsDocTags": [
{
"name": "maxItems",
Expand All @@ -119,9 +121,7 @@
}
]
}
],
"x-typia-required": true,
"x-typia-optional": false
]
},
"both": {
"type": "array",
Expand All @@ -148,6 +148,8 @@
"exclusive": true
}
],
"x-typia-required": true,
"x-typia-optional": false,
"x-typia-jsDocTags": [
{
"name": "minItems",
Expand All @@ -167,9 +169,7 @@
}
]
}
],
"x-typia-required": true,
"x-typia-optional": false
]
}
},
"required": [
Expand Down
Loading

0 comments on commit 781c8e1

Please sign in to comment.