From 812565e7e212463403e4a2e80d8f2b416b85ab85 Mon Sep 17 00:00:00 2001 From: Luis Tejeda <46000487+LuisTejedaS@users.noreply.github.com> Date: Fri, 10 Jun 2022 17:28:49 -0500 Subject: [PATCH 1/5] Added support for components Added support for components --- lib/30XUtils/componentsParentMatcher.js | 24 +++ .../referenced_header/expected.json | 73 ++++++++ .../referenced_header/header.yaml | 3 + .../referenced_header/root.yaml | 43 +++++ .../referenced_link/expected.json | 71 ++++++++ .../referenced_link/link.yaml | 4 + .../referenced_link/root.yaml | 42 +++++ .../referenced_parameter/expected.json | 77 ++++++++ .../referenced_parameter/hello.yaml | 8 + .../referenced_parameter/root.yaml | 42 +++++ .../referenced_request_body/expected.json | 80 +++++++++ .../referenced_request_body/hello.yaml | 9 + .../referenced_request_body/root.yaml | 41 +++++ .../referenced_response/expected.json | 52 ++++++ .../referenced_response/hello.yaml | 9 + .../referenced_response/root.yaml | 22 +++ test/unit/bundle.test.js | 167 +++++++++++++++++- 17 files changed, 766 insertions(+), 1 deletion(-) create mode 100644 test/data/toBundleExamples/referenced_header/expected.json create mode 100644 test/data/toBundleExamples/referenced_header/header.yaml create mode 100644 test/data/toBundleExamples/referenced_header/root.yaml create mode 100644 test/data/toBundleExamples/referenced_link/expected.json create mode 100644 test/data/toBundleExamples/referenced_link/link.yaml create mode 100644 test/data/toBundleExamples/referenced_link/root.yaml create mode 100644 test/data/toBundleExamples/referenced_parameter/expected.json create mode 100644 test/data/toBundleExamples/referenced_parameter/hello.yaml create mode 100644 test/data/toBundleExamples/referenced_parameter/root.yaml create mode 100644 test/data/toBundleExamples/referenced_request_body/expected.json create mode 100644 test/data/toBundleExamples/referenced_request_body/hello.yaml create mode 100644 test/data/toBundleExamples/referenced_request_body/root.yaml create mode 100644 test/data/toBundleExamples/referenced_response/expected.json create mode 100644 test/data/toBundleExamples/referenced_response/hello.yaml create mode 100644 test/data/toBundleExamples/referenced_response/root.yaml diff --git a/lib/30XUtils/componentsParentMatcher.js b/lib/30XUtils/componentsParentMatcher.js index 570f9b9..f37f7b7 100644 --- a/lib/30XUtils/componentsParentMatcher.js +++ b/lib/30XUtils/componentsParentMatcher.js @@ -23,6 +23,18 @@ const COMPONENTS_KEYS_30 = [ ], PROPERTY_DEFINITION = [ 'properties' + ], + RESPONSE_DEFINITION = [ + 'responses' + ], + REQUEST_BODY_CONTAINER = [ + 'requestBody' + ], + LINKS_CONTAINER = [ + 'links' + ], + HEADER_DEFINITION = [ + 'headers' ]; module.exports = { @@ -55,6 +67,12 @@ module.exports = { if (EXAMPLE_CONTAINERS.includes(item)) { item = 'examples'; } + if (REQUEST_BODY_CONTAINER.includes(item)) { + item = 'requestBodies'; + } + if (LINKS_CONTAINER.includes(item)) { + item = 'links'; + } if (PROPERTY_DEFINITION.includes(trace[index + 2])) { trace[index + 1] = 'schemas'; } @@ -63,6 +81,12 @@ module.exports = { matchFound = true; break; } + if (RESPONSE_DEFINITION.includes(trace[index + 2])) { + trace[index + 1] = 'responses'; + } + if (HEADER_DEFINITION.includes(trace[index + 2])) { + trace[index + 1] = 'headers'; + } } return matchFound ? traceToKey.reverse() : diff --git a/test/data/toBundleExamples/referenced_header/expected.json b/test/data/toBundleExamples/referenced_header/expected.json new file mode 100644 index 0000000..1aa5b7d --- /dev/null +++ b/test/data/toBundleExamples/referenced_header/expected.json @@ -0,0 +1,73 @@ +{ + "openapi": "3.0.2", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore", + "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "name": "Swagger API Team", + "email": "apiteam@swagger.io", + "url": "http://swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "https://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "paths": { + "/pets": { + "get": { + "description": "Returns all pets alesuada ac...", + "operationId": "findPets", + "responses": { + "200": { + "description": "An paged array of pets", + "headers": { + "x-next": { + "$ref": "#/components/headers/~1header.yaml" + } + }, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Pets" + } + } + } + } + } + } + } + }, + "components": { + "schemas": { + "Pet": { + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "tag": { + "type": "string" + } + } + } + }, + "headers": { + "/header.yaml": { + "description": "A link to the next page of responses", + "schema": { + "type": "string" + } + } + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/referenced_header/header.yaml b/test/data/toBundleExamples/referenced_header/header.yaml new file mode 100644 index 0000000..1f14cc4 --- /dev/null +++ b/test/data/toBundleExamples/referenced_header/header.yaml @@ -0,0 +1,3 @@ +description: A link to the next page of responses +schema: + type: string diff --git a/test/data/toBundleExamples/referenced_header/root.yaml b/test/data/toBundleExamples/referenced_header/root.yaml new file mode 100644 index 0000000..f040a0a --- /dev/null +++ b/test/data/toBundleExamples/referenced_header/root.yaml @@ -0,0 +1,43 @@ + +openapi: "3.0.2" +info: + version: 1.0.0 + title: Swagger Petstore + description: A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification + termsOfService: http://swagger.io/terms/ + contact: + name: Swagger API Team + email: apiteam@swagger.io + url: http://swagger.io + license: + name: Apache 2.0 + url: https://www.apache.org/licenses/LICENSE-2.0.html +paths: + /pets: + get: + description: Returns all pets alesuada ac... + operationId: findPets + responses: + 200: + description: An paged array of pets + headers: + x-next: + $ref: "./header.yaml" + content: + application/json: + schema: + $ref: "#/components/schemas/Pets" +components: + schemas: + Pet: + required: + - id + - name + properties: + id: + type: integer + format: int64 + name: + type: string + tag: + type: string diff --git a/test/data/toBundleExamples/referenced_link/expected.json b/test/data/toBundleExamples/referenced_link/expected.json new file mode 100644 index 0000000..824042e --- /dev/null +++ b/test/data/toBundleExamples/referenced_link/expected.json @@ -0,0 +1,71 @@ +{ + "openapi": "3.0.2", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore", + "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "name": "Swagger API Team", + "email": "apiteam@swagger.io", + "url": "http://swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "https://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "paths": { + "/pets": { + "get": { + "description": "Returns all pets alesuada ac...", + "operationId": "findPets", + "responses": { + "200": { + "description": "pet response", + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Pet" + } + }, + "links": { + "$ref": "#/components/links/~1link.yaml" + } + } + } + } + } + }, + "components": { + "schemas": { + "Pet": { + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "tag": { + "type": "string" + } + } + } + }, + "links": { + "/link.yaml": { + "operationId": "getRepository", + "parameters": { + "username": "$response.body#/owner/username", + "slug": "$response.body#/slug" + } + } + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/referenced_link/link.yaml b/test/data/toBundleExamples/referenced_link/link.yaml new file mode 100644 index 0000000..3875200 --- /dev/null +++ b/test/data/toBundleExamples/referenced_link/link.yaml @@ -0,0 +1,4 @@ +operationId: getRepository +parameters: + username: $response.body#/owner/username + slug: $response.body#/slug diff --git a/test/data/toBundleExamples/referenced_link/root.yaml b/test/data/toBundleExamples/referenced_link/root.yaml new file mode 100644 index 0000000..900c550 --- /dev/null +++ b/test/data/toBundleExamples/referenced_link/root.yaml @@ -0,0 +1,42 @@ + +openapi: "3.0.2" +info: + version: 1.0.0 + title: Swagger Petstore + description: A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification + termsOfService: http://swagger.io/terms/ + contact: + name: Swagger API Team + email: apiteam@swagger.io + url: http://swagger.io + license: + name: Apache 2.0 + url: https://www.apache.org/licenses/LICENSE-2.0.html +paths: + /pets: + get: + description: Returns all pets alesuada ac... + operationId: findPets + responses: + 200: + description: pet response + schema: + type: array + items: + $ref: "#/components/schemas/Pet" + links: + $ref: "./link.yaml" +components: + schemas: + Pet: + required: + - id + - name + properties: + id: + type: integer + format: int64 + name: + type: string + tag: + type: string diff --git a/test/data/toBundleExamples/referenced_parameter/expected.json b/test/data/toBundleExamples/referenced_parameter/expected.json new file mode 100644 index 0000000..cf7b4bb --- /dev/null +++ b/test/data/toBundleExamples/referenced_parameter/expected.json @@ -0,0 +1,77 @@ +{ + "openapi": "3.0.2", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore", + "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "name": "Swagger API Team", + "email": "apiteam@swagger.io", + "url": "http://swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "https://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "paths": { + "/pets": { + "get": { + "description": "Returns all pets alesuada ac...", + "operationId": "findPets", + "parameters": [ + { + "$ref": "#/components/parameters/~1hello.yaml" + } + ], + "responses": { + "200": { + "description": "pet response", + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Pet" + } + } + } + } + } + } + }, + "components": { + "schemas": { + "Pet": { + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "tag": { + "type": "string" + } + } + } + }, + "parameters": { + "/hello.yaml": { + "name": "tags", + "in": "query", + "description": "tags to filter by", + "required": false, + "type": "array", + "collectionFormat": "csv", + "items": { + "type": "string" + } + } + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/referenced_parameter/hello.yaml b/test/data/toBundleExamples/referenced_parameter/hello.yaml new file mode 100644 index 0000000..266a34d --- /dev/null +++ b/test/data/toBundleExamples/referenced_parameter/hello.yaml @@ -0,0 +1,8 @@ +name: tags +in: query +description: tags to filter by +required: false +type: array +collectionFormat: csv +items: + type: string diff --git a/test/data/toBundleExamples/referenced_parameter/root.yaml b/test/data/toBundleExamples/referenced_parameter/root.yaml new file mode 100644 index 0000000..8dc8c64 --- /dev/null +++ b/test/data/toBundleExamples/referenced_parameter/root.yaml @@ -0,0 +1,42 @@ + +openapi: "3.0.2" +info: + version: 1.0.0 + title: Swagger Petstore + description: A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification + termsOfService: http://swagger.io/terms/ + contact: + name: Swagger API Team + email: apiteam@swagger.io + url: http://swagger.io + license: + name: Apache 2.0 + url: https://www.apache.org/licenses/LICENSE-2.0.html +paths: + /pets: + get: + description: Returns all pets alesuada ac... + operationId: findPets + parameters: + - $ref: "./hello.yaml" + responses: + 200: + description: pet response + schema: + type: array + items: + $ref: "#/components/schemas/Pet" +components: + schemas: + Pet: + required: + - id + - name + properties: + id: + type: integer + format: int64 + name: + type: string + tag: + type: string diff --git a/test/data/toBundleExamples/referenced_request_body/expected.json b/test/data/toBundleExamples/referenced_request_body/expected.json new file mode 100644 index 0000000..583bc5c --- /dev/null +++ b/test/data/toBundleExamples/referenced_request_body/expected.json @@ -0,0 +1,80 @@ +{ + "openapi": "3.0.2", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore", + "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "name": "Swagger API Team", + "email": "apiteam@swagger.io", + "url": "http://swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "https://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "paths": { + "/pets": { + "post": { + "operationId": "savePets", + "responses": { + "200": { + "description": "pet response", + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Pet" + } + } + } + }, + "requestBody": { + "$ref": "#/components/requestBodies/~1hello.yaml" + } + } + } + }, + "components": { + "schemas": { + "Pet": { + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "tag": { + "type": "string" + } + } + } + }, + "requestBodies": { + "/hello.yaml": { + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "address": { + "type": "string" + } + } + } + } + } + } + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/referenced_request_body/hello.yaml b/test/data/toBundleExamples/referenced_request_body/hello.yaml new file mode 100644 index 0000000..28e93d5 --- /dev/null +++ b/test/data/toBundleExamples/referenced_request_body/hello.yaml @@ -0,0 +1,9 @@ +content: + application/json: + schema: + type: object + properties: + name: + type: string + address: + type: string diff --git a/test/data/toBundleExamples/referenced_request_body/root.yaml b/test/data/toBundleExamples/referenced_request_body/root.yaml new file mode 100644 index 0000000..9eb8115 --- /dev/null +++ b/test/data/toBundleExamples/referenced_request_body/root.yaml @@ -0,0 +1,41 @@ + +openapi: "3.0.2" +info: + version: 1.0.0 + title: Swagger Petstore + description: A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification + termsOfService: http://swagger.io/terms/ + contact: + name: Swagger API Team + email: apiteam@swagger.io + url: http://swagger.io + license: + name: Apache 2.0 + url: https://www.apache.org/licenses/LICENSE-2.0.html +paths: + /pets: + post: + operationId: savePets + responses: + 200: + description: pet response + schema: + type: array + items: + $ref: "#/components/schemas/Pet" + requestBody: + $ref: "./hello.yaml" +components: + schemas: + Pet: + required: + - id + - name + properties: + id: + type: integer + format: int64 + name: + type: string + tag: + type: string diff --git a/test/data/toBundleExamples/referenced_response/expected.json b/test/data/toBundleExamples/referenced_response/expected.json new file mode 100644 index 0000000..23892d8 --- /dev/null +++ b/test/data/toBundleExamples/referenced_response/expected.json @@ -0,0 +1,52 @@ +{ + "openapi": "3.0.2", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore", + "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "name": "Swagger API Team", + "email": "apiteam@swagger.io", + "url": "http://swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "https://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "paths": { + "/hello": { + "get": { + "description": "Returns all pets alesuada ac...", + "operationId": "findPets", + "responses": { + "200": { + "$ref": "#/components/responses/~1hello.yaml" + } + } + } + } + }, + "components": { + "responses": { + "/hello.yaml": { + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "address": { + "type": "string" + } + } + } + } + } + } + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/referenced_response/hello.yaml b/test/data/toBundleExamples/referenced_response/hello.yaml new file mode 100644 index 0000000..28e93d5 --- /dev/null +++ b/test/data/toBundleExamples/referenced_response/hello.yaml @@ -0,0 +1,9 @@ +content: + application/json: + schema: + type: object + properties: + name: + type: string + address: + type: string diff --git a/test/data/toBundleExamples/referenced_response/root.yaml b/test/data/toBundleExamples/referenced_response/root.yaml new file mode 100644 index 0000000..6e2e91b --- /dev/null +++ b/test/data/toBundleExamples/referenced_response/root.yaml @@ -0,0 +1,22 @@ + +openapi: "3.0.2" +info: + version: 1.0.0 + title: Swagger Petstore + description: A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification + termsOfService: http://swagger.io/terms/ + contact: + name: Swagger API Team + email: apiteam@swagger.io + url: http://swagger.io + license: + name: Apache 2.0 + url: https://www.apache.org/licenses/LICENSE-2.0.html +paths: + /hello: + get: + description: Returns all pets alesuada ac... + operationId: findPets + responses: + 200: + $ref: "./hello.yaml" diff --git a/test/unit/bundle.test.js b/test/unit/bundle.test.js index 2bb650b..e82c12c 100644 --- a/test/unit/bundle.test.js +++ b/test/unit/bundle.test.js @@ -26,7 +26,12 @@ let expect = require('chai').expect, refExample = path.join(__dirname, BUNDLES_FOLDER + '/referenced_examples'), properties = path.join(__dirname, BUNDLES_FOLDER + '/properties'), sameSourceDifferentPlace = path.join(__dirname, BUNDLES_FOLDER + '/same_source_different_place'), - nestedProperties = path.join(__dirname, BUNDLES_FOLDER + '/nestedProperties'); + nestedProperties = path.join(__dirname, BUNDLES_FOLDER + '/nestedProperties'), + referencedResponse = path.join(__dirname, BUNDLES_FOLDER + '/referenced_response'), + referencedParameter = path.join(__dirname, BUNDLES_FOLDER + '/referenced_parameter'), + referencedRequestBody = path.join(__dirname, BUNDLES_FOLDER + '/referenced_request_body'), + referencedHeader = path.join(__dirname, BUNDLES_FOLDER + '/referenced_header'), + referencedLink = path.join(__dirname, BUNDLES_FOLDER + '/referenced_link'); describe('bundle files method - 3.0', function () { @@ -1520,6 +1525,166 @@ describe('bundle files method - 3.0', function () { expect(JSON.stringify(res.output.data[0].bundledContent, null, 2)).to.be.equal(expectedJSON); expect(res.output.data[1].bundledContent).to.be.equal(expectedYAML); }); + + it('Should return bundled file - referenced response', async function () { + let contentRoot = fs.readFileSync(referencedResponse + '/root.yaml', 'utf8'), + contentRef = fs.readFileSync(referencedResponse + '/hello.yaml', 'utf8'), + expected = fs.readFileSync(referencedResponse + '/expected.json', 'utf8'), + input = { + type: 'multiFile', + specificationVersion: '3.0', + rootFiles: [ + { + path: '/root.yaml' + } + ], + data: [ + { + path: '/root.yaml', + content: contentRoot + }, + { + path: '/hello.yaml', + content: contentRef + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(JSON.stringify(res.output.data[0].bundledContent, null, 2)).to.be.equal(expected); + }); + + it('Should return bundled file - referenced Parameter', async function () { + let contentRoot = fs.readFileSync(referencedParameter + '/root.yaml', 'utf8'), + contentRef = fs.readFileSync(referencedParameter + '/hello.yaml', 'utf8'), + expected = fs.readFileSync(referencedParameter + '/expected.json', 'utf8'), + input = { + type: 'multiFile', + specificationVersion: '3.0', + rootFiles: [ + { + path: '/root.yaml' + } + ], + data: [ + { + path: '/root.yaml', + content: contentRoot + }, + { + path: '/hello.yaml', + content: contentRef + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(JSON.stringify(res.output.data[0].bundledContent, null, 2)).to.be.equal(expected); + }); + + it('Should return bundled file - referenced Request Body', async function () { + let contentRoot = fs.readFileSync(referencedRequestBody + '/root.yaml', 'utf8'), + contentRef = fs.readFileSync(referencedRequestBody + '/hello.yaml', 'utf8'), + expected = fs.readFileSync(referencedRequestBody + '/expected.json', 'utf8'), + input = { + type: 'multiFile', + specificationVersion: '3.0', + rootFiles: [ + { + path: '/root.yaml' + } + ], + data: [ + { + path: '/root.yaml', + content: contentRoot + }, + { + path: '/hello.yaml', + content: contentRef + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(JSON.stringify(res.output.data[0].bundledContent, null, 2)).to.be.equal(expected); + }); + + it('Should return bundled file - referenced Header', async function () { + let contentRoot = fs.readFileSync(referencedHeader + '/root.yaml', 'utf8'), + contentRef = fs.readFileSync(referencedHeader + '/header.yaml', 'utf8'), + expected = fs.readFileSync(referencedHeader + '/expected.json', 'utf8'), + input = { + type: 'multiFile', + specificationVersion: '3.0', + rootFiles: [ + { + path: '/root.yaml' + } + ], + data: [ + { + path: '/root.yaml', + content: contentRoot + }, + { + path: '/header.yaml', + content: contentRef + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(JSON.stringify(res.output.data[0].bundledContent, null, 2)).to.be.equal(expected); + }); + + it('Should return bundled file - referenced Link', async function () { + let contentRoot = fs.readFileSync(referencedLink + '/root.yaml', 'utf8'), + contentRef = fs.readFileSync(referencedLink + '/link.yaml', 'utf8'), + expected = fs.readFileSync(referencedLink + '/expected.json', 'utf8'), + input = { + type: 'multiFile', + specificationVersion: '3.0', + rootFiles: [ + { + path: '/root.yaml' + } + ], + data: [ + { + path: '/root.yaml', + content: contentRoot + }, + { + path: '/link.yaml', + content: contentRef + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(JSON.stringify(res.output.data[0].bundledContent, null, 2)).to.be.equal(expected); + }); }); From 4f5958534f5b0a4714b59e495b3c7d0553a4c7b7 Mon Sep 17 00:00:00 2001 From: Luis Tejeda <46000487+LuisTejedaS@users.noreply.github.com> Date: Mon, 13 Jun 2022 10:01:33 -0500 Subject: [PATCH 2/5] Change test expected Change test expected --- test/data/toBundleExamples/referenced_header/expected.json | 4 ++-- test/data/toBundleExamples/referenced_link/expected.json | 4 ++-- test/data/toBundleExamples/referenced_parameter/expected.json | 4 ++-- .../toBundleExamples/referenced_request_body/expected.json | 4 ++-- test/data/toBundleExamples/referenced_response/expected.json | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/test/data/toBundleExamples/referenced_header/expected.json b/test/data/toBundleExamples/referenced_header/expected.json index 1aa5b7d..d4c2b00 100644 --- a/test/data/toBundleExamples/referenced_header/expected.json +++ b/test/data/toBundleExamples/referenced_header/expected.json @@ -25,7 +25,7 @@ "description": "An paged array of pets", "headers": { "x-next": { - "$ref": "#/components/headers/~1header.yaml" + "$ref": "#/components/headers/_header.yaml" } }, "content": { @@ -62,7 +62,7 @@ } }, "headers": { - "/header.yaml": { + "_header.yaml": { "description": "A link to the next page of responses", "schema": { "type": "string" diff --git a/test/data/toBundleExamples/referenced_link/expected.json b/test/data/toBundleExamples/referenced_link/expected.json index 824042e..6411b35 100644 --- a/test/data/toBundleExamples/referenced_link/expected.json +++ b/test/data/toBundleExamples/referenced_link/expected.json @@ -30,7 +30,7 @@ } }, "links": { - "$ref": "#/components/links/~1link.yaml" + "$ref": "#/components/links/_link.yaml" } } } @@ -59,7 +59,7 @@ } }, "links": { - "/link.yaml": { + "_link.yaml": { "operationId": "getRepository", "parameters": { "username": "$response.body#/owner/username", diff --git a/test/data/toBundleExamples/referenced_parameter/expected.json b/test/data/toBundleExamples/referenced_parameter/expected.json index cf7b4bb..6a7c603 100644 --- a/test/data/toBundleExamples/referenced_parameter/expected.json +++ b/test/data/toBundleExamples/referenced_parameter/expected.json @@ -22,7 +22,7 @@ "operationId": "findPets", "parameters": [ { - "$ref": "#/components/parameters/~1hello.yaml" + "$ref": "#/components/parameters/_hello.yaml" } ], "responses": { @@ -61,7 +61,7 @@ } }, "parameters": { - "/hello.yaml": { + "_hello.yaml": { "name": "tags", "in": "query", "description": "tags to filter by", diff --git a/test/data/toBundleExamples/referenced_request_body/expected.json b/test/data/toBundleExamples/referenced_request_body/expected.json index 583bc5c..2a0c5b6 100644 --- a/test/data/toBundleExamples/referenced_request_body/expected.json +++ b/test/data/toBundleExamples/referenced_request_body/expected.json @@ -31,7 +31,7 @@ } }, "requestBody": { - "$ref": "#/components/requestBodies/~1hello.yaml" + "$ref": "#/components/requestBodies/_hello.yaml" } } } @@ -58,7 +58,7 @@ } }, "requestBodies": { - "/hello.yaml": { + "_hello.yaml": { "content": { "application/json": { "schema": { diff --git a/test/data/toBundleExamples/referenced_response/expected.json b/test/data/toBundleExamples/referenced_response/expected.json index 23892d8..47e2bf8 100644 --- a/test/data/toBundleExamples/referenced_response/expected.json +++ b/test/data/toBundleExamples/referenced_response/expected.json @@ -22,7 +22,7 @@ "operationId": "findPets", "responses": { "200": { - "$ref": "#/components/responses/~1hello.yaml" + "$ref": "#/components/responses/_hello.yaml" } } } @@ -30,7 +30,7 @@ }, "components": { "responses": { - "/hello.yaml": { + "_hello.yaml": { "content": { "application/json": { "schema": { From 9078e2ad910eebbb89b25ea2644a08aac15c9144 Mon Sep 17 00:00:00 2001 From: Luis Tejeda <46000487+LuisTejedaS@users.noreply.github.com> Date: Mon, 13 Jun 2022 12:35:59 -0500 Subject: [PATCH 3/5] Add callback and security schemes support Add callback and security schemes support --- lib/30XUtils/componentsParentMatcher.js | 6 + .../referenced_callback/callback.yaml | 22 ++++ .../referenced_callback/expected.json | 122 ++++++++++++++++++ .../referenced_callback/root.yaml | 59 +++++++++ .../referenced_security_schemes/expected.json | 105 +++++++++++++++ .../referenced_security_schemes/root.yaml | 63 +++++++++ .../referenced_security_schemes/sschemes.yaml | 7 + test/unit/bundle.test.js | 68 +++++++++- 8 files changed, 451 insertions(+), 1 deletion(-) create mode 100644 test/data/toBundleExamples/referenced_callback/callback.yaml create mode 100644 test/data/toBundleExamples/referenced_callback/expected.json create mode 100644 test/data/toBundleExamples/referenced_callback/root.yaml create mode 100644 test/data/toBundleExamples/referenced_security_schemes/expected.json create mode 100644 test/data/toBundleExamples/referenced_security_schemes/root.yaml create mode 100644 test/data/toBundleExamples/referenced_security_schemes/sschemes.yaml diff --git a/lib/30XUtils/componentsParentMatcher.js b/lib/30XUtils/componentsParentMatcher.js index f37f7b7..fb840a3 100644 --- a/lib/30XUtils/componentsParentMatcher.js +++ b/lib/30XUtils/componentsParentMatcher.js @@ -35,6 +35,9 @@ const COMPONENTS_KEYS_30 = [ ], HEADER_DEFINITION = [ 'headers' + ], + CALLBACK_DEFINITION = [ + 'callbacks' ]; module.exports = { @@ -87,6 +90,9 @@ module.exports = { if (HEADER_DEFINITION.includes(trace[index + 2])) { trace[index + 1] = 'headers'; } + if (CALLBACK_DEFINITION.includes(trace[index + 2])) { + trace[index + 1] = 'callbacks'; + } } return matchFound ? traceToKey.reverse() : diff --git a/test/data/toBundleExamples/referenced_callback/callback.yaml b/test/data/toBundleExamples/referenced_callback/callback.yaml new file mode 100644 index 0000000..7ef46ee --- /dev/null +++ b/test/data/toBundleExamples/referenced_callback/callback.yaml @@ -0,0 +1,22 @@ +'{$request.query.callbackUrl}/data': + post: + requestBody: + description: subscription payload + content: + application/json: + schema: + properties: + timestamp: + type: string + format: date-time + userData: + type: string + responses: + '202': + description: | + Your server implementation should return this HTTP status code + if the data was received successfully + '204': + description: | + Your server should return this HTTP status code if no longer interested + in further updates diff --git a/test/data/toBundleExamples/referenced_callback/expected.json b/test/data/toBundleExamples/referenced_callback/expected.json new file mode 100644 index 0000000..e500c6d --- /dev/null +++ b/test/data/toBundleExamples/referenced_callback/expected.json @@ -0,0 +1,122 @@ +{ + "openapi": "3.0.2", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore", + "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "name": "Swagger API Team", + "email": "apiteam@swagger.io", + "url": "http://swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "https://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "paths": { + "/pets": { + "get": { + "tags": [ + "Authorization" + ], + "description": "Returns all pets alesuada ac...", + "operationId": "findPets", + "responses": { + "200": { + "description": "pet response", + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Pet" + } + } + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "#/components/schemas/Error" + } + } + }, + "callbacks": { + "onData": { + "$ref": "#/components/callbacks/_callback.yaml" + } + } + } + } + }, + "components": { + "schemas": { + "Pet": { + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "tag": { + "type": "string" + } + } + }, + "Error": { + "required": [ + "code", + "message" + ], + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + } + } + } + }, + "callbacks": { + "_callback.yaml": { + "{$request.query.callbackUrl}/data": { + "post": { + "requestBody": { + "description": "subscription payload", + "content": { + "application/json": { + "schema": { + "properties": { + "timestamp": { + "type": "string", + "format": "date-time" + }, + "userData": { + "type": "string" + } + } + } + } + } + }, + "responses": { + "202": { + "description": "Your server implementation should return this HTTP status code\nif the data was received successfully\n" + }, + "204": { + "description": "Your server should return this HTTP status code if no longer interested\nin further updates\n" + } + } + } + } + } + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/referenced_callback/root.yaml b/test/data/toBundleExamples/referenced_callback/root.yaml new file mode 100644 index 0000000..ce14f97 --- /dev/null +++ b/test/data/toBundleExamples/referenced_callback/root.yaml @@ -0,0 +1,59 @@ + +openapi: "3.0.2" +info: + version: 1.0.0 + title: Swagger Petstore + description: A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification + termsOfService: http://swagger.io/terms/ + contact: + name: Swagger API Team + email: apiteam@swagger.io + url: http://swagger.io + license: + name: Apache 2.0 + url: https://www.apache.org/licenses/LICENSE-2.0.html +paths: + /pets: + get: + tags: + - Authorization + description: Returns all pets alesuada ac... + operationId: findPets + responses: + "200": + description: pet response + schema: + type: array + items: + $ref: "#/components/schemas/Pet" + default: + description: unexpected error + schema: + $ref: "#/components/schemas/Error" + callbacks: + onData: + $ref: "./callback.yaml" +components: + schemas: + Pet: + required: + - id + - name + properties: + id: + type: integer + format: int64 + name: + type: string + tag: + type: string + Error: + required: + - code + - message + properties: + code: + type: integer + format: int32 + message: + type: string diff --git a/test/data/toBundleExamples/referenced_security_schemes/expected.json b/test/data/toBundleExamples/referenced_security_schemes/expected.json new file mode 100644 index 0000000..7d07a9c --- /dev/null +++ b/test/data/toBundleExamples/referenced_security_schemes/expected.json @@ -0,0 +1,105 @@ +{ + "openapi": "3.0.2", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore", + "description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "name": "Swagger API Team", + "email": "apiteam@swagger.io", + "url": "http://swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "https://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "paths": { + "/pets": { + "get": { + "tags": [ + "Authorization" + ], + "description": "Returns all pets alesuada ac...", + "operationId": "findPets", + "responses": { + "200": { + "description": "pet response", + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Pet" + } + } + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "#/components/schemas/Error" + } + } + }, + "security": [ + { + "petstore_auth": [ + "write:pets", + "read:pets" + ] + } + ] + } + } + }, + "components": { + "schemas": { + "Pet": { + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "tag": { + "type": "string" + } + } + }, + "Error": { + "required": [ + "code", + "message" + ], + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + } + } + } + }, + "securitySchemes": { + "petstore_auth": { + "type": "oauth2", + "flows": { + "implicit": { + "authorizationUrl": "http://petstore.swagger.io/api/oauth/dialog", + "scopes": { + "write:pets": "modify pets in your account", + "read:pets": "read your pets" + } + } + } + } + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/referenced_security_schemes/root.yaml b/test/data/toBundleExamples/referenced_security_schemes/root.yaml new file mode 100644 index 0000000..4d5ca35 --- /dev/null +++ b/test/data/toBundleExamples/referenced_security_schemes/root.yaml @@ -0,0 +1,63 @@ + +openapi: "3.0.2" +info: + version: 1.0.0 + title: Swagger Petstore + description: A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification + termsOfService: http://swagger.io/terms/ + contact: + name: Swagger API Team + email: apiteam@swagger.io + url: http://swagger.io + license: + name: Apache 2.0 + url: https://www.apache.org/licenses/LICENSE-2.0.html +paths: + /pets: + get: + tags: + - Authorization + description: Returns all pets alesuada ac... + operationId: findPets + responses: + "200": + description: pet response + schema: + type: array + items: + $ref: "#/components/schemas/Pet" + default: + description: unexpected error + schema: + $ref: "#/components/schemas/Error" + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' +components: + schemas: + Pet: + required: + - id + - name + properties: + id: + type: integer + format: int64 + name: + type: string + tag: + type: string + Error: + required: + - code + - message + properties: + code: + type: integer + format: int32 + message: + type: string + securitySchemes: + petstore_auth: + $ref: "./sschemes.yaml" diff --git a/test/data/toBundleExamples/referenced_security_schemes/sschemes.yaml b/test/data/toBundleExamples/referenced_security_schemes/sschemes.yaml new file mode 100644 index 0000000..cfe4d8b --- /dev/null +++ b/test/data/toBundleExamples/referenced_security_schemes/sschemes.yaml @@ -0,0 +1,7 @@ +type: oauth2 +flows: + implicit: + authorizationUrl: 'http://petstore.swagger.io/api/oauth/dialog' + scopes: + 'write:pets': modify pets in your account + 'read:pets': read your pets diff --git a/test/unit/bundle.test.js b/test/unit/bundle.test.js index e82c12c..65b93fb 100644 --- a/test/unit/bundle.test.js +++ b/test/unit/bundle.test.js @@ -31,7 +31,9 @@ let expect = require('chai').expect, referencedParameter = path.join(__dirname, BUNDLES_FOLDER + '/referenced_parameter'), referencedRequestBody = path.join(__dirname, BUNDLES_FOLDER + '/referenced_request_body'), referencedHeader = path.join(__dirname, BUNDLES_FOLDER + '/referenced_header'), - referencedLink = path.join(__dirname, BUNDLES_FOLDER + '/referenced_link'); + referencedLink = path.join(__dirname, BUNDLES_FOLDER + '/referenced_link'), + referencedCallback = path.join(__dirname, BUNDLES_FOLDER + '/referenced_callback'), + referencedSecuritySchemes = path.join(__dirname, BUNDLES_FOLDER + '/referenced_security_schemes'); describe('bundle files method - 3.0', function () { @@ -1685,6 +1687,70 @@ describe('bundle files method - 3.0', function () { expect(res.result).to.be.true; expect(JSON.stringify(res.output.data[0].bundledContent, null, 2)).to.be.equal(expected); }); + + it('Should return bundled file - referenced Callback', async function () { + let contentRoot = fs.readFileSync(referencedCallback + '/root.yaml', 'utf8'), + contentRef = fs.readFileSync(referencedCallback + '/callback.yaml', 'utf8'), + expected = fs.readFileSync(referencedCallback + '/expected.json', 'utf8'), + input = { + type: 'multiFile', + specificationVersion: '3.0', + rootFiles: [ + { + path: '/root.yaml' + } + ], + data: [ + { + path: '/root.yaml', + content: contentRoot + }, + { + path: '/callback.yaml', + content: contentRef + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(JSON.stringify(res.output.data[0].bundledContent, null, 2)).to.be.equal(expected); + }); + + it('Should return bundled file - referenced Security Schemes', async function () { + let contentRoot = fs.readFileSync(referencedSecuritySchemes + '/root.yaml', 'utf8'), + contentRef = fs.readFileSync(referencedSecuritySchemes + '/sschemes.yaml', 'utf8'), + expected = fs.readFileSync(referencedSecuritySchemes + '/expected.json', 'utf8'), + input = { + type: 'multiFile', + specificationVersion: '3.0', + rootFiles: [ + { + path: '/root.yaml' + } + ], + data: [ + { + path: '/root.yaml', + content: contentRoot + }, + { + path: '/sschemes.yaml', + content: contentRef + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(JSON.stringify(res.output.data[0].bundledContent, null, 2)).to.be.equal(expected); + }); }); From b05958d308d3b069da37a43f70984d5e14927f3e Mon Sep 17 00:00:00 2001 From: Luis Tejeda <46000487+LuisTejedaS@users.noreply.github.com> Date: Mon, 13 Jun 2022 13:38:21 -0500 Subject: [PATCH 4/5] rename files rename files --- .../referenced_parameter/expected.json | 4 ++-- .../{hello.yaml => parameter.yaml} | 0 .../toBundleExamples/referenced_parameter/root.yaml | 2 +- .../referenced_request_body/expected.json | 4 ++-- .../{hello.yaml => rbody.yaml} | 0 .../referenced_request_body/root.yaml | 2 +- .../referenced_response/expected.json | 4 ++-- .../{hello.yaml => response.yaml} | 0 .../toBundleExamples/referenced_response/root.yaml | 2 +- test/unit/bundle.test.js | 12 ++++++------ 10 files changed, 15 insertions(+), 15 deletions(-) rename test/data/toBundleExamples/referenced_parameter/{hello.yaml => parameter.yaml} (100%) rename test/data/toBundleExamples/referenced_request_body/{hello.yaml => rbody.yaml} (100%) rename test/data/toBundleExamples/referenced_response/{hello.yaml => response.yaml} (100%) diff --git a/test/data/toBundleExamples/referenced_parameter/expected.json b/test/data/toBundleExamples/referenced_parameter/expected.json index 6a7c603..61e514f 100644 --- a/test/data/toBundleExamples/referenced_parameter/expected.json +++ b/test/data/toBundleExamples/referenced_parameter/expected.json @@ -22,7 +22,7 @@ "operationId": "findPets", "parameters": [ { - "$ref": "#/components/parameters/_hello.yaml" + "$ref": "#/components/parameters/_parameter.yaml" } ], "responses": { @@ -61,7 +61,7 @@ } }, "parameters": { - "_hello.yaml": { + "_parameter.yaml": { "name": "tags", "in": "query", "description": "tags to filter by", diff --git a/test/data/toBundleExamples/referenced_parameter/hello.yaml b/test/data/toBundleExamples/referenced_parameter/parameter.yaml similarity index 100% rename from test/data/toBundleExamples/referenced_parameter/hello.yaml rename to test/data/toBundleExamples/referenced_parameter/parameter.yaml diff --git a/test/data/toBundleExamples/referenced_parameter/root.yaml b/test/data/toBundleExamples/referenced_parameter/root.yaml index 8dc8c64..2e35e08 100644 --- a/test/data/toBundleExamples/referenced_parameter/root.yaml +++ b/test/data/toBundleExamples/referenced_parameter/root.yaml @@ -18,7 +18,7 @@ paths: description: Returns all pets alesuada ac... operationId: findPets parameters: - - $ref: "./hello.yaml" + - $ref: "./parameter.yaml" responses: 200: description: pet response diff --git a/test/data/toBundleExamples/referenced_request_body/expected.json b/test/data/toBundleExamples/referenced_request_body/expected.json index 2a0c5b6..9de50c8 100644 --- a/test/data/toBundleExamples/referenced_request_body/expected.json +++ b/test/data/toBundleExamples/referenced_request_body/expected.json @@ -31,7 +31,7 @@ } }, "requestBody": { - "$ref": "#/components/requestBodies/_hello.yaml" + "$ref": "#/components/requestBodies/_rbody.yaml" } } } @@ -58,7 +58,7 @@ } }, "requestBodies": { - "_hello.yaml": { + "_rbody.yaml": { "content": { "application/json": { "schema": { diff --git a/test/data/toBundleExamples/referenced_request_body/hello.yaml b/test/data/toBundleExamples/referenced_request_body/rbody.yaml similarity index 100% rename from test/data/toBundleExamples/referenced_request_body/hello.yaml rename to test/data/toBundleExamples/referenced_request_body/rbody.yaml diff --git a/test/data/toBundleExamples/referenced_request_body/root.yaml b/test/data/toBundleExamples/referenced_request_body/root.yaml index 9eb8115..aa11208 100644 --- a/test/data/toBundleExamples/referenced_request_body/root.yaml +++ b/test/data/toBundleExamples/referenced_request_body/root.yaml @@ -24,7 +24,7 @@ paths: items: $ref: "#/components/schemas/Pet" requestBody: - $ref: "./hello.yaml" + $ref: "./rbody.yaml" components: schemas: Pet: diff --git a/test/data/toBundleExamples/referenced_response/expected.json b/test/data/toBundleExamples/referenced_response/expected.json index 47e2bf8..82f10a7 100644 --- a/test/data/toBundleExamples/referenced_response/expected.json +++ b/test/data/toBundleExamples/referenced_response/expected.json @@ -22,7 +22,7 @@ "operationId": "findPets", "responses": { "200": { - "$ref": "#/components/responses/_hello.yaml" + "$ref": "#/components/responses/_response.yaml" } } } @@ -30,7 +30,7 @@ }, "components": { "responses": { - "_hello.yaml": { + "_response.yaml": { "content": { "application/json": { "schema": { diff --git a/test/data/toBundleExamples/referenced_response/hello.yaml b/test/data/toBundleExamples/referenced_response/response.yaml similarity index 100% rename from test/data/toBundleExamples/referenced_response/hello.yaml rename to test/data/toBundleExamples/referenced_response/response.yaml diff --git a/test/data/toBundleExamples/referenced_response/root.yaml b/test/data/toBundleExamples/referenced_response/root.yaml index 6e2e91b..5e585e3 100644 --- a/test/data/toBundleExamples/referenced_response/root.yaml +++ b/test/data/toBundleExamples/referenced_response/root.yaml @@ -19,4 +19,4 @@ paths: operationId: findPets responses: 200: - $ref: "./hello.yaml" + $ref: "./response.yaml" diff --git a/test/unit/bundle.test.js b/test/unit/bundle.test.js index 65b93fb..434e65f 100644 --- a/test/unit/bundle.test.js +++ b/test/unit/bundle.test.js @@ -1530,7 +1530,7 @@ describe('bundle files method - 3.0', function () { it('Should return bundled file - referenced response', async function () { let contentRoot = fs.readFileSync(referencedResponse + '/root.yaml', 'utf8'), - contentRef = fs.readFileSync(referencedResponse + '/hello.yaml', 'utf8'), + contentRef = fs.readFileSync(referencedResponse + '/response.yaml', 'utf8'), expected = fs.readFileSync(referencedResponse + '/expected.json', 'utf8'), input = { type: 'multiFile', @@ -1546,7 +1546,7 @@ describe('bundle files method - 3.0', function () { content: contentRoot }, { - path: '/hello.yaml', + path: '/response.yaml', content: contentRef } ], @@ -1562,7 +1562,7 @@ describe('bundle files method - 3.0', function () { it('Should return bundled file - referenced Parameter', async function () { let contentRoot = fs.readFileSync(referencedParameter + '/root.yaml', 'utf8'), - contentRef = fs.readFileSync(referencedParameter + '/hello.yaml', 'utf8'), + contentRef = fs.readFileSync(referencedParameter + '/parameter.yaml', 'utf8'), expected = fs.readFileSync(referencedParameter + '/expected.json', 'utf8'), input = { type: 'multiFile', @@ -1578,7 +1578,7 @@ describe('bundle files method - 3.0', function () { content: contentRoot }, { - path: '/hello.yaml', + path: '/parameter.yaml', content: contentRef } ], @@ -1594,7 +1594,7 @@ describe('bundle files method - 3.0', function () { it('Should return bundled file - referenced Request Body', async function () { let contentRoot = fs.readFileSync(referencedRequestBody + '/root.yaml', 'utf8'), - contentRef = fs.readFileSync(referencedRequestBody + '/hello.yaml', 'utf8'), + contentRef = fs.readFileSync(referencedRequestBody + '/rbody.yaml', 'utf8'), expected = fs.readFileSync(referencedRequestBody + '/expected.json', 'utf8'), input = { type: 'multiFile', @@ -1610,7 +1610,7 @@ describe('bundle files method - 3.0', function () { content: contentRoot }, { - path: '/hello.yaml', + path: '/rbody.yaml', content: contentRef } ], From f74efe1dcd1a62fe821402883c7663693ec250ed Mon Sep 17 00:00:00 2001 From: Erik Mendoza Date: Mon, 13 Jun 2022 14:57:18 -0500 Subject: [PATCH 5/5] moving the link scenario to the correct rule while resolving it - fixing the expected file - fixing the root file --- lib/30XUtils/componentsParentMatcher.js | 4 ++-- test/data/toBundleExamples/referenced_link/expected.json | 4 +++- test/data/toBundleExamples/referenced_link/root.yaml | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/30XUtils/componentsParentMatcher.js b/lib/30XUtils/componentsParentMatcher.js index fb840a3..330e717 100644 --- a/lib/30XUtils/componentsParentMatcher.js +++ b/lib/30XUtils/componentsParentMatcher.js @@ -73,8 +73,8 @@ module.exports = { if (REQUEST_BODY_CONTAINER.includes(item)) { item = 'requestBodies'; } - if (LINKS_CONTAINER.includes(item)) { - item = 'links'; + if (LINKS_CONTAINER.includes(trace[index + 2])) { + trace[index + 1] = 'links'; } if (PROPERTY_DEFINITION.includes(trace[index + 2])) { trace[index + 1] = 'schemas'; diff --git a/test/data/toBundleExamples/referenced_link/expected.json b/test/data/toBundleExamples/referenced_link/expected.json index 6411b35..f96373c 100644 --- a/test/data/toBundleExamples/referenced_link/expected.json +++ b/test/data/toBundleExamples/referenced_link/expected.json @@ -30,7 +30,9 @@ } }, "links": { - "$ref": "#/components/links/_link.yaml" + "theLinkId": { + "$ref": "#/components/links/_link.yaml" + } } } } diff --git a/test/data/toBundleExamples/referenced_link/root.yaml b/test/data/toBundleExamples/referenced_link/root.yaml index 900c550..c4310e8 100644 --- a/test/data/toBundleExamples/referenced_link/root.yaml +++ b/test/data/toBundleExamples/referenced_link/root.yaml @@ -25,7 +25,8 @@ paths: items: $ref: "#/components/schemas/Pet" links: - $ref: "./link.yaml" + theLinkId: + $ref: "./link.yaml" components: schemas: Pet: