mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Add scenario referenced path points to local schema
Add scenario referenced path points to local schema
This commit is contained in:
@@ -1 +1 @@
|
||||
"{\n \"openapi\": \"3.0.2\",\n \"info\": {\n \"version\": \"1.0.0\",\n \"title\": \"Swagger Petstore\",\n \"description\": \"A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification\",\n \"termsOfService\": \"http://swagger.io/terms/\",\n \"contact\": {\n \"name\": \"Swagger API Team\",\n \"email\": \"apiteam@swagger.io\",\n \"url\": \"http://swagger.io\"\n },\n \"license\": {\n \"name\": \"Apache 2.0\",\n \"url\": \"https://www.apache.org/licenses/LICENSE-2.0.html\"\n }\n },\n \"paths\": {\n \"/pets\": {\n \"get\": {\n \"description\": \"Returns all pets alesuada ac...\",\n \"operationId\": \"findPets\",\n \"responses\": {\n \"200\": {\n \"description\": \"pet response\",\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"required\": [\n \"code\",\n \"message\"\n ],\n \"properties\": {\n \"code\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n },\n \"message\": {\n \"type\": \"string\"\n }\n }\n }\n }\n }\n },\n \"default\": {\n \"description\": \"unexpected error\",\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"required\": [\n \"code\",\n \"message\"\n ],\n \"properties\": {\n \"code\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n },\n \"message\": {\n \"type\": \"string\"\n }\n }\n }\n }\n }\n }\n }\n }\n }\n },\n \"components\": {\n \"schemas\": {\n \"Pet\": {\n \"required\": [\n \"id\",\n \"name\"\n ],\n \"properties\": {\n \"id\": {\n \"type\": \"integer\",\n \"format\": \"int64\"\n },\n \"name\": {\n \"type\": \"string\"\n },\n \"tag\": {\n \"type\": \"string\"\n }\n }\n },\n \"Error\": {\n \"required\": [\n \"code\",\n \"message\"\n ],\n \"properties\": {\n \"code\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n },\n \"message\": {\n \"type\": \"string\"\n }\n }\n }\n }\n }\n}"
|
||||
"{\n \"openapi\": \"3.0.2\",\n \"info\": {\n \"version\": \"1.0.0\",\n \"title\": \"Swagger Petstore\",\n \"description\": \"A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification\",\n \"termsOfService\": \"http://swagger.io/terms/\",\n \"contact\": {\n \"name\": \"Swagger API Team\",\n \"email\": \"apiteam@swagger.io\",\n \"url\": \"http://swagger.io\"\n },\n \"license\": {\n \"name\": \"Apache 2.0\",\n \"url\": \"https://www.apache.org/licenses/LICENSE-2.0.html\"\n }\n },\n \"paths\": {\n \"/pets\": {\n \"get\": {\n \"description\": \"Returns all pets\",\n \"operationId\": \"findPets\",\n \"responses\": {\n \"200\": {\n \"description\": \"pet response\",\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"type\": \"array\",\n \"items\": {\n \"$ref\": \"#/components/schemas/~1paths~1path.yaml%23~1components~1schemas~1Pet\"\n }\n }\n }\n }\n },\n \"default\": {\n \"description\": \"unexpected error\",\n \"content\": {\n \"application/json\": {\n \"schema\": {\n \"$ref\": \"#/components/schemas/~1paths~1path.yaml%23~1components~1schemas~1Error\"\n }\n }\n }\n }\n }\n }\n }\n },\n \"components\": {\n \"schemas\": {\n \"Pet\": {\n \"required\": [\n \"id\",\n \"name\"\n ],\n \"properties\": {\n \"id\": {\n \"type\": \"integer\",\n \"format\": \"int64\"\n },\n \"name\": {\n \"type\": \"string\"\n },\n \"tag\": {\n \"type\": \"string\"\n }\n }\n },\n \"Error\": {\n \"required\": [\n \"code\",\n \"message\"\n ],\n \"properties\": {\n \"code\": {\n \"type\": \"integer\",\n \"format\": \"int32\"\n },\n \"message\": {\n \"type\": \"string\"\n }\n }\n },\n \"/paths/path.yaml#/components/schemas/Pet\": {\n \"$ref\": \"#/components/schemas/Pet\"\n },\n \"/paths/path.yaml#/components/schemas/Error\": {\n \"$ref\": \"#/components/schemas/Error\"\n }\n }\n }\n}"
|
||||
@@ -26,7 +26,8 @@ let path = require('path'),
|
||||
'securitySchemes',
|
||||
'links',
|
||||
'callbacks'
|
||||
];
|
||||
],
|
||||
deref = require('./deref.js');
|
||||
|
||||
|
||||
/**
|
||||
@@ -137,9 +138,7 @@ function getContentFromTrace(content, partial) {
|
||||
partial = partial[0] === jsonPointerLevelSeparator ? partial.substring(1) : partial;
|
||||
const trace = partial.split(jsonPointerLevelSeparator);
|
||||
let currentValue = content;
|
||||
for (let place of trace) {
|
||||
currentValue = currentValue[place];
|
||||
}
|
||||
currentValue = deref._getEscaped(content, trace, undefined);
|
||||
return currentValue;
|
||||
}
|
||||
|
||||
@@ -351,7 +350,13 @@ function generateComponentsObject (documentContext, rootContent, refTypeResolver
|
||||
refData.inline = refData.keyInComponents.length === 0;
|
||||
}
|
||||
if (local) {
|
||||
refData.nodeContent = getContentFromTrace(refData.nodeContent, local);
|
||||
let contentFromTrace = getContentFromTrace(refData.nodeContent, local);
|
||||
if (!contentFromTrace) {
|
||||
refData.nodeContent = { $ref: `${localPointer + local}` };
|
||||
}
|
||||
else {
|
||||
refData.nodeContent = contentFromTrace;
|
||||
}
|
||||
}
|
||||
if (refData.inline) {
|
||||
refData.node = refData.nodeContent;
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
{
|
||||
"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",
|
||||
"operationId": "findPets",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "pet response",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/~1paths~1path.yaml%23~1components~1schemas~1Pet"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "unexpected error",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/~1paths~1path.yaml%23~1components~1schemas~1Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"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"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/paths/path.yaml#/components/schemas/Pet": {
|
||||
"$ref": "#/components/schemas/Pet"
|
||||
},
|
||||
"/paths/path.yaml#/components/schemas/Error": {
|
||||
"$ref": "#/components/schemas/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
description: Returns all pets
|
||||
operationId: findPets
|
||||
responses:
|
||||
"200":
|
||||
description: pet response
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: "#/components/schemas/Pet"
|
||||
default:
|
||||
description: unexpected error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Error"
|
||||
@@ -0,0 +1,3 @@
|
||||
/pets:
|
||||
get:
|
||||
"$ref": "./path.yaml"
|
||||
@@ -0,0 +1,40 @@
|
||||
|
||||
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:
|
||||
"$ref": "./paths/paths.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
|
||||
@@ -21,7 +21,8 @@ let expect = require('chai').expect,
|
||||
.join(__dirname, BUNDLES_FOLDER + '/bring_local_dependencies_from_external_multiple_local'),
|
||||
refTags = path.join(__dirname, BUNDLES_FOLDER + '/referenced_tags'),
|
||||
refInfo = path.join(__dirname, BUNDLES_FOLDER + '/referenced_info'),
|
||||
refPaths = path.join(__dirname, BUNDLES_FOLDER + '/referenced_paths');
|
||||
refPaths = path.join(__dirname, BUNDLES_FOLDER + '/referenced_paths'),
|
||||
refPathsRefToLocalSchema = path.join(__dirname, BUNDLES_FOLDER + '/referenced_paths_local_schema');
|
||||
|
||||
|
||||
describe('bundle files method - 3.0', function () {
|
||||
@@ -624,7 +625,7 @@ describe('bundle files method - 3.0', function () {
|
||||
expect(res.output.data.bundledContent).to.be.equal(expected);
|
||||
});
|
||||
|
||||
it('Should return bundled file with referenced tags', async function () {
|
||||
it('Should return bundled file with referenced tags from root', async function () {
|
||||
let contentRootFile = fs.readFileSync(refTags + '/root.yaml', 'utf8'),
|
||||
tags = fs.readFileSync(refTags + '/tags/tags.yaml', 'utf8'),
|
||||
expected = fs.readFileSync(refTags + '/expected.json', 'utf8'),
|
||||
@@ -653,7 +654,7 @@ describe('bundle files method - 3.0', function () {
|
||||
expect(res.output.data.bundledContent).to.be.equal(expected);
|
||||
});
|
||||
|
||||
it('Should return bundled file with referenced info', async function () {
|
||||
it('Should return bundled file with referenced info from root', async function () {
|
||||
let contentRootFile = fs.readFileSync(refInfo + '/root.yaml', 'utf8'),
|
||||
info = fs.readFileSync(refInfo + '/info/info.yaml', 'utf8'),
|
||||
expected = fs.readFileSync(refInfo + '/expected.json', 'utf8'),
|
||||
@@ -681,7 +682,7 @@ describe('bundle files method - 3.0', function () {
|
||||
expect(res.output.data.bundledContent).to.be.equal(expected);
|
||||
});
|
||||
|
||||
it('Should return bundled file with referenced paths', async function () {
|
||||
it('Should return bundled file with referenced paths from root', async function () {
|
||||
let contentRootFile = fs.readFileSync(refPaths + '/root.yaml', 'utf8'),
|
||||
paths = fs.readFileSync(refPaths + '/paths/paths.yaml', 'utf8'),
|
||||
path = fs.readFileSync(refPaths + '/paths/path.yaml', 'utf8'),
|
||||
@@ -711,6 +712,39 @@ describe('bundle files method - 3.0', function () {
|
||||
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 with referenced paths from root - path references local schema', async function () {
|
||||
let contentRootFile = fs.readFileSync(refPathsRefToLocalSchema + '/root.yaml', 'utf8'),
|
||||
paths = fs.readFileSync(refPathsRefToLocalSchema + '/paths/paths.yaml', 'utf8'),
|
||||
path = fs.readFileSync(refPathsRefToLocalSchema + '/paths/path.yaml', 'utf8'),
|
||||
expected = fs.readFileSync(refPathsRefToLocalSchema + '/expected.json', 'utf8'),
|
||||
input = {
|
||||
type: 'folder',
|
||||
specificationVersion: '3.0',
|
||||
rootFiles: [
|
||||
{
|
||||
path: '/root.yaml',
|
||||
content: contentRootFile
|
||||
}
|
||||
],
|
||||
data: [
|
||||
{
|
||||
path: '/paths/paths.yaml',
|
||||
content: paths
|
||||
},
|
||||
{
|
||||
path: '/paths/path.yaml',
|
||||
content: path
|
||||
}
|
||||
],
|
||||
options: {},
|
||||
bundleFormat: 'JSON'
|
||||
};
|
||||
const res = await Converter.bundle(input);
|
||||
expect(res).to.not.be.empty;
|
||||
expect(res.result).to.be.true;
|
||||
fs.writeFileSync('coll.json', JSON.stringify(res.output.data.bundledContent));
|
||||
expect(res.output.data.bundledContent).to.be.equal(expected);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user