From 04045e94adf63431d1e026dda141034e75fa93bc Mon Sep 17 00:00:00 2001 From: netanel-mce Date: Thu, 16 Mar 2023 08:43:27 +0200 Subject: [PATCH 1/2] all unit test pass --- .../programs/unique-names-multiple-subdefinitions/schema.json | 4 ++-- ...a.MyObject.fded1213.json => schema.MyObject.6aa2b6a1.json} | 0 ...a.MyObject.f2191116.json => schema.MyObject.87ee5ee4.json} | 0 test/schema.test.ts | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename test/programs/unique-names/{schema.MyObject.fded1213.json => schema.MyObject.6aa2b6a1.json} (100%) rename test/programs/unique-names/{schema.MyObject.f2191116.json => schema.MyObject.87ee5ee4.json} (100%) diff --git a/test/programs/unique-names-multiple-subdefinitions/schema.json b/test/programs/unique-names-multiple-subdefinitions/schema.json index 79b51025..e35111f2 100644 --- a/test/programs/unique-names-multiple-subdefinitions/schema.json +++ b/test/programs/unique-names-multiple-subdefinitions/schema.json @@ -2,7 +2,7 @@ "$schema": "http://json-schema.org/draft-07/schema#", "properties": { "sub": { - "$ref": "#/definitions/SubObject.0eb4e9af" + "$ref": "#/definitions/SubObject.9cf7c8c7" } }, "type": "object", @@ -10,7 +10,7 @@ "sub" ], "definitions": { - "SubObject.0eb4e9af": { + "SubObject.9cf7c8c7": { "properties": { "is": { "enum": [ diff --git a/test/programs/unique-names/schema.MyObject.fded1213.json b/test/programs/unique-names/schema.MyObject.6aa2b6a1.json similarity index 100% rename from test/programs/unique-names/schema.MyObject.fded1213.json rename to test/programs/unique-names/schema.MyObject.6aa2b6a1.json diff --git a/test/programs/unique-names/schema.MyObject.f2191116.json b/test/programs/unique-names/schema.MyObject.87ee5ee4.json similarity index 100% rename from test/programs/unique-names/schema.MyObject.f2191116.json rename to test/programs/unique-names/schema.MyObject.87ee5ee4.json diff --git a/test/schema.test.ts b/test/schema.test.ts index 73ccf20a..6a5c8460 100644 --- a/test/schema.test.ts +++ b/test/schema.test.ts @@ -45,7 +45,7 @@ export function assertSchema( settings.required = true; } - const files = [resolve(BASE + group + "/main.ts")]; + const files = [BASE + group + "/main.ts"]; const actual = TJS.generateSchema(TJS.getProgramFromFiles(files, compilerOptions), type, settings, files); // writeFileSync(BASE + group + "/schema.json", stringify(actual, {space: 4}) + "\n\n"); From f8d9ea574378205c5c29aeef7176c549e515cd82 Mon Sep 17 00:00:00 2001 From: netanel david <109151575+netanel-mce@users.noreply.github.com> Date: Wed, 22 Mar 2023 14:22:58 +0000 Subject: [PATCH 2/2] windows and linoxs --- api.md | 15 +++++++++++++++ .../unique-names/schema.MyObject.f2191116.json | 16 ++++++++++++++++ .../unique-names/schema.MyObject.fded1213.json | 15 +++++++++++++++ typescript-json-schema.ts | 3 ++- 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 test/programs/unique-names/schema.MyObject.f2191116.json create mode 100644 test/programs/unique-names/schema.MyObject.fded1213.json diff --git a/api.md b/api.md index 86f81567..0337383d 100644 --- a/api.md +++ b/api.md @@ -1769,6 +1769,21 @@ interface Foo { ``` +## [type-intersection-recursive-no-additional](./test/programs/type-intersection-recursive-no-additional) + +```ts +type MyRecursiveNode = { + next?: MyNode; +} + +type MyNode = { + val: string; +} & MyRecursiveNode; + +type MyLinkedList = MyNode; +``` + + ## [type-mapped-types](./test/programs/type-mapped-types) ```ts diff --git a/test/programs/unique-names/schema.MyObject.f2191116.json b/test/programs/unique-names/schema.MyObject.f2191116.json new file mode 100644 index 00000000..b177159e --- /dev/null +++ b/test/programs/unique-names/schema.MyObject.f2191116.json @@ -0,0 +1,16 @@ +{ + "type": "object", + "properties": { + "is": { + "type": "string", + "enum": [ + "MyObject_1" + ] + } + }, + "required": [ + "is" + ], + "$schema": "http://json-schema.org/draft-07/schema#" +} + diff --git a/test/programs/unique-names/schema.MyObject.fded1213.json b/test/programs/unique-names/schema.MyObject.fded1213.json new file mode 100644 index 00000000..92aef3f0 --- /dev/null +++ b/test/programs/unique-names/schema.MyObject.fded1213.json @@ -0,0 +1,15 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "properties": { + "is": { + "enum": [ + "MyObject_2" + ], + "type": "string" + } + }, + "required": [ + "is" + ], + "type": "object" +} \ No newline at end of file diff --git a/typescript-json-schema.ts b/typescript-json-schema.ts index f5da6809..8e66f2b2 100644 --- a/typescript-json-schema.ts +++ b/typescript-json-schema.ts @@ -1545,11 +1545,12 @@ export function buildGenerator( args: PartialArgs = {}, onlyIncludeFiles?: string[] ): JsonSchemaGenerator | null { + const onlyIncludeFilesResolved = (onlyIncludeFiles || []).map(f => path.resolve(f)); function isUserFile(file: ts.SourceFile): boolean { if (onlyIncludeFiles === undefined) { return !file.hasNoDefaultLib; } - return onlyIncludeFiles.indexOf(file.fileName) >= 0; + return onlyIncludeFilesResolved.indexOf(path.resolve(file.fileName)) >= 0; } // Use defaults unless otherwise specified const settings = getDefaultArgs();