Skip to content

Commit dd45b48

Browse files
committed
feat: accept newer JSON Schema drafts
1 parent 29fa570 commit dd45b48

File tree

7 files changed

+53
-47
lines changed

7 files changed

+53
-47
lines changed

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@
3636
},
3737
"peerDependencies": {},
3838
"dependencies": {
39-
"@stoplight/json": "^3.10.0",
39+
"@stoplight/json": "^3.12.0",
4040
"@stoplight/json-schema-merge-allof": "^0.7.5",
4141
"@stoplight/lifecycle": "^2.3.2",
42+
"@types/json-schema": "^7.0.7",
4243
"magic-error": "^0.0.0"
4344
},
4445
"devDependencies": {
4546
"@rollup/plugin-typescript": "3",
4647
"@stoplight/eslint-config": "^2.0.0",
4748
"@stoplight/scripts": "8.2.1",
48-
"@stoplight/types": "^11.9.0",
49+
"@stoplight/types": "^12.0.0",
4950
"@types/jest": "^26.0.19",
50-
"@types/json-schema": "^7.0.6",
5151
"@types/node": "^14.14.14",
5252
"@types/treeify": "^1.0.0",
5353
"@typescript-eslint/eslint-plugin": "^4.11.0",

src/accessors/getValidations.ts

+5-15
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
11
import type { Dictionary } from '@stoplight/types';
2-
import type { JSONSchema4 } from 'json-schema';
32

43
import type { SchemaNodeKind } from '../nodes/types';
54
import type { SchemaFragment } from '../types';
65
import { pick } from '../utils/pick';
76

8-
export const COMMON_VALIDATION_TYPES: (keyof JSONSchema4)[] = [
9-
'default',
10-
'example',
11-
'nullable',
12-
'discriminator',
13-
'readOnly',
14-
'writeOnly',
15-
'xml',
16-
'externalDocs',
17-
];
18-
19-
const VALIDATION_TYPES: Partial<Dictionary<(keyof JSONSchema4)[], SchemaNodeKind>> = {
7+
export const COMMON_VALIDATION_TYPES: string[] = ['readOnly', 'writeOnly'];
8+
9+
const VALIDATION_TYPES: Partial<Dictionary<(keyof SchemaFragment)[], SchemaNodeKind>> = {
2010
string: ['minLength', 'maxLength', 'pattern'],
2111
number: ['multipleOf', 'minimum', 'exclusiveMinimum', 'maximum', 'exclusiveMaximum'],
2212
get integer() {
@@ -26,8 +16,8 @@ const VALIDATION_TYPES: Partial<Dictionary<(keyof JSONSchema4)[], SchemaNodeKind
2616
array: ['additionalItems', 'minItems', 'maxItems', 'uniqueItems'],
2717
};
2818

29-
function getTypeValidations(types: SchemaNodeKind[]): (keyof JSONSchema4)[] | null {
30-
let extraValidations: (keyof JSONSchema4)[] | null = null;
19+
function getTypeValidations(types: SchemaNodeKind[]): (keyof SchemaFragment)[] | null {
20+
let extraValidations: (keyof SchemaFragment)[] | null = null;
3121

3222
for (const type of types) {
3323
const value = VALIDATION_TYPES[type];

src/nodes/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ export enum SchemaCombinerName {
2525
OneOf = 'oneOf',
2626
}
2727

28-
export type SchemaAnnotations = 'description' | 'default' | 'examples' | 'const' | 'x-example';
28+
export type SchemaAnnotations = 'description' | 'default' | 'examples' | 'const' | 'example' | 'x-example';
2929

3030
export type SchemaMeta = 'id' | '$schema';

src/tree/tree.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,15 @@ export class SchemaTree {
6262
throw new ResolvingError('Cannot dereference external references');
6363
} else if (pointer === null) {
6464
throw new ResolvingError('The pointer is empty');
65-
} else {
65+
} else if (isObjectLiteral(this.schema)) {
6666
const value = resolveInlineRef(this.schema, pointer);
6767
if (!isObjectLiteral(value)) {
6868
throw new ResolvingError('Invalid value');
6969
}
7070

7171
return value;
72+
} else {
73+
throw new ResolvingError('Unexpected input');
7274
}
7375
};
7476
}

src/types.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import type { Dictionary } from '@stoplight/types';
2-
import type { JSONSchema4 } from 'json-schema';
1+
import type { JSONSchema4, JSONSchema6, JSONSchema7 } from 'json-schema';
32

43
export type ViewMode = 'read' | 'write' | 'standalone';
54

6-
export type SchemaFragment = Dictionary<unknown, keyof JSONSchema4>;
5+
export type SchemaFragment = Record<string, unknown> | JSONSchema4 | JSONSchema6 | JSONSchema7;

src/utils/pick.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Dictionary } from '@stoplight/types';
22

3-
export function pick(target: Dictionary<unknown>, keys: (string | number)[]) {
3+
export function pick(target: object, keys: (string | number)[]) {
44
const source: Dictionary<unknown, string | number> = {};
55

66
for (const key of keys) {

yarn.lock

+38-23
Original file line numberDiff line numberDiff line change
@@ -945,10 +945,10 @@
945945
json-schema-compare "^0.2.2"
946946
lodash "^4.17.4"
947947

948-
"@stoplight/json@^3.10.0":
949-
version "3.10.0"
950-
resolved "https://registry.yarnpkg.com/@stoplight/json/-/json-3.10.0.tgz#bd1af55081e1a47e0d01552d2a7e756931f46a4b"
951-
integrity sha512-Xb1kVQ0t5eqRDF24Y0a2A1o/CEaHjLeVehkBmphqEBkUo6X9L4z5oOUYBMzlAoR/ejhjVgWLzrDBxNOuzBFVDA==
948+
"@stoplight/json@^3.12.0":
949+
version "3.12.0"
950+
resolved "https://registry.yarnpkg.com/@stoplight/json/-/json-3.12.0.tgz#26c8d32da78eac6a760ba2c9cca6ae717dc417b4"
951+
integrity sha512-c0bvFOGICk8QWIat72Td2GG6Bdvq/6O2jQcDZ8rEjh56YOdC/YPn1S8ihKu3AntJCtvqC9eTfadWBqkNK9HAjw==
952952
dependencies:
953953
"@stoplight/ordered-object-literal" "^1.0.1"
954954
"@stoplight/types" "^11.9.0"
@@ -1006,6 +1006,14 @@
10061006
"@types/json-schema" "^7.0.4"
10071007
utility-types "^3.10.0"
10081008

1009+
"@stoplight/types@^12.0.0":
1010+
version "12.0.0"
1011+
resolved "https://registry.yarnpkg.com/@stoplight/types/-/types-12.0.0.tgz#3fc68ffa954e7c0a0e6261a982d5c0cb52d5d969"
1012+
integrity sha512-BbL0MIbcCwrU4RidcVyMKnRwACnhr7WAEgPH8d6rwhg/j2DegdLadnXCnq8UJXUWW9Apbntgvic3yVGvLtVmxA==
1013+
dependencies:
1014+
"@types/json-schema" "^7.0.4"
1015+
utility-types "^3.10.0"
1016+
10091017
"@tootallnate/once@1":
10101018
version "1.0.0"
10111019
resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.0.0.tgz#9c13c2574c92d4503b005feca8f2e16cc1611506"
@@ -1088,10 +1096,10 @@
10881096
jest-diff "^26.0.0"
10891097
pretty-format "^26.0.0"
10901098

1091-
"@types/json-schema@^7.0.3", "@types/json-schema@^7.0.4", "@types/json-schema@^7.0.6":
1092-
version "7.0.6"
1093-
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.6.tgz#f4c7ec43e81b319a9815115031709f26987891f0"
1094-
integrity sha512-3c+yGKvVP5Y9TYBEibGNR+kLtijnj7mYrXRg+WpFb2X9xm04g/DXYkfg4hmzJQosc9snFNUPkbYIhu+KAm6jJw==
1099+
"@types/json-schema@^7.0.3", "@types/json-schema@^7.0.4", "@types/json-schema@^7.0.7":
1100+
version "7.0.7"
1101+
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.7.tgz#98a993516c859eb0d5c4c8f098317a9ea68db9ad"
1102+
integrity sha512-cxWFQVseBm6O9Gbw1IWb8r6OS4OhSt3hPZLkFApLjM8TEXROBuQGLAH2i2gZpcXdLBIrpXuTDhH7Vbm1iXmNGA==
10951103

10961104
"@types/json5@^0.0.29":
10971105
version "0.0.29"
@@ -1922,9 +1930,9 @@ chalk@^3.0.0:
19221930
supports-color "^7.1.0"
19231931

19241932
chalk@^4.0.0:
1925-
version "4.1.0"
1926-
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.0.tgz#4e14870a618d9e2edd97dd8345fd9d9dc315646a"
1927-
integrity sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==
1933+
version "4.1.1"
1934+
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.1.tgz#c80b3fab28bf6371e6863325eee67e618b77e6ad"
1935+
integrity sha512-diHzdDKxcU+bAsUboHLPEDQiw0qEe0qd7SYUn3HgcFlWgbDcfLGswOHYeGrHKzG9z6UYf01d9VFMfZxPM1xZSg==
19281936
dependencies:
19291937
ansi-styles "^4.1.0"
19301938
supports-color "^7.1.0"
@@ -4079,9 +4087,9 @@ iferr@^1.0.2:
40794087
integrity sha512-9AfeLfji44r5TKInjhz3W9DyZI1zR1JAf2hVBMGhddAKPqBsupb89jGfbCTHIGZd6fGZl9WlHdn4AObygyMKwg==
40804088

40814089
ignore-walk@^3.0.1:
4082-
version "3.0.1"
4083-
resolved "https://registry.yarnpkg.com/ignore-walk/-/ignore-walk-3.0.1.tgz#a83e62e7d272ac0e3b551aaa82831a19b69f82f8"
4084-
integrity sha512-DTVlMx3IYPe0/JJcYP7Gxg7ttZZu3IInhuEhbchuqneY9wWe5Ojy2mXLBaQFUQmo0AW2r3qG7m1mg86js+gnlQ==
4090+
version "3.0.3"
4091+
resolved "https://registry.yarnpkg.com/ignore-walk/-/ignore-walk-3.0.3.tgz#017e2447184bfeade7c238e4aefdd1e8f95b1e37"
4092+
integrity sha512-m7o6xuOaT1aqheYHKf8W6J5pYH85ZI9w077erOzLje3JsB1gkafkAhHHY19dqjulgIZHFm32Cp5uNZgcQqdJKw==
40854093
dependencies:
40864094
minimatch "^3.0.4"
40874095

@@ -4091,9 +4099,9 @@ ignore@^4.0.6:
40914099
integrity sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==
40924100

40934101
ignore@^5.1.4:
4094-
version "5.1.4"
4095-
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.1.4.tgz#84b7b3dbe64552b6ef0eca99f6743dbec6d97adf"
4096-
integrity sha512-MzbUSahkTW1u7JpKKjY7LCARd1fU5W2rLdxlM4kdkayuCwZImjkpluF9CM1aLewYJguPDqewLam18Y6AU69A8A==
4102+
version "5.1.8"
4103+
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.1.8.tgz#f150a8b50a34289b33e22f5889abd4d8016f0e57"
4104+
integrity sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw==
40974105

40984106
import-fresh@^2.0.0:
40994107
version "2.0.0"
@@ -6186,9 +6194,11 @@ npm-audit-report@^1.3.2:
61866194
console-control-strings "^1.1.0"
61876195

61886196
npm-bundled@^1.0.1:
6189-
version "1.0.6"
6190-
resolved "https://registry.yarnpkg.com/npm-bundled/-/npm-bundled-1.0.6.tgz#e7ba9aadcef962bb61248f91721cd932b3fe6bdd"
6191-
integrity sha512-8/JCaftHwbd//k6y2rEWp6k1wxVfpFzB6t1p825+cUb7Ym2XQfhwIC5KwhrvzZRJu+LtDE585zVaS32+CGtf0g==
6197+
version "1.1.2"
6198+
resolved "https://registry.yarnpkg.com/npm-bundled/-/npm-bundled-1.1.2.tgz#944c78789bd739035b70baa2ca5cc32b8d860bc1"
6199+
integrity sha512-x5DHup0SuyQcmL3s7Rx/YQ8sbw/Hzg0rj48eN0dV7hf5cmQq5PXIeioroH3raV1QC1yh3uTYuMThvEQF3iKgGQ==
6200+
dependencies:
6201+
npm-normalize-package-bin "^1.0.1"
61926202

61936203
npm-cache-filename@~1.0.2:
61946204
version "1.0.2"
@@ -6221,6 +6231,11 @@ npm-logical-tree@^1.2.1:
62216231
resolved "https://registry.yarnpkg.com/npm-logical-tree/-/npm-logical-tree-1.2.1.tgz#44610141ca24664cad35d1e607176193fd8f5b88"
62226232
integrity sha512-AJI/qxDB2PWI4LG1CYN579AY1vCiNyWfkiquCsJWqntRu/WwimVrC8yXeILBFHDwxfOejxewlmnvW9XXjMlYIg==
62236233

6234+
npm-normalize-package-bin@^1.0.1:
6235+
version "1.0.1"
6236+
resolved "https://registry.yarnpkg.com/npm-normalize-package-bin/-/npm-normalize-package-bin-1.0.1.tgz#6e79a41f23fd235c0623218228da7d9c23b8f6e2"
6237+
integrity sha512-EPfafl6JL5/rU+ot6P3gRSCpPDW5VmIzX959Ob1+ySFUuuYHWHekXpwdUZcKP5C+DS4GEtdJluwBjnsNDl+fSA==
6238+
62246239
"npm-package-arg@^4.0.0 || ^5.0.0 || ^6.0.0", npm-package-arg@^6.0.0, npm-package-arg@^6.1.0, npm-package-arg@^6.1.1:
62256240
version "6.1.1"
62266241
resolved "https://registry.yarnpkg.com/npm-package-arg/-/npm-package-arg-6.1.1.tgz#02168cb0a49a2b75bf988a28698de7b529df5cb7"
@@ -9120,9 +9135,9 @@ yaml@^1.7.2:
91209135
"@babel/runtime" "^7.6.3"
91219136

91229137
9123-
version "20.2.3"
9124-
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.3.tgz#92419ba867b858c868acf8bae9bf74af0dd0ce26"
9125-
integrity sha512-emOFRT9WVHw03QSvN5qor9QQT9+sw5vwxfYweivSMHTcAXPefwVae2FjO7JJjj8hCE4CzPOPeFM83VwT29HCww==
9138+
version "20.2.7"
9139+
resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-20.2.7.tgz#61df85c113edfb5a7a4e36eb8aa60ef423cbc90a"
9140+
integrity sha512-FiNkvbeHzB/syOjIUxFDCnhSfzAL8R5vs40MgLFBorXACCOAEaWu0gRZl14vG8MR9AOJIZbmkjhusqBYZ3HTHw==
91269141

91279142
yargs-parser@^10.0.0:
91289143
version "10.1.0"

0 commit comments

Comments
 (0)