mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Changing the way the object keys are generated
This commit is contained in:
@@ -2,7 +2,6 @@ const {
|
||||
isExtRef,
|
||||
getKeyInComponents,
|
||||
getJsonPointerRelationToRoot,
|
||||
jsonPointerEncodeAndReplace,
|
||||
removeLocalReferenceFromPath,
|
||||
localPointer,
|
||||
jsonPointerLevelSeparator,
|
||||
@@ -245,7 +244,6 @@ function getReferences (currentNode, isOutOfRoot, pathSolver, parentFilename) {
|
||||
const tempRef = calculatePath(parentFilename, property.$ref),
|
||||
nodeTrace = getTraceFromParentKeyInComponents(this, tempRef),
|
||||
referenceInDocument = getJsonPointerRelationToRoot(
|
||||
jsonPointerEncodeAndReplace,
|
||||
tempRef,
|
||||
nodeTrace
|
||||
),
|
||||
|
||||
@@ -18,6 +18,17 @@ function jsonPointerEncodeAndReplace(filePathName) {
|
||||
return encodeURIComponent(filePathName.replace(tildes, escapedTildeString).replace(slashes, escapedSlashString));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a path and return a valid key name in openapi spec
|
||||
* @param {string} filePathName - The filePath from the ref called
|
||||
* @returns {string} A valid in openapi object name
|
||||
*/
|
||||
function generateObjectName(filePathName) {
|
||||
let validName = filePathName.replace(/\//g, '_').replace(/#/g, '-');
|
||||
validName = validName.replace(/[^a-zA-Z0-9\.\-_]/g, '');
|
||||
return validName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a json pointer
|
||||
* replaces ~0 and ~1 for tildes and slashes
|
||||
@@ -40,39 +51,35 @@ function getKeyInComponents(traceFromParent, filePathName, localPath) {
|
||||
const localPart = localPath ? `${localPointer}${localPath}` : '';
|
||||
let result;
|
||||
result = getKeyInComponents30(traceFromParent, filePathName, localPart, jsonPointerDecodeAndReplace);
|
||||
return result;
|
||||
return result.map(generateObjectName);
|
||||
}
|
||||
|
||||
/**
|
||||
* concats the inputs to generate the json pointer
|
||||
* @constructor
|
||||
* @param {Function} encodeFunction function to encode url
|
||||
* @param {string} traceFromParent the trace from parent.
|
||||
* @param {string} targetInRoot - The root element where we will point
|
||||
* @returns {string} - the concatenated json pointer
|
||||
*/
|
||||
function concatJsonPointer(encodeFunction, traceFromParent, targetInRoot) {
|
||||
const traceFromParentAsString = traceFromParent.map((trace) => {
|
||||
return encodeFunction(trace);
|
||||
}).join('/');
|
||||
function concatJsonPointer(traceFromParent, targetInRoot) {
|
||||
const traceFromParentAsString = traceFromParent.join('/');
|
||||
return localPointer + targetInRoot + jsonPointerLevelSeparator + traceFromParentAsString;
|
||||
}
|
||||
|
||||
/**
|
||||
* genereates the json pointer relative to the root
|
||||
* @constructor
|
||||
* @param {Function} encodeFunction function to encode url
|
||||
* @param {string} refValue the type of component e.g. schemas, parameters, etc.
|
||||
* @param {string} traceFromKey the trace from the parent node.
|
||||
* @param {string} version - The version we are working on
|
||||
* @returns {string} - the concatenated json pointer
|
||||
*/
|
||||
function getJsonPointerRelationToRoot(encodeFunction, refValue, traceFromKey) {
|
||||
function getJsonPointerRelationToRoot(refValue, traceFromKey) {
|
||||
let targetInRoot = '/components';
|
||||
if (refValue.startsWith(localPointer)) {
|
||||
return refValue;
|
||||
}
|
||||
return concatJsonPointer(encodeFunction, traceFromKey, targetInRoot);
|
||||
return concatJsonPointer(traceFromKey, targetInRoot);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,5 +192,6 @@ module.exports = {
|
||||
getEntityName,
|
||||
isRemoteRef,
|
||||
localPointer,
|
||||
jsonPointerLevelSeparator
|
||||
jsonPointerLevelSeparator,
|
||||
generateObjectName
|
||||
};
|
||||
|
||||
@@ -53,19 +53,19 @@ paths:
|
||||
euismod sapien.
|
||||
operationId: findPets
|
||||
parameters:
|
||||
- $ref: '#/components/parameters/~1spec~1parameters.yaml%23~1tagsParam'
|
||||
- $ref: '#/components/parameters/~1spec~1parameters.yaml%23~1limitsParam'
|
||||
- $ref: '#/components/parameters/_spec_parameters.yaml-_tagsParam'
|
||||
- $ref: '#/components/parameters/_spec_parameters.yaml-_limitsParam'
|
||||
responses:
|
||||
'200':
|
||||
description: pet response
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/~1spec~1Pet.yaml'
|
||||
$ref: '#/components/schemas/_spec_Pet.yaml'
|
||||
default:
|
||||
description: unexpected error
|
||||
schema:
|
||||
$ref: '#/components/schemas/~1common~1Error.yaml'
|
||||
$ref: '#/components/schemas/_common_Error.yaml'
|
||||
post:
|
||||
description: Creates a new pet in the store. Duplicates are allowed
|
||||
operationId: addPet
|
||||
@@ -75,16 +75,16 @@ paths:
|
||||
description: Pet to add to the store
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/components/schemas/~1spec~1NewPet.yaml'
|
||||
$ref: '#/components/schemas/_spec_NewPet.yaml'
|
||||
responses:
|
||||
'200':
|
||||
description: pet response
|
||||
schema:
|
||||
$ref: '#/components/schemas/~1spec~1Pet.yaml'
|
||||
$ref: '#/components/schemas/_spec_Pet.yaml'
|
||||
default:
|
||||
description: unexpected error
|
||||
schema:
|
||||
$ref: '#/components/schemas/~1common~1Error.yaml'
|
||||
$ref: '#/components/schemas/_common_Error.yaml'
|
||||
'/pets/{id}':
|
||||
get:
|
||||
description: >-
|
||||
@@ -102,11 +102,11 @@ paths:
|
||||
'200':
|
||||
description: pet response
|
||||
schema:
|
||||
$ref: '#/components/schemas/~1spec~1Pet.yaml'
|
||||
$ref: '#/components/schemas/_spec_Pet.yaml'
|
||||
default:
|
||||
description: unexpected error
|
||||
schema:
|
||||
$ref: '#/components/schemas/~1common~1Error.yaml'
|
||||
$ref: '#/components/schemas/_common_Error.yaml'
|
||||
delete:
|
||||
description: deletes a single pet based on the ID supplied
|
||||
operationId: deletePet
|
||||
@@ -123,10 +123,10 @@ paths:
|
||||
default:
|
||||
description: unexpected error
|
||||
schema:
|
||||
$ref: '#/components/schemas/~1common~1Error.yaml'
|
||||
$ref: '#/components/schemas/_common_Error.yaml'
|
||||
components:
|
||||
parameters:
|
||||
/spec/parameters.yaml#/tagsParam:
|
||||
_spec_parameters.yaml-_tagsParam:
|
||||
name: tags
|
||||
in: query
|
||||
description: tags to filter by
|
||||
@@ -135,7 +135,7 @@ components:
|
||||
collectionFormat: csv
|
||||
items:
|
||||
type: string
|
||||
/spec/parameters.yaml#/limitsParam:
|
||||
_spec_parameters.yaml-_limitsParam:
|
||||
name: limit
|
||||
in: query
|
||||
description: maximum number of results to return
|
||||
@@ -143,7 +143,7 @@ components:
|
||||
type: integer
|
||||
format: int32
|
||||
schemas:
|
||||
/spec/Pet.yaml:
|
||||
_spec_Pet.yaml:
|
||||
type: object
|
||||
required:
|
||||
- id
|
||||
@@ -156,7 +156,7 @@ components:
|
||||
type: string
|
||||
tag:
|
||||
type: string
|
||||
/common/Error.yaml:
|
||||
_common_Error.yaml:
|
||||
type: object
|
||||
required:
|
||||
- code
|
||||
@@ -167,10 +167,10 @@ components:
|
||||
format: int32
|
||||
message:
|
||||
type: string
|
||||
/spec/NewPet.yaml:
|
||||
_spec_NewPet.yaml:
|
||||
type: object
|
||||
allOf:
|
||||
- $ref: '#/components/schemas/~1spec~1Pet.yaml'
|
||||
- $ref: '#/components/schemas/_spec_Pet.yaml'
|
||||
- required:
|
||||
- name
|
||||
properties:
|
||||
|
||||
@@ -1,225 +0,0 @@
|
||||
{
|
||||
"openapi": "3.0",
|
||||
"info": {
|
||||
"version": "1.0.0",
|
||||
"title": "Swagger Petstore",
|
||||
"description": "A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification",
|
||||
"termsOfService": "http://swagger.io/terms/",
|
||||
"contact": {
|
||||
"name": "Swagger API Team",
|
||||
"email": "apiteam@swagger.io",
|
||||
"url": "http://swagger.io"
|
||||
},
|
||||
"license": {
|
||||
"name": "Apache 2.0",
|
||||
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
|
||||
}
|
||||
},
|
||||
"host": "petstore.swagger.io",
|
||||
"basePath": "/api",
|
||||
"schemes": [
|
||||
"http"
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"paths": {
|
||||
"/pets": {
|
||||
"get": {
|
||||
"description": "Returns all pets from the system that the user has access to\nNam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia.\n\nSed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien.\n",
|
||||
"operationId": "findPets",
|
||||
"parameters": [
|
||||
{
|
||||
"$ref": "#/components/parameters/~1spec~1parameters.yaml%23~1tagsParam"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/parameters/~1spec~1parameters.yaml%23~1limitsParam"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "pet response",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/~1spec~1Pet.yaml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/~1spec~1common~1Error.yaml"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"description": "Creates a new pet in the store. Duplicates are allowed",
|
||||
"operationId": "addPet",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "pet",
|
||||
"in": "body",
|
||||
"description": "Pet to add to the store",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/~1spec~1NewPet.yaml"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "pet response",
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/~1spec~1Pet.yaml"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/~1spec~1common~1Error.yaml"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/pets/{id}": {
|
||||
"get": {
|
||||
"description": "Returns a user based on a single ID, if the user does not have access to the pet",
|
||||
"operationId": "find pet by id",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"description": "ID of pet to fetch",
|
||||
"required": true,
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "pet response",
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/~1spec~1Pet.yaml"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/~1spec~1common~1Error.yaml"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"description": "deletes a single pet based on the ID supplied",
|
||||
"operationId": "deletePet",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"description": "ID of pet to delete",
|
||||
"required": true,
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "pet deleted"
|
||||
},
|
||||
"default": {
|
||||
"description": "unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/~1spec~1common~1Error.yaml"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"components": {
|
||||
"parameters": {
|
||||
"/spec/parameters.yaml#/tagsParam": {
|
||||
"name": "tags",
|
||||
"in": "query",
|
||||
"description": "tags to filter by",
|
||||
"required": false,
|
||||
"type": "array",
|
||||
"collectionFormat": "csv",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"/spec/parameters.yaml#/limitsParam": {
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
"description": "maximum number of results to return",
|
||||
"required": false,
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
}
|
||||
},
|
||||
"schemas": {
|
||||
"/spec/Pet.yaml": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"id",
|
||||
"name"
|
||||
],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"tag": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/spec/common/Error.yaml": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"code",
|
||||
"message"
|
||||
],
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/spec/NewPet.yaml": {
|
||||
"type": "object",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/~1spec~1Pet.yaml"
|
||||
},
|
||||
{
|
||||
"required": [
|
||||
"name"
|
||||
],
|
||||
"properties": {
|
||||
"description": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/~1schemas~1user.yaml%23~1User"
|
||||
"$ref": "#/components/schemas/_schemas_user.yaml-_User"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@
|
||||
},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"/schemas/user.yaml#/User": {
|
||||
"_schemas_user.yaml-_User": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
@@ -49,13 +49,13 @@
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"theUsersPet": {
|
||||
"$ref": "#/components/schemas/~1schemas~1user.yaml%23~1Pet"
|
||||
"$ref": "#/components/schemas/_schemas_user.yaml-_Pet"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/user.yaml#/Pet": {
|
||||
"_schemas_user.yaml-_Pet": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/~1schemas~1user.yaml%23~1User"
|
||||
"$ref": "#/components/schemas/_schemas_user.yaml-_User"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@
|
||||
},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"/schemas/user.yaml#/User": {
|
||||
"_schemas_user.yaml-_User": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
@@ -49,25 +49,25 @@
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"favoriteFood": {
|
||||
"$ref": "#/components/schemas/~1schemas~1food.yaml%23Food"
|
||||
"$ref": "#/components/schemas/_schemas_food.yaml-Food"
|
||||
},
|
||||
"theUsersPet": {
|
||||
"$ref": "#/components/schemas/~1schemas~1user.yaml%23~1Pet"
|
||||
"$ref": "#/components/schemas/_schemas_user.yaml-_Pet"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/food.yaml#Food": {
|
||||
"_schemas_food.yaml-Food": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"brand": {
|
||||
"$ref": "#/components/schemas/~1schemas~1food.yaml%23~1Brand"
|
||||
"$ref": "#/components/schemas/_schemas_food.yaml-_Brand"
|
||||
},
|
||||
"benefits": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/~1schemas~1food.yaml%23~1Benefit"
|
||||
"$ref": "#/components/schemas/_schemas_food.yaml-_Benefit"
|
||||
}
|
||||
},
|
||||
"cost": {
|
||||
@@ -75,7 +75,7 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/user.yaml#/Pet": {
|
||||
"_schemas_user.yaml-_Pet": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
@@ -85,23 +85,23 @@
|
||||
"type": "string"
|
||||
},
|
||||
"color": {
|
||||
"$ref": "#/components/schemas/~1schemas~1user.yaml%23~1Colors"
|
||||
"$ref": "#/components/schemas/_schemas_user.yaml-_Colors"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/user.yaml#/Colors": {
|
||||
"_schemas_user.yaml-_Colors": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/~1schemas~1user.yaml%23~1Color"
|
||||
"$ref": "#/components/schemas/_schemas_user.yaml-_Color"
|
||||
}
|
||||
},
|
||||
"/schemas/user.yaml#/Color": {
|
||||
"_schemas_user.yaml-_Color": {
|
||||
"type": "string"
|
||||
},
|
||||
"/schemas/food.yaml#/Brand": {
|
||||
"_schemas_food.yaml-_Brand": {
|
||||
"type": "string"
|
||||
},
|
||||
"/schemas/food.yaml#/Benefit": {
|
||||
"_schemas_food.yaml-_Benefit": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"benefit": {
|
||||
|
||||
@@ -80,13 +80,13 @@
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"userInfo": {
|
||||
"$ref": "#/components/schemas/~1schemas~1user.yaml"
|
||||
"$ref": "#/components/schemas/_schemas_user.yaml"
|
||||
},
|
||||
"carType": {
|
||||
"$ref": "#/components/schemas/~1schemas~1carType.yaml"
|
||||
"$ref": "#/components/schemas/_schemas_carType.yaml"
|
||||
},
|
||||
"work": {
|
||||
"$ref": "#/components/schemas/~1otherSchemas~1work.yaml"
|
||||
"$ref": "#/components/schemas/_otherSchemas_work.yaml"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -101,7 +101,7 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/user.yaml": {
|
||||
"_schemas_user.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
@@ -112,15 +112,15 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/carType.yaml": {
|
||||
"_schemas_carType.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"model": {
|
||||
"$ref": "#/components/schemas/~1otherSchemas~1model.yaml"
|
||||
"$ref": "#/components/schemas/_otherSchemas_model.yaml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/otherSchemas/work.yaml": {
|
||||
"_otherSchemas_work.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"office": {
|
||||
@@ -128,7 +128,7 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/otherSchemas/model.yaml": {
|
||||
"_otherSchemas_model.yaml": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/~1schemas~1user.yaml"
|
||||
"$ref": "#/components/schemas/_schemas_user.yaml"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@
|
||||
},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"/schemas/user.yaml": {
|
||||
"_schemas_user.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
@@ -46,11 +46,11 @@
|
||||
"type": "string"
|
||||
},
|
||||
"complexProp": {
|
||||
"$ref": "#/components/schemas/~1properties~1prop.yaml"
|
||||
"$ref": "#/components/schemas/_properties_prop.yaml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/properties/prop.yaml": {
|
||||
"_properties_prop.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"firstName": {
|
||||
@@ -63,17 +63,17 @@
|
||||
"type": "integer"
|
||||
},
|
||||
"nestedProp": {
|
||||
"$ref": "#/components/schemas/~1properties~1nestedProp.yaml"
|
||||
"$ref": "#/components/schemas/_properties_nestedProp.yaml"
|
||||
},
|
||||
"country": {
|
||||
"$ref": "#/components/schemas/~1properties~1country.yaml"
|
||||
"$ref": "#/components/schemas/_properties_country.yaml"
|
||||
},
|
||||
"warrior": {
|
||||
"$ref": "#/components/schemas/~1properties~1warrior.yaml"
|
||||
"$ref": "#/components/schemas/_properties_warrior.yaml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/properties/nestedProp.yaml": {
|
||||
"_properties_nestedProp.yaml": {
|
||||
"type": "object",
|
||||
"rock": {
|
||||
"type": "boolean"
|
||||
@@ -99,7 +99,7 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/properties/country.yaml": {
|
||||
"_properties_country.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"region": {
|
||||
@@ -110,7 +110,7 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/properties/warrior.yaml": {
|
||||
"_properties_warrior.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"power": {
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/~1schemas~1user.yaml"
|
||||
"$ref": "#/components/schemas/_schemas_user.yaml"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@
|
||||
},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"/schemas/user.yaml": {
|
||||
"_schemas_user.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
@@ -46,11 +46,11 @@
|
||||
"type": "string"
|
||||
},
|
||||
"complexProp": {
|
||||
"$ref": "#/components/schemas/~1schemas~1prop.yaml"
|
||||
"$ref": "#/components/schemas/_schemas_prop.yaml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/prop.yaml": {
|
||||
"_schemas_prop.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"firstName": {
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
}
|
||||
},
|
||||
"example": {
|
||||
"$ref": "#/components/examples/~1examples.yaml%23~1foo"
|
||||
"$ref": "#/components/examples/_examples.yaml-_foo"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -88,7 +88,7 @@
|
||||
}
|
||||
},
|
||||
"examples": {
|
||||
"/examples.yaml#/foo": {
|
||||
"_examples.yaml-_foo": {
|
||||
"summary": "sum",
|
||||
"value": {
|
||||
"code": 1,
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/~1paths~1path.yaml%23~1components~1schemas~1Pet"
|
||||
"$ref": "#/components/schemas/_paths_path.yaml-_components_schemas_Pet"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/~1paths~1path.yaml%23~1components~1schemas~1Error"
|
||||
"$ref": "#/components/schemas/_paths_path.yaml-_components_schemas_Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,10 +83,10 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/paths/path.yaml#/components/schemas/Pet": {
|
||||
"_paths_path.yaml-_components_schemas_Pet": {
|
||||
"$ref": "#/components/schemas/Pet"
|
||||
},
|
||||
"/paths/path.yaml#/components/schemas/Error": {
|
||||
"_paths_path.yaml-_components_schemas_Error": {
|
||||
"$ref": "#/components/schemas/Error"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/~1schemas~1user~1user.yaml"
|
||||
"$ref": "#/components/schemas/_schemas_user_user.yaml"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/~1schemas~1client~1client.yaml"
|
||||
"$ref": "#/components/schemas/_schemas_client_client.yaml"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,7 @@
|
||||
},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"/schemas/user/user.yaml": {
|
||||
"_schemas_user_user.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
@@ -63,11 +63,11 @@
|
||||
"type": "string"
|
||||
},
|
||||
"special": {
|
||||
"$ref": "#/components/schemas/~1schemas~1user~1special.yaml"
|
||||
"$ref": "#/components/schemas/_schemas_user_special.yaml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/client/client.yaml": {
|
||||
"_schemas_client_client.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"idClient": {
|
||||
@@ -77,22 +77,22 @@
|
||||
"type": "string"
|
||||
},
|
||||
"special": {
|
||||
"$ref": "#/components/schemas/~1schemas~1client~1special.yaml"
|
||||
"$ref": "#/components/schemas/_schemas_client_special.yaml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/client/special.yaml": {
|
||||
"_schemas_client_special.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"specialClientId": {
|
||||
"type": "string"
|
||||
},
|
||||
"magic": {
|
||||
"$ref": "#/components/schemas/~1schemas~1client~1magic.yaml"
|
||||
"$ref": "#/components/schemas/_schemas_client_magic.yaml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/client/magic.yaml": {
|
||||
"_schemas_client_magic.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"magicNumber": {
|
||||
@@ -103,7 +103,7 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/user/special.yaml": {
|
||||
"_schemas_user_special.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"specialUserId": {
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/~1schemas~1user~1user.yaml"
|
||||
"$ref": "#/components/schemas/_schemas_user_user.yaml"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/~1schemas~1client~1client.yaml"
|
||||
"$ref": "#/components/schemas/_schemas_client_client.yaml"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,7 @@
|
||||
},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"/schemas/user/user.yaml": {
|
||||
"_schemas_user_user.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
@@ -63,11 +63,11 @@
|
||||
"type": "string"
|
||||
},
|
||||
"special": {
|
||||
"$ref": "#/components/schemas/~1schemas~1user~1special.yaml"
|
||||
"$ref": "#/components/schemas/_schemas_user_special.yaml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/client/client.yaml": {
|
||||
"_schemas_client_client.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"idClient": {
|
||||
@@ -77,11 +77,11 @@
|
||||
"type": "string"
|
||||
},
|
||||
"special": {
|
||||
"$ref": "#/components/schemas/~1schemas~1user~1special.yaml"
|
||||
"$ref": "#/components/schemas/_schemas_user_special.yaml"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/user/special.yaml": {
|
||||
"_schemas_user_special.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"specialUserId": {
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/~1schemas~1user.yaml"
|
||||
"$ref": "#/components/schemas/_schemas_user.yaml"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@
|
||||
},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"/schemas/user.yaml": {
|
||||
"_schemas_user.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
|
||||
@@ -20,10 +20,10 @@ paths:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/~1schemas~1user.yaml'
|
||||
$ref: '#/components/schemas/_schemas_user.yaml'
|
||||
components:
|
||||
schemas:
|
||||
/schemas/user.yaml:
|
||||
_schemas_user.yaml:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/~1schemas~1user.yaml"
|
||||
"$ref": "#/components/schemas/_schemas_user.yaml"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@
|
||||
},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"/schemas/user.yaml": {
|
||||
"_schemas_user.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
|
||||
@@ -21,10 +21,10 @@
|
||||
"summary": "Get a user by ID",
|
||||
"parameters": [
|
||||
{
|
||||
"$ref": "#/components/parameters/~1parameters~1index.yaml%23tagsParam"
|
||||
"$ref": "#/components/parameters/_parameters_index.yaml-tagsParam"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/parameters/~1parameters~1index.yaml%23limitsParam"
|
||||
"$ref": "#/components/parameters/_parameters_index.yaml-limitsParam"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
@@ -33,7 +33,7 @@
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/~1schemas~1user.yaml"
|
||||
"$ref": "#/components/schemas/_schemas_user.yaml"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@
|
||||
},
|
||||
"components": {
|
||||
"parameters": {
|
||||
"/parameters/index.yaml#tagsParam": {
|
||||
"_parameters_index.yaml-tagsParam": {
|
||||
"name": "tags",
|
||||
"in": "query",
|
||||
"description": "tags to filter by",
|
||||
@@ -55,7 +55,7 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"/parameters/index.yaml#limitsParam": {
|
||||
"_parameters_index.yaml-limitsParam": {
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
"description": "maximum number of results to return",
|
||||
@@ -65,7 +65,7 @@
|
||||
}
|
||||
},
|
||||
"schemas": {
|
||||
"/schemas/user.yaml": {
|
||||
"_schemas_user.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/~1schemas~1user.yaml"
|
||||
"$ref": "#/components/schemas/_schemas_user.yaml"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@
|
||||
},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"/schemas/user.yaml": {
|
||||
"_schemas_user.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
@@ -48,12 +48,12 @@
|
||||
"superProps": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/~1schemas~1superProp.yaml"
|
||||
"$ref": "#/components/schemas/_schemas_superProp.yaml"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/schemas/superProp.yaml": {
|
||||
"_schemas_superProp.yaml": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"superInt": {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
|
||||
const expect = require('chai').expect,
|
||||
{ jsonPointerEncodeAndReplace,
|
||||
{
|
||||
getJsonPointerRelationToRoot,
|
||||
concatJsonPointer,
|
||||
getKeyInComponents } = require('./../../lib/jsonPointer');
|
||||
getKeyInComponents
|
||||
} = require('./../../lib/jsonPointer');
|
||||
|
||||
describe('getKeyInComponents function', function () {
|
||||
it('should return [] when is pointing to an element in components', function () {
|
||||
@@ -17,10 +18,42 @@ describe('getKeyInComponents function', function () {
|
||||
expect(result).to.be.an('array').with.length(0);
|
||||
});
|
||||
|
||||
it('should return ["schemas", "folder/pet.yaml"] when there is an scaped slash', function () {
|
||||
const result = getKeyInComponents(['path', 'schemas'], 'folder~1pet.yaml');
|
||||
it('should return ["schemas", "_folder_pet.yaml"] when the filename scaped slash', function () {
|
||||
const result = getKeyInComponents(['path', 'schemas'], '~1folder~1pet.yaml');
|
||||
expect(result).to.be.an('array').with.length(2);
|
||||
expect(result[0]).to.equal('schemas');
|
||||
expect(result[1]).to.equal('_folder_pet.yaml');
|
||||
});
|
||||
|
||||
it('should return ["schemas", "_folder_pet.yaml"] when the filename contains any slash', function () {
|
||||
const result = getKeyInComponents(['path', 'schemas'], '/folder/pet.yaml');
|
||||
expect(result).to.be.an('array').with.length(2);
|
||||
expect(result[0]).to.equal('schemas');
|
||||
expect(result[1]).to.equal('_folder_pet.yaml');
|
||||
});
|
||||
|
||||
it('should return ["schemas", "_folder_pet.yaml-_Name"] when the filename contains any sacped slash' +
|
||||
'and a local part using a scaped sharp', function () {
|
||||
const result = getKeyInComponents(['path', 'schemas'], '~1folder~1pet.yaml%23~1Name');
|
||||
expect(result).to.be.an('array').with.length(2);
|
||||
expect(result[0]).to.equal('schemas');
|
||||
expect(result[1]).to.equal('_folder_pet.yaml-_Name');
|
||||
});
|
||||
|
||||
it('should return ["schemas", "_folder_pet.yaml-_Name"] when the filename contains any slash' +
|
||||
'and a local part using a sharp', function () {
|
||||
const result = getKeyInComponents(['path', 'schemas'], '/folder/pet.yaml#/Name');
|
||||
expect(result).to.be.an('array').with.length(2);
|
||||
expect(result[0]).to.equal('schemas');
|
||||
expect(result[1]).to.equal('_folder_pet.yaml-_Name');
|
||||
});
|
||||
|
||||
it('should return ["schemas", "_foldertest_pet.yaml-_Name"] when the filename contains any slash' +
|
||||
'and a local part using a sharp and another not valid character', function () {
|
||||
const result = getKeyInComponents(['path', 'schemas'], '/folder@test/pet@.yaml#/Name');
|
||||
expect(result).to.be.an('array').with.length(2);
|
||||
expect(result[0]).to.equal('schemas');
|
||||
expect(result[1]).to.equal('_foldertest_pet.yaml-_Name');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -28,7 +61,6 @@ describe('getKeyInComponents function', function () {
|
||||
describe('getJsonPointerRelationToRoot function', function () {
|
||||
it('should return "#/components/schemas/Pets.yaml" no local path and schema', function () {
|
||||
let res = getJsonPointerRelationToRoot(
|
||||
jsonPointerEncodeAndReplace,
|
||||
'Pets.yaml',
|
||||
['schemas', 'Pets.yaml']
|
||||
);
|
||||
@@ -36,7 +68,6 @@ describe('getJsonPointerRelationToRoot function', function () {
|
||||
});
|
||||
it('should return "#/components/schemas/hello.yaml" no local path and schema', function () {
|
||||
let res = getJsonPointerRelationToRoot(
|
||||
jsonPointerEncodeAndReplace,
|
||||
'hello.yaml#/definitions/world',
|
||||
['schemas', 'hello.yaml']
|
||||
);
|
||||
@@ -44,7 +75,6 @@ describe('getJsonPointerRelationToRoot function', function () {
|
||||
});
|
||||
it('should return "#/components/schemas/Error" no file path', function () {
|
||||
let res = getJsonPointerRelationToRoot(
|
||||
jsonPointerEncodeAndReplace,
|
||||
'#/components/schemas/Error',
|
||||
['components', 'schemas', 'Error']
|
||||
);
|
||||
@@ -55,45 +85,40 @@ describe('getJsonPointerRelationToRoot function', function () {
|
||||
describe('concatJsonPointer function ', function () {
|
||||
it('should return "#/components/schemas/Pets.yaml" no local path and schema', function () {
|
||||
let res = concatJsonPointer(
|
||||
jsonPointerEncodeAndReplace,
|
||||
['schemas', 'Pets.yaml'],
|
||||
'/components'
|
||||
);
|
||||
expect(res).to.equal('#/components/schemas/Pets.yaml');
|
||||
});
|
||||
|
||||
it('should return "#/components/schemas/other~1Pets.yaml" no local path and schema folder in filename', function () {
|
||||
it('should return "#/components/schemas/other_Pets.yaml" no local path and schema folder in filename', function () {
|
||||
let res = concatJsonPointer(
|
||||
jsonPointerEncodeAndReplace,
|
||||
['schemas', 'other/Pets.yaml'],
|
||||
['schemas', 'other_Pets.yaml'],
|
||||
'/components'
|
||||
);
|
||||
expect(res).to.equal('#/components/schemas/other~1Pets.yaml');
|
||||
expect(res).to.equal('#/components/schemas/other_Pets.yaml');
|
||||
});
|
||||
it('should return "#/components/schemas/some~1Pet" no local path and schema folder in filename', function () {
|
||||
it('should return "#/components/schemas/some_Pet" no local path and schema folder in filename', function () {
|
||||
let res = concatJsonPointer(
|
||||
jsonPointerEncodeAndReplace,
|
||||
['schemas', 'some/Pet.yaml'],
|
||||
['schemas', 'some_Pet.yaml'],
|
||||
'/components'
|
||||
);
|
||||
expect(res).to.equal('#/components/schemas/some~1Pet.yaml');
|
||||
expect(res).to.equal('#/components/schemas/some_Pet.yaml');
|
||||
});
|
||||
it('should return "#/components/schemas/hello.yaml" no local path and schema', function () {
|
||||
let res = concatJsonPointer(
|
||||
jsonPointerEncodeAndReplace,
|
||||
['schemas', 'hello.yaml'],
|
||||
'/components'
|
||||
);
|
||||
expect(res).to.equal('#/components/schemas/hello.yaml');
|
||||
});
|
||||
|
||||
it('should return "#/components/schemas/~1Pets.yaml" no local path and schema', function () {
|
||||
it('should return "#/components/schemas/_Pets.yaml" no local path and schema', function () {
|
||||
let res = concatJsonPointer(
|
||||
jsonPointerEncodeAndReplace,
|
||||
['schemas', '/Pets.yaml'],
|
||||
['schemas', '_Pets.yaml'],
|
||||
'/components'
|
||||
);
|
||||
expect(res).to.equal('#/components/schemas/~1Pets.yaml');
|
||||
expect(res).to.equal('#/components/schemas/_Pets.yaml');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user