You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The plugin fails when the OpenAPI spec file contains vendor extensions at the path level (e.g. x-* fields directly under a path object). This results in a runtime error during the build process.
Motivation and Context
OpenAPI allows vendor extensions (x-*) at almost any level of the specification, including the path level. However, the current implementation assumes all path-level properties conform to expected schema objects and attempts to process vendor extensions as structured objects.
This leads to a crash when a primitive value (e.g. string or boolean) is encountered, as the code tries to assign properties like description to it.
This change ensures that vendor extensions at the path level are safely ignored or handled correctly, preventing the build from failing.
[ERROR] TypeError: Cannot create property 'description' on string 'hello'
After the fix
Running:
yarn build
Produces:
....
Successfully created "docs/petstore_versioned/versions.json"
[INFO] [en] Creating an optimized production build...
● Client ██████████████████████████████████████████████████ (100%) emitting after emit
● Server ██████████████████████████████████████████████████ (100%) emitting after emit
The build now completes successfully without errors.
Screenshots (if appropriate)
Types of changes
Bug fix (non-breaking change which fixes an issue)
New feature (non-breaking change which adds functionality)
Breaking change (fix or feature that would cause existing functionality to change)
Checklist
I have updated the documentation accordingly.
I have read the CONTRIBUTING document.
I have added tests to cover my changes if appropriate.
Thanks for the fix! Confirmed the crash and that this resolves it. A few suggestions before merging:
Prefer an HTTP-method allowlist over an x-* blocklist. The OpenAPI 3.x spec defines exactly 8 valid operation keys, so any other unexpected non-x- key (typo, third-party tooling, future spec addition) would still crash. Something like:
This makes the guard spec-correct and self-documenting (the comment becomes unnecessary).
Add a unit test under packages/docusaurus-plugin-openapi-docs/src/openapi/__tests__/ that constructs a path with vendor extensions and asserts createItems doesn't throw. The petstore demo edit is a nice smoke test but won't catch a future regression on its own.
Minor: drop the stray blank line between the comment and continue;.
Happy to merge once those are addressed (or as-is if you'd rather ship the fix now and file a follow-up).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The plugin fails when the OpenAPI spec file contains vendor extensions at the path level (e.g. x-* fields directly under a path object). This results in a runtime error during the build process.
Motivation and Context
OpenAPI allows vendor extensions (x-*) at almost any level of the specification, including the path level. However, the current implementation assumes all path-level properties conform to expected schema objects and attempts to process vendor extensions as structured objects.
This leads to a crash when a primitive value (e.g. string or boolean) is encountered, as the code tries to assign properties like description to it.
This change ensures that vendor extensions at the path level are safely ignored or handled correctly, preventing the build from failing.
Issue: #891
How Has This Been Tested?
I modified the petstore.yaml example to include vendor extensions at the path level:
Before the fix
Running:
Resulted in:
After the fix
Running:
Produces:
The build now completes successfully without errors.
Screenshots (if appropriate)
Types of changes
Checklist