Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@
"dependencies": {
"@fortawesome/free-solid-svg-icons": "^5.15.2",
"@stoplight/json": "^3.10.0",
"@stoplight/json-schema-tree": "^1.1.3",
"@stoplight/json-schema-tree": "^2.0.0",
"@stoplight/mosaic": "1.0.0-beta.46",
"@stoplight/react-error-boundary": "^1.0.0",
"@types/json-schema": "^7.0.7",
"classnames": "^2.2.6",
"lodash": "^4.17.19"
},
Expand All @@ -61,7 +62,6 @@
"@types/classnames": "^2.2.11",
"@types/enzyme": "^3.10.8",
"@types/jest": "^26.0.18",
"@types/json-schema": "^7.0.6",
"@types/lodash": "^4.14.149",
"@types/node": "^12.7.2",
"@types/react": "16.9.2",
Expand Down
18 changes: 9 additions & 9 deletions src/__tests__/__snapshots__/index.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1067,15 +1067,15 @@ exports[`HTML Output should match arrays/of-complex-objects.json 1`] = `
</div>
</div>
</div>
<div>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope the order doesn't matter for you.

<span>Allowed value:</span>
<span style=\\"background-color: rgb(237, 242, 247)\\">\\"Constant name\\"</span>
</div>
<div>
<span>Example values:</span>
<span style=\\"background-color: rgb(237, 242, 247)\\">\\"Example name\\"</span>
<span style=\\"background-color: rgb(237, 242, 247)\\">\\"Different name\\"</span>
</div>
<div>
<span>Allowed value:</span>
<span style=\\"background-color: rgb(237, 242, 247)\\">\\"Constant name\\"</span>
</div>
</div>
<div></div>
</div>
Expand Down Expand Up @@ -2816,15 +2816,15 @@ exports[`HTML Output should match default-schema.json 1`] = `
</div>
</div>
</div>
<div>
<span>Allowed value:</span>
<span style=\\"background-color: rgb(237, 242, 247)\\">\\"Constant name\\"</span>
</div>
<div>
<span>Example values:</span>
<span style=\\"background-color: rgb(237, 242, 247)\\">\\"Example name\\"</span>
<span style=\\"background-color: rgb(237, 242, 247)\\">\\"Different name\\"</span>
</div>
<div>
<span>Allowed value:</span>
<span style=\\"background-color: rgb(237, 242, 247)\\">\\"Constant name\\"</span>
</div>
</div>
<div></div>
</div>
Expand Down Expand Up @@ -3671,7 +3671,7 @@ exports[`HTML Output should match tickets.schema.json 1`] = `
</div>
</div>
</div>
<div><span style=\\"background-color: rgb(237, 242, 247)\\">example</span></div>
<div><span style=\\"background-color: rgb(237, 242, 247)\\">examples</span></div>
</div>
<div></div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/JsonSchemaViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { isRegularNode, SchemaTree as JsonSchemaTree, SchemaTreeRefDereferenceFn
import { Box, Provider as MosaicProvider } from '@stoplight/mosaic';
import { ErrorBoundaryForwardedProps, FallbackProps, withErrorBoundary } from '@stoplight/react-error-boundary';
import cn from 'classnames';
import type { JSONSchema4 } from 'json-schema';
import * as React from 'react';

import { JSVOptions, JSVOptionsContextProvider } from '../contexts';
import type { JSONSchema } from '../types';
import { TopLevelSchemaRow } from './SchemaRow';
import { ChildStack } from './shared/ChildStack';

export type JsonSchemaProps = Partial<JSVOptions> & {
schema: JSONSchema4;
schema: JSONSchema;
emptyText?: string;
className?: string;
resolveRef?: SchemaTreeRefDereferenceFn;
Expand Down
7 changes: 1 addition & 6 deletions src/components/shared/Validations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const numberValidationNames = [
'exclusiveMaximum',
];

const exampleValidationNames = ['examples', 'example', 'x-example'];
const exampleValidationNames = ['examples'];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http-spec will try to produce examples at all times now, thus there's no need to handle example and x-example separately.


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

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

const validationFormatters: Record<string, (value: unknown) => ValidationFormat | null> = {
['const']: createValidationsFormatter('Allowed'),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

json-schema-tree turns const into an enum with a single member

enum: createValidationsFormatter('Allowed'),
examples: createValidationsFormatter('Example'),
example: createValidationsFormatter('Example'),
['x-example']: createValidationsFormatter('Example'),
multipleOf: createValidationsFormatter('Multiple of', { exact: true }),
pattern: createValidationsFormatter('Match pattern', { exact: true, nowrap: true }),
default: createValidationsFormatter('Default'),
Expand Down Expand Up @@ -208,8 +205,6 @@ export function getValidationsFromSchema(schemaNode: RegularNode) {
? {
...(schemaNode.annotations.default ? { default: schemaNode.annotations.default } : null),
...(schemaNode.annotations.examples ? { examples: schemaNode.annotations.examples } : null),
...(schemaNode.annotations.const ? { const: schemaNode.annotations.const } : null),
...(schemaNode.annotations['x-example'] ? { ['x-example']: schemaNode.annotations['x-example'] } : null),
}
: null),
...getFilteredValidations(schemaNode),
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ReferenceNode, SchemaNode } from '@stoplight/json-schema-tree';
import { JSONSchema4, JSONSchema6, JSONSchema7 } from 'json-schema';
import * as React from 'react';

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

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

export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
29 changes: 23 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2365,14 +2365,15 @@
json-schema-compare "^0.2.2"
lodash "^4.17.4"

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

"@stoplight/json@^3.10.0", "@stoplight/json@^3.6":
Expand All @@ -2386,6 +2387,17 @@
lodash "^4.17.15"
safe-stable-stringify "^1.1"

"@stoplight/json@^3.12.0":
version "3.12.0"
resolved "https://registry.yarnpkg.com/@stoplight/json/-/json-3.12.0.tgz#26c8d32da78eac6a760ba2c9cca6ae717dc417b4"
integrity sha512-c0bvFOGICk8QWIat72Td2GG6Bdvq/6O2jQcDZ8rEjh56YOdC/YPn1S8ihKu3AntJCtvqC9eTfadWBqkNK9HAjw==
dependencies:
"@stoplight/ordered-object-literal" "^1.0.1"
"@stoplight/types" "^11.9.0"
jsonc-parser "~2.2.1"
lodash "^4.17.15"
safe-stable-stringify "^1.1"

"@stoplight/lifecycle@^2.3.2":
version "2.3.2"
resolved "https://registry.yarnpkg.com/@stoplight/lifecycle/-/lifecycle-2.3.2.tgz#d61dff9ba20648241432e2daaef547214dc8976e"
Expand Down Expand Up @@ -3200,11 +3212,16 @@
jest-diff "^26.0.0"
pretty-format "^26.0.0"

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

"@types/json-schema@^7.0.7":
version "7.0.7"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.7.tgz#98a993516c859eb0d5c4c8f098317a9ea68db9ad"
integrity sha512-cxWFQVseBm6O9Gbw1IWb8r6OS4OhSt3hPZLkFApLjM8TEXROBuQGLAH2i2gZpcXdLBIrpXuTDhH7Vbm1iXmNGA==

"@types/json5@^0.0.29":
version "0.0.29"
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
Expand Down