diff --git a/src/core/plugins/spec/actions.js b/src/core/plugins/spec/actions.js index 232b40bb..9bd9908c 100644 --- a/src/core/plugins/spec/actions.js +++ b/src/core/plugins/spec/actions.js @@ -82,7 +82,7 @@ let hasWarnedAboutResolveSpecDeprecation = false export const resolveSpec = (json, url) => ({specActions, specSelectors, errActions, fn: { fetch, resolve, AST }, getConfigs}) => { if(!hasWarnedAboutResolveSpecDeprecation) { - console.warn(`specActions.resolveSpec is deprecated since v3.10.0 and will be removed in v4.0.0; use resolveIn instead!`) + console.warn(`specActions.resolveSpec is deprecated since v3.10.0 and will be removed in v4.0.0; use requestResolvedSubtree instead!`) hasWarnedAboutResolveSpecDeprecation = true } @@ -162,11 +162,23 @@ const debResolveSubtrees = debounce(async () => { const specStr = specSelectors.specStr() + const { + modelPropertyMacro, + parameterMacro, + requestInterceptor, + responseInterceptor + } = system.getConfigs() + try { var batchResult = await requestBatch.reduce(async (prev, path) => { const { resultMap, specWithCurrentSubtrees } = await prev - - const { errors, spec } = await resolveSubtree(specWithCurrentSubtrees, path) + const { errors, spec } = await resolveSubtree(specWithCurrentSubtrees, path, { + baseDoc: specSelectors.url(), + modelPropertyMacro, + parameterMacro, + requestInterceptor, + responseInterceptor + }) if(errSelectors.allErrors().size) { errActions.clear({ diff --git a/test/e2e/scenarios/refs.js b/test/e2e/scenarios/refs.js new file mode 100644 index 00000000..ec6a2043 --- /dev/null +++ b/test/e2e/scenarios/refs.js @@ -0,0 +1,26 @@ +describe("Remote $ref rendering", function () { + let mainPage + beforeEach(function (client, done) { + + mainPage = client + // expand the models so we don't have to manually do it + .url("localhost:3200?defaultModelsExpandDepth=5") + .page.main() + + client.waitForElementVisible(".download-url-input", 5000) + .pause(2000) + .clearValue(".download-url-input") + .setValue(".download-url-input", "http://localhost:3200/test-specs/refs/api1.yaml") + .click("button.download-url-button") + .pause(1000) + + + done() + }) + + it("renders a remote $ref correctly", function (client) { + 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") + + client.end() + }) +}) diff --git a/test/e2e/specs/refs/api1.yaml b/test/e2e/specs/refs/api1.yaml new file mode 100644 index 00000000..4d120a3a --- /dev/null +++ b/test/e2e/specs/refs/api1.yaml @@ -0,0 +1,32 @@ +openapi: 3.0.0 +info: + description: | + This is a test to show how model refererence from another file are failing. + This file references api2.yaml. If you load this file first in the browser it fails. + However, if you load api2.yaml first, then load this one it will work. + version: 1.0.0 + title: API1 Test +paths: + '/test-api-1': + get: + summary: Api 1 + responses: + '200': + description: 'api 2 response' + content: + application/json: + schema: + $ref: '#/components/schemas/TestResponse' +components: + schemas: + Api1Prop: + type: string + example: 'api1prop-value' + + TestResponse: + type: object + properties: + api1prop: + $ref: '#/components/schemas/Api1Prop' + api2prop: + $ref: 'api2.yaml#/components/schemas/Api2Prop' \ No newline at end of file diff --git a/test/e2e/specs/refs/api2.yaml b/test/e2e/specs/refs/api2.yaml new file mode 100644 index 00000000..17b855e4 --- /dev/null +++ b/test/e2e/specs/refs/api2.yaml @@ -0,0 +1,32 @@ +openapi: 3.0.0 +info: + description: | + This is a test to show how model refererence from another file are failing. + This file is referenced api1.yaml. If you load api1.yaml first in the browser it fails. + However, if you load this file first, then load api1.yaml it will work. + version: 1.0.0 + title: API2 Test +paths: + '/test-api-2': + get: + summary: Api 2 + responses: + '200': + description: api 2 response + content: + application/json: + schema: + $ref: '#/components/schemas/TestResponse2' +components: + schemas: + Api2Prop: + type: string + description: this is a api2prop + example: 'api1prop-value' + + TestResponse2: + type: object + description: This is a test prop + properties: + api2prop: + $ref: '#/components/schemas/Api2Prop' \ No newline at end of file