diff --git a/package.json b/package.json index 1afcf090..e60bd5ef 100644 --- a/package.json +++ b/package.json @@ -83,8 +83,9 @@ "eslint-plugin-react": "^7.21.5", "eslint-plugin-react-hooks": "^4.2.0", "eslint-plugin-simple-import-sort": "^5.0.2", + "fast-glob": "^3.2.4", "jest": "^26.6.2", - "jest-enzyme": "7.1.2", + "jest-enzyme": "^7.1.2", "mobx": "^5.13.0", "prettier": "^2.2.1", "react": "^16.14.0", diff --git a/src/__fixtures__/allOf/allOf-resolved.json b/src/__fixtures__/allOf/allOf-resolved.json deleted file mode 100644 index aa0e6446..00000000 --- a/src/__fixtures__/allOf/allOf-resolved.json +++ /dev/null @@ -1,90 +0,0 @@ -{ - "type": "object", - "properties": { - "AllOfMergeObjects": { - "allOf": [ - { - "properties": { - "Object1Property": { - "type": "string", - "minLength": 1, - "x-val": "lol" - } - } - }, - { - "properties": { - "Object2Property": { - "type": "number", - "maximum": 2 - } - } - } - ], - "type": "object" - }, - "AllOfMergeValidations": { - "allOf": [ - { - "minLength": 1 - }, - { - "maxLength": 2 - } - ], - "type": "string" - }, - "AllOfMergeTakeMoreLogicalValidation": { - "allOf": [ - { - "maximum": 1 - }, - { - "maximum": 2 - } - ], - "type": "number" - }, - "AllOfMergeObjectPropertyValidations": { - "allOf": [ - { - "properties": { - "Property": { - "type": "string", - "minLength": 1 - } - } - }, - { - "properties": { - "Property": { - "type": "string", - "maxLength": 2 - } - } - } - ], - "type": "object" - }, - "AllOfMergeRemovesUnresolvedRefs": { - "allOf": [ - { - "type": "object", - "properties": { - "street_address": { - "type": "string" - }, - "city": { - "type": "string" - }, - "state": { - "type": "string" - } - }, - "required": ["street_address", "city", "state"] - }, - { "$ref": "#/definitions/ref1" } - ] - } - } -} diff --git a/src/__fixtures__/array-of-allofs.json b/src/__fixtures__/arrays/of-allofs.json similarity index 100% rename from src/__fixtures__/array-of-allofs.json rename to src/__fixtures__/arrays/of-allofs.json diff --git a/src/__fixtures__/arrays/of-arrays.json b/src/__fixtures__/arrays/of-arrays.json new file mode 100644 index 00000000..58891b18 --- /dev/null +++ b/src/__fixtures__/arrays/of-arrays.json @@ -0,0 +1,17 @@ +{ + "type": "array", + "items": { + "type": "object", + "properties": { + "bar": { + "type": "integer" + }, + "foo": { + "type": "array", + "items": { + "type": "array" + } + } + } + } +} diff --git a/src/__fixtures__/array-of-objects.json b/src/__fixtures__/arrays/of-objects.json similarity index 100% rename from src/__fixtures__/array-of-objects.json rename to src/__fixtures__/arrays/of-objects.json diff --git a/src/__fixtures__/array-of-refs.json b/src/__fixtures__/arrays/of-refs.json similarity index 100% rename from src/__fixtures__/array-of-refs.json rename to src/__fixtures__/arrays/of-refs.json diff --git a/src/__fixtures__/arrays/with-multiple-arrayish-items.json b/src/__fixtures__/arrays/with-multiple-arrayish-items.json new file mode 100644 index 00000000..e45d26da --- /dev/null +++ b/src/__fixtures__/arrays/with-multiple-arrayish-items.json @@ -0,0 +1,26 @@ +{ + "type": "array", + "items": [ + { + "type": "number" + }, + { + "type": "object", + "properties": { + "code": { + "type": "number" + }, + "msg": { + "type": "string" + }, + "ref": { + "type": "string" + } + }, + "required": [ + "code", + "msg" + ] + } + ] +} diff --git a/src/__fixtures__/arrays/with-ordered-items.json b/src/__fixtures__/arrays/with-ordered-items.json new file mode 100644 index 00000000..0273e023 --- /dev/null +++ b/src/__fixtures__/arrays/with-ordered-items.json @@ -0,0 +1,11 @@ +{ + "type": "array", + "items": [ + { + "type": "number" + }, + { + "type": "string" + } + ] +} diff --git a/src/__fixtures__/arrays/with-single-arrayish-items.json b/src/__fixtures__/arrays/with-single-arrayish-items.json new file mode 100644 index 00000000..f15e8d3d --- /dev/null +++ b/src/__fixtures__/arrays/with-single-arrayish-items.json @@ -0,0 +1,23 @@ +{ + "type": "array", + "items": [ + { + "type": "object", + "properties": { + "code": { + "type": "number" + }, + "msg": { + "type": "string" + }, + "ref": { + "type": "string" + } + }, + "required": [ + "code", + "msg" + ] + } + ] +} diff --git a/src/__fixtures__/allOf/allOf-schema.json b/src/__fixtures__/combiners/allOfs/base.json similarity index 100% rename from src/__fixtures__/allOf/allOf-schema.json rename to src/__fixtures__/combiners/allOfs/base.json diff --git a/src/__fixtures__/complex-allOf-model.json b/src/__fixtures__/combiners/allOfs/complex.json similarity index 100% rename from src/__fixtures__/complex-allOf-model.json rename to src/__fixtures__/combiners/allOfs/complex.json diff --git a/src/__fixtures__/combiner-schema.json b/src/__fixtures__/combiners/allOfs/todo-full-2.json similarity index 100% rename from src/__fixtures__/combiner-schema.json rename to src/__fixtures__/combiners/allOfs/todo-full-2.json diff --git a/src/__fixtures__/todo-allof.schema.json b/src/__fixtures__/combiners/allOfs/todo-full.json similarity index 100% rename from src/__fixtures__/todo-allof.schema.json rename to src/__fixtures__/combiners/allOfs/todo-full.json diff --git a/src/__fixtures__/allof-with-type.json b/src/__fixtures__/combiners/allOfs/with-type.json similarity index 100% rename from src/__fixtures__/allof-with-type.json rename to src/__fixtures__/combiners/allOfs/with-type.json diff --git a/src/__fixtures__/oneof-with-array-type.json b/src/__fixtures__/combiners/oneof-with-array-type.json similarity index 100% rename from src/__fixtures__/oneof-with-array-type.json rename to src/__fixtures__/combiners/oneof-with-array-type.json diff --git a/src/__fixtures__/ref/resolved.json b/src/__fixtures__/ref/resolved.json deleted file mode 100644 index 796b3586..00000000 --- a/src/__fixtures__/ref/resolved.json +++ /dev/null @@ -1,65 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "definitions": { - "address": { - "type": "object", - "properties": { - "street_address": { - "type": "string" - }, - "city": { - "type": "string" - }, - "state": { - "type": "string" - } - }, - "required": [ - "street_address", - "city", - "state" - ] - } - }, - "type": "object", - "properties": { - "billing_address": { - "type": "object", - "properties": { - "street_address": { - "type": "string" - }, - "city": { - "type": "string" - }, - "state": { - "type": "string" - } - }, - "required": [ - "street_address", - "city", - "state" - ] - }, - "shipping_address": { - "type": "object", - "properties": { - "street_address": { - "type": "string" - }, - "city": { - "type": "string" - }, - "state": { - "type": "string" - } - }, - "required": [ - "street_address", - "city", - "state" - ] - } - } -} diff --git a/src/__fixtures__/ref/original.json b/src/__fixtures__/references/base.json similarity index 100% rename from src/__fixtures__/ref/original.json rename to src/__fixtures__/references/base.json diff --git a/src/__fixtures__/nullish-ref.schema.json b/src/__fixtures__/references/nullish.json similarity index 100% rename from src/__fixtures__/nullish-ref.schema.json rename to src/__fixtures__/references/nullish.json diff --git a/src/__tests__/__snapshots__/index.spec.tsx.snap b/src/__tests__/__snapshots__/index.spec.tsx.snap index de406367..830c5d95 100644 --- a/src/__tests__/__snapshots__/index.spec.tsx.snap +++ b/src/__tests__/__snapshots__/index.spec.tsx.snap @@ -1176,18 +1176,14 @@ exports[`HTML Output given write mode, should populate proper nodes 1`] = ` " `; -exports[`HTML Output should match allof-with-type.json 1`] = ` +exports[`HTML Output should match arrays/of-allofs.json 1`] = ` "
- oneOf - - -
An example model to demonstrate a bug.
-
-
+ Test +
{1}
@@ -1200,13 +1196,8 @@ exports[`HTML Output should match allof-with-type.json 1`] = `
- BugExample -
{6}
- - -
An example model to demonstrate a bug.
-
-
+
array-all-objects
+ array[object]
@@ -1216,31 +1207,174 @@ exports[`HTML Output should match allof-with-type.json 1`] = `
-
actionType
+
foo
+ string +
+
+
+
+
+
+
+
+
+
bar
string
+
+
+
+
+
+" +`; + +exports[`HTML Output should match arrays/of-arrays.json 1`] = ` +"
+
+
+
+
+ array[object] +
{2}
+
+
+
+
+
+
+
+
+
+
bar
+ integer +
+
+
+
+
+
+
+
+
+
foo
+ array +
{1}
+
+
+
+
+
+
+" +`; + +exports[`HTML Output should match arrays/of-objects.json 1`] = ` +"
+
+
+
+
+ object +
{1}
+
-
- required - +1 -
+
+1
+
+
+
+ + + +
+
propertyIsArrayOfObjects
+
array[object]
+
{1}
+
+
+
+
+
-
id
+
ArrayObjectProperty
string - - -
The identifier of the existing reservation.
-
-
+
+
+
+
+
+
+" +`; + +exports[`HTML Output should match arrays/of-refs.json 1`] = ` +"
+
+
+
+ + + +
$ref(./models/todo-full.json)[]
+
+
+
+
+
+" +`; + +exports[`HTML Output should match arrays/with-multiple-arrayish-items.json 1`] = ` +"
+
+
+
+
array
+
+
+
+
+
+
+
+
+
0
+ number +
+
+
+
+
+
+
+
+ + + +
+
1
+ object +
{3}
+
+
+
+
+
+
+
+
+
+
code
+ number
required
@@ -1250,10 +1384,10 @@ exports[`HTML Output should match allof-with-type.json 1`] = `
-
externalId
+
msg
string
-
+
required
@@ -1261,19 +1395,33 @@ exports[`HTML Output should match allof-with-type.json 1`] = `
-
calculateCosts
- boolean +
ref
+ string
+
+" +`; + +exports[`HTML Output should match arrays/with-ordered-items.json 1`] = ` +"
-
+
+
array
+
+
+
+
+
+
+
-
calculateDates
- boolean +
0
+ number
@@ -1281,12 +1429,26 @@ exports[`HTML Output should match allof-with-type.json 1`] = `
-
+
-
items
- array[string] +
1
+ string
-
required
+
+
+
+
+
+" +`; + +exports[`HTML Output should match arrays/with-single-arrayish-items.json 1`] = ` +"
+
+
+
+
array
+
@@ -1296,18 +1458,10 @@ exports[`HTML Output should match allof-with-type.json 1`] = ` -
-
or
-
-
- BugExample -
{6}
- - -
An example model to demonstrate a bug.
-
-
+
0
+ object +
{3}
@@ -1317,17 +1471,10 @@ exports[`HTML Output should match allof-with-type.json 1`] = `
-
actionType
- string +
code
+ number
- - -
- required - +1 -
-
-
+
required
@@ -1335,15 +1482,10 @@ exports[`HTML Output should match allof-with-type.json 1`] = `
-
id
+
msg
string - - -
The identifier of the existing reservation.
-
-
-
+
required
@@ -1351,19 +1493,429 @@ exports[`HTML Output should match allof-with-type.json 1`] = `
-
externalId
+
ref
string
+ +" +`; + +exports[`HTML Output should match combiners/allOfs/base.json 1`] = ` +"
+
+
+
+
+ object +
{5}
+
+
+
+
+
+
+
+
+ + + +
+
AllOfMergeObjects
+ object +
{2}
+
+
+
+
+
-
calculateCosts
- boolean +
Object1Property
+ string +
+ + +
+1
+
+
+
+
+
+
+
+
+
+
Object2Property
+ number +
+ + +
+1
+
+
+
+
+
+
+
+
+
+
AllOfMergeValidations
+ string +
+ + +
+2
+
+
+
+
+
+
+
+
+
+
AllOfMergeTakeMoreLogicalValidation
+ number +
+ + +
+1
+
+
+
+
+
+
+
+
+ + + +
+
AllOfMergeObjectPropertyValidations
+ object +
{1}
+
+
+
+
+
+
+
+
+
+
Property
+ string +
+ + +
+2
+
+
+
+
+
+
+
+
+ + + +
+
AllOfMergeRefs
+ object +
{4}
+
+
+
+
+
+
+
+
+
+
street_address
+ string +
+
required
+
+
+
+
+
+
+
+
city
+ string +
+
required
+
+
+
+
+
+
+
+
state
+ string +
+
required
+
+
+
+
+
+
+
+
zipCode
+ string +
+
+
+
+
+
+" +`; + +exports[`HTML Output should match combiners/allOfs/complex.json 1`] = ` +"
+
+
+
+
+ object +
{2}
+
+
+
+
+
+
+
+
+ + + +
+
foo
+ object +
{1}
+
+
+
+
+
+
+
+
+ + + +
+
user
+ allOf +
+
+
+
+
+
+
+
+ + + +
+ object +
{2}
+
+
+
+
+
+
+
+
+ + + +
+
names
+ + $ref(#/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/name)[] + +
+
+
+
+
+
+
+
+ + + +
+
users
+ array[object] +
{3}
+
+
+
+
+
+
+
+
+ + + +
+
creation
+ #/allOf/0/allOf/0/properties/foo +
+
+
+
+
+
+
+
+ + + +
+
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 + +
+
+
+
+
+
+
+
+ + + +
+
bar
+ object +
{1}
+
+
+
+
+
+
+
+
+ + + +
+
foo
+ object +
{1}
+
+
+
+
+
+
+
+
+ + + +
+
user
+ allOf +
+
+
+
+
+
+
+
+ + + +
+ object +
{2}
+
+
+
+
+
+
+
+
+ + + +
+
names
+ + $ref(#/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/name)[] + +
+
+
+
+
+
+
+
+ + + +
+
users
+ array[object] +
{3}
+
+
+
+
+
+
+
+
+ + + +
+
creation
+ #/allOf/0/allOf/0/properties/foo
@@ -1371,10 +1923,15 @@ exports[`HTML Output should match allof-with-type.json 1`] = `
-
+
+ + +
-
calculateDates
- boolean +
foo
+ + #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts +
@@ -1382,12 +1939,17 @@ exports[`HTML Output should match allof-with-type.json 1`] = `
-
+
+ + +
-
items
- array[string] +
products
+ + #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts +
-
required
+
@@ -1395,14 +1957,22 @@ exports[`HTML Output should match allof-with-type.json 1`] = ` " `; -exports[`HTML Output should match array-of-allofs.json 1`] = ` +exports[`HTML Output should match combiners/allOfs/todo-full.json 1`] = ` "
+
Todo Full
+
+
+
+
+
+
+
- Test -
{1}
+
name
+ string
@@ -1411,12 +1981,13 @@ exports[`HTML Output should match array-of-allofs.json 1`] = `
- - -
-
array-all-objects
- array[object] +
completed
+
+ boolean + or + null +
@@ -1424,10 +1995,30 @@ exports[`HTML Output should match array-of-allofs.json 1`] = `
-
+
-
foo
- string +
id
+ integer +
+ + +
+2
+
+
+
+
+
+
+
+
+
+
completed_at
+
+ string + or + null +
+ <date-time>
@@ -1435,33 +2026,25 @@ exports[`HTML Output should match array-of-allofs.json 1`] = `
-
+
-
bar
+
created_at
string + <date-time>
-
-" -`; - -exports[`HTML Output should match array-of-objects.json 1`] = ` -"
-
+
- object -
{1}
+
updated_at
+ string + <date-time>
- - -
+1
-
-
+
@@ -1472,9 +2055,9 @@ exports[`HTML Output should match array-of-objects.json 1`] = `
-
propertyIsArrayOfObjects
-
array[object]
-
{1}
+
user
+ User +
{2}
@@ -1484,27 +2067,33 @@ exports[`HTML Output should match array-of-objects.json 1`] = `
-
ArrayObjectProperty
+
name
string + + +
The user's full name.
+
+
-
+
required
-
-" -`; - -exports[`HTML Output should match array-of-refs.json 1`] = ` -"
-
- - +
+
+
age
+ number +
+ + +
+ required + +2 +
+
-
$ref(./models/todo-full.json)[]
-
@@ -1512,7 +2101,7 @@ exports[`HTML Output should match array-of-refs.json 1`] = ` " `; -exports[`HTML Output should match combiner-schema.json 1`] = ` +exports[`HTML Output should match combiners/allOfs/todo-full-2.json 1`] = ` "
@@ -1598,14 +2187,18 @@ exports[`HTML Output should match combiner-schema.json 1`] = ` " `; -exports[`HTML Output should match complex-allOf-model.json 1`] = ` +exports[`HTML Output should match combiners/allOfs/with-type.json 1`] = ` "
- object -
{2}
+ oneOf + + +
An example model to demonstrate a bug.
+
+
@@ -1618,9 +2211,13 @@ exports[`HTML Output should match complex-allOf-model.json 1`] = `
-
foo
- object -
{1}
+ BugExample +
{6}
+ + +
An example model to demonstrate a bug.
+
+
@@ -1629,12 +2226,43 @@ exports[`HTML Output should match complex-allOf-model.json 1`] = `
- - +
+
actionType
+ string +
+ + +
+ required + +1 +
+
+
+
+
+
+
+
-
user
- allOf +
id
+ string + + +
The identifier of the existing reservation.
+
+
+
+
required
+
+
+
+
+
+
+
+
externalId
+ string
@@ -1642,13 +2270,10 @@ exports[`HTML Output should match complex-allOf-model.json 1`] = `
-
- - - +
- object -
{2}
+
calculateCosts
+ boolean
@@ -1656,14 +2281,43 @@ exports[`HTML Output should match complex-allOf-model.json 1`] = `
-
+
+
+
calculateDates
+ boolean +
+
+
+
+
+
+
+
+
+
items
+ array[string] +
+
required
+
+
+
+
+
+
- + +
+
or
+
+
-
names
- - $ref(#/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/name)[] + BugExample +
{6}
+ + +
An example model to demonstrate a bug.
+
@@ -1672,28 +2326,33 @@ exports[`HTML Output should match complex-allOf-model.json 1`] = `
-
- - +
+
+
actionType
+ string +
+ + +
+ required + +1 +
+
-
-
users
- array[object] -
{3}
-
-
-
- - - +
-
creation
- #/allOf/0/allOf/0/properties/foo +
id
+ string + + +
The identifier of the existing reservation.
+
+
@@ -1701,15 +2360,10 @@ exports[`HTML Output should match complex-allOf-model.json 1`] = `
-
- - - +
-
foo
- - #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts - +
externalId
+ string
@@ -1717,15 +2371,10 @@ exports[`HTML Output should match complex-allOf-model.json 1`] = `
-
- - - +
-
products
- - #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts - +
calculateCosts
+ boolean
@@ -1733,14 +2382,10 @@ exports[`HTML Output should match complex-allOf-model.json 1`] = `
-
- - - +
-
bar
- object -
{1}
+
calculateDates
+ boolean
@@ -1749,40 +2394,36 @@ exports[`HTML Output should match complex-allOf-model.json 1`] = `
- - -
-
foo
- object -
{1}
+
items
+ array[string]
-
+
required
+
+" +`; + +exports[`HTML Output should match combiners/oneof-with-array-type.json 1`] = ` +"
-
- - - -
-
user
- allOf -
+
+
oneOf
-
+
- object + array[object]
{2}
@@ -1791,15 +2432,25 @@ exports[`HTML Output should match complex-allOf-model.json 1`] = `
-
- - - +
-
names
- - $ref(#/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/name)[] +
foo
+ string +
+ + +
+1
+
+
+
+
+
+
+
+
+
baz
+ integer
@@ -1807,12 +2458,15 @@ exports[`HTML Output should match complex-allOf-model.json 1`] = `
-
+
+
+
or
+
+
-
users
array[object]
{3}
@@ -1822,13 +2476,10 @@ exports[`HTML Output should match complex-allOf-model.json 1`] = `
-
- - - +
-
creation
- #/allOf/0/allOf/0/properties/foo +
foo
+ number
@@ -1836,15 +2487,10 @@ exports[`HTML Output should match complex-allOf-model.json 1`] = `
-
- - - +
-
foo
- - #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts - +
baz
+ integer
@@ -1852,15 +2498,10 @@ exports[`HTML Output should match complex-allOf-model.json 1`] = `
-
- - - +
-
products
- - #/allOf/0/allOf/0/properties/foo/definitions/event/allOf/0/properties/contacts - +
bar
+ string
@@ -2099,137 +2740,23 @@ exports[`HTML Output should match default-schema.json 1`] = `
-
-
foo
- integer -
(pattern property)
-
-
-
-
-
-
-
-
-
-
_name$
- string -
(pattern property)
-
-
-
-
-
-
-" -`; - -exports[`HTML Output should match formats-schema.json 1`] = ` -"
-
-
-
-
- model-with-formats -
{5}
-
-
-
-
-
-
-
-
-
-
date-of-birth
-
- number - or - string - or - array -
- <date-time> -
-
-
-
-
-
-
-
-
-
name
- string -
-
-
-
-
-
-
-
-
-
id
- number - <float> -
-
-
-
-
-
-
-
-
notype
-
-
-
-
-
-
-
- - - -
-
permissions
-
- string - or - object -
-
{1}
- <password> -
-
-
-
-
-
-
-
-
-
ids
- array[integer] +
+
foo
+ integer +
(pattern property)
-
-" -`; - -exports[`HTML Output should match nullish-ref.schema.json 1`] = ` -"
-
- - - -
$ref
+
+
+
_name$
+ string +
(pattern property)
+
@@ -2238,12 +2765,15 @@ exports[`HTML Output should match nullish-ref.schema.json 1`] = ` " `; -exports[`HTML Output should match oneof-with-array-type.json 1`] = ` +exports[`HTML Output should match formats-schema.json 1`] = ` "
-
oneOf
+
+ model-with-formats +
{5}
+
@@ -2251,12 +2781,16 @@ exports[`HTML Output should match oneof-with-array-type.json 1`] = `
- - -
- array[object] -
{2}
+
date-of-birth
+
+ number + or + string + or + array +
+ <date-time>
@@ -2264,26 +2798,11 @@ exports[`HTML Output should match oneof-with-array-type.json 1`] = `
-
+
-
foo
+
name
string
- - -
+1
-
-
-
-
-
-
-
-
-
-
baz
- integer -
@@ -2291,16 +2810,10 @@ exports[`HTML Output should match oneof-with-array-type.json 1`] = `
- - - -
-
or
-
-
- array[object] -
{3}
+
id
+ number + <float>
@@ -2308,21 +2821,27 @@ exports[`HTML Output should match oneof-with-array-type.json 1`] = `
-
-
-
foo
- number -
+
+
notype
-
+
+ + +
-
baz
- integer +
permissions
+
+ string + or + object +
+
{1}
+ <password>
@@ -2332,8 +2851,8 @@ exports[`HTML Output should match oneof-with-array-type.json 1`] = `
-
bar
- string +
ids
+ array[integer]
@@ -2343,7 +2862,7 @@ exports[`HTML Output should match oneof-with-array-type.json 1`] = ` " `; -exports[`HTML Output should match ref/original.json 1`] = ` +exports[`HTML Output should match references/base.json 1`] = ` "
@@ -2388,6 +2907,23 @@ exports[`HTML Output should match ref/original.json 1`] = ` " `; +exports[`HTML Output should match references/nullish.json 1`] = ` +"
+
+
+
+ + + +
$ref
+
+
+
+
+
+" +`; + exports[`HTML Output should match tickets.schema.json 1`] = ` "
@@ -2694,147 +3230,3 @@ exports[`HTML Output should match tickets.schema.json 1`] = `
" `; - -exports[`HTML Output should match todo-allof.schema.json 1`] = ` -"
-
-
-
-
Todo Full
-
-
-
-
-
-
-
-
-
name
- string -
-
-
-
-
-
-
-
-
-
completed
-
- boolean - or - null -
-
-
-
-
-
-
-
-
-
-
id
- integer -
- - -
+2
-
-
-
-
-
-
-
-
-
-
completed_at
-
- string - or - null -
- <date-time> -
-
-
-
-
-
-
-
-
-
created_at
- string - <date-time> -
-
-
-
-
-
-
-
-
-
updated_at
- string - <date-time> -
-
-
-
-
-
-
-
- - - -
-
user
- User -
{2}
-
-
-
-
-
-
-
-
-
-
name
- string - - -
The user's full name.
-
-
-
-
required
-
-
-
-
-
-
-
-
age
- number -
- - -
- required - +2 -
-
-
-
-
-
-
-" -`; diff --git a/src/__tests__/index.spec.tsx b/src/__tests__/index.spec.tsx index 9b2d524e..ad034fbe 100644 --- a/src/__tests__/index.spec.tsx +++ b/src/__tests__/index.spec.tsx @@ -1,3 +1,6 @@ +import 'jest-enzyme'; + +import * as fastGlob from 'fast-glob'; import * as fs from 'fs'; import { JSONSchema4 } from 'json-schema'; import * as path from 'path'; @@ -8,21 +11,12 @@ import { ViewMode } from '../types'; import { dumpDom } from './utils/dumpDom'; describe('HTML Output', () => { - it.each([ - 'ref/original.json', - 'allof-with-type.json', - 'array-of-allofs.json', - 'array-of-objects.json', - 'array-of-refs.json', - 'combiner-schema.json', - 'complex-allOf-model.json', - 'default-schema.json', - 'formats-schema.json', - 'nullish-ref.schema.json', - 'oneof-with-array-type.json', - 'todo-allof.schema.json', - 'tickets.schema.json', - ])('should match %s', filename => { + it.each( + fastGlob.sync('**/*.json', { + cwd: path.join(__dirname, '../__fixtures__'), + ignore: ['stress-schema.json'], + }), + )('should match %s', filename => { const schema = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../__fixtures__/', filename), 'utf8')); expect(dumpDom()).toMatchSnapshot(); @@ -186,3 +180,59 @@ describe('HTML Output', () => { expect(dumpDom()).toMatchSnapshot(); }); }); + +describe('$ref resolving', () => { + it('should render caret for schema with top-level $ref pointing at complex type', () => { + const schema: JSONSchema4 = { + $ref: '#/definitions/foo', + definitions: { + foo: { + type: 'string', + }, + }, + }; + + expect(dumpDom()).toMatchInlineSnapshot(` + "
+
+
+
+ + + +
#/definitions/foo
+
+
+
+
+
+ " + `); + }); + + it('should render caret for top-level array with $ref items', () => { + const schema: JSONSchema4 = { + type: 'array', + items: { + $ref: '#/foo', + }, + }; + + expect(dumpDom()).toMatchInlineSnapshot(` + "
+
+
+
+ + + +
$ref(#/foo)[]
+
+
+
+
+
+ " + `); + }); +}); diff --git a/src/tree/__tests__/__snapshots__/tree.spec.ts.snap b/src/tree/__tests__/__snapshots__/tree.spec.ts.snap index a5b08bf7..8dc55655 100644 --- a/src/tree/__tests__/__snapshots__/tree.spec.ts.snap +++ b/src/tree/__tests__/__snapshots__/tree.spec.ts.snap @@ -369,7 +369,7 @@ exports[`SchemaTree tree correctness given oneOf combiner placed next to allOf g " `; -exports[`SchemaTree tree correctness should match array-of-allofs.json 1`] = ` +exports[`SchemaTree tree correctness should match arrays/of-allofs.json 1`] = ` "└─ # ├─ type: object └─ children diff --git a/src/tree/__tests__/tree.spec.ts b/src/tree/__tests__/tree.spec.ts index 28c421ab..f8fd469d 100644 --- a/src/tree/__tests__/tree.spec.ts +++ b/src/tree/__tests__/tree.spec.ts @@ -775,7 +775,7 @@ describe('SchemaTree', () => { }); it('given very complex model with circular references, should bail out and display unmerged allOf', () => { - const schema = require('../../__fixtures__/complex-allOf-model.json'); + const schema = require('../../__fixtures__/combiners/allOfs/complex.json'); const tree = new SchemaTree(schema, new SchemaTreeState(), { expandedDepth: Infinity, @@ -1595,7 +1595,7 @@ describe('SchemaTree', () => { expect(tree.count).toEqual(mode === 'standalone' ? 3 : 2); }); - it.each(['array-of-allofs.json'])('should match %s', filename => { + it.each(['arrays/of-allofs.json'])('should match %s', filename => { const schema = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../__fixtures__', filename), 'utf8')); const tree = new SchemaTree(schema, new SchemaTreeState(), { expandedDepth: Infinity, diff --git a/yarn.lock b/yarn.lock index 89a623fd..78fb9870 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1784,11 +1784,10 @@ safe-stable-stringify "^1.1" "@stoplight/lifecycle@^2.2.1": - version "2.2.1" - resolved "https://registry.yarnpkg.com/@stoplight/lifecycle/-/lifecycle-2.2.1.tgz#bfa837d1dd3bd97eab96d8c8cf1bc3ea5ddcd263" - integrity sha512-XOyfoJyWp5tXRFWq43mvnOoYTvkupwqGjDQnQ2o1qRNnfTrE70bjNK5ptD9A6m3zajAXgbl0puFa7P2CMg7+ew== + version "2.3.2" + resolved "https://registry.yarnpkg.com/@stoplight/lifecycle/-/lifecycle-2.3.2.tgz#d61dff9ba20648241432e2daaef547214dc8976e" + integrity sha512-v0u8p27FA/eg04b4z6QXw4s0NeeFcRzyvseBW0+k/q4jtpg7EhVCqy42EbbbU43NTNDpIeQ81OcvkFz+6CYshw== dependencies: - strict-event-emitter-types "^2.0.0" wolfy87-eventemitter "~5.2.8" "@stoplight/markdown-viewer@^4.3.2": @@ -6977,6 +6976,18 @@ fast-glob@^3.1.1: merge2 "^1.3.0" micromatch "^4.0.2" +fast-glob@^3.2.4: + version "3.2.4" + resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.4.tgz#d20aefbf99579383e7f3cc66529158c9b98554d3" + integrity sha512-kr/Oo6PX51265qeuCYsyGypiO5uJFgBS0jksyG7FUeCyQzNwYnzrNIMR1NXfkZXsMYXYLRAHgISHBz8gQcxKHQ== + dependencies: + "@nodelib/fs.stat" "^2.0.2" + "@nodelib/fs.walk" "^1.2.3" + glob-parent "^5.1.0" + merge2 "^1.3.0" + micromatch "^4.0.2" + picomatch "^2.2.1" + fast-json-parse@^1.0.0: version "1.0.3" resolved "https://registry.yarnpkg.com/fast-json-parse/-/fast-json-parse-1.0.3.tgz#43e5c61ee4efa9265633046b770fb682a7577c4d" @@ -9175,7 +9186,7 @@ jest-environment-node@^26.6.2: jest-mock "^26.6.2" jest-util "^26.6.2" -jest-enzyme@7.1.2: +jest-enzyme@^7.1.2: version "7.1.2" resolved "https://registry.yarnpkg.com/jest-enzyme/-/jest-enzyme-7.1.2.tgz#91a10b2d3be1b56c0d65b34286e5bdc41ab4ba3d" integrity sha512-j+jkph3t5hGBS12eOldpfsnERYRCHi4c/0KWPMnqRPoJJXvCpLIc5th1MHl0xDznQDXVU0AHUXg3rqMrf8vGpA== @@ -12310,7 +12321,7 @@ performance-now@^2.1.0: resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b" integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns= -picomatch@^2.0.4, picomatch@^2.0.5, picomatch@^2.2.2: +picomatch@^2.0.4, picomatch@^2.0.5, picomatch@^2.2.1, picomatch@^2.2.2: version "2.2.2" resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.2.2.tgz#21f333e9b6b8eaff02468f5146ea406d345f4dad" integrity sha512-q0M/9eZHzmr0AulXyPwNfZjtwZ/RBZlbN3K3CErVrk50T2ASYI7Bye0EvekFY3IP1Nt2DHu0re+V2ZHIpMkuWg==