Skip to content

Commit 30b8a5a

Browse files
authored
feat: accept JSON Schema Draft 6 & Draft 7 (#139)
* feat: accept JSON Schema Draft 6 & Draft 7 * revert: reduce diff
1 parent 50ca5cd commit 30b8a5a

File tree

6 files changed

+40
-25
lines changed

6 files changed

+40
-25
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@
4343
"dependencies": {
4444
"@fortawesome/free-solid-svg-icons": "^5.15.2",
4545
"@stoplight/json": "^3.10.0",
46-
"@stoplight/json-schema-tree": "^1.1.3",
46+
"@stoplight/json-schema-tree": "^2.0.0",
4747
"@stoplight/mosaic": "1.0.0-beta.46",
4848
"@stoplight/react-error-boundary": "^1.0.0",
49+
"@types/json-schema": "^7.0.7",
4950
"classnames": "^2.2.6",
5051
"lodash": "^4.17.19"
5152
},
@@ -61,7 +62,6 @@
6162
"@types/classnames": "^2.2.11",
6263
"@types/enzyme": "^3.10.8",
6364
"@types/jest": "^26.0.18",
64-
"@types/json-schema": "^7.0.6",
6565
"@types/lodash": "^4.14.149",
6666
"@types/node": "^12.7.2",
6767
"@types/react": "16.9.2",

src/__tests__/__snapshots__/index.spec.tsx.snap

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,15 +1067,15 @@ exports[`HTML Output should match arrays/of-complex-objects.json 1`] = `
10671067
</div>
10681068
</div>
10691069
</div>
1070+
<div>
1071+
<span>Allowed value:</span>
1072+
<span style=\\"background-color: rgb(237, 242, 247)\\">\\"Constant name\\"</span>
1073+
</div>
10701074
<div>
10711075
<span>Example values:</span>
10721076
<span style=\\"background-color: rgb(237, 242, 247)\\">\\"Example name\\"</span>
10731077
<span style=\\"background-color: rgb(237, 242, 247)\\">\\"Different name\\"</span>
10741078
</div>
1075-
<div>
1076-
<span>Allowed value:</span>
1077-
<span style=\\"background-color: rgb(237, 242, 247)\\">\\"Constant name\\"</span>
1078-
</div>
10791079
</div>
10801080
<div></div>
10811081
</div>
@@ -2816,15 +2816,15 @@ exports[`HTML Output should match default-schema.json 1`] = `
28162816
</div>
28172817
</div>
28182818
</div>
2819+
<div>
2820+
<span>Allowed value:</span>
2821+
<span style=\\"background-color: rgb(237, 242, 247)\\">\\"Constant name\\"</span>
2822+
</div>
28192823
<div>
28202824
<span>Example values:</span>
28212825
<span style=\\"background-color: rgb(237, 242, 247)\\">\\"Example name\\"</span>
28222826
<span style=\\"background-color: rgb(237, 242, 247)\\">\\"Different name\\"</span>
28232827
</div>
2824-
<div>
2825-
<span>Allowed value:</span>
2826-
<span style=\\"background-color: rgb(237, 242, 247)\\">\\"Constant name\\"</span>
2827-
</div>
28282828
</div>
28292829
<div></div>
28302830
</div>
@@ -3671,7 +3671,7 @@ exports[`HTML Output should match tickets.schema.json 1`] = `
36713671
</div>
36723672
</div>
36733673
</div>
3674-
<div><span style=\\"background-color: rgb(237, 242, 247)\\">example</span></div>
3674+
<div><span style=\\"background-color: rgb(237, 242, 247)\\">examples</span></div>
36753675
</div>
36763676
<div></div>
36773677
</div>

src/components/JsonSchemaViewer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { isRegularNode, SchemaTree as JsonSchemaTree, SchemaTreeRefDereferenceFn
22
import { Box, Provider as MosaicProvider } from '@stoplight/mosaic';
33
import { ErrorBoundaryForwardedProps, FallbackProps, withErrorBoundary } from '@stoplight/react-error-boundary';
44
import cn from 'classnames';
5-
import type { JSONSchema4 } from 'json-schema';
65
import * as React from 'react';
76

87
import { JSVOptions, JSVOptionsContextProvider } from '../contexts';
8+
import type { JSONSchema } from '../types';
99
import { TopLevelSchemaRow } from './SchemaRow';
1010
import { ChildStack } from './shared/ChildStack';
1111

1212
export type JsonSchemaProps = Partial<JSVOptions> & {
13-
schema: JSONSchema4;
13+
schema: JSONSchema;
1414
emptyText?: string;
1515
className?: string;
1616
resolveRef?: SchemaTreeRefDereferenceFn;

src/components/shared/Validations.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const numberValidationNames = [
2525
'exclusiveMaximum',
2626
];
2727

28-
const exampleValidationNames = ['examples', 'example', 'x-example'];
28+
const exampleValidationNames = ['examples'];
2929

3030
const excludedValidations = ['exclusiveMinimum', 'exclusiveMaximum', 'readOnly', 'writeOnly'];
3131

@@ -58,11 +58,8 @@ const createValidationsFormatter = (name: string, options?: { exact?: boolean; n
5858
};
5959

6060
const validationFormatters: Record<string, (value: unknown) => ValidationFormat | null> = {
61-
['const']: createValidationsFormatter('Allowed'),
6261
enum: createValidationsFormatter('Allowed'),
6362
examples: createValidationsFormatter('Example'),
64-
example: createValidationsFormatter('Example'),
65-
['x-example']: createValidationsFormatter('Example'),
6663
multipleOf: createValidationsFormatter('Multiple of', { exact: true }),
6764
pattern: createValidationsFormatter('Match pattern', { exact: true, nowrap: true }),
6865
default: createValidationsFormatter('Default'),
@@ -208,8 +205,6 @@ export function getValidationsFromSchema(schemaNode: RegularNode) {
208205
? {
209206
...(schemaNode.annotations.default ? { default: schemaNode.annotations.default } : null),
210207
...(schemaNode.annotations.examples ? { examples: schemaNode.annotations.examples } : null),
211-
...(schemaNode.annotations.const ? { const: schemaNode.annotations.const } : null),
212-
...(schemaNode.annotations['x-example'] ? { ['x-example']: schemaNode.annotations['x-example'] } : null),
213208
}
214209
: null),
215210
...getFilteredValidations(schemaNode),

src/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { ReferenceNode, SchemaNode } from '@stoplight/json-schema-tree';
2+
import { JSONSchema4, JSONSchema6, JSONSchema7 } from 'json-schema';
23
import * as React from 'react';
34

45
export type GoToRefHandler = (node: ReferenceNode) => void;
@@ -11,3 +12,5 @@ export interface SchemaRowProps {
1112
export type RowAddonRenderer = (props: SchemaRowProps) => React.ReactNode;
1213

1314
export type ViewMode = 'read' | 'write' | 'standalone';
15+
16+
export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;

yarn.lock

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2365,14 +2365,15 @@
23652365
json-schema-compare "^0.2.2"
23662366
lodash "^4.17.4"
23672367

2368-
"@stoplight/json-schema-tree@^1.1.3":
2369-
version "1.1.3"
2370-
resolved "https://registry.yarnpkg.com/@stoplight/json-schema-tree/-/json-schema-tree-1.1.3.tgz#c2aafa1b10c506e7ebec7a4904ff3bd325f7102f"
2371-
integrity sha512-n/mmhLEu4qrZO/UxQBYyPNid2v4Zq6fuzUK9pBMpNxQtxXmmge62lFWDnc3Q8nzXwRio0OPuMmZS9RO0Q0hmOg==
2368+
"@stoplight/json-schema-tree@^2.0.0":
2369+
version "2.0.0"
2370+
resolved "https://registry.yarnpkg.com/@stoplight/json-schema-tree/-/json-schema-tree-2.0.0.tgz#00d54cb6aa2a791c34be91fc30cc92e6d448258c"
2371+
integrity sha512-vnzcb0TC07xh89lAVGjBTJ2CWvCqmDJDIs3u+gvgvjDPY86CQ0Wl4D2Cmb0iuqd986aiDPc8vDQf1N0dSq5+9A==
23722372
dependencies:
2373-
"@stoplight/json" "^3.10.0"
2373+
"@stoplight/json" "^3.12.0"
23742374
"@stoplight/json-schema-merge-allof" "^0.7.5"
23752375
"@stoplight/lifecycle" "^2.3.2"
2376+
"@types/json-schema" "^7.0.7"
23762377
magic-error "^0.0.0"
23772378

23782379
"@stoplight/json@^3.10.0", "@stoplight/json@^3.6":
@@ -2386,6 +2387,17 @@
23862387
lodash "^4.17.15"
23872388
safe-stable-stringify "^1.1"
23882389

2390+
"@stoplight/json@^3.12.0":
2391+
version "3.12.0"
2392+
resolved "https://registry.yarnpkg.com/@stoplight/json/-/json-3.12.0.tgz#26c8d32da78eac6a760ba2c9cca6ae717dc417b4"
2393+
integrity sha512-c0bvFOGICk8QWIat72Td2GG6Bdvq/6O2jQcDZ8rEjh56YOdC/YPn1S8ihKu3AntJCtvqC9eTfadWBqkNK9HAjw==
2394+
dependencies:
2395+
"@stoplight/ordered-object-literal" "^1.0.1"
2396+
"@stoplight/types" "^11.9.0"
2397+
jsonc-parser "~2.2.1"
2398+
lodash "^4.17.15"
2399+
safe-stable-stringify "^1.1"
2400+
23892401
"@stoplight/lifecycle@^2.3.2":
23902402
version "2.3.2"
23912403
resolved "https://registry.yarnpkg.com/@stoplight/lifecycle/-/lifecycle-2.3.2.tgz#d61dff9ba20648241432e2daaef547214dc8976e"
@@ -3200,11 +3212,16 @@
32003212
jest-diff "^26.0.0"
32013213
pretty-format "^26.0.0"
32023214

3203-
"@types/json-schema@^7.0.3", "@types/json-schema@^7.0.4", "@types/json-schema@^7.0.5", "@types/json-schema@^7.0.6":
3215+
"@types/json-schema@^7.0.3", "@types/json-schema@^7.0.4", "@types/json-schema@^7.0.5":
32043216
version "7.0.6"
32053217
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.6.tgz#f4c7ec43e81b319a9815115031709f26987891f0"
32063218
integrity sha512-3c+yGKvVP5Y9TYBEibGNR+kLtijnj7mYrXRg+WpFb2X9xm04g/DXYkfg4hmzJQosc9snFNUPkbYIhu+KAm6jJw==
32073219

3220+
"@types/json-schema@^7.0.7":
3221+
version "7.0.7"
3222+
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.7.tgz#98a993516c859eb0d5c4c8f098317a9ea68db9ad"
3223+
integrity sha512-cxWFQVseBm6O9Gbw1IWb8r6OS4OhSt3hPZLkFApLjM8TEXROBuQGLAH2i2gZpcXdLBIrpXuTDhH7Vbm1iXmNGA==
3224+
32083225
"@types/json5@^0.0.29":
32093226
version "0.0.29"
32103227
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"

0 commit comments

Comments
 (0)