fix swagger $ref resolve error#22
Merged
Merged
Conversation
qazsato
force-pushed
the
fix_resolve_ref
branch
2 times, most recently
from
July 8, 2025 13:46
3e01b7c to
1830996
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR centralizes OpenAPI parsing with proper $ref resolution, updates UI constants for consistency, and bumps related dependencies/templates to fix Swagger reference errors.
- Refactor parsing into
src/utils/parser.jsusing@apidevtools/json-schema-ref-parserandfast-safe-stringify. - Change
UIconstant from an array to an object, updating CLI validation and Inquirer defaults/choices. - Update Swagger UI CDN links and bump
json-schema-ref-parserand addfast-safe-stringifyinpackage.json.
Reviewed Changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/utils/validate.js | Updated validateCommandUi to use Object.values(UI) and removed JSON/YAML helpers. |
| src/utils/parser.js | New parsing utility handling JSON/YAML, $ref resolution, and stringification. |
| src/index.js | Replaced inline parsing with parseOpenApi, adjusted imports and CLI UI options. |
| src/constants/index.js | Converted UI from array to object for named variants. |
| resources/swagger/template.ejs | Bumped Swagger UI CSS/JS versions to 5.26.2. |
| package.json | Upgraded @apidevtools/json-schema-ref-parser and added fast-safe-stringify. |
Comments suppressed due to low confidence (2)
src/utils/parser.js:6
- Add unit tests for
parseOpenApicovering JSON and YAML inputs, invalid formats, and both$refresolution modes to ensure parsing logic is robust.
export async function parseOpenApi(rawApiDocsText, ui) {
src/utils/parser.js:6
- Consider adding JSDoc or comments to explain parameters and return values (e.g., that this returns a JSON string with resolved
$refpointers), which will aid future maintainers.
export async function parseOpenApi(rawApiDocsText, ui) {
| } | ||
| // https://github.com/APIDevTools/json-schema-ref-parser/blob/main/docs/ref-parser.md#bundleschema-options-callback | ||
| const apiDocs = await $RefParser.bundle(rawApiDocs) | ||
| return JSON.stringify(apiDocs) |
There was a problem hiding this comment.
The non-Swagger branch uses JSON.stringify, which can fail on circular references; consider using fast-safe-stringify here as well for consistency and to avoid runtime errors.
Suggested change
| return JSON.stringify(apiDocs) | |
| return stringify(apiDocs) |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.