Skip to content

Commit

Permalink
add changeset and update the test
Browse files Browse the repository at this point in the history
  • Loading branch information
tatomyr committed Jan 23, 2025
1 parent b642946 commit 7fde139
Show file tree
Hide file tree
Showing 3 changed files with 203 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/angry-taxis-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@redocly/openapi-core": minor
"@redocly/cli": minor
---

Added JSON Schema format validation.
9 changes: 9 additions & 0 deletions __tests__/lint/validate-schema-formats/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ components:
- 09:00 # correct
- incorrect
- 09.00 # wrong type
Oneof:
type: string
oneOf:
- format: date
- pattern: ^(month|year)ly$
examples:
- '2000-01-01' # correct
- monthly # correct
- wrong

examples:
Date:
Expand Down
188 changes: 188 additions & 0 deletions __tests__/lint/validate-schema-formats/snapshot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`E2E lint validate-schema-formats 1`] = `
validating /openapi.yaml...
[1] openapi.yaml:65:14 at #/components/examples/Date/value
Example value must conform to the schema: must match format "date-time".
63 | examples:
64 | Date:
65 | value: '2000-01-01'
| ^^^^^^^^^^^^
66 | DateTime:
67 | value: '2000-01-01T12:00:00Z'
referenced from openapi.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json
Error was generated by the no-invalid-media-type-examples rule.
[2] openapi.yaml:29:11 at #/components/schemas/Date/examples/1
Example value must conform to the schema: type must be string.
27 | examples:
28 | - '2000-01-01' # correct
29 | - 2000 # incorrect type
| ^^^^
30 | - incorrect
31 | Email:
referenced from openapi.yaml:25:7 at #/components/schemas/Date
Error was generated by the no-invalid-schema-examples rule.
[3] openapi.yaml:30:11 at #/components/schemas/Date/examples/2
Example value must conform to the schema: must match format "date".
28 | - '2000-01-01' # correct
29 | - 2000 # incorrect type
30 | - incorrect
| ^^^^^^^^^
31 | Email:
32 | description: Email address for ticket purchaser.
referenced from openapi.yaml:25:7 at #/components/schemas/Date
Error was generated by the no-invalid-schema-examples rule.
[4] openapi.yaml:37:11 at #/components/schemas/Email/examples/1
Example value must conform to the schema: must match format "email".
35 | examples:
36 | - [email protected] # correct
37 | - wrong.format
| ^^^^^^^^^^^^
38 | Id:
39 | type: string
referenced from openapi.yaml:32:7 at #/components/schemas/Email
Error was generated by the no-invalid-schema-examples rule.
[5] openapi.yaml:43:11 at #/components/schemas/Id/examples/1
Example value must conform to the schema: must match format "uuid".
41 | examples:
42 | - 3be6453c-03eb-4357-ae5a-984a0e574a54 # correct
43 | - incorrect
| ^^^^^^^^^
44 | - 42 # wrong type
45 | Time:
referenced from openapi.yaml:39:7 at #/components/schemas/Id
Error was generated by the no-invalid-schema-examples rule.
[6] openapi.yaml:44:11 at #/components/schemas/Id/examples/2
Example value must conform to the schema: type must be string.
42 | - 3be6453c-03eb-4357-ae5a-984a0e574a54 # correct
43 | - incorrect
44 | - 42 # wrong type
| ^^
45 | Time:
46 | type: string
referenced from openapi.yaml:39:7 at #/components/schemas/Id
Error was generated by the no-invalid-schema-examples rule.
[7] openapi.yaml:51:11 at #/components/schemas/Time/examples/1
Example value must conform to the schema: must match pattern "^([01]\\d|2[0-3]):?([0-5]\\d)$".
49 | examples:
50 | - 09:00 # correct
51 | - incorrect
| ^^^^^^^^^
52 | - 09.00 # wrong type
53 | Oneof:
referenced from openapi.yaml:46:7 at #/components/schemas/Time
Error was generated by the no-invalid-schema-examples rule.
[8] openapi.yaml:52:11 at #/components/schemas/Time/examples/2
Example value must conform to the schema: type must be string.
50 | - 09:00 # correct
51 | - incorrect
52 | - 09.00 # wrong type
| ^^^^^
53 | Oneof:
54 | type: string
referenced from openapi.yaml:46:7 at #/components/schemas/Time
Error was generated by the no-invalid-schema-examples rule.
[9] openapi.yaml:61:11 at #/components/schemas/Oneof/examples/2
Example value must conform to the schema: must match format "date".
59 | - '2000-01-01' # correct
60 | - monthly # correct
61 | - wrong
| ^^^^^
62 |
63 | examples:
referenced from openapi.yaml:54:7 at #/components/schemas/Oneof
Error was generated by the no-invalid-schema-examples rule.
[10] openapi.yaml:61:11 at #/components/schemas/Oneof/examples/2
Example value must conform to the schema: must match pattern "^(month|year)ly$".
59 | - '2000-01-01' # correct
60 | - monthly # correct
61 | - wrong
| ^^^^^
62 |
63 | examples:
referenced from openapi.yaml:54:7 at #/components/schemas/Oneof
Error was generated by the no-invalid-schema-examples rule.
[11] openapi.yaml:61:11 at #/components/schemas/Oneof/examples/2
Example value must conform to the schema: must match exactly one schema in oneOf.
59 | - '2000-01-01' # correct
60 | - monthly # correct
61 | - wrong
| ^^^^^
62 |
63 | examples:
referenced from openapi.yaml:54:7 at #/components/schemas/Oneof
Error was generated by the no-invalid-schema-examples rule.
/openapi.yaml: validated in <test>ms
❌ Validation failed with 11 errors.
run \`redocly lint --generate-ignore-file\` to add all problems to the ignore file.
`;

0 comments on commit 7fde139

Please sign in to comment.