Skip to content

Commit 57b732f

Browse files
authored
feat(openapi): improvements to circular ref detection, validation errors (#1189)
## 🧰 Changes Over the past couple weeks I've been rewriting our OpenAPI parser, `@readme/openapi-parser`, to support a new error leveling system -- you can read up on details on this in readmeio/oas#943. This PR pulls in the fruits of my labor there and across `oas` and `oas-normalize`. * [x] Upgrades `oas-normalize` to pull in our new parser engine and error handling. The error leveling work is not being used within `rdme` but for things like specification validation that our parser does `rdme` will now be able to surface more than one of these errors at a time. 🎉 * Support for Node 18 has also been removed. * [x] Upgrades `oas` and `@readme/oas-examples` to pull in the removal of Node 18 support. All told this overhaul is mostly a drop-in replacement with the exception that instead of `SyntaxError` and `MissingPointerError` exceptions being thrown from the parser for some invalid API definition cases it will now always be a `ValidationError.`
1 parent 96fe620 commit 57b732f

File tree

4 files changed

+71
-61
lines changed

4 files changed

+71
-61
lines changed

__tests__/commands/openapi/__snapshots__/inspect.test.ts.snap

+16-1
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,13 @@ additionalProperties:
9393
· #/components/schemas/ParameterizedHeader/properties/parameters/additionalProperties
9494
9595
circularRefs:
96+
· #/components/schemas/BodyPart/properties/parent
97+
· #/components/schemas/MultiPart/properties/bodyParts/items
9698
· #/components/schemas/MultiPart/properties/parent
97-
· #/components/schemas/ZoneOffset/properties/rules"
99+
· #/components/schemas/ZoneOffset/properties/rules
100+
· #/components/schemas/ZoneOffsetTransition/properties/offsetAfter
101+
· #/components/schemas/ZoneOffsetTransition/properties/offsetBefore
102+
· #/components/schemas/ZoneRules/properties/transitions/items"
98103
`;
99104

100105
exports[`rdme openapi inspect > feature reports > should generate a report for '@readme/oas-examples/3.0/json/schema-…' (w/ [ 'additionalProperties', …(2) ]) 1`] = `
@@ -114,8 +119,13 @@ additionalProperties:
114119
· #/components/schemas/ParameterizedHeader/properties/parameters/additionalProperties
115120
116121
circularRefs:
122+
· #/components/schemas/BodyPart/properties/parent
123+
· #/components/schemas/MultiPart/properties/bodyParts/items
117124
· #/components/schemas/MultiPart/properties/parent
118125
· #/components/schemas/ZoneOffset/properties/rules
126+
· #/components/schemas/ZoneOffsetTransition/properties/offsetAfter
127+
· #/components/schemas/ZoneOffsetTransition/properties/offsetBefore
128+
· #/components/schemas/ZoneRules/properties/transitions/items
119129
120130
x-default: You do not use this.
121131
x-readme.code-samples: You do not use this.
@@ -128,8 +138,13 @@ x-readme.samples-languages: You do not use this."
128138
exports[`rdme openapi inspect > feature reports > should generate a report for '@readme/oas-examples/3.0/json/schema-…' (w/ [ 'circularRefs', 'readme' ]) 1`] = `
129139
"
130140
circularRefs:
141+
· #/components/schemas/BodyPart/properties/parent
142+
· #/components/schemas/MultiPart/properties/bodyParts/items
131143
· #/components/schemas/MultiPart/properties/parent
132144
· #/components/schemas/ZoneOffset/properties/rules
145+
· #/components/schemas/ZoneOffsetTransition/properties/offsetAfter
146+
· #/components/schemas/ZoneOffsetTransition/properties/offsetBefore
147+
· #/components/schemas/ZoneRules/properties/transitions/items
133148
134149
x-default: You do not use this.
135150
x-readme.code-samples: You do not use this.

__tests__/commands/openapi/__snapshots__/validate.test.ts.snap

+6-4
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ exports[`rdme openapi validate > GHA onboarding E2E tests > should reject if use
232232
233233
exports[`rdme openapi validate > error handling > should throw an error if an invalid API definition has many errors 1`] = `
234234
{
235-
"error": [SyntaxError: OpenAPI schema validation failed.
235+
"error": [ValidationError: OpenAPI schema validation failed.
236236
237237
REQUIRED must have required property 'url'
238238
@@ -262,7 +262,9 @@ ADDITIONAL PROPERTY must NOT have additional properties
262262
263263
exports[`rdme openapi validate > error handling > should throw an error if an invalid OpenAPI 3.0 definition is supplied 1`] = `
264264
{
265-
"error": [MissingPointerError: Token "Error" does not exist.],
265+
"error": [ValidationError: API definition schema validation failed.
266+
267+
Missing $ref pointer "#/components/schemas/Error". Token "Error" does not exist.],
266268
"stderr": "- Validating the API definition located at ./__tests__/__fixtures__/invalid-oas.json...
267269
Validating the API definition located at ./__tests__/__fixtures__/invalid-oas.json...
268270
",
@@ -272,7 +274,7 @@ exports[`rdme openapi validate > error handling > should throw an error if an in
272274
273275
exports[`rdme openapi validate > error handling > should throw an error if an invalid OpenAPI 3.1 definition is supplied 1`] = `
274276
{
275-
"error": [SyntaxError: OpenAPI schema validation failed.
277+
"error": [ValidationError: OpenAPI schema validation failed.
276278
277279
REQUIRED must have required property 'name'
278280
@@ -292,7 +294,7 @@ REQUIRED must have required property 'name'
292294
293295
exports[`rdme openapi validate > error handling > should throw an error if an invalid Swagger definition is supplied 1`] = `
294296
{
295-
"error": [SyntaxError: Swagger schema validation failed.
297+
"error": [ValidationError: Swagger schema validation failed.
296298
297299
ADDITIONAL PROPERTY must NOT have additional properties
298300

package-lock.json

+45-52
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"@oclif/plugin-help": "^6.2.15",
4848
"@oclif/plugin-not-found": "^3.2.28",
4949
"@oclif/plugin-warn-if-update-available": "^3.1.19",
50-
"@readme/better-ajv-errors": "^2.0.0",
50+
"@readme/better-ajv-errors": "^2.3.2",
5151
"ajv": "^8.17.1",
5252
"ajv-formats": "^3.0.1",
5353
"chalk": "^5.3.0",
@@ -58,8 +58,8 @@
5858
"ignore": "^7.0.0",
5959
"js-yaml": "^4.1.0",
6060
"mime-types": "^2.1.35",
61-
"oas": "^25.3.0",
62-
"oas-normalize": "^12.1.0",
61+
"oas": "^26.0.1",
62+
"oas-normalize": "^13.0.1",
6363
"ora": "^8.1.1",
6464
"prompts": "^2.4.2",
6565
"semver": "^7.5.3",
@@ -77,7 +77,7 @@
7777
"@commitlint/config-conventional": "^19.0.3",
7878
"@oclif/test": "^4.1.0",
7979
"@readme/eslint-config": "^14.3.0",
80-
"@readme/oas-examples": "^5.10.0",
80+
"@readme/oas-examples": "^5.19.1",
8181
"@rollup/plugin-commonjs": "^28.0.0",
8282
"@rollup/plugin-json": "^6.0.0",
8383
"@rollup/plugin-node-resolve": "^16.0.0",

0 commit comments

Comments
 (0)