Skip to content

Commit 46abcdc

Browse files
casserniP0lip
authored andcommitted
feat: add mergeAllOf (#20)
* feat: add mergeAllOf * fix: tests
1 parent f7df910 commit 46abcdc

File tree

15 files changed

+702
-1461
lines changed

15 files changed

+702
-1461
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
"@stoplight/tree-list": "^3.6.0",
4747
"@types/json-schema": "^7.0.3",
4848
"lodash": "4.17.x",
49-
"mobx": "^5.9.4"
49+
"mobx": "^5.9.4",
50+
"json-schema-merge-allof": "^0.6.0"
5051
},
5152
"devDependencies": {
5253
"@sambego/storybook-state": "^1.3.4",
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"AllOfMergeObjects": {
5+
"allOf": [
6+
{
7+
"properties": {
8+
"Object1Property": {
9+
"type": "string",
10+
"minLength": 1,
11+
"x-val": "lol"
12+
}
13+
}
14+
},
15+
{
16+
"properties": {
17+
"Object2Property": {
18+
"type": "number",
19+
"maximum": 2
20+
}
21+
}
22+
}
23+
],
24+
"type": "object"
25+
},
26+
"AllOfMergeValidations": {
27+
"allOf": [
28+
{
29+
"minLength": 1
30+
},
31+
{
32+
"maxLength": 2
33+
}
34+
],
35+
"type": "string"
36+
},
37+
"AllOfMergeTakeMoreLogicalValidation": {
38+
"allOf": [
39+
{
40+
"maximum": 1
41+
},
42+
{
43+
"maximum": 2
44+
}
45+
],
46+
"type": "number"
47+
},
48+
"AllOfMergeObjectPropertyValidations": {
49+
"allOf": [
50+
{
51+
"properties": {
52+
"Property": {
53+
"type": "string",
54+
"minLength": 1
55+
}
56+
}
57+
},
58+
{
59+
"properties": {
60+
"Property": {
61+
"type": "string",
62+
"maxLength": 2
63+
}
64+
}
65+
}
66+
],
67+
"type": "object"
68+
},
69+
"AllOfMergeRemovesUnresolvedRefs": {
70+
"allOf": [
71+
{
72+
"type": "object",
73+
"properties": {
74+
"street_address": {
75+
"type": "string"
76+
},
77+
"city": {
78+
"type": "string"
79+
},
80+
"state": {
81+
"type": "string"
82+
}
83+
},
84+
"required": ["street_address", "city", "state"]
85+
},
86+
{ "$ref": "#/definitions/ref1" }
87+
]
88+
}
89+
}
90+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
{
2+
"type": "object",
3+
"properties": {
4+
"AllOfMergeObjects": {
5+
"allOf": [
6+
{
7+
"properties": {
8+
"Object1Property": {
9+
"type": "string",
10+
"minLength": 1,
11+
"x-val": "lol"
12+
}
13+
}
14+
},
15+
{
16+
"properties": {
17+
"Object2Property": {
18+
"type": "number",
19+
"maximum": 2
20+
}
21+
}
22+
}
23+
],
24+
"type": "object"
25+
},
26+
"AllOfMergeValidations": {
27+
"allOf": [
28+
{
29+
"minLength": 1
30+
},
31+
{
32+
"maxLength": 2
33+
}
34+
],
35+
"type": "string"
36+
},
37+
"AllOfMergeTakeMoreLogicalValidation": {
38+
"allOf": [
39+
{
40+
"maximum": 1
41+
},
42+
{
43+
"maximum": 2
44+
}
45+
],
46+
"type": "number"
47+
},
48+
"AllOfMergeObjectPropertyValidations": {
49+
"allOf": [
50+
{
51+
"properties": {
52+
"Property": {
53+
"type": "string",
54+
"minLength": 1
55+
}
56+
}
57+
},
58+
{
59+
"properties": {
60+
"Property": {
61+
"type": "string",
62+
"maxLength": 2
63+
}
64+
}
65+
}
66+
],
67+
"type": "object"
68+
},
69+
"AllOfMergeRefs": {
70+
"allOf": [
71+
{ "$ref": "#/definitions/ref1" },
72+
{
73+
"type": "object",
74+
"properties": {
75+
"zipCode": {
76+
"type": "string"
77+
}
78+
}
79+
}
80+
]
81+
}
82+
},
83+
84+
"definitions": {
85+
"ref1": {
86+
"type": "object",
87+
"properties": {
88+
"street_address": {
89+
"type": "string"
90+
},
91+
"city": {
92+
"type": "string"
93+
},
94+
"state": {
95+
"type": "string"
96+
}
97+
},
98+
"required": ["street_address", "city", "state"]
99+
},
100+
"ref2": {
101+
"type": "object",
102+
"properties": {
103+
"firstName": {
104+
"type": "string"
105+
},
106+
"lastName": {
107+
"type": "string"
108+
}
109+
}
110+
}
111+
}
112+
}

src/__fixtures__/array-of-objects.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
},
66
"properties": {
77
"propertyIsArrayOfObjects": {
8-
"type": [
9-
"array"
10-
],
8+
"type": ["array"],
119
"items": {
1210
"type": "object",
1311
"properties": {

src/__fixtures__/combiner-schema.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
"maximum": 1000000
1717
},
1818
"completed_at": {
19-
"type": [
20-
"string",
21-
"null"
22-
],
19+
"type": ["string", "null"],
2320
"format": "date-time"
2421
},
2522
"created_at": {
@@ -31,9 +28,7 @@
3128
"format": "date-time"
3229
}
3330
},
34-
"required": [
35-
"id"
36-
]
31+
"required": ["id"]
3732
}
3833
],
3934
"type": "object"

src/__fixtures__/default-schema.json

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,9 @@
1616
"format": "date-time"
1717
},
1818
"items": {
19-
"type": [
20-
"null",
21-
"array"
22-
],
19+
"type": ["null", "array"],
2320
"items": {
24-
"type": [
25-
"string",
26-
"number"
27-
]
21+
"type": ["string", "number"]
2822
}
2923
},
3024
"email": {
@@ -44,10 +38,7 @@
4438
"type": "string"
4539
}
4640
},
47-
"required": [
48-
"foo",
49-
"bar"
50-
]
41+
"required": ["foo", "bar"]
5142
},
5243
{
5344
"type": "array",
@@ -58,10 +49,7 @@
5849
]
5950
},
6051
"permissions": {
61-
"type": [
62-
"string",
63-
"object"
64-
],
52+
"type": ["string", "object"],
6553
"properties": {
6654
"ids": {
6755
"type": "array",
@@ -80,9 +68,5 @@
8068
"foo": { "type": "integer" },
8169
"_name$": { "type": "string" }
8270
},
83-
"required": [
84-
"name",
85-
"age",
86-
"completed_at"
87-
]
71+
"required": ["name", "age", "completed_at"]
8872
}

0 commit comments

Comments
 (0)