Skip to content

fix swagger $ref resolve error#22

Merged
qazsato merged 5 commits into
mainfrom
fix_resolve_ref
Jul 8, 2025
Merged

fix swagger $ref resolve error#22
qazsato merged 5 commits into
mainfrom
fix_resolve_ref

Conversation

@qazsato

@qazsato qazsato commented Jul 7, 2025

Copy link
Copy Markdown
Owner

No description provided.

@qazsato
qazsato requested a review from Copilot July 7, 2025 23:58

This comment was marked as outdated.

@qazsato
qazsato force-pushed the fix_resolve_ref branch from 5dc66c5 to 34ea135 Compare July 8, 2025 00:01
@qazsato
qazsato requested a review from Copilot July 8, 2025 00:02

This comment was marked as outdated.

@qazsato
qazsato force-pushed the fix_resolve_ref branch 2 times, most recently from 3e01b7c to 1830996 Compare July 8, 2025 13:46
@qazsato
qazsato force-pushed the fix_resolve_ref branch from 1830996 to c1635ca Compare July 8, 2025 13:48
@qazsato
qazsato requested a review from Copilot July 8, 2025 18:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.js using @apidevtools/json-schema-ref-parser and fast-safe-stringify.
  • Change UI constant from an array to an object, updating CLI validation and Inquirer defaults/choices.
  • Update Swagger UI CDN links and bump json-schema-ref-parser and add fast-safe-stringify in package.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 parseOpenApi covering JSON and YAML inputs, invalid formats, and both $ref resolution 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 $ref pointers), which will aid future maintainers.
export async function parseOpenApi(rawApiDocsText, ui) {

Comment thread src/utils/parser.js
}
// 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)

Copilot AI Jul 8, 2025

Copy link

Choose a reason for hiding this comment

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

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)

Copilot uses AI. Check for mistakes.
@qazsato
qazsato merged commit 27f31c3 into main Jul 8, 2025
3 checks passed
@qazsato
qazsato deleted the fix_resolve_ref branch July 8, 2025 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants