Skip to content

Commit

Permalink
Fix samchon/nestia#777 - JSON schema for Date | null type.
Browse files Browse the repository at this point in the history
There had been a bug that `Date | null` type being considered as non nullable type when generating JSON schema.

This PR fixes the bug, so that no problem would be occured more.
  • Loading branch information
samchon committed Feb 2, 2024
1 parent f4d1fbd commit 7abbf81
Show file tree
Hide file tree
Showing 88 changed files with 6,265 additions and 368 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node_modules/

packages/typescript-json/src/
package-lock.json
pnpm-lock.yaml

*.log
*.tgz
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.4.1.tgz"
"typia": "D:\\github\\samchon\\typia@master\\typia-5.4.2.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.4.1.tgz"
"typia": "D:\\github\\samchon\\typia@master\\typia-5.4.2.tgz"
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typia",
"version": "5.4.1",
"version": "5.4.2",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -79,6 +79,7 @@
"@types/ts-expose-internals": "npm:[email protected]",
"@typescript-eslint/eslint-plugin": "^5.59.11",
"@typescript-eslint/parser": "^5.59.11",
"chalk": "^4.0.0",
"prettier": "^2.6.2",
"rimraf": "^5.0.5",
"ts-node": "^10.9.1",
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.4.1",
"version": "5.4.2",
"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.4.1"
"typia": "5.4.2"
},
"peerDependencies": {
"typescript": ">=4.8.0 <5.5.0"
Expand Down
6 changes: 3 additions & 3 deletions src/programmers/internal/application_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ export const application_schema =

// toJSON() METHOD
if (meta.escaped !== null)
union.push(
...application_escaped(options)(blockNever)(components)(meta.escaped),
);
application_escaped(options)(blockNever)(components)(
meta.escaped,
).forEach(insert);

// ATOMIC TYPES
if (meta.templates.length && AtomicPredicator.template(meta))
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.4.1.tgz"
"typia": "D:\\github\\samchon\\typia@master\\typia-5.4.2.tgz"
}
}
80 changes: 80 additions & 0 deletions test/schemas/json/ajv_standard/ObjectDate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"schemas": [
{
"$ref": "#/components/schemas/ObjectDate"
}
],
"components": {
"schemas": {
"ObjectDate": {
"$id": "#/components/schemas/ObjectDate",
"type": "object",
"properties": {
"classDate": {
"oneOf": [
{
"type": "null"
},
{
"type": "string",
"format": "date-time"
}
]
},
"date": {
"oneOf": [
{
"type": "null"
},
{
"type": "string",
"format": "date"
}
]
},
"datetime": {
"oneOf": [
{
"type": "null"
},
{
"type": "string",
"format": "date-time"
}
]
},
"time": {
"oneOf": [
{
"type": "null"
},
{
"type": "string",
"format": "time"
}
]
},
"duration": {
"oneOf": [
{
"type": "null"
},
{
"type": "string",
"format": "duration"
}
]
}
},
"required": [
"date",
"datetime",
"time",
"duration"
]
}
}
},
"purpose": "ajv",
"surplus": false
}
153 changes: 153 additions & 0 deletions test/schemas/json/ajv_surplus/ObjectDate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
{
"schemas": [
{
"$ref": "#/components/schemas/ObjectDate"
}
],
"components": {
"schemas": {
"ObjectDate": {
"$id": "#/components/schemas/ObjectDate",
"type": "object",
"properties": {
"classDate": {
"oneOf": [
{
"x-typia-required": true,
"x-typia-optional": true,
"type": "null"
},
{
"type": "string",
"format": "date-time"
}
],
"x-typia-required": true,
"x-typia-optional": true
},
"date": {
"oneOf": [
{
"x-typia-required": true,
"x-typia-optional": false,
"type": "null"
},
{
"type": "string",
"format": "date",
"x-typia-typeTags": [
{
"target": "string",
"name": "Format<\"date\">",
"kind": "format",
"value": "date",
"validate": "/^(\\d{4})-(\\d{2})-(\\d{2})$/.test($input)",
"exclusive": [
"format",
"pattern"
]
}
]
}
],
"x-typia-required": true,
"x-typia-optional": false
},
"datetime": {
"oneOf": [
{
"x-typia-required": true,
"x-typia-optional": false,
"type": "null"
},
{
"type": "string",
"format": "date-time",
"x-typia-typeTags": [
{
"target": "string",
"name": "Format<\"date-time\">",
"kind": "format",
"value": "date-time",
"validate": "!isNaN(new Date($input).getTime())",
"exclusive": [
"format",
"pattern"
]
}
]
}
],
"x-typia-required": true,
"x-typia-optional": false
},
"time": {
"oneOf": [
{
"x-typia-required": true,
"x-typia-optional": false,
"type": "null"
},
{
"type": "string",
"format": "time",
"x-typia-typeTags": [
{
"target": "string",
"name": "Format<\"time\">",
"kind": "format",
"value": "time",
"validate": "/^(\\d\\d):(\\d\\d):(\\d\\d(?:\\.\\d+)?)(z|([+-])(\\d\\d)(?::?(\\d\\d))?)?$/i.test($input)",
"exclusive": [
"format",
"pattern"
]
}
]
}
],
"x-typia-required": true,
"x-typia-optional": false
},
"duration": {
"oneOf": [
{
"x-typia-required": true,
"x-typia-optional": false,
"type": "null"
},
{
"type": "string",
"format": "duration",
"x-typia-typeTags": [
{
"target": "string",
"name": "Format<\"duration\">",
"kind": "format",
"value": "duration",
"validate": "/^P(?!$)((\\d+Y)?(\\d+M)?(\\d+D)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+S)?)?|(\\d+W)?)$/.test($input)",
"exclusive": [
"format",
"pattern"
]
}
]
}
],
"x-typia-required": true,
"x-typia-optional": false
}
},
"required": [
"date",
"datetime",
"time",
"duration"
],
"x-typia-jsDocTags": []
}
}
},
"purpose": "ajv",
"surplus": true
}
50 changes: 50 additions & 0 deletions test/schemas/json/swagger_standard/ObjectDate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"schemas": [
{
"$ref": "#/components/schemas/ObjectDate"
}
],
"components": {
"schemas": {
"ObjectDate": {
"type": "object",
"properties": {
"classDate": {
"type": "string",
"format": "date-time",
"nullable": true
},
"date": {
"type": "string",
"format": "date",
"nullable": true
},
"datetime": {
"type": "string",
"format": "date-time",
"nullable": true
},
"time": {
"type": "string",
"format": "time",
"nullable": true
},
"duration": {
"type": "string",
"format": "duration",
"nullable": true
}
},
"nullable": false,
"required": [
"date",
"datetime",
"time",
"duration"
]
}
}
},
"purpose": "swagger",
"surplus": false
}
Loading

0 comments on commit 7abbf81

Please sign in to comment.