Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: YousefED/typescript-json-schema
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.55.0
Choose a base ref
...
head repository: YousefED/typescript-json-schema
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.56.0
Choose a head ref
  • 6 commits
  • 12 files changed
  • 6 contributors

Commits on Jan 22, 2023

  1. Copy the full SHA
    b4e055b View commit details

Commits on Jan 29, 2023

  1. add skiplibcheck (#521)

    seren5240 authored Jan 29, 2023
    Copy the full SHA
    3abdaa4 View commit details

Commits on Mar 4, 2023

  1. Bump minimist from 1.2.5 to 1.2.8 (#525)

    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Mar 4, 2023
    Copy the full SHA
    ebe3ccd View commit details

Commits on Mar 6, 2023

  1. Copy the full SHA
    d791ca8 View commit details

Commits on Mar 22, 2023

  1. Copy the full SHA
    34f427a View commit details

Commits on Apr 2, 2023

  1. v0.56.0

    domoritz committed Apr 2, 2023
    Copy the full SHA
    4642f6d View commit details
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@ Options:
--required Create required array for non-optional properties. [boolean] [default: false]
--strictNullChecks Make values non-nullable by default. [boolean] [default: false]
--esModuleInterop Use esModuleInterop when loading typescript modules. [boolean] [default: false]
--skipLibCheck Use skipLibCheck when loading typescript modules. [boolean] [default: false]
--useTypeOfKeyword Use `typeOf` keyword (https://goo.gl/DC6sni) for functions. [boolean] [default: false]
--out, -o The output file, defaults to using stdout
--validationKeywords Provide additional validation keywords to include [array] [default: []]
279 changes: 157 additions & 122 deletions api.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript-json-schema",
"version": "0.55.0",
"version": "0.56.0",
"description": "typescript-json-schema generates JSON Schema files from your Typescript sources",
"main": "dist/typescript-json-schema.js",
"typings": "dist/typescript-json-schema.d.ts",
@@ -47,7 +47,7 @@
"path-equal": "^1.1.2",
"safe-stable-stringify": "^2.2.0",
"ts-node": "^10.9.1",
"typescript": "~4.8.2",
"typescript": "~4.9.5",
"yargs": "^17.1.1"
},
"devDependencies": {
14 changes: 14 additions & 0 deletions test/programs/satisfies-keyword/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
interface Basic {
a: string;
b: number;
c: boolean;
}

const myObject = {
a: "a" as const,
b: 1 as const,
c: true as const,
// tslint:disable-next-line:variable-name
} satisfies Basic;

export type Specific = typeof myObject;
29 changes: 29 additions & 0 deletions test/programs/satisfies-keyword/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"a": {
"enum": [
"a"
],
"type": "string"
},
"b": {
"enum": [
1
],
"type": "number"
},
"c": {
"enum": [
true
],
"type": "boolean"
}
},
"required": [
"a",
"b",
"c"
],
"type": "object"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type MyRecursiveNode = {
next?: MyNode;
}

type MyNode = {
val: string;
} & MyRecursiveNode;

type MyLinkedList = MyNode;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$ref": "#/definitions/MyNode",
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"MyNode": {
"additionalProperties": false,
"properties": {
"next": {
"$ref": "#/definitions/MyNode"
},
"val": {
"type": "string"
}
},
"required": [
"val"
],
"type": "object"
}
}
}
1 change: 1 addition & 0 deletions test/programs/type-intersection-recursive/schema.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$ref": "#/definitions/Foo",
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"ChildFoo": {
9 changes: 8 additions & 1 deletion test/schema.test.ts
Original file line number Diff line number Diff line change
@@ -259,7 +259,10 @@ describe("schema", () => {
});
assertSchema("type-union-tagged", "Shape");
assertSchema("type-aliases-union-namespace", "MyModel");
assertSchema("type-intersection-recursive", "*");
assertSchema("type-intersection-recursive", "Foo");
assertSchema("type-intersection-recursive-no-additional", "MyLinkedList", {
noExtraProps: true,
});
});

describe("annotations", () => {
@@ -487,3 +490,7 @@ describe("when reusing a generator", () => {
});
});
});

