Skip to content

Commit 7fde139

Browse files
committed
add changeset and update the test
1 parent b642946 commit 7fde139

File tree

3 files changed

+203
-0
lines changed

3 files changed

+203
-0
lines changed

.changeset/angry-taxis-share.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@redocly/openapi-core": minor
3+
"@redocly/cli": minor
4+
---
5+
6+
Added JSON Schema format validation.

__tests__/lint/validate-schema-formats/openapi.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ components:
5050
- 09:00 # correct
5151
- incorrect
5252
- 09.00 # wrong type
53+
Oneof:
54+
type: string
55+
oneOf:
56+
- format: date
57+
- pattern: ^(month|year)ly$
58+
examples:
59+
- '2000-01-01' # correct
60+
- monthly # correct
61+
- wrong
5362

5463
examples:
5564
Date:
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`E2E lint validate-schema-formats 1`] = `
4+
5+
validating /openapi.yaml...
6+
[1] openapi.yaml:65:14 at #/components/examples/Date/value
7+
8+
Example value must conform to the schema: must match format "date-time".
9+
10+
63 | examples:
11+
64 | Date:
12+
65 | value: '2000-01-01'
13+
| ^^^^^^^^^^^^
14+
66 | DateTime:
15+
67 | value: '2000-01-01T12:00:00Z'
16+
17+
referenced from openapi.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json
18+
19+
Error was generated by the no-invalid-media-type-examples rule.
20+
21+
22+
[2] openapi.yaml:29:11 at #/components/schemas/Date/examples/1
23+
24+
Example value must conform to the schema: type must be string.
25+
26+
27 | examples:
27+
28 | - '2000-01-01' # correct
28+
29 | - 2000 # incorrect type
29+
| ^^^^
30+
30 | - incorrect
31+
31 | Email:
32+
33+
referenced from openapi.yaml:25:7 at #/components/schemas/Date
34+
35+
Error was generated by the no-invalid-schema-examples rule.
36+
37+
38+
[3] openapi.yaml:30:11 at #/components/schemas/Date/examples/2
39+
40+
Example value must conform to the schema: must match format "date".
41+
42+
28 | - '2000-01-01' # correct
43+
29 | - 2000 # incorrect type
44+
30 | - incorrect
45+
| ^^^^^^^^^
46+
31 | Email:
47+
32 | description: Email address for ticket purchaser.
48+
49+
referenced from openapi.yaml:25:7 at #/components/schemas/Date
50+
51+
Error was generated by the no-invalid-schema-examples rule.
52+
53+
54+
[4] openapi.yaml:37:11 at #/components/schemas/Email/examples/1
55+
56+
Example value must conform to the schema: must match format "email".
57+
58+
35 | examples:
59+
36 | - museum-lover@example.com # correct
60+
37 | - wrong.format
61+
| ^^^^^^^^^^^^
62+
38 | Id:
63+
39 | type: string
64+
65+
referenced from openapi.yaml:32:7 at #/components/schemas/Email
66+
67+
Error was generated by the no-invalid-schema-examples rule.
68+
69+
70+
[5] openapi.yaml:43:11 at #/components/schemas/Id/examples/1
71+
72+
Example value must conform to the schema: must match format "uuid".
73+
74+
41 | examples:
75+
42 | - 3be6453c-03eb-4357-ae5a-984a0e574a54 # correct
76+
43 | - incorrect
77+
| ^^^^^^^^^
78+
44 | - 42 # wrong type
79+
45 | Time:
80+
81+
referenced from openapi.yaml:39:7 at #/components/schemas/Id
82+
83+
Error was generated by the no-invalid-schema-examples rule.
84+
85+
86+
[6] openapi.yaml:44:11 at #/components/schemas/Id/examples/2
87+
88+
Example value must conform to the schema: type must be string.
89+
90+
42 | - 3be6453c-03eb-4357-ae5a-984a0e574a54 # correct
91+
43 | - incorrect
92+
44 | - 42 # wrong type
93+
| ^^
94+
45 | Time:
95+
46 | type: string
96+
97+
referenced from openapi.yaml:39:7 at #/components/schemas/Id
98+
99+
Error was generated by the no-invalid-schema-examples rule.
100+
101+
102+
[7] openapi.yaml:51:11 at #/components/schemas/Time/examples/1
103+
104+
Example value must conform to the schema: must match pattern "^([01]\\d|2[0-3]):?([0-5]\\d)$".
105+
106+
49 | examples:
107+
50 | - 09:00 # correct
108+
51 | - incorrect
109+
| ^^^^^^^^^
110+
52 | - 09.00 # wrong type
111+
53 | Oneof:
112+
113+
referenced from openapi.yaml:46:7 at #/components/schemas/Time
114+
115+
Error was generated by the no-invalid-schema-examples rule.
116+
117+
118+
[8] openapi.yaml:52:11 at #/components/schemas/Time/examples/2
119+
120+
Example value must conform to the schema: type must be string.
121+
122+
50 | - 09:00 # correct
123+
51 | - incorrect
124+
52 | - 09.00 # wrong type
125+
| ^^^^^
126+
53 | Oneof:
127+
54 | type: string
128+
129+
referenced from openapi.yaml:46:7 at #/components/schemas/Time
130+
131+
Error was generated by the no-invalid-schema-examples rule.
132+
133+
134+
[9] openapi.yaml:61:11 at #/components/schemas/Oneof/examples/2
135+
136+
Example value must conform to the schema: must match format "date".
137+
138+
59 | - '2000-01-01' # correct
139+
60 | - monthly # correct
140+
61 | - wrong
141+
| ^^^^^
142+
62 |
143+
63 | examples:
144+
145+
referenced from openapi.yaml:54:7 at #/components/schemas/Oneof
146+
147+
Error was generated by the no-invalid-schema-examples rule.
148+
149+
150+
[10] openapi.yaml:61:11 at #/components/schemas/Oneof/examples/2
151+
152+
Example value must conform to the schema: must match pattern "^(month|year)ly$".
153+
154+
59 | - '2000-01-01' # correct
155+
60 | - monthly # correct
156+
61 | - wrong
157+
| ^^^^^
158+
62 |
159+
63 | examples:
160+
161+
referenced from openapi.yaml:54:7 at #/components/schemas/Oneof
162+
163+
Error was generated by the no-invalid-schema-examples rule.
164+
165+
166+
[11] openapi.yaml:61:11 at #/components/schemas/Oneof/examples/2
167+
168+
Example value must conform to the schema: must match exactly one schema in oneOf.
169+
170+
59 | - '2000-01-01' # correct
171+
60 | - monthly # correct
172+
61 | - wrong
173+
| ^^^^^
174+
62 |
175+
63 | examples:
176+
177+
referenced from openapi.yaml:54:7 at #/components/schemas/Oneof
178+
179+
Error was generated by the no-invalid-schema-examples rule.
180+
181+
182+
/openapi.yaml: validated in <test>ms
183+
184+
❌ Validation failed with 11 errors.
185+
run \`redocly lint --generate-ignore-file\` to add all problems to the ignore file.
186+
187+
188+
`;

0 commit comments

Comments
 (0)