diff --git a/src/__fixtures__/combiners/oneof-within-array-item.json b/src/__fixtures__/combiners/oneof-within-array-item.json new file mode 100644 index 00000000..79a0b3dd --- /dev/null +++ b/src/__fixtures__/combiners/oneof-within-array-item.json @@ -0,0 +1,31 @@ +{ + "type": "array", + "items": { + "oneOf": [ + { + "type": "object", + "title": "A", + "properties": { + "foo": { + "type": "string", + "enum": [ + "test" + ] + } + } + }, + { + "type": "object", + "title": "B", + "properties": { + "foo": { + "type": "number" + }, + "bar": { + "type": "string" + } + } + } + ] + } +} diff --git a/src/__stories__/JsonSchemaViewer.tsx b/src/__stories__/JsonSchemaViewer.tsx index 15142033..6859d578 100644 --- a/src/__stories__/JsonSchemaViewer.tsx +++ b/src/__stories__/JsonSchemaViewer.tsx @@ -15,6 +15,7 @@ const refSchema = require('../__fixtures__/references/base.json'); const nullRefSchema = require('../__fixtures__/references/nullish.json'); const brokenRefArraySchema = require('../__fixtures__/arrays/of-refs.json'); const oneOfWithArraySchema = require('../__fixtures__/combiners/oneof-with-array-type.json'); +const oneOfWithArraySchema2 = require('../__fixtures__/combiners/oneof-within-array-item.json'); subscribeTheme({ mode: 'light' }); @@ -83,6 +84,13 @@ storiesOf('JsonSchemaViewer', module) onGoToRef={action('onGoToRef')} /> )) + .add('anyOf-array-schema2', () => ( + + )) .add('error boundary', () => ( -
-
+"
+
+
-
- object -
{2}
+
+
object
+
-
-
-
-
-
+
+
-
-
bar
- object -
{3}
+
+
+
bar
+ object +
+
-
-
-
-
-
+
+
-
-
foo
- array[object] -
{2}
+
+
+
foo
+ array of objects +
+
-
@@ -60,138 +57,134 @@ 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`] = ` -"
-
-
+"
+
+
-
- object -
{2}
+
+
object
+
-
-
-
-
-
+
+
-
-
bar
- object -
{3}
+
+
+
bar
+ object +
+
-
-
-
-
-
+
+
-
-
barFoo
- object -
{1}
+
+
+
barFoo
+ object +
+
-
-
-
-
-
+
+
-
barBar
- string +
+
barBar
+ string +
+
-
-
-
-
-
+
+
-
barBaz
- boolean +
+
barBaz
+ boolean +
+
-
-
-
-
-
+
+
-
-
foo
- array[object] -
{2}
+
+
+
foo
+ array of objects +
+
-
-
-
-
-
+
+
-
fooBar
- string +
+
fooBar
+ string +
+
-
-
-
-
-
+
+
-
fooFoo
- number +
+
fooFoo
+ number +
+
-
@@ -203,155 +196,151 @@ 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`] = ` -"
-
-
+"
+
+
-
- object -
{2}
+
+
object
+
-
-
-
-
-
+
+
-
-
bar
- object -
{3}
+
+
+
bar
+ object +
+
-
-
-
-
-
+
+
-
-
barFoo
- object -
{1}
+
+
+
barFoo
+ object +
+
-
-
-
-
-
+
+
-
barFooBar
- object +
+
barFooBar
+ object +
+
-
-
-
-
-
+
+
-
barBar
- string +
+
barBar
+ string +
+
-
-
-
-
-
+
+
-
barBaz
- boolean +
+
barBaz
+ boolean +
+
-
-
-
-
-
+
+
-
-
foo
- array[object] -
{2}
+
+
+
foo
+ array of objects +
+
-
-
-
-
-
+
+
-
fooBar
- string +
+
fooBar
+ string +
+
-
-
-
-
-
+
+
-
fooFoo
- number +
+
fooFoo
+ number +
+
-
@@ -363,214 +352,144 @@ 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`] = ` -"
-
-
+"
+
+
-
-
- anyOf -
{2}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Admin -
{5}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
type
- string -
- required -
-
-
- Allowed values: - \\"admin\\" - \\"editor\\" -
-
-
-
-
-
-
-
-
-
-
-
enabled
- boolean -
-
-
Is this account enabled
-
-
-
-
-
-
-
-
-
-
-
-
-
root
- boolean -
+
+
+
+
+ + +
+
+
-
-
-
+
+
+
+
+
+
-
-
group
- string -
+
type
+ string
+ required
-
-
-
-
-
-
-
-
-
-
expirationDate
- string -
-
-
+ Allowed values: + \\"admin\\" + \\"editor\\"
-
+
-
-
-
-
+
+
-
-
-
-
and/or
-
- Editor -
{4}
-
-
-
-
-
-
-
-
-
-
type
- string -
- required +
enabled
+ boolean
-
- Allowed values: - \\"admin\\" - \\"editor\\" -
+
Is this account enabled
-
+
-
-
+
+
+
+
-
-
enabled
- boolean -
+
root
+ boolean
-
Is this account enabled
-
+
-
-
+
+
+
+
-
-
supervisor
- string -
+
group
+ string
-
+
-
-
+
+
+
+
-
-
key
- string -
+
expirationDate
+ string
-
+
@@ -581,48 +500,57 @@ 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`] = ` -"
-
-
+"
+
+
-
-
-
-
- oneOf -
{2}
-
-
-
-
-
-
-
-
-
-
-
-
-
array[string]
-
-
-
-
-
-
-
-
-
or
-
array[number]
+
+
+ + +
+
+ +
+
-
+
@@ -631,48 +559,47 @@ 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`] = ` -"
-
-
+"
+
+
-
- object -
{1}
+
+
object
+
-
-
-
-
-
+
+
-
items
- null - or - array[string,number] +
items
+
+ null + or + array of strings/numbers +
-
-
-
- This description can be long and should truncate once it reaches the end of the row. If it's not - truncating then theres and issue that needs to be fixed. Help! +
+
+ This description can be long and should truncate once it reaches the end of the row. If it's not + truncating then theres and issue that needs to be fixed. Help! +
+
-
@@ -682,40 +609,41 @@ 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`] = ` -"
-
-
+"
+
+
-
+
- string - or - object +
+ string + or + object +
-
{1}
+
-
-
-
-
-
+
+
-
ids
- array[integer] +
+
ids
+ array of integers +
+
-
@@ -725,214 +653,144 @@ 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`] = ` -"
-
-
+"
+
+
-
- oneOf -
{2}
+
+
+
+
+ + +
+
+ +
+
+
+
-
-
-
-
-
+
+
-
- Admin -
{5}
+
+
type
+ string +
+ required
+
+ Allowed values: + \\"admin\\" + \\"editor\\" +
+
-
-
-
+
+
+
-
-
type
- string -
- required -
-
-
- Allowed values: - \\"admin\\" - \\"editor\\" -
-
-
-
-
-
-
-
-
-
-
-
-
enabled
- boolean -
-
-
Is this account enabled
-
-
-
-
-
-
-
-
-
-
-
-
-
root
- boolean -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
group
- string -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
expirationDate
- string -
+
enabled
+ boolean
+
Is this account enabled
-
+
-
-
-
-
+
+
-
-
-
-
or
-
- Editor -
{4}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
type
- string -
- required -
-
-
- Allowed values: - \\"admin\\" - \\"editor\\" -
-
-
-
-
-
-
-
-
enabled
- boolean -
+
root
+ boolean
-
Is this account enabled
-
+
-
-
+
+
+
+
-
-
supervisor
- string -
+
group
+ string
-
+
-
-
+
+
+
+
-
-
key
- string -
+
expirationDate
+ string
-
+
@@ -943,40 +801,41 @@ exports[`HTML Output given oneOf combiner placed next to allOf given allOf mergi `; exports[`HTML Output given read mode, should populate proper nodes 1`] = ` -"
-
-
+"
+
+
-
+
- string - or - object +
+ string + or + object +
-
{1}
+
-
-
-
-
-
+
+
-
id
- string +
+
id
+ string +
+
-
@@ -986,58 +845,59 @@ exports[`HTML Output given read mode, should populate proper nodes 1`] = ` `; exports[`HTML Output given standalone mode, should populate proper nodes 1`] = ` -"
-
-
+"
+
+
-
+
- string - or - object +
+ string + or + object +
-
{2}
+
-
-
-
-
-
+
+
-
id
- string +
+
id
+ string +
+ read-only
- read-only
+
-
-
-
-
-
+
+
-
description
- string +
+
description
+ string +
+ write-only
- write-only
+
-
@@ -1047,73 +907,70 @@ 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`] = ` -"
-
-
+"
+
+
-
- object -
{2}
+
+
object
+
-
-
-
-
-
+
+
-
-
foo
- User -
{1}
+
+
+
foo
+ User +
+
-
-
-
-
-
+
+
-
name
- string +
+
name
+ string +
+
-
-
-
-
-
+
+
-
-
user
- User -
{1}
+
+
+
user
+ User +
+
-
@@ -1123,40 +980,41 @@ 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`] = ` -"
-
-
+"
+
+
-
+
- string - or - object +
+ string + or + object +
-
{1}
+
-
-
-
-
-
+
+
-
description
- string +
+
description
+ string +
+
-
@@ -1166,69 +1024,67 @@ exports[`HTML Output given write mode, should populate proper nodes 1`] = ` `; exports[`HTML Output should match arrays/of-allofs.json 1`] = ` -"
-
-
+"
+
+
-
- Test -
{1}
+
+
Test
+
-
-
-
-
-
+
+
-
-
array-all-objects
- array[object] -
{2}
+
+
+
array-all-objects
+ array of objects +
+
-
-
-
-
-
+
+
-
foo
- string +
+
foo
+ string +
+
-
-
-
-
-
+
+
-
bar
- string +
+
bar
+ string +
+
-
@@ -1240,52 +1096,51 @@ exports[`HTML Output should match arrays/of-allofs.json 1`] = ` `; exports[`HTML Output should match arrays/of-arrays.json 1`] = ` -"
-
-
+"
+
+
-
- array[object] -
{2}
+
+
array of objects
+
-
-
-
-
-
+
+
-
bar
- integer +
+
bar
+ integer +
+
-
-
-
-
-
+
+
-
foo
- array[array] +
+
foo
+ array of arrays +
+
-
@@ -1295,53 +1150,51 @@ exports[`HTML Output should match arrays/of-arrays.json 1`] = ` `; exports[`HTML Output should match arrays/of-objects.json 1`] = ` -"
-
-
+"
+
+
-
- object -
{1}
+
+
object
+
-
-
-
-
-
+
+
-
-
propertyIsArrayOfObjects
- array[object] -
{1}
+
+
+
propertyIsArrayOfObjects
+ array of objects +
+
-
-
-
-
-
+
+
-
ArrayObjectProperty
- string +
+
ArrayObjectProperty
+ string +
+
-
@@ -1353,33 +1206,32 @@ exports[`HTML Output should match arrays/of-objects.json 1`] = ` `; exports[`HTML Output should match arrays/of-refs.json 1`] = ` -"
-
-
+"
+
+
-
- $ref(./models/todo-full.json)[] -
{1}
+
+
$ref(./models/todo-full.json)[]
+
-
-
-
-
-
+
+
-
./models/todo-full.json
+
+
./models/todo-full.json
+
+
-
@@ -1389,99 +1241,95 @@ exports[`HTML Output should match arrays/of-refs.json 1`] = ` `; exports[`HTML Output should match arrays/with-multiple-arrayish-items.json 1`] = ` -"
-
-
+"
+
+
-
- array -
{2}
+
+
array
+
-
-
-
-
-
+
+
-
number
+
+
number
+
+
-
-
-
-
-
+
+
-
- object -
{3}
+
+
object
+
-
-
-
-
-
+
+
-
code
- number +
+
code
+ number +
+ required
- required
+
-
-
-
-
-
+
+
-
msg
- string +
+
msg
+ string +
+ required
- required
+
-
-
-
-
-
+
+
-
ref
- string +
+
ref
+ string +
+
-
@@ -1493,46 +1341,45 @@ exports[`HTML Output should match arrays/with-multiple-arrayish-items.json 1`] = `; exports[`HTML Output should match arrays/with-ordered-items.json 1`] = ` -"
-
-
+"
+
+
-
- array -
{2}
+
+
array
+
-
-
-
-
-
+
+
-
number
+
+
number
+
+
-
-
-
-
-
+
+
-
string
+
+
string
+
+
-
@@ -1542,70 +1389,69 @@ exports[`HTML Output should match arrays/with-ordered-items.json 1`] = ` `; exports[`HTML Output should match arrays/with-single-arrayish-items.json 1`] = ` -"
-
-
+"
+
+
-
- array[object] -
{3}
+
+
array of objects
+
-
-
-
-
-
+
+
-
code
- number +
+
code
+ number +
+ required
- required
+
-
-
-
-
-
+
+
-
msg
- string +
+
msg
+ string +
+ required
- required
+
-
-
-
-
-
+
+
-
ref
- string +
+
ref
+ string +
+
-
@@ -1615,233 +1461,229 @@ exports[`HTML Output should match arrays/with-single-arrayish-items.json 1`] = ` `; exports[`HTML Output should match combiners/allOfs/base.json 1`] = ` -"
-
-
+"
+
+
-
- object -
{5}
+
+
object
+
-
-
-
-
-
+
+
-
-
AllOfMergeObjects
- object -
{2}
+
+
+
AllOfMergeObjects
+ object +
+
-
-
-
-
-
+
+
-
Object1Property
- string +
+
Object1Property
+ string +
+
>= 1 characters
-
>= 1 characters
+
-
-
-
-
-
+
+
-
Object2Property
- number +
+
Object2Property
+ number +
+
<= 2
-
<= 2
+
-
-
-
-
-
+
+
-
AllOfMergeValidations
- string +
+
AllOfMergeValidations
+ string +
+
+ >= 1 characters + <= 2 characters +
-
- >= 1 characters - <= 2 characters -
+
-
-
-
-
-
+
+
-
AllOfMergeTakeMoreLogicalValidation
- number +
+
AllOfMergeTakeMoreLogicalValidation
+ number +
+
<= 1
-
<= 1
+
-
-
-
-
-
+
+
-
-
AllOfMergeObjectPropertyValidations
- object -
{1}
+
+
+
AllOfMergeObjectPropertyValidations
+ object +
+
-
-
-
-
-
+
+
-
Property
- string +
+
Property
+ string +
+
+ >= 1 characters + <= 2 characters +
-
- >= 1 characters - <= 2 characters -
+
-
-
-
-
-
+
+
-
-
AllOfMergeRefs
- object -
{4}
+
+
+
AllOfMergeRefs
+ object +
+
-
-
-
-
-
+
+
-
street_address
- string +
+
street_address
+ string +
+ required
- required
+
-
-
-
-
-
+
+
-
city
- string +
+
city
+ string +
+ required
- required
+
-
-
-
-
-
+
+
-
state
- string +
+
state
+ string +
+ required
- required
+
-
-
-
-
-
+
+
-
zipCode
- string +
+
zipCode
+ string +
+
-
@@ -1853,330 +1695,310 @@ exports[`HTML Output should match combiners/allOfs/base.json 1`] = ` `; exports[`HTML Output should match combiners/allOfs/complex.json 1`] = ` -"
-
-
+"
+
+
-
- object -
{2}
+
+
object
+
-
-
-
-
-
+
+
-
-
foo
- object -
{1}
+
+
+
foo
+ object +
+
-
-
-
-
-
+
+
-
-
user
- allOf -
{1}
+
+
+
user
+ allOf +
+
-
-
-
-
-
+
+
-
- object -
{2}
+
+
object
+
-
-
-
-
-
+
+
-
-
names
- - $ref(#/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/name)[] - -
{1}
+
+
+
names
+ + $ref(#/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/name)[] + +
+
-
-
-
-
-
+
+
- - #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/name - +
+ + #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/name + +
+
-
-
-
-
-
+
+
-
-
users
- array[object] -
{3}
+
+
+
users
+ array of objects +
+
-
-
-
-
-
+
+
-
-
creation
- object -
{1}
+
+
+
creation
+ object +
+
-
-
-
-
-
+
+
-
-
user
- allOf -
{1}
+
+
+
user
+ allOf +
+
-
-
-
-
-
+
+
-
- object -
{2}
+
+
object
+
-
-
-
-
-
+
+
-
-
names
- - $ref(#/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/name)[] - -
{1}
+
+
+
names
+ + $ref(#/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/name)[] + +
+
-
-
-
-
-
+
+
- - #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/name - +
+ + #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/name + +
+
-
-
-
-
-
+
+
-
-
users
- array[object] -
{3}
+
+
+
users
+ array of objects +
+
-
-
-
-
-
+
+
-
-
creation
- object -
{1}
+
+
+
creation
+ object +
+
-
-
-
-
-
+
+
-
-
user
- allOf -
{1}
+
+
+
user
+ allOf +
+
-
-
-
-
-
+
+
-
- object -
{2}
+
+
object
+
-
-
-
-
-
+
+
-
foo
- - #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts - +
+
foo
+ + #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts + +
+
-
-
-
-
-
+
+
-
products
- - #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts - +
+
products
+ + #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts + +
+
-
@@ -2186,41 +2008,41 @@ exports[`HTML Output should match combiners/allOfs/complex.json 1`] = `
-
-
-
-
+
+
-
foo
- - #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts - +
+
foo
+ + #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts + +
+
-
-
-
-
-
+
+
-
products
- - #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts - +
+
products
+ + #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts + +
+
-
@@ -2230,218 +2052,205 @@ exports[`HTML Output should match combiners/allOfs/complex.json 1`] = `
-
-
-
-
+
+
-
-
bar
- object -
{1}
+
+
+
bar
+ object +
+
-
-
-
-
-
+
+
-
-
foo
- object -
{1}
+
+
+
foo
+ object +
+
-
-
-
-
-
+
+
-
-
user
- allOf -
{1}
+
+
+
user
+ allOf +
+
-
-
-
-
-
+
+
-
- object -
{2}
+
+
object
+
-
-
-
-
-
+
+
-
-
names
- - $ref(#/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/name)[] - -
{1}
+
+
+
names
+ + $ref(#/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/name)[] + +
+
-
-
-
-
-
+
+
- - #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/name - +
+ + #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/name + +
+
-
-
-
-
-
+
+
-
-
users
- array[object] -
{3}
+
+
+
users
+ array of objects +
+
-
-
-
-
-
+
+
-
-
creation
- object -
{1}
+
+
+
creation
+ object +
+
-
-
-
-
-
+
+
-
-
user
- allOf -
{1}
+
+
+
user
+ allOf +
+
-
-
-
-
-
+
+
-
- object -
{2}
+
+
object
+
-
-
-
-
-
+
+
-
foo
- - #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts - +
+
foo
+ + #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts + +
+
-
-
-
-
-
+
+
-
products
- - #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts - +
+
products
+ + #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts + +
+
-
@@ -2461,191 +2270,189 @@ exports[`HTML Output should match combiners/allOfs/complex.json 1`] = ` `; exports[`HTML Output should match combiners/allOfs/todo-full.json 1`] = ` -"
-
-
+"
+
+
-
- Todo Partial[] -
{7}
+
+
array of Todo Partial-s
+
-
-
-
-
-
+
+
-
name
- string +
+
name
+ string +
+ required
- required
+
-
-
-
-
-
+
+
-
completed
- boolean - or - null +
completed
+
+ boolean + or + null +
+ required
- required
+
-
-
-
-
-
+
+
-
id
- integer +
+
id
+ integer +
+ required
- required +
+
+ >= 0 + <= 1000000
-
- >= 0 - <= 1000000 -
+
-
-
-
-
-
+
+
-
completed_at
- string - or - null +
completed_at
+
+ string + or + null +
+ <date-time>
- <date-time>
+
-
-
-
-
-
+
+
-
created_at
- string - <date-time> +
+
created_at
+ string + <date-time> +
+
-
-
-
-
-
+
+
-
updated_at
- string - <date-time> +
+
updated_at
+ string + <date-time> +
+
-
-
-
-
-
+
+
-
-
user
- User -
{2}
+
+
+
user
+ User +
+ required
- required
+
-
-
-
-
-
+
+
-
name
- string +
+
name
+ string +
+ required
- required +
The user's full name.
-
The user's full name.
+
-
-
-
-
-
+
+
-
age
- number +
+
age
+ number +
+ required
- required +
+
+ >= 0 + <= 150
-
- >= 0 - <= 150 -
+
-
@@ -2657,112 +2464,111 @@ exports[`HTML Output should match combiners/allOfs/todo-full.json 1`] = ` `; exports[`HTML Output should match combiners/allOfs/todo-full-2.json 1`] = ` -"
-
-
+"
+
+
-
- Todo Full -
{5}
+
+
Todo Full
+
-
-
-
-
-
+
+
-
test
- string +
+
test
+ string +
+
-
-
-
-
-
+
+
-
id
- integer +
+
id
+ integer +
+ required
- required +
+
+ >= 0 + <= 1000000
-
- >= 0 - <= 1000000 -
+
-
-
-
-
-
+
+
-
completed_at
- string - or - null +
completed_at
+
+ string + or + null +
+ <date-time>
- <date-time>
+
-
-
-
-
-
+
+
-
created_at
- string - <date-time> +
+
created_at
+ string + <date-time> +
+
-
-
-
-
-
+
+
-
updated_at
- string - <date-time> +
+
updated_at
+ string + <date-time> +
+
-
@@ -2772,279 +2578,345 @@ exports[`HTML Output should match combiners/allOfs/todo-full-2.json 1`] = ` `; exports[`HTML Output should match combiners/allOfs/with-type.json 1`] = ` -"
-
-
+"
+
+
-
- oneOf -
{2}
+
+
+
+
+ + +
+
+ +
+
+
+
-
-
-
-
-
+
+
-
- BugExample -
{6}
+
+
actionType
+ string +
+ required
-
An example model to demonstrate a bug.
+ Allowed values: + \\"Cancel\\" + \\"Confirm\\" + \\"Update\\"
+
-
-
-
+
+
+
-
-
actionType
- string -
- required +
id
+ string
+ required
- Allowed values: - \\"Cancel\\" - \\"Confirm\\" - \\"Update\\" -
-
-
-
-
-
-
-
-
-
-
-
-
id
- string -
- required -
-
-
- The identifier of the existing reservation. -
+
+ The identifier of the existing reservation.
-
+
-
-
+
+
+
+
-
-
externalId
- string -
+
externalId
+ string
-
+
-
-
+
+
+
+
-
-
calculateCosts
- boolean -
+
calculateCosts
+ boolean
-
+
-
-
+
+
+
+
-
-
calculateDates
- boolean -
+
calculateDates
+ boolean
-
+
-
-
+
+
+
+
-
-
items
- array[string] -
- required +
items
+ array of strings
+ required
-
+
-
-
+
+
+
+" +`; + +exports[`HTML Output should match combiners/oneof-with-array-type.json 1`] = ` +"
+
+
+
-
-
-
or
-
- BugExample -
{6}
+
+
+
+
+ + +
+
+ +
-
-
An example model to demonstrate a bug.
-
-
-
-
+
+
+
+
+
-
-
actionType
- string -
- required +
foo
+ string
-
- Allowed value: - \\"Create\\" -
-
-
-
-
-
-
-
-
-
-
id
- string -
-
-
-
- The identifier of the existing reservation. -
-
-
+ Allowed value: + \\"test\\"
-
+
-
-
+
+
+
+
-
-
externalId
- string -
+
baz
+ integer
-
+
-
-
+
+
+
+
+
+" +`; + +exports[`HTML Output should match combiners/oneof-within-array-item.json 1`] = ` +"
+
+
+
+
+
-
-
-
-
-
calculateCosts
- boolean -
+
+
+
+
+ + +
+
+
-
-
-
+
+
+
+
+
+
-
-
calculateDates
- boolean -
+
foo
+ string
-
-
-
-
-
-
-
-
-
-
items
- array[string] -
- required -
-
+ Allowed value: + \\"test\\"
-
+
@@ -3054,537 +2926,390 @@ exports[`HTML Output should match combiners/allOfs/with-type.json 1`] = ` " `; -exports[`HTML Output should match combiners/oneof-with-array-type.json 1`] = ` -"
-
-
+exports[`HTML Output should match default-schema.json 1`] = ` +"
+
+
-
- oneOf -
{2}
+
+
User
+
-
-
-
-
-
+
+
-
-
-
-
- array[object] -
{2}
-
-
-
-
-
-
-
-
-
-
foo
- string -
+
name
+ string
+ required
- Allowed value: - \\"test\\" +
+ The user's full name. This description can be long and should truncate once it reaches the end of + the row. If it's not truncating then theres and issue that needs to be fixed. Help! +
-
-
-
-
-
-
-
-
-
-
baz
- integer -
-
-
+ Example values: + \\"Example name\\" + \\"Different name\\"
-
-
-
-
-
-
-
-
-
-
-
-
or
-
- array[object] -
{3}
-
+ Allowed value: + \\"Constant name\\"
+
-
-
-
+
+
+
-
-
foo
- number -
+
age
+ number
+ read-only + required
-
-
-
-
-
-
-
-
-
-
baz
- integer -
-
-
+ >= 10 + <= 40
-
-
-
-
-
-
-
-
-
-
bar
- string -
-
-
+ Allowed values: + 10 + 20 + 30 + 40
-
-
-
-
-
-
-
-
-" -`; - -exports[`HTML Output should match default-schema.json 1`] = ` -"
-
-
-
-
-
-
-
- User -
{11}
-
-
-
-
-
-
-
-
-
-
-
-
-
name
- string -
- required + Default value: + 20
-
- The user's full name. This description can be long and should truncate once it reaches the end of the - row. If it's not truncating then theres and issue that needs to be fixed. Help! -
+ Multiple of: + 10
-
- Example values: - \\"Example name\\" - \\"Different name\\" -
-
- Allowed value: - \\"Constant name\\" -
+
-
-
-
-
-
+
+
-
age
- number +
+
completed_at
+ string + <date-time> +
+ write-only + required
- read-only - required
-
-
- >= 10 - <= 40 -
-
- Allowed values: - 10 - 20 - 30 - 40 -
-
- Default value: - 20 -
-
- Multiple of: - 10 -
-
-
-
-
-
-
-
-
-
-
-
completed_at
- string - <date-time> -
- write-only - required + Match pattern: + ^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$
-
- Match pattern: - ^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$ -
+
-
-
-
-
-
+
+
-
items
- null - or - array[string,number] +
items
+
+ null + or + array of strings/numbers +
+
+
+
+
+ This description can be long and should truncate once it reaches the end of the row. If it's not + truncating then theres and issue that needs to be fixed. Help!
-
- This description can be long and should truncate once it reaches the end of the row. If it's not - truncating then theres and issue that needs to be fixed. Help! -
+ >= 1 items + <= 4 items
-
- >= 1 items - <= 4 items -
+
-
-
-
-
-
+
+
-
email
- string - <email> +
+
email
+ string + <email> +
+ deprecated
- deprecated
-
-
>= 2 characters
-
- Default value: - \\"default@email.com\\" -
-
- Example values: - \\"one@email.com\\" - \\"two@email.com\\" -
-
-
-
-
-
-
-
-
-
+
>= 2 characters
-
-
-
plan
- anyOf -
{2}
-
+ Default value: + \\"default@email.com\\" +
+
+ Example values: + \\"one@email.com\\" + \\"two@email.com\\"
+
-
-
-
+
+
+
+
-
+
plan
- object -
{2}
+
+ + +
+
+ +
-
- Example value: - \\"hi\\" -
-
-
-
+
+
+
+
+
-
-
foo
- string -
- required +
foo
+ string
+ required
-
+
-
-
+
+
+
+
-
-
bar
- string -
- required +
bar
+ string
+ required
-
+
-
-
-
-
-
-
-
and/or
-
array[integer]
-
-
-
-
-
-
-
-
-
-
+
+
-
-
permissions
+
- string - or - object +
permissions
+
+ string + or + object +
-
{1}
+
-
-
-
-
-
+
+
-
ids
- array[integer] +
+
ids
+ array of integers +
+
-
-
-
-
-
+
+
-
-
ref
+
- string - or - object +
ref
+
+ string + or + object +
-
{1}
+
-
-
-
-
-
+
+
-
ids
- array[integer] +
+
ids
+ array of integers +
+
-
-
-
-
-
+
+
-
^id_
- number -
(pattern property)
+
+
^id_
+ number +
(pattern property)
+
+
-
-
-
-
-
+
+
-
foo
- integer -
(pattern property)
+
+
foo
+ integer +
(pattern property)
+
+
-
-
-
-
-
+
+
-
_name$
- string -
(pattern property)
+
+
_name$
+ string +
(pattern property)
+
+
-
@@ -3594,130 +3319,128 @@ exports[`HTML Output should match default-schema.json 1`] = ` `; exports[`HTML Output should match formats-schema.json 1`] = ` -"
-
-
+"
+
+
-
- model-with-formats -
{5}
+
+
model-with-formats
+
-
-
-
-
-
+
+
-
date-of-birth
- number - or - string - or - array +
date-of-birth
+
+ number + or + string + or + array +
+ <date-time>
- <date-time>
+
-
-
-
-
-
+
+
-
name
- string +
+
name
+ string +
+
-
-
-
-
-
+
+
-
id
- number - <float> +
+
id
+ number + <float> +
+
-
-
-
-
-
+
+
-
notype
- <date-time> +
+
notype
+ <date-time> +
+
-
-
-
-
-
+
+
-
-
permissions
+
- string - or - object +
permissions
+
+ string + or + object +
+ <password>
-
{1}
- <password>
+
-
-
-
-
-
+
+
-
ids
- array[integer] +
+
ids
+ array of integers +
+
-
@@ -3729,158 +3452,155 @@ exports[`HTML Output should match formats-schema.json 1`] = ` `; exports[`HTML Output should match references/base.json 1`] = ` -"
-
-
+"
+
+
-
- object -
{2}
+
+
object
+
-
-
-
-
-
+
+
-
-
billing_address
- object -
{3}
+
+
+
billing_address
+ object +
+
-
-
-
-
-
+
+
-
street_address
- string +
+
street_address
+ string +
+ required
- required
+
-
-
-
-
-
+
+
-
city
- string +
+
city
+ string +
+ required
- required
+
-
-
-
-
-
+
+
-
state
- string +
+
state
+ string +
+ required
- required
+
-
-
-
-
-
+
+
-
-
shipping_address
- object -
{3}
+
+
+
shipping_address
+ object +
+
-
-
-
-
-
+
+
-
street_address
- string +
+
street_address
+ string +
+ required
- required
+
-
-
-
-
-
+
+
-
city
- string +
+
city
+ string +
+ required
- required
+
-
-
-
-
-
+
+
-
state
- string +
+
state
+ string +
+ required
- required
+
-
@@ -3892,36 +3612,35 @@ exports[`HTML Output should match references/base.json 1`] = ` `; exports[`HTML Output should match references/nullish.json 1`] = ` -"
-
-
+"
+
+
-
- object -
{1}
+
+
object
+
-
-
-
-
-
+
+
-
empty-ref
- $ref +
+
empty-ref
+ $ref +
+
-
@@ -3931,376 +3650,372 @@ exports[`HTML Output should match references/nullish.json 1`] = ` `; exports[`HTML Output should match tickets.schema.json 1`] = ` -"
-
-
+"
+
+
-
- object -
{3}
+
+
object
-
-
-
- This section allows the selection of the ticketing options for all sales of the order. +
+
+ This section allows the selection of the ticketing options for all sales of the order. +
+
-
-
-
-
-
+
+
-
-
availableTicketingOptions
- $ref(../TicketingOptionInfo/TicketingOptionInfo.v1-0.yaml)[] -
{1}
+
+
+
availableTicketingOptions
+ $ref(../TicketingOptionInfo/TicketingOptionInfo.v1-0.yaml)[] +
+
+
+
List of ticketing options of the order.
-
-
List of ticketing options of the order.
-
+
-
-
-
-
-
+
+
-
../TicketingOptionInfo/TicketingOptionInfo.v1-0.yaml
+
+
../TicketingOptionInfo/TicketingOptionInfo.v1-0.yaml
+
+
-
-
-
-
-
+
+
-
commonTicketingOptions
- array[string] +
+
commonTicketingOptions
+ array of strings +
-
-
-
- Common ticketing options to all order items. +
+
+ Common ticketing options to all order items. +
+
-
-
-
-
-
+
+
-
-
ticketingOptionChoice
- array[object] -
{2}
+
+
+
ticketingOptionChoice
+ array of objects +
+
+
+
+ Ticketing option selection per order item. +
-
-
-
Ticketing option selection per order item.
+
-
-
-
-
-
+
+
-
state
- string +
+
state
+ string +
+
+
+
+ The status that addresses if a specific ticket option is active or not. The status active is + used before ticketing or before exchange confirmation. After ticketing, the status changes in + completed. This allows to store ticketing options already used at ticketing time and to clean up + all non selected options after ticketing or exchanged confirmation. +
-
- The status that addresses if a specific ticket option is active or not. The status active is used - before ticketing or before exchange confirmation. After ticketing, the status changes in - completed. This allows to store ticketing options already used at ticketing time and to clean up - all non selected options after ticketing or exchanged confirmation. -
+ Allowed values: + \\"COMPLETED\\" + \\"ACTIVE\\" +
+
+ Default value: + \\"ACTIVE\\"
-
- Allowed values: - \\"COMPLETED\\" - \\"ACTIVE\\" -
-
- Default value: - \\"ACTIVE\\" -
+
-
-
-
-
-
+
+
-
-
orderItemBreakdown
- array[object] -
{2}
+
+
+
orderItemBreakdown
+ array of objects +
-
-
-
- Structure that contains ticketing options per order item. +
+
+ Structure that contains ticketing options per order item. +
+
-
-
-
-
-
+
+
-
orderItemId
- string - <uuid> +
+
orderItemId
+ string + <uuid> +
+
-
-
-
-
-
+
+
-
-
options
- array[object] -
{4}
+
+
+
options
+ array of objects +
-
-
-
- Available ticketing options for a given order item. +
+
+ Available ticketing options for a given order item. +
+
-
-
-
-
-
+
+
-
title
- string +
+
title
+ string +
+ read-only +
+
+
Ticketing option short-description.
- read-only
-
Ticketing option short-description.
+ Allowed values: + \\"HOMEPRINT\\" + \\"TICKETLESS\\" + \\"PRINT_AT_KIOSK\\" + \\"SECURE_PAPER\\"
-
- Allowed values: - \\"HOMEPRINT\\" - \\"TICKETLESS\\" - \\"PRINT_AT_KIOSK\\" - \\"SECURE_PAPER\\" -
+
-
-
-
-
-
+
+
-
selected
- boolean +
+
selected
+ boolean +
-
-
-
- Flag to specify which ticketing option is selected. Only one option is allowed to be - selected. +
+
+ Flag to specify which ticketing option is selected. Only one option is allowed to be + selected. +
+
example
-
example
+
-
-
-
-
-
+
+
-
additionalRequiredInfo
- string +
+
additionalRequiredInfo
+ string +
-
-
-
- Additional passenger required info specific to the given ticketing option. +
+
+ Additional passenger required info specific to the given ticketing option. +
+
-
-
-
-
-
+
+
-
-
deliveryInfo
- object -
{5}
+
+
+
deliveryInfo
+ object +
+
Data for ticket delivery.
-
Data for ticket delivery.
+
-
-
-
-
-
+
+
-
availableDeliveryTypes
- array[string] +
+
availableDeliveryTypes
+ array of strings +
+
-
-
-
-
-
+
+
-
ticketRecipients
- array[string] +
+
ticketRecipients
+ array of strings +
+
-
-
-
-
-
+
+
-
ccEmail
- string - <email> +
+
ccEmail
+ string + <email> +
+
-
-
-
-
-
+
+
-
postalAddress
- ../Address/Address.v0-1.yaml +
+
postalAddress
+ ../Address/Address.v0-1.yaml +
+
-
-
-
-
-
+
+
-
pickUpAtStation
- string +
+
pickUpAtStation
+ string +
-
-
-
- The name of the Station in case you select pick up at station as a delivery type +
+
+ The name of the Station in case you select pick up at station as a delivery type +
+
-
diff --git a/src/__tests__/index.spec.tsx b/src/__tests__/index.spec.tsx index 76889946..01b9e03b 100644 --- a/src/__tests__/index.spec.tsx +++ b/src/__tests__/index.spec.tsx @@ -236,21 +236,20 @@ describe('Expanded depth', () => { const wrapper = mountWithAutoUnmount(); expect(dumpDom(wrapper.getElement())).toMatchInlineSnapshot(` - "
-
-
+ "
+
+
-
- array[object] -
{1}
+
+
array of objects
+
-
@@ -262,38 +261,36 @@ describe('Expanded depth', () => { const wrapper = mountWithAutoUnmount(); expect(dumpDom(wrapper.getElement())).toMatchInlineSnapshot(` - "
-
-
+ "
+
+
-
- array[object] -
{1}
+
+
array of objects
+
-
-
-
-
-
+
+
-
-
foo
- array[object] -
{1}
+
+
+
foo
+ array of objects +
+
-
@@ -307,55 +304,52 @@ describe('Expanded depth', () => { const wrapper = mountWithAutoUnmount(); expect(dumpDom(wrapper.getElement())).toMatchInlineSnapshot(` - "
-
-
+ "
+
+
-
- array[object] -
{1}
+
+
array of objects
+
-
-
-
-
-
+
+
-
-
foo
- array[object] -
{1}
+
+
+
foo
+ array of objects +
+
-
-
-
-
-
+
+
-
-
bar
- object -
{1}
+
+
+
bar
+ object +
+
-
@@ -405,21 +399,20 @@ describe('Expanded depth', () => { const wrapper = mountWithAutoUnmount(); expect(dumpDom(wrapper.getElement())).toMatchInlineSnapshot(` - "
-
-
+ "
+
+
-
- array[object] -
{2}
+
+
array of objects
+
-
@@ -431,54 +424,52 @@ describe('Expanded depth', () => { const wrapper = mountWithAutoUnmount(); expect(dumpDom(wrapper.getElement())).toMatchInlineSnapshot(` - "
-
-
+ "
+
+
-
- array[object] -
{2}
+
+
array of objects
+
-
-
-
-
-
+
+
-
bar
- integer +
+
bar
+ integer +
+
-
-
-
-
-
+
+
-
-
foo
- array[object] -
{2}
+
+
+
foo
+ array of objects +
+
-
@@ -492,85 +483,83 @@ describe('Expanded depth', () => { const wrapper = mountWithAutoUnmount(); expect(dumpDom(wrapper.getElement())).toMatchInlineSnapshot(` - "
-
-
+ "
+
+
-
- array[object] -
{2}
+
+
array of objects
+
-
-
-
-
-
+
+
-
bar
- integer +
+
bar
+ integer +
+
-
-
-
-
-
+
+
-
-
foo
- array[object] -
{2}
+
+
+
foo
+ array of objects +
+
-
-
-
-
-
+
+
-
bar
- string +
+
bar
+ string +
+
-
-
-
-
-
+
+
-
foo
- number +
+
foo
+ number +
+
-
@@ -633,21 +622,20 @@ describe('Expanded depth', () => { const wrapper = mountWithAutoUnmount(); expect(dumpDom(wrapper.getElement())).toMatchInlineSnapshot(` - "
-
-
+ "
+
+
-
- object -
{2}
+
+
object
+
-
@@ -688,17 +676,19 @@ describe('$ref resolving', () => { }; expect(dumpDom()).toMatchInlineSnapshot(` - "
-
-
+ "
+
+
-
string
+
+
string
+
+
-
@@ -715,33 +705,32 @@ describe('$ref resolving', () => { }; expect(dumpDom()).toMatchInlineSnapshot(` - "
-
-
+ "
+
+
-
- $ref(#/foo)[] -
{1}
+
+
$ref(#/foo)[]
+
-
-
-
-
-
+
+
-
#/foo
+
+
#/foo
+
+
-
diff --git a/src/components/JsonSchemaViewer.tsx b/src/components/JsonSchemaViewer.tsx index 51c5e7ba..058f8415 100644 --- a/src/components/JsonSchemaViewer.tsx +++ b/src/components/JsonSchemaViewer.tsx @@ -1,5 +1,5 @@ import { isRegularNode, SchemaTree as JsonSchemaTree, SchemaTreeRefDereferenceFn } from '@stoplight/json-schema-tree'; -import { Box } from '@stoplight/mosaic'; +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'; @@ -61,13 +61,15 @@ const JsonSchemaViewerComponent: React.FC - - + + + + + ); }; diff --git a/src/components/SchemaRow.tsx b/src/components/SchemaRow/SchemaRow.tsx similarity index 56% rename from src/components/SchemaRow.tsx rename to src/components/SchemaRow/SchemaRow.tsx index c3560645..d2b4c60c 100644 --- a/src/components/SchemaRow.tsx +++ b/src/components/SchemaRow/SchemaRow.tsx @@ -7,17 +7,18 @@ import { SchemaNode, SchemaNodeKind, } from '@stoplight/json-schema-tree'; -import { Icon } from '@stoplight/mosaic'; +import { Icon, Select } from '@stoplight/mosaic'; import cn from 'classnames'; +import { last } from 'lodash'; import * as React from 'react'; -import { CARET_ICON_BOX_DIMENSION, CARET_ICON_SIZE, SCHEMA_ROW_OFFSET } from '../consts'; -import { useJSVOptionsContext } from '../contexts'; -import { isCombiner } from '../guards/isCombiner'; -import { calculateChildrenToShow, isFlattenableNode, isPropertyRequired } from '../tree'; -import { Caret, Description, Divider, Format, getValidationsFromSchema, Property, Validations } from './shared'; -import { ChildStack } from './shared/ChildStack'; -import { Properties } from './shared/Properties'; +import { CARET_ICON_BOX_DIMENSION, CARET_ICON_SIZE, SCHEMA_ROW_OFFSET } from '../../consts'; +import { useJSVOptionsContext } from '../../contexts'; +import { calculateChildrenToShow, isFlattenableNode, isPropertyRequired } from '../../tree'; +import { Caret, Description, Format, getValidationsFromSchema, Types, Validations } from '../shared'; +import { ChildStack } from '../shared/ChildStack'; +import { Properties } from '../shared/Properties'; +import { useChoices } from './useChoices'; export interface SchemaRowProps { schemaNode: SchemaNode; @@ -27,12 +28,15 @@ export interface SchemaRowProps { export const SchemaRow: React.FunctionComponent = ({ schemaNode, nestingLevel }) => { const description = isRegularNode(schemaNode) ? schemaNode.annotations.description : null; - const { defaultExpandedDepth, renderRowAddon } = useJSVOptionsContext(); + const { defaultExpandedDepth, renderRowAddon, onGoToRef } = useJSVOptionsContext(); const [isExpanded, setExpanded] = React.useState( !isMirroredNode(schemaNode) && nestingLevel <= defaultExpandedDepth, ); + const { selectedChoice, setSelectedChoice, choices } = useChoices(schemaNode); + const typeToShow = selectedChoice.type; + const refNode = React.useMemo(() => { if (isReferenceNode(schemaNode)) { return schemaNode; @@ -51,7 +55,7 @@ export const SchemaRow: React.FunctionComponent = ({ schemaNode, const isBrokenRef = typeof refNode?.error === 'string'; - const childNodes = React.useMemo(() => calculateChildrenToShow(schemaNode), [schemaNode]); + const childNodes = React.useMemo(() => calculateChildrenToShow(typeToShow), [typeToShow]); return (
@@ -61,7 +65,7 @@ export const SchemaRow: React.FunctionComponent = ({ schemaNode, onClick={childNodes.length > 0 ? () => setExpanded(!isExpanded) : undefined} className={cn({ 'sl-cursor-pointer': childNodes.length > 0 })} > -
+
{childNodes.length > 0 ? ( = ({ schemaNode, /> ) : null} - {schemaNode.subpath.length > 0 && - isCombiner(schemaNode.subpath[0]) && - schemaNode.parent?.children?.indexOf(schemaNode as any) !== 0 && ( - +
+ {schemaNode.subpath.length > 0 && shouldShowPropertyName(schemaNode) && ( +
{last(schemaNode.subpath)}
+ )} + + {choices.length === 1 && ( + <> + + + )} -
- - + {onGoToRef && isReferenceNode(schemaNode) && schemaNode.external ? ( + { + e.preventDefault(); + e.stopPropagation(); + onGoToRef(schemaNode); + }} + > + (go to ref) + + ) : null} + + {schemaNode.subpath.length > 1 && schemaNode.subpath[0] === 'patternProperties' ? ( +
(pattern property)
+ ) : null} + {choices.length > 1 && ( +
"`, ); }); @@ -200,8 +163,8 @@ describe('Property component', () => { }; const wrapper = render(schema); - expect(wrapper).toHaveHTML( - 'array[object]
{3}
', + expect(wrapper.html()).toMatchInlineSnapshot( + `"
array of objects
foo
bar
baz
"`, ); }); @@ -235,13 +198,13 @@ describe('Property component', () => { }; let wrapper = render(schema, ['properties', 'array-all-objects', 'items', 'properties', 'foo']); - expect(wrapper).toHaveHTML( - '
foo
string', + expect(wrapper.html()).toMatchInlineSnapshot( + `"
foo
string
"`, ); wrapper = render(schema, ['properties', 'array-all-objects', 'items', 'properties', 'bar']); - expect(wrapper).toHaveHTML( - '
bar
string', + expect(wrapper.html()).toMatchInlineSnapshot( + `"
bar
string
"`, ); }); @@ -259,8 +222,10 @@ describe('Property component', () => { const tree = buildTree(schema); - const wrapper = mount(); - expect(wrapper.find('div')).toHaveHTML('
foo
'); + const wrapper = mount(); + expect(wrapper.html()).toMatchInlineSnapshot( + `"
foo
object
"`, + ); wrapper.unmount(); }); }); @@ -278,7 +243,9 @@ describe('Property component', () => { }; const wrapper = render(schema); - expect(wrapper.find(Types)).toHaveHTML('User'); + expect(wrapper.find(Types).first().html()).toMatchInlineSnapshot( + `"User"`, + ); }); it('given array type with non-array items, should render title', () => { @@ -296,7 +263,9 @@ describe('Property component', () => { }; const wrapper = render(schema); - expect(wrapper.find(Types)).toHaveHTML('User[]'); + expect(wrapper.find(Types).first().html()).toMatchInlineSnapshot( + `"array of User-s"`, + ); }); it('given array with no items, should render title', () => { @@ -306,7 +275,9 @@ describe('Property component', () => { }; const wrapper = render(schema); - expect(wrapper.find(Types)).toHaveHTML('User'); + expect(wrapper.find(Types).first().html()).toMatchInlineSnapshot( + `"User"`, + ); }); it('given array with defined items, should not render title', () => { @@ -325,62 +296,9 @@ describe('Property component', () => { }; const wrapper = render(schema); - expect(wrapper.find(Types)).toHaveHTML('array'); + expect(wrapper.find(Types).first().html()).toMatchInlineSnapshot( + `"array"`, + ); }); }); - - it("no title for combiner's children", () => { - const schema: JSONSchema4 = { - type: 'object', - title: 'Account', - allOf: [ - { - type: 'object', - properties: { - type: { - type: 'string', - enum: ['admin', 'editor'], - }, - enabled: { - type: 'boolean', - description: 'Is this account enabled', - }, - }, - required: ['type'], - }, - ], - oneOf: [ - { - type: 'object', - title: 'Admin', - properties: { - root: { - type: 'boolean', - }, - group: { - type: 'string', - }, - expirationDate: { - type: 'string', - }, - }, - }, - { - type: 'object', - title: 'Editor', - properties: { - supervisor: { - type: 'string', - }, - key: { - type: 'string', - }, - }, - }, - ], - }; - - const wrapper = render(schema); - expect(wrapper.children().first()).toEqual(wrapper.find(Types)); - }); }); diff --git a/src/components/shared/index.ts b/src/components/shared/index.ts index 8ac6dd5b..676fbd43 100644 --- a/src/components/shared/index.ts +++ b/src/components/shared/index.ts @@ -1,7 +1,5 @@ export * from './Caret'; export * from './Description'; -export * from './Divider'; export * from './Format'; -export * from './Property'; export * from './Types'; export * from './Validations'; diff --git a/src/tree/utils.ts b/src/tree/utils.ts index 7d3d35fb..c8a0bf28 100644 --- a/src/tree/utils.ts +++ b/src/tree/utils.ts @@ -1,9 +1,23 @@ -import { isReferenceNode, isRegularNode, SchemaNode, SchemaNodeKind } from '@stoplight/json-schema-tree'; +import { + isReferenceNode, + isRegularNode, + MirroredSchemaNode, + ReferenceNode, + RegularNode, + SchemaNode, + SchemaNodeKind, +} from '@stoplight/json-schema-tree'; import { isNonNullable } from '../guards/isNonNullable'; import { ComplexArrayNode, FlattenableNode, PrimitiveArrayNode } from './types'; -export const isParentNode = (node: SchemaNode) => isRegularNode(node) && !!node.children && node.children.length > 0; +export type ChildNode = RegularNode | ReferenceNode | MirroredSchemaNode; + +export const isNonEmptyParentNode = ( + node: SchemaNode, +): node is RegularNode & { + children: ChildNode[] & { 0: ChildNode }; +} => isRegularNode(node) && !!node.children && node.children.length > 0; export function isFlattenableNode(node: SchemaNode): node is FlattenableNode { if (!isRegularNode(node)) return false; diff --git a/src/utils/printName.ts b/src/utils/printName.ts index 3504758c..f31c84d1 100644 --- a/src/utils/printName.ts +++ b/src/utils/printName.ts @@ -41,14 +41,19 @@ function printArrayName(schemaNode: RegularNode): string | null { return mergedTypes; }, []) ?? null; - return val !== null && val.length > 0 ? `${SchemaNodeKind.Array}[${val.join(',')}]` : null; + return val !== null && val.length > 0 ? `array of ${val.join('s/')}s` : 'array'; } if (isComplexArray(schemaNode)) { const firstChild = schemaNode.children[0]; - return firstChild.title !== null - ? `${firstChild.title}[]` - : `${SchemaNodeKind.Array}[${firstChild.primaryType ?? firstChild.combiners?.join(',')}]`; + if (firstChild.title) { + return `array of ${firstChild.title}-s`; + } else if (firstChild.primaryType) { + return `array of ${firstChild.primaryType}s`; + } else if (firstChild.combiners?.length) { + return `array of ${firstChild.combiners.join('/')}`; + } + return 'array'; } return null;