Skip to content

Commit 4fd7f1d

Browse files
authored
fix: remote ref resolution regression (#4273)
* Use `parameterWithMeta` to get parameter data in <ParameterRow> * Prefer specPath when fetching resolved subtrees in OperationContainer * Add test for OAS3 callback rendering * Remove debugger statement * Pass base resolution URL directly to Swagger-Client subtree resolver * Remove accidental comment * Migrate additional options
1 parent 8777d8b commit 4fd7f1d

File tree

4 files changed

+105
-3
lines changed

4 files changed

+105
-3
lines changed

src/core/plugins/spec/actions.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ let hasWarnedAboutResolveSpecDeprecation = false
8282

8383
export const resolveSpec = (json, url) => ({specActions, specSelectors, errActions, fn: { fetch, resolve, AST }, getConfigs}) => {
8484
if(!hasWarnedAboutResolveSpecDeprecation) {
85-
console.warn(`specActions.resolveSpec is deprecated since v3.10.0 and will be removed in v4.0.0; use resolveIn instead!`)
85+
console.warn(`specActions.resolveSpec is deprecated since v3.10.0 and will be removed in v4.0.0; use requestResolvedSubtree instead!`)
8686
hasWarnedAboutResolveSpecDeprecation = true
8787
}
8888

@@ -162,11 +162,23 @@ const debResolveSubtrees = debounce(async () => {
162162

163163
const specStr = specSelectors.specStr()
164164

165+
const {
166+
modelPropertyMacro,
167+
parameterMacro,
168+
requestInterceptor,
169+
responseInterceptor
170+
} = system.getConfigs()
171+
165172
try {
166173
var batchResult = await requestBatch.reduce(async (prev, path) => {
167174
const { resultMap, specWithCurrentSubtrees } = await prev
168-
169-
const { errors, spec } = await resolveSubtree(specWithCurrentSubtrees, path)
175+
const { errors, spec } = await resolveSubtree(specWithCurrentSubtrees, path, {
176+
baseDoc: specSelectors.url(),
177+
modelPropertyMacro,
178+
parameterMacro,
179+
requestInterceptor,
180+
responseInterceptor
181+
})
170182

171183
if(errSelectors.allErrors().size) {
172184
errActions.clear({

test/e2e/scenarios/refs.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
describe("Remote $ref rendering", function () {
2+
let mainPage
3+
beforeEach(function (client, done) {
4+
5+
mainPage = client
6+
// expand the models so we don't have to manually do it
7+
.url("localhost:3200?defaultModelsExpandDepth=5")
8+
.page.main()
9+
10+
client.waitForElementVisible(".download-url-input", 5000)
11+
.pause(2000)
12+
.clearValue(".download-url-input")
13+
.setValue(".download-url-input", "http://localhost:3200/test-specs/refs/api1.yaml")
14+
.click("button.download-url-button")
15+
.pause(1000)
16+
17+
18+
done()
19+
})
20+
21+
it("renders a remote $ref correctly", function (client) {
22+
mainPage.expect.element("#model-TestResponse > span > div > span > span > span.inner-object > table > tbody > tr:nth-child(2) > td:nth-child(2) > span > span > div > div > p").text.to.equal("this is a api2prop")
23+
24+
client.end()
25+
})
26+
})

test/e2e/specs/refs/api1.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
openapi: 3.0.0
2+
info:
3+
description: |
4+
This is a test to show how model refererence from another file are failing.
5+
This file references api2.yaml. If you load this file first in the browser it fails.
6+
However, if you load api2.yaml first, then load this one it will work.
7+
version: 1.0.0
8+
title: API1 Test
9+
paths:
10+
'/test-api-1':
11+
get:
12+
summary: Api 1
13+
responses:
14+
'200':
15+
description: 'api 2 response'
16+
content:
17+
application/json:
18+
schema:
19+
$ref: '#/components/schemas/TestResponse'
20+
components:
21+
schemas:
22+
Api1Prop:
23+
type: string
24+
example: 'api1prop-value'
25+
26+
TestResponse:
27+
type: object
28+
properties:
29+
api1prop:
30+
$ref: '#/components/schemas/Api1Prop'
31+
api2prop:
32+
$ref: 'api2.yaml#/components/schemas/Api2Prop'

test/e2e/specs/refs/api2.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
openapi: 3.0.0
2+
info:
3+
description: |
4+
This is a test to show how model refererence from another file are failing.
5+
This file is referenced api1.yaml. If you load api1.yaml first in the browser it fails.
6+
However, if you load this file first, then load api1.yaml it will work.
7+
version: 1.0.0
8+
title: API2 Test
9+
paths:
10+
'/test-api-2':
11+
get:
12+
summary: Api 2
13+
responses:
14+
'200':
15+
description: api 2 response
16+
content:
17+
application/json:
18+
schema:
19+
$ref: '#/components/schemas/TestResponse2'
20+
components:
21+
schemas:
22+
Api2Prop:
23+
type: string
24+
description: this is a api2prop
25+
example: 'api1prop-value'
26+
27+
TestResponse2:
28+
type: object
29+
description: This is a test prop
30+
properties:
31+
api2prop:
32+
$ref: '#/components/schemas/Api2Prop'

0 commit comments

Comments
 (0)