Skip to content

Commit 921dc10

Browse files
JemarJonesdomoritz
authored andcommitted
Use @types/json-schema definition for more standard json schema Defin… (YousefED#311)
Fixes YousefED#310
1 parent 6a63e6b commit 921dc10

File tree

2 files changed

+39
-28
lines changed

2 files changed

+39
-28
lines changed

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"schema"
4646
],
4747
"dependencies": {
48+
"@types/json-schema": "^7.0.3",
4849
"glob": "~7.1.4",
4950
"json-stable-stringify": "^1.0.1",
5051
"typescript": "^3.5.1",

Diff for: typescript-json-schema.ts

+38-28
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as stringify from "json-stable-stringify";
33
import * as path from "path";
44
import { createHash } from "crypto";
55
import * as ts from "typescript";
6+
import { JSONSchema7 } from "json-schema";
67
export { Program, CompilerOptions, Symbol } from "typescript";
78

89

@@ -65,34 +66,43 @@ export type PartialArgs = Partial<Args>;
6566

6667
export type PrimitiveType = number | boolean | string | null;
6768

68-
export type Definition = {
69-
$ref?: string,
70-
$schema?: string,
71-
$id?: string,
72-
description?: string,
73-
examples?: any[],
74-
allOf?: Definition[],
75-
oneOf?: Definition[],
76-
anyOf?: Definition[],
77-
title?: string,
78-
type?: string | string[],
79-
definitions?: {[key: string]: any},
80-
format?: string,
81-
items?: Definition | Definition[],
82-
minItems?: number,
83-
additionalItems?: {
84-
anyOf: Definition[]
85-
} | Definition,
86-
enum?: PrimitiveType[] | Definition[],
87-
default?: PrimitiveType | Object,
88-
additionalProperties?: Definition | boolean,
89-
required?: string[],
90-
propertyOrder?: string[],
91-
properties?: {[key: string]: any},
92-
defaultProperties?: string[],
93-
patternProperties?: {[pattern: string]: Definition},
94-
typeof?: "function"
95-
};
69+
type RedifinedFields = "type" | "items" | "additionalItems" | "contains" | "properties" | "patternProperties" | "additionalProperties" | "dependencies" | "propertyNames" | "if" | "then" | "else" | "allOf" | "anyOf" | "oneOf" | "not" | "definitions";
70+
export type DefinitionOrBoolean = Definition | boolean;
71+
export interface Definition extends Omit<JSONSchema7, RedifinedFields> {
72+
// The type field here is incompatible with the standard definition
73+
type?: string | string[];
74+
75+
// Non-standard fields
76+
propertyOrder?: string[];
77+
defaultProperties?: string[];
78+
typeof?: "function";
79+
80+
// Fields that must be redifined because they make use of this definition itself
81+
items?: DefinitionOrBoolean | DefinitionOrBoolean[];
82+
additionalItems?: DefinitionOrBoolean;
83+
contains?: JSONSchema7;
84+
properties?: {
85+
[key: string]: DefinitionOrBoolean;
86+
};
87+
patternProperties?: {
88+
[key: string]: DefinitionOrBoolean;
89+
};
90+
additionalProperties?: DefinitionOrBoolean;
91+
dependencies?: {
92+
[key: string]: DefinitionOrBoolean | string[];
93+
};
94+
propertyNames?: DefinitionOrBoolean;
95+
if?: DefinitionOrBoolean;
96+
then?: DefinitionOrBoolean;
97+
else?: DefinitionOrBoolean;
98+
allOf?: DefinitionOrBoolean[];
99+
anyOf?: DefinitionOrBoolean[];
100+
oneOf?: DefinitionOrBoolean[];
101+
not?: DefinitionOrBoolean;
102+
definitions?: {
103+
[key: string]: DefinitionOrBoolean;
104+
};
105+
}
96106

97107
export type SymbolRef = {
98108
name: string;

0 commit comments

Comments
 (0)