diff --git a/src/__tests__/__snapshots__/index.spec.tsx.snap b/src/__tests__/__snapshots__/index.spec.tsx.snap index 65daf60e..4b684cef 100644 --- a/src/__tests__/__snapshots__/index.spec.tsx.snap +++ b/src/__tests__/__snapshots__/index.spec.tsx.snap @@ -3,7 +3,7 @@ exports[`Expanded depth nested object static given initial level set to 0, should render top 2 levels 1`] = ` "
-
+
@@ -59,7 +59,7 @@ exports[`Expanded depth nested object static given initial level set to 0, shoul exports[`Expanded depth nested object static given initial level set to 1, should render top 3 levels 1`] = ` "
-
+
@@ -198,7 +198,7 @@ exports[`Expanded depth nested object static given initial level set to 1, shoul exports[`Expanded depth nested object static given initial level set to 2, should render top 4 levels 1`] = ` "
-
+
@@ -354,7 +354,7 @@ exports[`Expanded depth nested object static given initial level set to 2, shoul exports[`HTML Output given anyOf combiner placed next to allOf given allOf merging enabled, should merge contents of allOf combiners 1`] = ` "
-
+
@@ -420,8 +420,8 @@ exports[`HTML Output given anyOf combiner placed next to allOf given allOf mergi
Allowed values: - \\"admin\\" - \\"editor\\" + \\"admin\\" + \\"editor\\"
@@ -502,7 +502,7 @@ exports[`HTML Output given anyOf combiner placed next to allOf given allOf mergi exports[`HTML Output given array with oneOf containing items, should merge it correctly 1`] = ` "
-
+
@@ -561,7 +561,7 @@ exports[`HTML Output given array with oneOf containing items, should merge it co exports[`HTML Output given complex type that includes array and complex array subtype, should not ignore subtype 1`] = ` "
-
+
@@ -611,7 +611,7 @@ exports[`HTML Output given complex type that includes array and complex array su exports[`HTML Output given multiple object and string type, should process properties 1`] = ` "
-
+
@@ -655,7 +655,7 @@ exports[`HTML Output given multiple object and string type, should process prope exports[`HTML Output given oneOf combiner placed next to allOf given allOf merging enabled, should merge contents of allOf combiners 1`] = ` "
-
+
@@ -721,8 +721,8 @@ exports[`HTML Output given oneOf combiner placed next to allOf given allOf mergi
Allowed values: - \\"admin\\" - \\"editor\\" + \\"admin\\" + \\"editor\\"
@@ -803,7 +803,7 @@ exports[`HTML Output given oneOf combiner placed next to allOf given allOf mergi exports[`HTML Output given read mode, should populate proper nodes 1`] = ` "
-
+
@@ -847,7 +847,7 @@ exports[`HTML Output given read mode, should populate proper nodes 1`] = ` exports[`HTML Output given standalone mode, should populate proper nodes 1`] = ` "
-
+
@@ -909,7 +909,7 @@ exports[`HTML Output given standalone mode, should populate proper nodes 1`] = ` exports[`HTML Output given visible $ref node, should try to inject the title immediately 1`] = ` "
-
+
@@ -982,7 +982,7 @@ exports[`HTML Output given visible $ref node, should try to inject the title imm exports[`HTML Output given write mode, should populate proper nodes 1`] = ` "
-
+
@@ -1026,7 +1026,7 @@ exports[`HTML Output given write mode, should populate proper nodes 1`] = ` exports[`HTML Output should match arrays/of-allofs.json 1`] = ` "
-
+
@@ -1098,7 +1098,7 @@ exports[`HTML Output should match arrays/of-allofs.json 1`] = ` exports[`HTML Output should match arrays/of-arrays.json 1`] = ` "
-
+
@@ -1152,7 +1152,7 @@ exports[`HTML Output should match arrays/of-arrays.json 1`] = ` exports[`HTML Output should match arrays/of-objects.json 1`] = ` "
-
+
@@ -1208,7 +1208,7 @@ exports[`HTML Output should match arrays/of-objects.json 1`] = ` exports[`HTML Output should match arrays/of-refs.json 1`] = ` "
-
+
@@ -1243,7 +1243,7 @@ exports[`HTML Output should match arrays/of-refs.json 1`] = ` exports[`HTML Output should match arrays/with-multiple-arrayish-items.json 1`] = ` "
-
+
@@ -1343,7 +1343,7 @@ exports[`HTML Output should match arrays/with-multiple-arrayish-items.json 1`] = exports[`HTML Output should match arrays/with-ordered-items.json 1`] = ` "
-
+
@@ -1391,7 +1391,7 @@ exports[`HTML Output should match arrays/with-ordered-items.json 1`] = ` exports[`HTML Output should match arrays/with-single-arrayish-items.json 1`] = ` "
-
+
@@ -1463,7 +1463,7 @@ exports[`HTML Output should match arrays/with-single-arrayish-items.json 1`] = ` exports[`HTML Output should match combiners/allOfs/base.json 1`] = ` "
-
+
@@ -1503,7 +1503,7 @@ exports[`HTML Output should match combiners/allOfs/base.json 1`] = `
-
>= 1 characters
+
>= 1 characters
@@ -1520,7 +1520,7 @@ exports[`HTML Output should match combiners/allOfs/base.json 1`] = `
-
<= 2
+
<= 2
@@ -1540,8 +1540,8 @@ exports[`HTML Output should match combiners/allOfs/base.json 1`] = `
- >= 1 characters - <= 2 characters + >= 1 characters + <= 2 characters
@@ -1559,7 +1559,7 @@ exports[`HTML Output should match combiners/allOfs/base.json 1`] = `
-
<= 1
+
<= 1
@@ -1593,8 +1593,8 @@ exports[`HTML Output should match combiners/allOfs/base.json 1`] = `
- >= 1 characters - <= 2 characters + >= 1 characters + <= 2 characters
@@ -1697,7 +1697,7 @@ exports[`HTML Output should match combiners/allOfs/base.json 1`] = ` exports[`HTML Output should match combiners/allOfs/complex.json 1`] = ` "
-
+
@@ -1979,7 +1979,7 @@ exports[`HTML Output should match combiners/allOfs/complex.json 1`] = ` exports[`HTML Output should match combiners/allOfs/todo-full.json 1`] = ` "
-
+
@@ -2043,8 +2043,8 @@ exports[`HTML Output should match combiners/allOfs/todo-full.json 1`] = `
- >= 0 - <= 1000000 + >= 0 + <= 1000000
@@ -2154,8 +2154,8 @@ exports[`HTML Output should match combiners/allOfs/todo-full.json 1`] = `
- >= 0 - <= 150 + >= 0 + <= 150
@@ -2173,7 +2173,7 @@ exports[`HTML Output should match combiners/allOfs/todo-full.json 1`] = ` exports[`HTML Output should match combiners/allOfs/todo-full-2.json 1`] = ` "
-
+
@@ -2215,8 +2215,8 @@ exports[`HTML Output should match combiners/allOfs/todo-full-2.json 1`] = `
- >= 0 - <= 1000000 + >= 0 + <= 1000000
@@ -2287,7 +2287,7 @@ exports[`HTML Output should match combiners/allOfs/todo-full-2.json 1`] = ` exports[`HTML Output should match combiners/allOfs/with-type.json 1`] = ` "
-
+
@@ -2353,9 +2353,9 @@ exports[`HTML Output should match combiners/allOfs/with-type.json 1`] = `
Allowed values: - \\"Cancel\\" - \\"Confirm\\" - \\"Update\\" + \\"Cancel\\" + \\"Confirm\\" + \\"Update\\"
@@ -2458,7 +2458,7 @@ exports[`HTML Output should match combiners/allOfs/with-type.json 1`] = ` exports[`HTML Output should match combiners/oneof-with-array-type.json 1`] = ` "
-
+
@@ -2523,7 +2523,7 @@ exports[`HTML Output should match combiners/oneof-with-array-type.json 1`] = `
Allowed value: - \\"test\\" + \\"test\\"
@@ -2555,7 +2555,7 @@ exports[`HTML Output should match combiners/oneof-with-array-type.json 1`] = ` exports[`HTML Output should match combiners/oneof-within-array-item.json 1`] = ` "
-
+
@@ -2620,7 +2620,7 @@ exports[`HTML Output should match combiners/oneof-within-array-item.json 1`] = `
Allowed value: - \\"test\\" + \\"test\\"
@@ -2636,7 +2636,7 @@ exports[`HTML Output should match combiners/oneof-within-array-item.json 1`] = ` exports[`HTML Output should match default-schema.json 1`] = ` "
-
+
@@ -2671,12 +2671,12 @@ exports[`HTML Output should match default-schema.json 1`] = `
Example values: - \\"Example name\\" - \\"Different name\\" + \\"Example name\\" + \\"Different name\\"
Allowed value: - \\"Constant name\\" + \\"Constant name\\"
@@ -2697,23 +2697,23 @@ exports[`HTML Output should match default-schema.json 1`] = `
- >= 10 - <= 40 + >= 10 + <= 40
Allowed values: - 10 - 20 - 30 - 40 + 10 + 20 + 30 + 40
Default value: - 20 + 20
Multiple of: - 10 + 10
@@ -2736,7 +2736,7 @@ exports[`HTML Output should match default-schema.json 1`] = `
Match pattern: - ^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$ + ^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$
@@ -2767,8 +2767,8 @@ exports[`HTML Output should match default-schema.json 1`] = `
- >= 1 items - <= 4 items + >= 1 items + <= 4 items
@@ -2788,15 +2788,15 @@ exports[`HTML Output should match default-schema.json 1`] = ` deprecated
-
>= 2 characters
+
>= 2 characters
Default value: - \\"default@email.com\\" + \\"default@email.com\\"
Example values: - \\"one@email.com\\" - \\"two@email.com\\" + \\"one@email.com\\" + \\"two@email.com\\"
@@ -3011,7 +3011,7 @@ exports[`HTML Output should match default-schema.json 1`] = ` exports[`HTML Output should match formats-schema.json 1`] = ` "
-
+
@@ -3144,7 +3144,7 @@ exports[`HTML Output should match formats-schema.json 1`] = ` exports[`HTML Output should match references/base.json 1`] = ` "
-
+
@@ -3252,7 +3252,7 @@ exports[`HTML Output should match references/base.json 1`] = ` exports[`HTML Output should match references/nested.json 1`] = ` "
-
+
@@ -3311,7 +3311,7 @@ exports[`HTML Output should match references/nested.json 1`] = ` exports[`HTML Output should match references/nullish.json 1`] = ` "
-
+
@@ -3349,7 +3349,7 @@ exports[`HTML Output should match references/nullish.json 1`] = ` exports[`HTML Output should match tickets.schema.json 1`] = ` "
-
+
@@ -3466,12 +3466,12 @@ exports[`HTML Output should match tickets.schema.json 1`] = `
Allowed values: - \\"COMPLETED\\" - \\"ACTIVE\\" + \\"COMPLETED\\" + \\"ACTIVE\\"
Default value: - \\"ACTIVE\\" + \\"ACTIVE\\"
@@ -3554,10 +3554,10 @@ exports[`HTML Output should match tickets.schema.json 1`] = `
Allowed values: - \\"HOMEPRINT\\" - \\"TICKETLESS\\" - \\"PRINT_AT_KIOSK\\" - \\"SECURE_PAPER\\" + \\"HOMEPRINT\\" + \\"TICKETLESS\\" + \\"PRINT_AT_KIOSK\\" + \\"SECURE_PAPER\\"
@@ -3583,7 +3583,7 @@ exports[`HTML Output should match tickets.schema.json 1`] = `
-
example
+
example
diff --git a/src/__tests__/index.spec.tsx b/src/__tests__/index.spec.tsx index 3350f324..679fafb0 100644 --- a/src/__tests__/index.spec.tsx +++ b/src/__tests__/index.spec.tsx @@ -238,7 +238,7 @@ describe('Expanded depth', () => { expect(dumpDom(wrapper.getElement())).toMatchInlineSnapshot(` "
-
+
@@ -263,7 +263,7 @@ describe('Expanded depth', () => { expect(dumpDom(wrapper.getElement())).toMatchInlineSnapshot(` "
-
+
@@ -306,7 +306,7 @@ describe('Expanded depth', () => { expect(dumpDom(wrapper.getElement())).toMatchInlineSnapshot(` "
-
+
@@ -401,7 +401,7 @@ describe('Expanded depth', () => { expect(dumpDom(wrapper.getElement())).toMatchInlineSnapshot(` "
-
+
@@ -426,7 +426,7 @@ describe('Expanded depth', () => { expect(dumpDom(wrapper.getElement())).toMatchInlineSnapshot(` "
-
+
@@ -485,7 +485,7 @@ describe('Expanded depth', () => { expect(dumpDom(wrapper.getElement())).toMatchInlineSnapshot(` "
-
+
@@ -624,7 +624,7 @@ describe('Expanded depth', () => { expect(dumpDom(wrapper.getElement())).toMatchInlineSnapshot(` "
-
+
@@ -678,7 +678,7 @@ describe('$ref resolving', () => { expect(dumpDom()).toMatchInlineSnapshot(` "
-
+
@@ -707,7 +707,7 @@ describe('$ref resolving', () => { expect(dumpDom()).toMatchInlineSnapshot(` "
-
+
diff --git a/src/components/JsonSchemaViewer.tsx b/src/components/JsonSchemaViewer.tsx index ddbe7b80..058f8415 100644 --- a/src/components/JsonSchemaViewer.tsx +++ b/src/components/JsonSchemaViewer.tsx @@ -66,7 +66,7 @@ const JsonSchemaViewerComponent: React.FC diff --git a/src/components/SchemaRow/SchemaRow.tsx b/src/components/SchemaRow/SchemaRow.tsx index 1793cbe2..e11879c3 100644 --- a/src/components/SchemaRow/SchemaRow.tsx +++ b/src/components/SchemaRow/SchemaRow.tsx @@ -3,6 +3,7 @@ import { isMirroredNode, isReferenceNode, isRegularNode, + isRootNode, ReferenceNode, SchemaNode, SchemaNodeKind, @@ -56,9 +57,13 @@ export const SchemaRow: React.FunctionComponent = ({ schemaNode, const isBrokenRef = typeof refNode?.error === 'string'; const childNodes = React.useMemo(() => calculateChildrenToShow(typeToShow), [typeToShow]); - return ( -
+
= ({ schemaNode, /> ) : null} -
+
{schemaNode.subpath.length > 0 && shouldShowPropertyName(schemaNode) && (
{last(schemaNode.subpath)}
)} @@ -137,7 +142,7 @@ export const SchemaRow: React.FunctionComponent = ({ schemaNode,
{typeof description === 'string' && description.length > 0 && ( -
+
)} diff --git a/src/components/shared/Caret.tsx b/src/components/shared/Caret.tsx index b1c1f3b6..59e591e1 100644 --- a/src/components/shared/Caret.tsx +++ b/src/components/shared/Caret.tsx @@ -10,7 +10,7 @@ export interface ICaret { export const Caret: React.FunctionComponent = ({ style, size, isExpanded }) => (
diff --git a/src/components/shared/Validations.tsx b/src/components/shared/Validations.tsx index bf1edcd1..b7187f12 100644 --- a/src/components/shared/Validations.tsx +++ b/src/components/shared/Validations.tsx @@ -1,5 +1,6 @@ import { RegularNode } from '@stoplight/json-schema-tree'; import { Dictionary } from '@stoplight/types'; +import cn from 'classnames'; import { capitalize, keys, omit, pick, pickBy, uniq } from 'lodash'; import * as React from 'react'; @@ -99,9 +100,7 @@ const NumberValidations = ({ {entries .map(([key, value]) => numberValidationFormatters[key](value)) .map((value, i) => ( - - {value} - + ))}
); @@ -127,9 +126,7 @@ const KeyValueValidation = ({ name, values }: { name: string; values: string[] }
{capitalize(name)}: {uniq(values).map(value => ( - - {value} - + ))}
); @@ -137,20 +134,27 @@ const KeyValueValidation = ({ name, values }: { name: string; values: string[] } const NameValidations = ({ validations }: { validations: Dictionary }) => ( <> - {keys(validations) - .filter(key => validations[key]) - .map(key => { - return ( -
- - {key} - -
- ); - })} + {keys(validations).length ? ( +
+ {keys(validations) + .filter(key => validations[key]) + .map(key => ( + + ))} +
+ ) : null} ); +const Value = ({ name, className }: { name: string; className?: string }) => ( + + {name} + +); + export function validationCount(schemaNode: RegularNode) { const validations = getValidationsFromSchema(schemaNode); const validationKeys = keys(omit(validations, excludedValidations)); diff --git a/src/components/shared/__tests__/Property.spec.tsx b/src/components/shared/__tests__/Property.spec.tsx index 4674f726..14aad0c4 100644 --- a/src/components/shared/__tests__/Property.spec.tsx +++ b/src/components/shared/__tests__/Property.spec.tsx @@ -83,7 +83,7 @@ describe('Property component', () => { const wrapper = render(schema, ['properties', 'foo']); expect(wrapper.find(SchemaRow).html()).toMatchInlineSnapshot( - `"
foo
string
"`, + `"
foo
string
"`, ); }); @@ -102,7 +102,7 @@ describe('Property component', () => { const wrapper = render(schema, ['properties', 'foo']); expect(wrapper.find(SchemaRow).html()).toMatchInlineSnapshot( - `"
foo
array of integers
"`, + `"
foo
array of integers
"`, ); }); @@ -120,7 +120,7 @@ describe('Property component', () => { const wrapper = render(schema, ['items', 'properties', 'foo']); expect(wrapper.html()).toMatchInlineSnapshot( - `"
foo
string
"`, + `"
foo
string
"`, ); }); @@ -141,7 +141,7 @@ describe('Property component', () => { const wrapper = render(schema); expect(wrapper.html()).toMatchInlineSnapshot( - `"
"`, + `"
"`, ); }); @@ -164,7 +164,7 @@ describe('Property component', () => { const wrapper = render(schema); expect(wrapper.html()).toMatchInlineSnapshot( - `"
array of objects
foo
bar
baz
"`, + `"
array of objects
foo
bar
baz
"`, ); }); @@ -199,12 +199,12 @@ describe('Property component', () => { let wrapper = render(schema, ['properties', 'array-all-objects', 'items', 'properties', 'foo']); expect(wrapper.html()).toMatchInlineSnapshot( - `"
foo
string
"`, + `"
foo
string
"`, ); wrapper = render(schema, ['properties', 'array-all-objects', 'items', 'properties', 'bar']); expect(wrapper.html()).toMatchInlineSnapshot( - `"
bar
string
"`, + `"
bar
string
"`, ); }); @@ -224,7 +224,7 @@ describe('Property component', () => { const wrapper = mount(); expect(wrapper.html()).toMatchInlineSnapshot( - `"
foo
object
"`, + `"
foo
object
"`, ); wrapper.unmount(); }); diff --git a/src/index.ts b/src/index.ts index 598bd62c..f07e59b3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,2 @@ -export { JsonSchemaViewer } from './components'; +export { JsonSchemaViewer, Validations } from './components'; export * from './types';