Skip to content

Commit 3c8e60a

Browse files
authored
JSON schema supports @x-plugin null comment. (#1717)
* JSON schema supports `@x-plugin null` comment. * trim
1 parent 7f01e50 commit 3c8e60a

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typia",
3-
"version": "11.0.1",
3+
"version": "11.0.2",
44
"description": "Superfast runtime validators with only one line",
55
"main": "lib/index.js",
66
"typings": "lib/index.d.ts",

src/programmers/internal/json_schema_jsDocTags.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ export const json_schema_jsDocTags = <Schema extends OpenApi.IJsonSchema>(
1111

1212
const value: string | undefined = tag.text
1313
?.filter((s) => s.kind === "text")
14-
.map((s) => s.text.split("\r\n").join("\n"))[0];
14+
.map((s) => s.text.trim().split("\r\n").join("\n"))[0];
1515
if (value === undefined) continue;
1616
else (schema as any)[tag.name] = cast(value);
1717
}
1818
return schema;
1919
};
2020

21-
const cast = (value: string): string | number | boolean => {
21+
const cast = (value: string): string | number | boolean | null => {
2222
if (value === "true") return true;
2323
if (value === "false") return false;
2424
const num: number = Number(value);
2525
if (Number.isNaN(num) === false) return num;
26-
return value;
26+
return value === "null" ? null : value;
2727
};

test/src/features/issues/test_pr_1714_json_schema_plugin_by_jsDocTags.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export const test_pr_1714_json_schema_plugin_by_jsDocTags = (): void => {
1515
TestValidator.equals("x-autobe-database-schema")(
1616
(something as any)?.["x-autobe-database-schema"],
1717
)("somethings");
18+
TestValidator.equals("x-null-value")(
19+
(something.properties?.id as any)?.["x-null-value"],
20+
)(null);
1821
TestValidator.equals("x-custom-tag")(
1922
(something.properties?.id as any)?.["x-custom-tag"],
2023
)(3);
@@ -36,6 +39,7 @@ interface ISomething {
3639
* Primary Key.
3740
*
3841
* @x-autobe-database-schema-member id
42+
* @x-null-value null
3943
* @x-custom-tag 3
4044
* @x-valid true
4145
* @regular This is a regular tag and should be ignored.

0 commit comments

Comments
 (0)