describe("satisfies keyword - ignore from a \"satisfies\" and build by rally type", () => {
assertSchema("satisfies-keyword", "Specific");
});
3 changes: 3 additions & 0 deletions typescript-json-schema-cli.ts
Original file line number Diff line number Diff line change
@@ -30,6 +30,8 @@ export function run() {
.describe("strictNullChecks", "Make values non-nullable by default.")
.boolean("esModuleInterop").default("esModuleInterop", defaultArgs.esModuleInterop)
.describe("esModuleInterop", "Use esModuleInterop when loading typescript modules.")
.boolean("skipLibCheck").default("skipLibCheck", defaultArgs.skipLibCheck)
.describe("skipLibCheck", "Use skipLibCheck when loading typescript modules.")
.boolean("ignoreErrors").default("ignoreErrors", defaultArgs.ignoreErrors)
.describe("ignoreErrors", "Generate even if the program has errors.")
.alias("out", "o")
@@ -65,6 +67,7 @@ export function run() {
required: args.required,
strictNullChecks: args.strictNullChecks,
esModuleInterop: args.esModuleInterop,
skipLibCheck: args.skipLibCheck,
ignoreErrors: args.ignoreErrors,
out: args.out,
validationKeywords: args.validationKeywords,
15 changes: 10 additions & 5 deletions typescript-json-schema.ts
Original file line number Diff line number Diff line change
@@ -48,6 +48,7 @@ export function getDefaultArgs(): Args {
required: false,
strictNullChecks: false,
esModuleInterop: false,
skipLibCheck: false,
ignoreErrors: false,
out: "",
validationKeywords: [],
@@ -77,6 +78,7 @@ export type Args = {
required: boolean;
strictNullChecks: boolean;
esModuleInterop: boolean;
skipLibCheck: boolean;
ignoreErrors: boolean;
out: string;
validationKeywords: string[];
@@ -520,7 +522,7 @@ export class JsonSchemaGenerator {

private isFromDefaultLib(symbol: ts.Symbol) {
const declarations = symbol.getDeclarations();
if (declarations && declarations.length > 0) {
if (declarations && declarations.length > 0 && declarations[0].parent) {
return declarations[0].parent.getSourceFile().hasNoDefaultLib;
}
return false;
@@ -1182,7 +1184,8 @@ export class JsonSchemaGenerator {
unionModifier: string = "anyOf",
prop?: ts.Symbol,
reffedType?: ts.Symbol,
pairedSymbol?: ts.Symbol
pairedSymbol?: ts.Symbol,
forceNotRef: boolean = false
): Definition {
const definition: Definition = {}; // real definition

@@ -1287,7 +1290,7 @@ export class JsonSchemaGenerator {

// Handle recursive types
if (!isRawType || !!typ.aliasSymbol) {
if (this.recursiveTypeRef.has(fullTypeName)) {
if (this.recursiveTypeRef.has(fullTypeName) && !forceNotRef) {
asRef = true;
} else {
this.recursiveTypeRef.set(fullTypeName, definition);
@@ -1345,12 +1348,13 @@ export class JsonSchemaGenerator {

const types = (<ts.IntersectionType>typ).types;
for (const member of types) {
const other = this.getTypeDefinition(member, false);
const other = this.getTypeDefinition(member, false, undefined, undefined, undefined, undefined, true);
definition.type = other.type; // should always be object
definition.properties = {
...definition.properties,
...other.properties,
};

if (Object.keys(other.default || {}).length > 0) {
definition.default = extend(definition.default || {}, other.default);
}
@@ -1386,7 +1390,7 @@ export class JsonSchemaGenerator {
}
}

if (this.recursiveTypeRef.get(fullTypeName) === definition) {
if (this.recursiveTypeRef.get(fullTypeName) === definition && !forceNotRef) {
this.recursiveTypeRef.delete(fullTypeName);
// If the type was recursive (there is reffedDefinitions) - lets replace it to reference
if (this.reffedDefinitions[fullTypeName]) {
@@ -1711,6 +1715,7 @@ export async function exec(filePattern: string, fullTypeName: string, args = get
program = getProgramFromFiles(onlyIncludeFiles, {
strictNullChecks: args.strictNullChecks,
esModuleInterop: args.esModuleInterop,
skipLibCheck: args.skipLibCheck,
});
onlyIncludeFiles = onlyIncludeFiles.map(normalizeFileName);
}
1,840 changes: 915 additions & 925 deletions yarn.lock

Large diffs are not rendered by default.