-
Notifications
You must be signed in to change notification settings - Fork 217
fix: resolve $ref siblings during bundling #2772
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
base: main
Are you sure you want to change the base?
Changes from all commits
b39d04f
81a63b9
b8066fb
e41e843
3bad21b
3fee16d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@redocly/openapi-core": patch | ||
| "@redocly/cli": patch | ||
| --- | ||
|
|
||
| Fixed an issue where sibling properties next to `$ref` were not resolved during bundling. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| openapi: 3.1.0 | ||
| info: | ||
| title: Nested external refs in schema $ref siblings | ||
| version: 1.0.0 | ||
| paths: | ||
| /sample: | ||
| get: | ||
| responses: | ||
| '200': | ||
| description: OK | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/Base' | ||
| properties: | ||
| second: | ||
| $ref: ./schema-ref-sibling-external-value.yaml#/Second | ||
| components: | ||
| schemas: | ||
| Base: | ||
| type: object | ||
| properties: | ||
| first: | ||
| type: integer | ||
| second: | ||
| type: integer |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Second: | ||
| title: Referenced model | ||
| type: string |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import type { Config, RuleSeverity } from './config/index.js'; | ||
| import { YamlParseError } from './errors/yaml-parse-error.js'; | ||
| import type { SpecVersion } from './oas-types.js'; | ||
| import { Location, isRef } from './ref-utils.js'; | ||
| import { Location, isRef, refHasSibling } from './ref-utils.js'; | ||
| import type { ResolveError, Source, ResolvedRefMap, Document } from './resolve.js'; | ||
| import { isNamedType, SpecExtension, type NormalizedNodeType } from './types/index.js'; | ||
| import type { Referenced } from './typings/openapi.js'; | ||
|
|
@@ -353,12 +353,16 @@ export function walkDocument<T extends BaseVisitor>(opts: { | |
| propType = { name: 'scalar', properties: {} }; | ||
| } | ||
|
|
||
| if (isRef(node[propName]) && propType?.name === 'scalar') { | ||
| if (!isNamedType(propType)) { | ||
| continue; | ||
| } | ||
|
|
||
| if (nodeIsRef && refHasSibling(node, propName)) { | ||
| walkNode(node[propName], propType, location.child([propName]), node, propName); | ||
| continue; | ||
| } | ||
|
|
||
| if (!isNamedType(propType) || (propType.name === 'scalar' && !isRef(value))) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sibling walked with propType derived from resolved valueMedium Severity When a property exists in both the resolved Reviewed by Cursor Bugbot for commit 3fee16d. Configure here. |
||
| if (propType.name === 'scalar' && !isRef(value)) { | ||
| continue; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| openapi: 3.1.0 | ||
| info: | ||
| title: E2E bundle - ref with sibling keys | ||
| version: 1.0.0 | ||
| servers: | ||
| - url: https://api.redocly.com | ||
| security: [] | ||
| paths: | ||
| /sample: | ||
| get: | ||
| operationId: getSample | ||
| description: parameter $ref with sibling name | ||
| parameters: | ||
| - $ref: '#/components/parameters/id' | ||
| name: | ||
| $ref: reference.yaml#/title | ||
| responses: | ||
| '200': | ||
| description: JSON schema using $ref and sibling properties | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/test' | ||
| properties: | ||
| second: | ||
| $ref: reference.yaml | ||
| third: | ||
| type: array | ||
| items: | ||
| $ref: reference.yaml | ||
| additionalProperties: | ||
| $ref: reference.yaml | ||
| /submit: | ||
| post: | ||
| description: requestBody $ref with sibling description | ||
| operationId: postSubmit | ||
| requestBody: | ||
| $ref: '#/components/requestBodies/SampleBody' | ||
| description: | ||
| $ref: reference.yaml#/title | ||
|
|
||
| components: | ||
| parameters: | ||
| id: | ||
| name: id | ||
| in: query | ||
| required: false | ||
| schema: | ||
| type: string | ||
| schemas: | ||
| test: | ||
| type: object | ||
| properties: | ||
| first: | ||
| type: integer | ||
| additionalProperties: false | ||
| requestBodies: | ||
| SampleBody: | ||
| required: true | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: object | ||
| properties: | ||
| value: | ||
| type: string |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| apis: | ||
| main: | ||
| root: ./openapi.yaml |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| title: Referenced model | ||
| type: string |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| openapi: 3.1.0 | ||
| info: | ||
| title: E2E bundle - ref with sibling keys | ||
| version: 1.0.0 | ||
| servers: | ||
| - url: https://api.redocly.com | ||
| security: [] | ||
| paths: | ||
| /sample: | ||
| get: | ||
| operationId: getSample | ||
| description: parameter $ref with sibling name | ||
| parameters: | ||
| - $ref: '#/components/parameters/id' | ||
| name: Referenced model | ||
| responses: | ||
| '200': | ||
| description: JSON schema using $ref and sibling properties | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/test' | ||
| properties: | ||
| second: | ||
| $ref: '#/components/schemas/reference' | ||
| third: | ||
| type: array | ||
| items: | ||
| $ref: '#/components/schemas/reference' | ||
| additionalProperties: | ||
| title: Referenced model | ||
| type: string | ||
| /submit: | ||
| post: | ||
| description: requestBody $ref with sibling description | ||
| operationId: postSubmit | ||
| requestBody: | ||
| $ref: '#/components/requestBodies/SampleBody' | ||
| description: Referenced model | ||
| components: | ||
| parameters: | ||
| id: | ||
| name: id | ||
| in: query | ||
| required: false | ||
| schema: | ||
| type: string | ||
| schemas: | ||
| test: | ||
| type: object | ||
| properties: | ||
| first: | ||
| type: integer | ||
| additionalProperties: false | ||
| reference: | ||
| title: Referenced model | ||
| type: string | ||
| requestBodies: | ||
| SampleBody: | ||
| required: true | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: object | ||
| properties: | ||
| value: | ||
| type: string | ||
|
|
||
| bundling openapi.yaml using configuration for api 'main'... | ||
| 📦 Created a bundle for openapi.yaml at stdout <test>ms. |


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to avoid duplication in the two checks below