Merge branch 'feature/swagger20BundleSupport' into feat/response20

This commit is contained in:
Luis Tejeda
2022-06-14 16:26:27 -05:00
4 changed files with 186 additions and 0 deletions

View File

@@ -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"
}
}
}
}

View File

@@ -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"

View File

@@ -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

View File

@@ -55,6 +55,7 @@ let expect = require('chai').expect,
SWAGGER_PETSTORE_FOLDER = path.join(__dirname, '../data/swaggerMultifile/petstore-separate-yaml'), SWAGGER_PETSTORE_FOLDER = path.join(__dirname, '../data/swaggerMultifile/petstore-separate-yaml'),
additionalProperties20 = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + '/additionalProperties'), additionalProperties20 = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + '/additionalProperties'),
additionalProperties = path.join(__dirname, BUNDLES_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'); referencedResponse20 = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + '/referenced_response');
describe('bundle files method - 3.0', function () { 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); 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() { it('Should bundle file from - referenced response 2.0', async function() {
let contentRootFile = fs.readFileSync(referencedResponse20 + '/root.yaml', 'utf8'), let contentRootFile = fs.readFileSync(referencedResponse20 + '/root.yaml', 'utf8'),
referenced = fs.readFileSync(referencedResponse20 + '/response.yaml', 'utf8'), referenced = fs.readFileSync(referencedResponse20 + '/response.yaml', 'utf8'),
@@ -2574,6 +2607,7 @@ describe('bundle files method - 2.0', function() {
bundleFormat: 'JSON' bundleFormat: 'JSON'
}; };
const res = await Converter.bundle(input); const res = await Converter.bundle(input);
expect(res).to.not.be.empty; expect(res).to.not.be.empty;
expect(res.result).to.be.true; expect(res.result).to.be.true;
expect(JSON.stringify(res.output.data[0].bundledContent, null, 2)).to.be.equal(expected); expect(JSON.stringify(res.output.data[0].bundledContent, null, 2)).to.be.equal(expected);