From 1bbf4a910d6b3d59fe34ae781f46c01322ce7b20 Mon Sep 17 00:00:00 2001 From: andriskaaz Date: Thu, 30 May 2024 19:10:32 +0200 Subject: [PATCH] feat: $comment keyword (#604) --- api.md | 24 ++++++++++++++++++++++ test/programs/comments-comment/main.ts | 9 ++++++++ test/programs/comments-comment/schema.json | 16 +++++++++++++++ test/schema.test.ts | 1 + typescript-json-schema.ts | 1 + 5 files changed, 51 insertions(+) create mode 100644 test/programs/comments-comment/main.ts create mode 100644 test/programs/comments-comment/schema.json diff --git a/api.md b/api.md index 94c3f5d2..7e863391 100644 --- a/api.md +++ b/api.md @@ -492,6 +492,21 @@ interface MyObject { ``` +## [comments-comment](./test/programs/comments-comment) + +```ts +/** + * @$comment Object comment + */ +interface MyObject { + /** + * @$comment Property comment + */ + text: string; +} +``` + + ## [comments-from-lib](./test/programs/comments-from-lib) ```ts @@ -607,6 +622,15 @@ export interface MyObject { ``` +## [const-as-enum](./test/programs/const-as-enum) + +```ts +export interface MyObject { + reference: true; +} +``` + + ## [const-keyword](./test/programs/const-keyword) ```ts diff --git a/test/programs/comments-comment/main.ts b/test/programs/comments-comment/main.ts new file mode 100644 index 00000000..35bd19a0 --- /dev/null +++ b/test/programs/comments-comment/main.ts @@ -0,0 +1,9 @@ +/** + * @$comment Object comment + */ +interface MyObject { + /** + * @$comment Property comment + */ + text: string; +} diff --git a/test/programs/comments-comment/schema.json b/test/programs/comments-comment/schema.json new file mode 100644 index 00000000..e6062458 --- /dev/null +++ b/test/programs/comments-comment/schema.json @@ -0,0 +1,16 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "additionalProperties": false, + "$comment": "Object comment", + "properties": { + "text": { + "$comment": "Property comment", + "type": "string" + } + }, + "required": [ + "text" + ], + "type": "object" +} + diff --git a/test/schema.test.ts b/test/schema.test.ts index a29fe972..d2962505 100644 --- a/test/schema.test.ts +++ b/test/schema.test.ts @@ -371,6 +371,7 @@ describe("schema", () => { describe("comments", () => { assertSchema("comments", "MyObject"); + assertSchema("comments-comment", "MyObject"); assertSchema("comments-override", "MyObject"); assertSchema("comments-imports", "MyObject", { aliasRef: true, diff --git a/typescript-json-schema.ts b/typescript-json-schema.ts index 40439843..86f38724 100644 --- a/typescript-json-schema.ts +++ b/typescript-json-schema.ts @@ -426,6 +426,7 @@ const validationKeywords = { $ref: true, id: true, $id: true, + $comment: true, title: true };