Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(openapi): improvements to circular ref detection, validation errors #1189

Merged
merged 3 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion __tests__/commands/openapi/__snapshots__/inspect.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,13 @@ additionalProperties:
· #/components/schemas/ParameterizedHeader/properties/parameters/additionalProperties

circularRefs:
· #/components/schemas/BodyPart/properties/parent
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These circular refs weren't being picked up before but @apidevtools/json-schema-ref-parser is better at detecting them now with an onCircular hook I submitted to them. APIDevTools/json-schema-ref-parser#366

· #/components/schemas/MultiPart/properties/bodyParts/items
· #/components/schemas/MultiPart/properties/parent
· #/components/schemas/ZoneOffset/properties/rules"
· #/components/schemas/ZoneOffset/properties/rules
· #/components/schemas/ZoneOffsetTransition/properties/offsetAfter
· #/components/schemas/ZoneOffsetTransition/properties/offsetBefore
· #/components/schemas/ZoneRules/properties/transitions/items"
`;

exports[`rdme openapi inspect > feature reports > should generate a report for '@readme/oas-examples/3.0/json/schema-…' (w/ [ 'additionalProperties', …(2) ]) 1`] = `
Expand All @@ -114,8 +119,13 @@ additionalProperties:
· #/components/schemas/ParameterizedHeader/properties/parameters/additionalProperties

circularRefs:
· #/components/schemas/BodyPart/properties/parent
· #/components/schemas/MultiPart/properties/bodyParts/items
· #/components/schemas/MultiPart/properties/parent
· #/components/schemas/ZoneOffset/properties/rules
· #/components/schemas/ZoneOffsetTransition/properties/offsetAfter
· #/components/schemas/ZoneOffsetTransition/properties/offsetBefore
· #/components/schemas/ZoneRules/properties/transitions/items

x-default: You do not use this.
x-readme.code-samples: You do not use this.
Expand All @@ -128,8 +138,13 @@ x-readme.samples-languages: You do not use this."
exports[`rdme openapi inspect > feature reports > should generate a report for '@readme/oas-examples/3.0/json/schema-…' (w/ [ 'circularRefs', 'readme' ]) 1`] = `
"
circularRefs:
· #/components/schemas/BodyPart/properties/parent
· #/components/schemas/MultiPart/properties/bodyParts/items
· #/components/schemas/MultiPart/properties/parent
· #/components/schemas/ZoneOffset/properties/rules
· #/components/schemas/ZoneOffsetTransition/properties/offsetAfter
· #/components/schemas/ZoneOffsetTransition/properties/offsetBefore
· #/components/schemas/ZoneRules/properties/transitions/items

x-default: You do not use this.
x-readme.code-samples: You do not use this.
Expand Down
10 changes: 6 additions & 4 deletions __tests__/commands/openapi/__snapshots__/validate.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ exports[`rdme openapi validate > GHA onboarding E2E tests > should reject if use

exports[`rdme openapi validate > error handling > should throw an error if an invalid API definition has many errors 1`] = `
{
"error": [SyntaxError: OpenAPI schema validation failed.
"error": [ValidationError: OpenAPI schema validation failed.

REQUIRED must have required property 'url'

Expand Down Expand Up @@ -262,7 +262,9 @@ ADDITIONAL PROPERTY must NOT have additional properties

exports[`rdme openapi validate > error handling > should throw an error if an invalid OpenAPI 3.0 definition is supplied 1`] = `
{
"error": [MissingPointerError: Token "Error" does not exist.],
"error": [ValidationError: API definition schema validation failed.

Missing $ref pointer "#/components/schemas/Error". Token "Error" does not exist.],
"stderr": "- Validating the API definition located at ./__tests__/__fixtures__/invalid-oas.json...
✖ Validating the API definition located at ./__tests__/__fixtures__/invalid-oas.json...
",
Expand All @@ -272,7 +274,7 @@ exports[`rdme openapi validate > error handling > should throw an error if an in

exports[`rdme openapi validate > error handling > should throw an error if an invalid OpenAPI 3.1 definition is supplied 1`] = `
{
"error": [SyntaxError: OpenAPI schema validation failed.
"error": [ValidationError: OpenAPI schema validation failed.

REQUIRED must have required property 'name'

Expand All @@ -292,7 +294,7 @@ REQUIRED must have required property 'name'

exports[`rdme openapi validate > error handling > should throw an error if an invalid Swagger definition is supplied 1`] = `
{
"error": [SyntaxError: Swagger schema validation failed.
"error": [ValidationError: Swagger schema validation failed.

ADDITIONAL PROPERTY must NOT have additional properties

Expand Down
97 changes: 45 additions & 52 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@oclif/plugin-help": "^6.2.15",
"@oclif/plugin-not-found": "^3.2.28",
"@oclif/plugin-warn-if-update-available": "^3.1.19",
"@readme/better-ajv-errors": "^2.0.0",
"@readme/better-ajv-errors": "^2.3.2",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v2.3.2 was already installed but I just bumped it in the package file.

"ajv": "^8.17.1",
"ajv-formats": "^3.0.1",
"chalk": "^5.3.0",
Expand All @@ -58,8 +58,8 @@
"ignore": "^7.0.0",
"js-yaml": "^4.1.0",
"mime-types": "^2.1.35",
"oas": "^25.3.0",
"oas-normalize": "^12.1.0",
"oas": "^26.0.1",
"oas-normalize": "^13.0.1",
"ora": "^8.1.1",
"prompts": "^2.4.2",
"semver": "^7.5.3",
Expand All @@ -77,7 +77,7 @@
"@commitlint/config-conventional": "^19.0.3",
"@oclif/test": "^4.1.0",
"@readme/eslint-config": "^14.3.0",
"@readme/oas-examples": "^5.10.0",
"@readme/oas-examples": "^5.19.1",
"@rollup/plugin-commonjs": "^28.0.0",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^16.0.0",
Expand Down
Loading