Merge pull request #544 from postmanlabs/fix/referencedComponents

Fix/referenced components
This commit is contained in:
Carlos-Veloz
2022-06-13 17:31:50 -05:00
committed by GitHub
23 changed files with 1219 additions and 1 deletions

View File

@@ -23,6 +23,21 @@ const COMPONENTS_KEYS_30 = [
],
PROPERTY_DEFINITION = [
'properties'
],
RESPONSE_DEFINITION = [
'responses'
],
REQUEST_BODY_CONTAINER = [
'requestBody'
],
LINKS_CONTAINER = [
'links'
],
HEADER_DEFINITION = [
'headers'
],
CALLBACK_DEFINITION = [
'callbacks'
];
module.exports = {
@@ -55,6 +70,12 @@ module.exports = {
if (EXAMPLE_CONTAINERS.includes(item)) {
item = 'examples';
}
if (REQUEST_BODY_CONTAINER.includes(item)) {
item = 'requestBodies';
}
if (LINKS_CONTAINER.includes(trace[index + 2])) {
trace[index + 1] = 'links';
}
if (PROPERTY_DEFINITION.includes(trace[index + 2])) {
trace[index + 1] = 'schemas';
}
@@ -63,6 +84,15 @@ 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';
}
if (CALLBACK_DEFINITION.includes(trace[index + 2])) {
trace[index + 1] = 'callbacks';
}
}
return matchFound ?
traceToKey.reverse() :

View File

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

View File

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

View File

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

View File

@@ -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/_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"
}
}
}
},
"headers": {
"_header.yaml": {
"description": "A link to the next page of responses",
"schema": {
"type": "string"
}
}
}
}
}

View File

@@ -0,0 +1,3 @@
description: A link to the next page of responses
schema:
type: string

View File

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

View File

@@ -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": "pet response",
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Pet"
}
},
"links": {
"theLinkId": {
"$ref": "#/components/links/_link.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"
}
}
}
}
}

View File

@@ -0,0 +1,4 @@
operationId: getRepository
parameters:
username: $response.body#/owner/username
slug: $response.body#/slug

View File

@@ -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: pet response
schema:
type: array
items:
$ref: "#/components/schemas/Pet"
links:
theLinkId:
$ref: "./link.yaml"
components:
schemas:
Pet:
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string

View File

@@ -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/_parameter.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": {
"_parameter.yaml": {
"name": "tags",
"in": "query",
"description": "tags to filter by",
"required": false,
"type": "array",
"collectionFormat": "csv",
"items": {
"type": "string"
}
}
}
}
}

View File

@@ -0,0 +1,8 @@
name: tags
in: query
description: tags to filter by
required: false
type: array
collectionFormat: csv
items:
type: string

View File

@@ -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: "./parameter.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

View File

@@ -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/_rbody.yaml"
}
}
}
},
"components": {
"schemas": {
"Pet": {
"required": [
"id",
"name"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},
"tag": {
"type": "string"
}
}
}
},
"requestBodies": {
"_rbody.yaml": {
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"address": {
"type": "string"
}
}
}
}
}
}
}
}
}

View File

@@ -0,0 +1,9 @@
content:
application/json:
schema:
type: object
properties:
name:
type: string
address:
type: string

View File

@@ -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: "./rbody.yaml"
components:
schemas:
Pet:
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string

View File

@@ -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/_response.yaml"
}
}
}
}
},
"components": {
"responses": {
"_response.yaml": {
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"address": {
"type": "string"
}
}
}
}
}
}
}
}
}

View File

@@ -0,0 +1,9 @@
content:
application/json:
schema:
type: object
properties:
name:
type: string
address:
type: string

View File

@@ -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: "./response.yaml"

View File

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

View File

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

View File

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

View File

@@ -26,7 +26,14 @@ 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'),
referencedCallback = path.join(__dirname, BUNDLES_FOLDER + '/referenced_callback'),
referencedSecuritySchemes = path.join(__dirname, BUNDLES_FOLDER + '/referenced_security_schemes');
describe('bundle files method - 3.0', function () {
@@ -1520,6 +1527,230 @@ 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 + '/response.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: '/response.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 + '/parameter.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: '/parameter.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 + '/rbody.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: '/rbody.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);
});
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);
});
});