fix: restore external $ref resolution without redocly bundler#2558
fix: restore external $ref resolution without redocly bundler#2558stijnvanhulle merged 4 commits intochore/remove-redoclyfrom
Conversation
|
|
@copilot resolving external refs is broken, make this work again without the redoc package |
|
@copilot add test cases for external refs (different file) and for external refs (url to other swagger file) |
…guard dereference() Co-authored-by: stijnvanhulle <5904681+stijnvanhulle@users.noreply.github.com>
Fixed in commit The two regressions introduced by the
Changes:
|
Co-authored-by: stijnvanhulle <5904681+stijnvanhulle@users.noreply.github.com>
Added in commit Two new test cases in
Two new mock files were added:
|
| // The $ref pointer must be preserved (not inlined) so SchemaGenerator can emit a named type reference | ||
| const petSchema = (oas.api as any).components?.schemas?.Pet | ||
| expect(petSchema).toBeDefined() | ||
| expect(petSchema.properties.category.$ref).toBe('./category.yaml#/components/schemas/Category') |
There was a problem hiding this comment.
Done in 3f40fda — added assertions for type, required, id, and name properties alongside the $ref check on category.
| // The external HTTP $ref must be preserved (not inlined) so SchemaGenerator can emit a named type reference | ||
| const petSchema = (oas.api as any).components?.schemas?.Pet | ||
| expect(petSchema).toBeDefined() | ||
| expect(petSchema.properties.category.$ref).toBe('https://petstore3.swagger.io/api/v3/openapi.json#/components/schemas/Category') |
There was a problem hiding this comment.
Done in 3f40fda — added assertions for type, required, id, name, and tag properties alongside the $ref check on category.
Co-authored-by: stijnvanhulle <5904681+stijnvanhulle@users.noreply.github.com>
Two regressions were introduced by the
oas-normalize.bundle()pre-pass approach and are fixed here:MissingPointerError–@apidevtools/json-schema-ref-parser.bundle()throws when it encounters$ref: '#/definitions/...'inside an OpenAPI 3.1 document (where nodefinitionskey exists at the root).External HTTP refs being inlined –
bundle()replaces external HTTP$refschemas with their resolved inline content, stripping the$refpointer. Kubb'sSchemaGeneratorneeds the$refintact to generate a named type reference (e.g.category?: category) rather than an anonymous inline object type.🎯 Changes
packages/oas/src/utils.ts— Removed thebundle()pre-pass fromparse(). Back tooas-normalize.load()only; all$refpointers are preserved and resolved on-the-fly bySchemaGenerator.dereferenceWithRef().canBundleis kept in the option type for backward compatibility.packages/plugin-oas/src/plugin.ts—oas.dereference()is now wrapped in.catch()so that specs with invalid internal$refpointers (e.g.#/definitions/...in OpenAPI 3.x docs) don't abort schema generation. The error is emitted as a debug event so it remains visible.packages/plugin-redoc/src/plugin.ts— Same defensive.catch()guard onoas.dereference().packages/oas/src/utils.spec.ts— Added two test cases to guard against regressions: one for external file$ref(relative path tocategory.yaml) and one for external URL$ref(https://petstore3.swagger.io/...). Both assert the$refpointer is preserved intact afterparse()and verify all individual schema properties (type,required,id,name,tag).packages/oas/mocks/category.yaml— New minimal OpenAPI doc with aCategoryschema, used as the target of the external file ref test.packages/oas/mocks/petStoreExternalFileRef.yaml— New petstore spec that references./category.yaml#/components/schemas/Categoryvia a relative file path$ref.$refresolution (file + HTTP) via preserved$refpointersswagger2openapi#/definitions/...refs in OpenAPI 3.x docs✅ Checklist
pnpm run test.🚀 Release Impact
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.