diff --git a/test/data/toBundleExamples/swagger20/referenced_security_schemes/expected.json b/test/data/toBundleExamples/swagger20/referenced_security_schemes/expected.json new file mode 100644 index 0000000..f003055 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_security_schemes/expected.json @@ -0,0 +1,91 @@ +{ + "swagger": "2.0", + "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": "#/definitions/Pet" + } + } + } + }, + "security": [ + { + "petstore_auth": [ + "write:pets", + "read:pets" + ] + } + ] + } + } + }, + "definitions": { + "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" + } + } + } + }, + "securityDefinitions": { + "petstore_auth": { + "type": "oauth2", + "authorizationUrl": "http://swagger.io/api/oauth/dialog", + "flow": "implicit", + "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/swagger20/referenced_security_schemes/root.yaml b/test/data/toBundleExamples/swagger20/referenced_security_schemes/root.yaml new file mode 100644 index 0000000..cfef5e9 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_security_schemes/root.yaml @@ -0,0 +1,55 @@ +swagger: '2.0' +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: '#/definitions/Pet' + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' +definitions: + 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 +securityDefinitions: + petstore_auth: + $ref: "./sschemes.yaml" diff --git a/test/data/toBundleExamples/swagger20/referenced_security_schemes/sschemes.yaml b/test/data/toBundleExamples/swagger20/referenced_security_schemes/sschemes.yaml new file mode 100644 index 0000000..68a4da3 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_security_schemes/sschemes.yaml @@ -0,0 +1,6 @@ +type: oauth2 +authorizationUrl: http://swagger.io/api/oauth/dialog +flow: implicit +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 65422e0..dbe5e2b 100644 --- a/test/unit/bundle.test.js +++ b/test/unit/bundle.test.js @@ -55,6 +55,7 @@ let expect = require('chai').expect, SWAGGER_PETSTORE_FOLDER = path.join(__dirname, '../data/swaggerMultifile/petstore-separate-yaml'), additionalProperties20 = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + '/additionalProperties'), additionalProperties = path.join(__dirname, BUNDLES_FOLDER + '/additionalProperties'), + referencedSecuritySchemes20 = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + '/referenced_security_schemes'), referencedResponse20 = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + '/referenced_response'); describe('bundle files method - 3.0', function () { @@ -2548,6 +2549,38 @@ describe('bundle files method - 2.0', function() { 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 contentRootFile = fs.readFileSync(referencedSecuritySchemes20 + '/root.yaml', 'utf8'), + contentRef = fs.readFileSync(referencedSecuritySchemes20 + '/sschemes.yaml', 'utf8'), + expected = fs.readFileSync(referencedSecuritySchemes20 + '/expected.json', 'utf8'), + input = { + type: 'multiFile', + specificationVersion: '2.0', + rootFiles: [ + { + path: '/root.yaml' + } + ], + data: [ + { + path: '/root.yaml', + content: contentRootFile + }, + { + 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); + }); + it('Should bundle file from - referenced response 2.0', async function() { let contentRootFile = fs.readFileSync(referencedResponse20 + '/root.yaml', 'utf8'), referenced = fs.readFileSync(referencedResponse20 + '/response.yaml', 'utf8'), @@ -2574,6 +2607,7 @@ describe('bundle files method - 2.0', function() { 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);