mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Merging last swagger20Support with last version
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,4 +11,4 @@ properties:
|
||||
country:
|
||||
$ref: "./country.yaml"
|
||||
warrior:
|
||||
$ref: "./warrior.yaml"
|
||||
$ref: "./warrior.yaml"
|
||||
|
||||
@@ -3,4 +3,4 @@ properties:
|
||||
power:
|
||||
type: string
|
||||
weapon:
|
||||
type: string
|
||||
type: string
|
||||
|
||||
@@ -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,42 +47,38 @@
|
||||
}
|
||||
},
|
||||
"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"
|
||||
}
|
||||
"/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"
|
||||
}
|
||||
"/otherSchemas/client.yaml#Client": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"id",
|
||||
"name"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"details": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/~1otherSchemas~1detail.yaml%23~1Detail"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,13 +40,13 @@ 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'),
|
||||
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 () {
|
||||
let contentRootFile = fs.readFileSync(schemaFromResponse + '/root.yaml', 'utf8'),
|
||||
@@ -997,6 +997,8 @@ describe('bundle files method - 3.0', function () {
|
||||
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[1].bundledContent, null, 2)).to.be.equal(expected2);
|
||||
expect(res.output.data[0].rootFile.path).to.equal('/root.yaml');
|
||||
expect(res.output.data[1].rootFile.path).to.equal('/root2.yaml');
|
||||
});
|
||||
|
||||
it('Should throw error when root is not present in data array', async function () {
|
||||
@@ -1492,6 +1494,62 @@ describe('bundle files method - 3.0', function () {
|
||||
});
|
||||
|
||||
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: 'multiFile',
|
||||
specificationVersion: '2.0',
|
||||
rootFiles: [
|
||||
{
|
||||
path: '/index.yaml'
|
||||
}
|
||||
],
|
||||
data: [
|
||||
{
|
||||
path: '/index.yaml',
|
||||
content: contentRootFile
|
||||
},
|
||||
{
|
||||
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(JSON.stringify(res.output.data[0].bundledContent, null, 2)).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