Skip to content

Commit 60694f4

Browse files
committed
Refactor the package to support multiple JSON Schema drafts
1 parent 0c8e6aa commit 60694f4

File tree

4 files changed

+105
-256
lines changed

4 files changed

+105
-256
lines changed

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
"name": "@fosfad/json-schema-typescript-definitions",
33
"description": "Types and interfaces for writing valid JSON schema in TypeScript.",
44
"repository": "github:fosfad/json-schema-typescript-definitions",
5-
"main": "dist/index.js",
6-
"types": "dist/index.d.ts",
75
"files": [
86
"dist"
97
],
@@ -16,6 +14,11 @@
1614
"url": "https://github.com/fosfad/json-schema-typescript-definitions/issues"
1715
},
1816
"homepage": "https://github.com/fosfad/json-schema-typescript-definitions",
17+
"exports": {
18+
"./2020-12": {
19+
"import": "./dist/2020-12.d.ts"
20+
}
21+
},
1922
"devDependencies": {
2023
"@types/node": "15.12.4",
2124
"@typescript-eslint/eslint-plugin": "4.28.0",

src/2020-12.ts

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
type CoreKeywords = {
2+
$anchor?: string;
3+
$comment?: string;
4+
$defs?: { [key: string]: JsonSchema };
5+
$dynamicAnchor?: string;
6+
$dynamicRef?: string;
7+
$id?: string;
8+
$ref?: string;
9+
$schema?: string;
10+
$vocabulary?: { [uri: string]: boolean };
11+
};
12+
13+
type LogicSubschemasKeywords = {
14+
allOf?: Array<JsonSchema>;
15+
anyOf?: Array<JsonSchema>;
16+
not?: JsonSchema;
17+
oneOf?: Array<JsonSchema>;
18+
};
19+
20+
type ConditionalSubschemasKeywords = {
21+
dependentSchemas?: { [key: string]: JsonSchema };
22+
else?: JsonSchema;
23+
if?: JsonSchema;
24+
then?: JsonSchema;
25+
};
26+
27+
type JsonSchemaType = 'null' | 'boolean' | 'string' | 'integer' | 'number' | 'array' | 'object';
28+
29+
type AnyValidationKeywords = {
30+
const?: any;
31+
enum?: Array<any>;
32+
type?: JsonSchemaType | Array<JsonSchemaType>;
33+
};
34+
35+
type MetaDataAnnotationKeywords = {
36+
default?: any;
37+
deprecated?: boolean;
38+
description?: string;
39+
examples?: Array<any>;
40+
readOnly?: boolean;
41+
title?: string;
42+
writeOnly?: boolean;
43+
};
44+
45+
type StringValidationKeywords = {
46+
maxLength?: number;
47+
minLength?: number;
48+
pattern?: string;
49+
};
50+
51+
type NumericValidationKeywords = {
52+
exclusiveMaximum?: number;
53+
exclusiveMinimum?: number;
54+
maximum?: number;
55+
minimum?: number;
56+
multipleOf?: number;
57+
};
58+
59+
type ArrayValidationKeywords = {
60+
contains?: JsonSchema;
61+
items?: JsonSchema;
62+
maxContains?: number;
63+
maxItems?: number;
64+
minContains?: number;
65+
minItems?: number;
66+
prefixItems?: Array<JsonSchema>;
67+
uniqueItems?: boolean;
68+
};
69+
70+
type ObjectValidationKeywords = {
71+
dependentRequired?: Record<string, Array<string>>;
72+
maxProperties?: number;
73+
minProperties?: number;
74+
required: string[];
75+
};
76+
77+
type ObjectSubschemaKeywords = {
78+
additionalProperties?: JsonSchema;
79+
patternProperties?: { [propertyNameRegex: string]: JsonSchema };
80+
properties?: { [propertyName: string]: JsonSchema };
81+
propertyNames?: JsonSchema;
82+
};
83+
84+
type UnevaluatedLocationsKeywords = {
85+
unevaluatedItems?: JsonSchema;
86+
unevaluatedProperties?: JsonSchema;
87+
};
88+
89+
export type JsonSchema = CoreKeywords &
90+
LogicSubschemasKeywords &
91+
ConditionalSubschemasKeywords &
92+
JsonSchemaType &
93+
AnyValidationKeywords &
94+
MetaDataAnnotationKeywords &
95+
StringValidationKeywords &
96+
NumericValidationKeywords &
97+
ArrayValidationKeywords &
98+
ObjectValidationKeywords &
99+
UnevaluatedLocationsKeywords &
100+
ObjectSubschemaKeywords;

src/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/jsonSchema.ts

Lines changed: 0 additions & 253 deletions
This file was deleted.

0 commit comments

Comments
 (0)