mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Fixing properties resolving
Properties should be resolved as independant schema not always inline
This commit is contained in:
@@ -20,6 +20,9 @@ const COMPONENTS_KEYS_30 = [
|
||||
],
|
||||
EXAMPLE_CONTAINERS = [
|
||||
'example'
|
||||
],
|
||||
PROPERTY_DEFINITION = [
|
||||
'properties'
|
||||
];
|
||||
|
||||
module.exports = {
|
||||
@@ -45,13 +48,16 @@ module.exports = {
|
||||
res.push(jsonPointerDecodeAndReplace(`${filePathName}${localPart}`));
|
||||
trace = [...res].reverse();
|
||||
|
||||
for (let item of trace) {
|
||||
for (let [index, item] of trace.entries()) {
|
||||
if (SCHEMA_CONTAINERS.includes(item)) {
|
||||
item = 'schemas';
|
||||
}
|
||||
if (EXAMPLE_CONTAINERS.includes(item)) {
|
||||
item = 'examples';
|
||||
}
|
||||
if (PROPERTY_DEFINITION.includes(trace[index + 2])) {
|
||||
trace[index + 1] = 'schemas';
|
||||
}
|
||||
traceToKey.push(item);
|
||||
if (COMPONENTS_KEYS_30.includes(item)) {
|
||||
matchFound = true;
|
||||
|
||||
@@ -334,6 +334,18 @@ function getNodeContentAndReferences (currentNode, allData, specRoot, version) {
|
||||
* @returns {object} The components object related to the file
|
||||
*/
|
||||
function generateComponentsObject (documentContext, rootContent, refTypeResolver, components, version) {
|
||||
let notInLine = Object.entries(documentContext.globalReferences).filter(([, value]) => {
|
||||
return value.keyInComponents.length !== 0;
|
||||
});
|
||||
notInLine.forEach(([key, value]) => {
|
||||
let [, partial] = key.split('#');
|
||||
setValueInComponents(
|
||||
value.keyInComponents,
|
||||
components,
|
||||
getContentFromTrace(documentContext.nodeContents[key], partial),
|
||||
version
|
||||
);
|
||||
});
|
||||
[rootContent, components].forEach((contentData) => {
|
||||
traverseUtility(contentData).forEach(function (property) {
|
||||
if (property) {
|
||||
|
||||
@@ -12,6 +12,9 @@ const COMPONENTS_KEYS_20 = [
|
||||
],
|
||||
INLINE = [
|
||||
'examples'
|
||||
],
|
||||
PROPERTY_DEFINITION = [
|
||||
'properties'
|
||||
];
|
||||
|
||||
module.exports = {
|
||||
@@ -28,7 +31,8 @@ module.exports = {
|
||||
trace = [],
|
||||
traceToKey = [],
|
||||
matchFound = false,
|
||||
isRootKey = false;
|
||||
isRootKey = false,
|
||||
traceModified = false;
|
||||
|
||||
res.push(jsonPointerDecodeAndReplace(`${filePathName}${localPart}`));
|
||||
trace = [...res].reverse();
|
||||
@@ -36,6 +40,11 @@ module.exports = {
|
||||
for (let [index, item] of trace.entries()) {
|
||||
if (SCHEMA_PARENTS.includes(item)) {
|
||||
item = 'definitions';
|
||||
traceModified = true;
|
||||
}
|
||||
if (PROPERTY_DEFINITION.includes(trace[index + 2])) {
|
||||
trace[index + 1] = 'definitions';
|
||||
traceModified = true;
|
||||
}
|
||||
if (INLINE.includes(item)) {
|
||||
matchFound = false;
|
||||
@@ -44,7 +53,8 @@ module.exports = {
|
||||
traceToKey.push(item);
|
||||
if (COMPONENTS_KEYS_20.includes(item)) {
|
||||
matchFound = true;
|
||||
isRootKey = trace[index + 1] === undefined;
|
||||
isRootKey = trace[index + 1] === undefined &&
|
||||
!traceModified;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,19 +49,22 @@
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"theUsersPet": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"breed": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
"$ref": "#/components/schemas/~1schemas~1user.yaml%23~1Pet"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/user.yaml#/Pet": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"breed": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,43 +49,58 @@
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"favoriteFood": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"brand": {
|
||||
"type": "string"
|
||||
},
|
||||
"benefits": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/~1schemas~1food.yaml%23~1Benefit"
|
||||
}
|
||||
},
|
||||
"cost": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
"$ref": "#/components/schemas/~1schemas~1food.yaml%23Food"
|
||||
},
|
||||
"theUsersPet": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"breed": {
|
||||
"type": "string"
|
||||
},
|
||||
"color": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/~1schemas~1user.yaml%23~1Color"
|
||||
}
|
||||
}
|
||||
}
|
||||
"$ref": "#/components/schemas/~1schemas~1user.yaml%23~1Pet"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/food.yaml#Food": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"brand": {
|
||||
"$ref": "#/components/schemas/~1schemas~1food.yaml%23~1Brand"
|
||||
},
|
||||
"benefits": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/~1schemas~1food.yaml%23~1Benefit"
|
||||
}
|
||||
},
|
||||
"cost": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/user.yaml#/Pet": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"breed": {
|
||||
"type": "string"
|
||||
},
|
||||
"color": {
|
||||
"$ref": "#/components/schemas/~1schemas~1user.yaml%23~1Colors"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/user.yaml#/Colors": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/~1schemas~1user.yaml%23~1Color"
|
||||
}
|
||||
},
|
||||
"/schemas/user.yaml#/Color": {
|
||||
"type": "string"
|
||||
},
|
||||
"/schemas/food.yaml#/Brand": {
|
||||
"type": "string"
|
||||
},
|
||||
"/schemas/food.yaml#/Benefit": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -96,9 +111,6 @@
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/user.yaml#/Color": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,31 +80,13 @@
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"userInfo": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"userName": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
"$ref": "#/components/schemas/~1schemas~1user.yaml"
|
||||
},
|
||||
"carType": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"model": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
"$ref": "#/components/schemas/~1schemas~1carType.yaml"
|
||||
},
|
||||
"work": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"office": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
"$ref": "#/components/schemas/~1otherSchemas~1work.yaml"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -118,6 +100,36 @@
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/user.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"userName": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/carType.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"model": {
|
||||
"$ref": "#/components/schemas/~1otherSchemas~1model.yaml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/otherSchemas/work.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"office": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/otherSchemas/model.yaml": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
126
test/data/toBundleExamples/nestedProperties/expected.json
Normal file
126
test/data/toBundleExamples/nestedProperties/expected.json
Normal file
@@ -0,0 +1,126 @@
|
||||
{
|
||||
"openapi": "3.0.0",
|
||||
"info": {
|
||||
"title": "Sample API",
|
||||
"description": "Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.",
|
||||
"version": "0.1.9"
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "http://api.example.com/v1",
|
||||
"description": "Optional server description, e.g. Main (production) server"
|
||||
},
|
||||
{
|
||||
"url": "http://staging-api.example.com",
|
||||
"description": "Optional server description, e.g. Internal staging server for testing"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/users/{userId}": {
|
||||
"get": {
|
||||
"summary": "Get a user by ID",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A single user.",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/~1schemas~1user.yaml"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"/schemas/user.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"userName": {
|
||||
"type": "string"
|
||||
},
|
||||
"complexProp": {
|
||||
"$ref": "#/components/schemas/~1properties~1prop.yaml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/properties/prop.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"firstName": {
|
||||
"type": "string"
|
||||
},
|
||||
"secondName": {
|
||||
"type": "string"
|
||||
},
|
||||
"age": {
|
||||
"type": "integer"
|
||||
},
|
||||
"nestedProp": {
|
||||
"$ref": "#/components/schemas/~1properties~1nestedProp.yaml"
|
||||
},
|
||||
"country": {
|
||||
"$ref": "#/components/schemas/~1properties~1country.yaml"
|
||||
},
|
||||
"warrior": {
|
||||
"$ref": "#/components/schemas/~1properties~1warrior.yaml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/properties/nestedProp.yaml": {
|
||||
"type": "object",
|
||||
"rock": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"friendly": {
|
||||
"type": "string"
|
||||
},
|
||||
"lastNested": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"this": {
|
||||
"type": "string"
|
||||
},
|
||||
"is": {
|
||||
"type": "string"
|
||||
},
|
||||
"the": {
|
||||
"type": "string"
|
||||
},
|
||||
"last": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/properties/country.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"region": {
|
||||
"type": "string"
|
||||
},
|
||||
"flag": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/properties/warrior.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"power": {
|
||||
"type": "string"
|
||||
},
|
||||
"weapon": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
type: object
|
||||
properties:
|
||||
region:
|
||||
type: string
|
||||
flag:
|
||||
type: string
|
||||
@@ -0,0 +1,10 @@
|
||||
type: object
|
||||
properties:
|
||||
this:
|
||||
type: string
|
||||
is:
|
||||
type: string
|
||||
the:
|
||||
type: string
|
||||
last:
|
||||
type: integer
|
||||
@@ -0,0 +1,7 @@
|
||||
type: object
|
||||
rock:
|
||||
type: boolean
|
||||
friendly:
|
||||
type: string
|
||||
lastNested:
|
||||
$ref: "./lastNested.yaml"
|
||||
@@ -0,0 +1,14 @@
|
||||
type: object
|
||||
properties:
|
||||
firstName:
|
||||
type: string
|
||||
secondName:
|
||||
type: string
|
||||
age:
|
||||
type: integer
|
||||
nestedProp:
|
||||
$ref: "./nestedProp.yaml"
|
||||
country:
|
||||
$ref: "./country.yaml"
|
||||
warrior:
|
||||
$ref: "./warrior.yaml"
|
||||
@@ -0,0 +1,6 @@
|
||||
type: object
|
||||
properties:
|
||||
power:
|
||||
type: string
|
||||
weapon:
|
||||
type: string
|
||||
23
test/data/toBundleExamples/nestedProperties/root.yaml
Normal file
23
test/data/toBundleExamples/nestedProperties/root.yaml
Normal file
@@ -0,0 +1,23 @@
|
||||
openapi: 3.0.0
|
||||
info:
|
||||
title: Sample API
|
||||
description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.
|
||||
version: 0.1.9
|
||||
|
||||
servers:
|
||||
- url: http://api.example.com/v1
|
||||
description: Optional server description, e.g. Main (production) server
|
||||
- url: http://staging-api.example.com
|
||||
description: Optional server description, e.g. Internal staging server for testing
|
||||
|
||||
paths:
|
||||
/users/{userId}:
|
||||
get:
|
||||
summary: Get a user by ID
|
||||
responses:
|
||||
200:
|
||||
description: A single user.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "./schemas/user.yaml"
|
||||
@@ -0,0 +1,8 @@
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
userName:
|
||||
type: string
|
||||
complexProp:
|
||||
$ref: "../properties/prop.yaml"
|
||||
69
test/data/toBundleExamples/properties/expected.json
Normal file
69
test/data/toBundleExamples/properties/expected.json
Normal file
@@ -0,0 +1,69 @@
|
||||
{
|
||||
"openapi": "3.0.0",
|
||||
"info": {
|
||||
"title": "Sample API",
|
||||
"description": "Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.",
|
||||
"version": "0.1.9"
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "http://api.example.com/v1",
|
||||
"description": "Optional server description, e.g. Main (production) server"
|
||||
},
|
||||
{
|
||||
"url": "http://staging-api.example.com",
|
||||
"description": "Optional server description, e.g. Internal staging server for testing"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/users/{userId}": {
|
||||
"get": {
|
||||
"summary": "Get a user by ID",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A single user.",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/~1schemas~1user.yaml"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"/schemas/user.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"userName": {
|
||||
"type": "string"
|
||||
},
|
||||
"complexProp": {
|
||||
"$ref": "#/components/schemas/~1schemas~1prop.yaml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/prop.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"firstName": {
|
||||
"type": "string"
|
||||
},
|
||||
"secondName": {
|
||||
"type": "string"
|
||||
},
|
||||
"age": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
23
test/data/toBundleExamples/properties/root.yaml
Normal file
23
test/data/toBundleExamples/properties/root.yaml
Normal file
@@ -0,0 +1,23 @@
|
||||
openapi: 3.0.0
|
||||
info:
|
||||
title: Sample API
|
||||
description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.
|
||||
version: 0.1.9
|
||||
|
||||
servers:
|
||||
- url: http://api.example.com/v1
|
||||
description: Optional server description, e.g. Main (production) server
|
||||
- url: http://staging-api.example.com
|
||||
description: Optional server description, e.g. Internal staging server for testing
|
||||
|
||||
paths:
|
||||
/users/{userId}:
|
||||
get:
|
||||
summary: Get a user by ID
|
||||
responses:
|
||||
200:
|
||||
description: A single user.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "./schemas/user.yaml"
|
||||
8
test/data/toBundleExamples/properties/schemas/prop.yaml
Normal file
8
test/data/toBundleExamples/properties/schemas/prop.yaml
Normal file
@@ -0,0 +1,8 @@
|
||||
type: object
|
||||
properties:
|
||||
firstName:
|
||||
type: string
|
||||
secondName:
|
||||
type: string
|
||||
age:
|
||||
type: integer
|
||||
8
test/data/toBundleExamples/properties/schemas/user.yaml
Normal file
8
test/data/toBundleExamples/properties/schemas/user.yaml
Normal file
@@ -0,0 +1,8 @@
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
userName:
|
||||
type: string
|
||||
complexProp:
|
||||
$ref: ./prop.yaml
|
||||
@@ -63,12 +63,7 @@
|
||||
"type": "string"
|
||||
},
|
||||
"special": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"specialUserId": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
"$ref": "#/components/schemas/~1schemas~1user~1special.yaml"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -82,23 +77,37 @@
|
||||
"type": "string"
|
||||
},
|
||||
"special": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"specialClientId": {
|
||||
"type": "string"
|
||||
},
|
||||
"magic": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"magicNumber": {
|
||||
"type": "integer"
|
||||
},
|
||||
"magicString": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"$ref": "#/components/schemas/~1schemas~1client~1special.yaml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/client/special.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"specialClientId": {
|
||||
"type": "string"
|
||||
},
|
||||
"magic": {
|
||||
"$ref": "#/components/schemas/~1schemas~1client~1magic.yaml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/client/magic.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"magicNumber": {
|
||||
"type": "integer"
|
||||
},
|
||||
"magicString": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/user/special.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"specialUserId": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
{
|
||||
"openapi": "3.0.0",
|
||||
"info": {
|
||||
"title": "Sample API",
|
||||
"description": "Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.",
|
||||
"version": "0.1.9"
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "http://api.example.com/v1",
|
||||
"description": "Optional server description, e.g. Main (production) server"
|
||||
},
|
||||
{
|
||||
"url": "http://staging-api.example.com",
|
||||
"description": "Optional server description, e.g. Internal staging server for testing"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/users": {
|
||||
"get": {
|
||||
"summary": "Get a user by ID",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A single user.",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/~1schemas~1user~1user.yaml"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/clients": {
|
||||
"get": {
|
||||
"summary": "Get a user by ID",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A single user.",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/~1schemas~1client~1client.yaml"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"/schemas/user/user.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"userName": {
|
||||
"type": "string"
|
||||
},
|
||||
"special": {
|
||||
"$ref": "#/components/schemas/~1schemas~1user~1special.yaml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/client/client.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"idClient": {
|
||||
"type": "integer"
|
||||
},
|
||||
"clientName": {
|
||||
"type": "string"
|
||||
},
|
||||
"special": {
|
||||
"$ref": "#/components/schemas/~1schemas~1user~1special.yaml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/user/special.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"specialUserId": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
openapi: 3.0.0
|
||||
info:
|
||||
title: Sample API
|
||||
description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.
|
||||
version: 0.1.9
|
||||
|
||||
servers:
|
||||
- url: http://api.example.com/v1
|
||||
description: Optional server description, e.g. Main (production) server
|
||||
- url: http://staging-api.example.com
|
||||
description: Optional server description, e.g. Internal staging server for testing
|
||||
|
||||
paths:
|
||||
/users:
|
||||
get:
|
||||
summary: Get a user by ID
|
||||
responses:
|
||||
200:
|
||||
description: A single user.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "./schemas/user/user.yaml"
|
||||
/clients:
|
||||
get:
|
||||
summary: Get a user by ID
|
||||
responses:
|
||||
200:
|
||||
description: A single user.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "./schemas/client/client.yaml"
|
||||
@@ -0,0 +1,8 @@
|
||||
type: object
|
||||
properties:
|
||||
idClient:
|
||||
type: integer
|
||||
clientName:
|
||||
type: string
|
||||
special:
|
||||
$ref: ../user/special.yaml
|
||||
@@ -0,0 +1,4 @@
|
||||
type: object
|
||||
properties:
|
||||
specialUserId:
|
||||
type: string
|
||||
@@ -0,0 +1,8 @@
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
userName:
|
||||
type: string
|
||||
special:
|
||||
$ref: ./special.yaml
|
||||
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"openapi": "3.0.0",
|
||||
"info": {
|
||||
"title": "Sample API",
|
||||
"description": "Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.",
|
||||
"version": "0.1.9"
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"url": "http://api.example.com/v1",
|
||||
"description": "Optional server description, e.g. Main (production) server"
|
||||
},
|
||||
{
|
||||
"url": "http://staging-api.example.com",
|
||||
"description": "Optional server description, e.g. Internal staging server for testing"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/users/{userId}": {
|
||||
"get": {
|
||||
"summary": "Get a user by ID",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A single user.",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/~1schemas~1user.yaml"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"/schemas/user.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"userName": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
openapi: 3.0.0
|
||||
info:
|
||||
title: Sample API
|
||||
description: >-
|
||||
Optional multiline or single-line description in
|
||||
[CommonMark](http://commonmark.org/help/) or HTML.
|
||||
version: 0.1.9
|
||||
servers:
|
||||
- url: 'http://api.example.com/v1'
|
||||
description: 'Optional server description, e.g. Main (production) server'
|
||||
- url: 'http://staging-api.example.com'
|
||||
description: 'Optional server description, e.g. Internal staging server for testing'
|
||||
paths:
|
||||
'/users/{userId}':
|
||||
get:
|
||||
summary: Get a user by ID
|
||||
responses:
|
||||
'200':
|
||||
description: A single user.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/~1schemas~1user.yaml'
|
||||
components:
|
||||
schemas:
|
||||
/schemas/user.yaml:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
userName:
|
||||
type: string
|
||||
@@ -0,0 +1,6 @@
|
||||
headerTest:
|
||||
schema:
|
||||
type: integer
|
||||
example: 5000
|
||||
description: >-
|
||||
The test header
|
||||
@@ -0,0 +1,26 @@
|
||||
openapi: 3.0.0
|
||||
info:
|
||||
title: Sample API
|
||||
description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.
|
||||
version: 0.1.9
|
||||
|
||||
servers:
|
||||
- url: http://api.example.com/v1
|
||||
description: Optional server description, e.g. Main (production) server
|
||||
- url: http://staging-api.example.com
|
||||
description: Optional server description, e.g. Internal staging server for testing
|
||||
|
||||
paths:
|
||||
/users/{userId}:
|
||||
get:
|
||||
summary: Get a user by ID
|
||||
responses:
|
||||
200:
|
||||
description: A single user.
|
||||
headers:
|
||||
ratelimit-limit:
|
||||
$ref: '../headers.yaml#/headerTest'
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "./schemas/user.yaml"
|
||||
@@ -0,0 +1,6 @@
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
userName:
|
||||
type: string
|
||||
@@ -51,18 +51,21 @@
|
||||
"type": "string"
|
||||
},
|
||||
"Color": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"uses": {
|
||||
"type": "string"
|
||||
},
|
||||
"color": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
"$ref": "#/definitions/~1pet.yaml%23~1Color"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/pet.yaml#/Color": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"uses": {
|
||||
"type": "string"
|
||||
},
|
||||
"color": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,38 +80,47 @@
|
||||
"type": "string"
|
||||
},
|
||||
"Color": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"uses": {
|
||||
"type": "string"
|
||||
},
|
||||
"color": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
"$ref": "#/definitions/~1pet.yaml%23~1Color"
|
||||
},
|
||||
"FavoriteFood": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"brand": {
|
||||
"type": "string"
|
||||
},
|
||||
"benefits": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/~1food.yaml%23~1Benefit"
|
||||
}
|
||||
},
|
||||
"cost": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
"$ref": "#/definitions/~1food.yaml%23~1Food"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/pet.yaml#/Color": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"uses": {
|
||||
"type": "string"
|
||||
},
|
||||
"color": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/food.yaml#/Food": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"brand": {
|
||||
"$ref": "#/definitions/~1food.yaml%23~1Brand"
|
||||
},
|
||||
"benefits": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/~1food.yaml%23~1Benefit"
|
||||
}
|
||||
},
|
||||
"cost": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/food.yaml#/Brand": {
|
||||
"type": "string"
|
||||
},
|
||||
"/food.yaml#/Benefit": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -52,18 +52,21 @@
|
||||
"type": "string"
|
||||
},
|
||||
"Color": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"uses": {
|
||||
"type": "string"
|
||||
},
|
||||
"color": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
"$ref": "#/definitions/~1pet.yaml%23~1Color"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/pet.yaml#/Color": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"uses": {
|
||||
"type": "string"
|
||||
},
|
||||
"color": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,20 +47,26 @@
|
||||
"type": "string"
|
||||
},
|
||||
"favoriteFood": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"brand": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
"$ref": "#/definitions/~1schemas~1favorite_food.yaml%23~1FavoriteFood"
|
||||
},
|
||||
"foodPrice": {
|
||||
"type": "integer"
|
||||
"$ref": "#/definitions/~1schemas~1favorite_food.yaml%23~1Price"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/favorite_food.yaml#/FavoriteFood": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"brand": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/favorite_food.yaml#/Price": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"title": "Sample API",
|
||||
"description": "API description in Markdown.",
|
||||
"version": "1.0.0"
|
||||
},
|
||||
"host": "api.example.com",
|
||||
"basePath": "/v1",
|
||||
"schemes": [
|
||||
"https"
|
||||
],
|
||||
"paths": {
|
||||
"/users": {
|
||||
"get": {
|
||||
"summary": "Returns a list of users.",
|
||||
"description": "Optional extended description in Markdown.",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/~1schemas~1user.yaml"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"/schemas/user.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"age": {
|
||||
"$ref": "#/definitions/~1schemas~1age.yaml"
|
||||
},
|
||||
"hobbies": {
|
||||
"$ref": "#/definitions/~1schemas~1hobbies.yaml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/age.yaml": {
|
||||
"type": "string"
|
||||
},
|
||||
"/schemas/hobbies.yaml": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/~1schemas~1hobby.yaml"
|
||||
}
|
||||
},
|
||||
"/schemas/hobby.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"position": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
swagger: "2.0"
|
||||
info:
|
||||
$ref: ./info.yaml
|
||||
host: api.example.com
|
||||
basePath: /v1
|
||||
schemes:
|
||||
- https
|
||||
paths:
|
||||
$ref: ./paths.yaml
|
||||
@@ -0,0 +1,3 @@
|
||||
title: Sample API
|
||||
description: API description in Markdown.
|
||||
version: 1.0.0
|
||||
@@ -0,0 +1,13 @@
|
||||
/users:
|
||||
get:
|
||||
summary: Returns a list of users.
|
||||
description: Optional extended description in Markdown.
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
200:
|
||||
description: OK
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: "./schemas/user.yaml"
|
||||
@@ -0,0 +1 @@
|
||||
type: string
|
||||
@@ -0,0 +1,3 @@
|
||||
type: array
|
||||
items:
|
||||
$ref: "./hobby.yaml"
|
||||
@@ -0,0 +1,6 @@
|
||||
type: object
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
position:
|
||||
type: integer
|
||||
@@ -0,0 +1,6 @@
|
||||
type: object
|
||||
properties:
|
||||
age:
|
||||
$ref: "./age.yaml"
|
||||
hobbies:
|
||||
$ref: "./hobbies.yaml"
|
||||
@@ -47,15 +47,18 @@
|
||||
"type": "string"
|
||||
},
|
||||
"favoriteFood": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"brand": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
"$ref": "#/definitions/~1schemas~1favorite_food.yaml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/favorite_food.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"brand": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/~1schemas~1user.yaml"
|
||||
"$ref": "#/definitions/~1schemas~1user.yaml%23User"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/~1otherSchemas~1client.yaml"
|
||||
"$ref": "#/definitions/~1otherSchemas~1client.yaml%23Client"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,58 +47,39 @@
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"/schemas/user.yaml": {
|
||||
"User": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"id",
|
||||
"name"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"detail": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/~1schemas~1detail.yaml%23~1Detail"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/otherSchemas/client.yaml": {
|
||||
"Client": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"id",
|
||||
"name"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"details": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/~1otherSchemas~1detail.yaml%23~1Detail"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/detail.yaml#/Detail": {
|
||||
"/schemas/user.yaml#User": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"id",
|
||||
"name"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
"type": "integer"
|
||||
},
|
||||
"userName": {
|
||||
"type": "string"
|
||||
"detail": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/~1schemas~1detail.yaml%23~1Detail"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/otherSchemas/client.yaml#Client": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"id",
|
||||
"name"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"userDescription": {
|
||||
"type": "string"
|
||||
"details": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/~1otherSchemas~1detail.yaml%23~1Detail"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -116,6 +97,21 @@
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/detail.yaml#/Detail": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"userName": {
|
||||
"type": "string"
|
||||
},
|
||||
"userDescription": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
200:
|
||||
description: OK
|
||||
schema:
|
||||
$ref: "./schemas/user.yaml"
|
||||
$ref: "./schemas/user.yaml#User"
|
||||
/clients:
|
||||
get:
|
||||
summary: Returns a list of users.
|
||||
@@ -19,4 +19,4 @@
|
||||
200:
|
||||
description: OK
|
||||
schema:
|
||||
$ref: "./otherSchemas/client.yaml"
|
||||
$ref: "./otherSchemas/client.yaml#Client"
|
||||
@@ -40,8 +40,12 @@ let expect = require('chai').expect,
|
||||
'/bringLocalDependenciesFromExternalMultiple'),
|
||||
multipleRefFromRootComponents = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + '/multipleRefFromRootComponents'),
|
||||
sameRefDifferentSource = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + '/sameRefDifferentSource'),
|
||||
nestedProperties20 = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + '/nestedProperties20'),
|
||||
simpleRef = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + '/simpleRef'),
|
||||
refExample20 = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + '/referenced_example');
|
||||
refExample20 = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + '/referenced_example'),
|
||||
properties = path.join(__dirname, BUNDLES_FOLDER + '/properties'),
|
||||
sameSourceDifferentPlace = path.join(__dirname, BUNDLES_FOLDER + '/same_source_different_place'),
|
||||
nestedProperties = path.join(__dirname, BUNDLES_FOLDER + '/nestedProperties');
|
||||
|
||||
describe('bundle files method - 3.0', function () {
|
||||
it('Should return bundled file as json - schema_from_response', async function () {
|
||||
@@ -861,9 +865,186 @@ describe('bundle files method - 3.0', function () {
|
||||
expect(error.message).to.equal('"RootFiles" parameter should be provided');
|
||||
}
|
||||
});
|
||||
|
||||
it('Should return bundled file as json - sameSourceDifferentPlace', async function () {
|
||||
let contentRootFile = fs.readFileSync(sameSourceDifferentPlace + '/root.yaml', 'utf8'),
|
||||
user = fs.readFileSync(sameSourceDifferentPlace + '/schemas/user/user.yaml', 'utf8'),
|
||||
special = fs.readFileSync(sameSourceDifferentPlace + '/schemas/user/special.yaml', 'utf8'),
|
||||
client = fs.readFileSync(sameSourceDifferentPlace + '/schemas/client/client.yaml', 'utf8'),
|
||||
expected = fs.readFileSync(sameSourceDifferentPlace + '/expected.json', 'utf8'),
|
||||
input = {
|
||||
type: 'folder',
|
||||
specificationVersion: '3.0',
|
||||
rootFiles: [
|
||||
{
|
||||
path: '/root.yaml',
|
||||
content: contentRootFile
|
||||
}
|
||||
],
|
||||
data: [
|
||||
{
|
||||
path: '/schemas/user/user.yaml',
|
||||
content: user
|
||||
},
|
||||
{
|
||||
path: '/schemas/user/special.yaml',
|
||||
content: special
|
||||
},
|
||||
{
|
||||
path: '/schemas/client/client.yaml',
|
||||
content: client
|
||||
}
|
||||
],
|
||||
options: {},
|
||||
bundleFormat: 'JSON'
|
||||
};
|
||||
const res = await Converter.bundle(input);
|
||||
expect(res).to.not.be.empty;
|
||||
expect(res.result).to.be.true;
|
||||
expect(res.output.data.bundledContent).to.be.equal(expected);
|
||||
});
|
||||
|
||||
it('Should return bundled file as json - nestedProperties', async function () {
|
||||
let contentRootFile = fs.readFileSync(nestedProperties + '/root.yaml', 'utf8'),
|
||||
user = fs.readFileSync(nestedProperties + '/schemas/user.yaml', 'utf8'),
|
||||
prop = fs.readFileSync(nestedProperties + '/properties/prop.yaml', 'utf8'),
|
||||
nestedProp = fs.readFileSync(nestedProperties + '/properties/nestedProp.yaml', 'utf8'),
|
||||
lastNested = fs.readFileSync(nestedProperties + '/properties/lastNested.yaml', 'utf8'),
|
||||
warrior = fs.readFileSync(nestedProperties + '/properties/warrior.yaml', 'utf8'),
|
||||
country = fs.readFileSync(nestedProperties + '/properties/country.yaml', 'utf8'),
|
||||
expected = fs.readFileSync(nestedProperties + '/expected.json', 'utf8'),
|
||||
input = {
|
||||
type: 'folder',
|
||||
specificationVersion: '3.0',
|
||||
rootFiles: [
|
||||
{
|
||||
path: '/root.yaml',
|
||||
content: contentRootFile
|
||||
}
|
||||
],
|
||||
data: [
|
||||
{
|
||||
path: '/schemas/user.yaml',
|
||||
content: user
|
||||
},
|
||||
{
|
||||
path: '/properties/prop.yaml',
|
||||
content: prop
|
||||
},
|
||||
{
|
||||
path: '/properties/nestedProp.yaml',
|
||||
content: nestedProp
|
||||
},
|
||||
{
|
||||
path: '/properties/country.yaml',
|
||||
content: country
|
||||
},
|
||||
{
|
||||
path: '/properties/lastNested.yaml',
|
||||
content: lastNested
|
||||
},
|
||||
{
|
||||
path: '/properties/warrior.yaml',
|
||||
content: warrior
|
||||
}
|
||||
],
|
||||
options: {},
|
||||
bundleFormat: 'JSON'
|
||||
};
|
||||
const res = await Converter.bundle(input);
|
||||
expect(res).to.not.be.empty;
|
||||
expect(res.result).to.be.true;
|
||||
expect(res.output.data.bundledContent).to.be.equal(expected);
|
||||
});
|
||||
|
||||
it('Should return bundled file as json - properties', async function () {
|
||||
let contentRootFile = fs.readFileSync(properties + '/root.yaml', 'utf8'),
|
||||
user = fs.readFileSync(properties + '/schemas/user.yaml', 'utf8'),
|
||||
prop = fs.readFileSync(properties + '/schemas/prop.yaml', 'utf8'),
|
||||
expected = fs.readFileSync(properties + '/expected.json', 'utf8'),
|
||||
input = {
|
||||
type: 'folder',
|
||||
specificationVersion: '3.0',
|
||||
rootFiles: [
|
||||
{
|
||||
path: '/root.yaml',
|
||||
content: contentRootFile
|
||||
}
|
||||
],
|
||||
data: [
|
||||
{
|
||||
path: '/schemas/user.yaml',
|
||||
content: user
|
||||
},
|
||||
{
|
||||
path: '/schemas/prop.yaml',
|
||||
content: prop
|
||||
}
|
||||
],
|
||||
options: {},
|
||||
bundleFormat: 'JSON'
|
||||
};
|
||||
const res = await Converter.bundle(input);
|
||||
expect(res).to.not.be.empty;
|
||||
expect(res.result).to.be.true;
|
||||
expect(res.output.data.bundledContent).to.be.equal(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('bundle files method - 2.0', function() {
|
||||
it('Should return bundled result from - nestedProperties20', async function() {
|
||||
let contentRootFile = fs.readFileSync(nestedProperties20 + '/index.yaml', 'utf8'),
|
||||
info = fs.readFileSync(nestedProperties20 + '/info.yaml', 'utf8'),
|
||||
paths = fs.readFileSync(nestedProperties20 + '/paths.yaml', 'utf8'),
|
||||
age = fs.readFileSync(nestedProperties20 + '/schemas/age.yaml', 'utf8'),
|
||||
hobbies = fs.readFileSync(nestedProperties20 + '/schemas/hobbies.yaml', 'utf8'),
|
||||
hobby = fs.readFileSync(nestedProperties20 + '/schemas/hobby.yaml', 'utf8'),
|
||||
user = fs.readFileSync(nestedProperties20 + '/schemas/user.yaml', 'utf8'),
|
||||
expected = fs.readFileSync(nestedProperties20 + '/bundleExpected.json', 'utf8'),
|
||||
input = {
|
||||
type: 'folder',
|
||||
specificationVersion: '2.0',
|
||||
rootFiles: [
|
||||
{
|
||||
path: '/index.yaml',
|
||||
content: contentRootFile
|
||||
}
|
||||
],
|
||||
data: [
|
||||
{
|
||||
path: '/info.yaml',
|
||||
content: info
|
||||
},
|
||||
{
|
||||
path: '/paths.yaml',
|
||||
content: paths
|
||||
},
|
||||
{
|
||||
path: '/schemas/user.yaml',
|
||||
content: user
|
||||
},
|
||||
{
|
||||
path: '/schemas/age.yaml',
|
||||
content: age
|
||||
},
|
||||
{
|
||||
path: '/schemas/hobbies.yaml',
|
||||
content: hobbies
|
||||
},
|
||||
{
|
||||
path: '/schemas/hobby.yaml',
|
||||
content: hobby
|
||||
}
|
||||
],
|
||||
options: {},
|
||||
bundleFormat: 'JSON'
|
||||
};
|
||||
const res = await Converter.bundle(input);
|
||||
expect(res).to.not.be.empty;
|
||||
expect(res.result).to.be.true;
|
||||
expect(res.output.data.bundledContent).to.be.equal(expected);
|
||||
});
|
||||
|
||||
it('Should return bundled result from - sameRefDifferentSource', async function() {
|
||||
let contentRootFile = fs.readFileSync(sameRefDifferentSource + '/index.yaml', 'utf8'),
|
||||
info = fs.readFileSync(sameRefDifferentSource + '/info.yaml', 'utf8'),
|
||||
|
||||
Reference in New Issue
Block a user