diff --git a/lib/bundle.js b/lib/bundle.js index acaab0e..f7108fc 100644 --- a/lib/bundle.js +++ b/lib/bundle.js @@ -14,14 +14,15 @@ const _ = require('lodash'), parse = require('./parse.js'), { ParseError } = require('./common/ParseError'), Utils = require('./utils'), - crypto = require('crypto'), - { getBundleRulesDataByVersion } = require('./common/versionUtils'); + crypto = require('crypto'); let path = require('path'), pathBrowserify = require('path-browserify'), BROWSER = 'browser', { DFS } = require('./dfs'), - deref = require('./deref.js'); + deref = require('./deref.js'), + { isSwagger, getBundleRulesDataByVersion } = require('./common/versionUtils'), + CIRCULAR_REF_EXT_PROP = 'x-circularRef'; /** @@ -165,17 +166,16 @@ function getContentFromTrace(content, partial) { * @param {array} keyInComponents - The trace to the key in components * @param {object} components - A global components object * @param {object} value - The value from node matched with data - * @param {string} version - The current version + * @param {array} componentsKeys - The keys of the reusable component * @returns {null} It modifies components global context */ -function setValueInComponents(keyInComponents, components, value, version) { - const { COMPONENTS_KEYS } = getBundleRulesDataByVersion(version); +function setValueInComponents(keyInComponents, components, value, componentsKeys) { let currentPlace = components, target = keyInComponents[keyInComponents.length - 2], - key = keyInComponents.length === 2 && COMPONENTS_KEYS.includes(keyInComponents[0]) ? + key = keyInComponents.length === 2 && componentsKeys.includes(keyInComponents[0]) ? keyInComponents[1] : null; - if (COMPONENTS_KEYS.includes(keyInComponents[0])) { + if (componentsKeys.includes(keyInComponents[0])) { if (keyInComponents[0] === 'schema') { keyInComponents[0] = 'schemas'; } @@ -463,6 +463,24 @@ function resolveJsonPointerInlineNodes(parents, key) { return pointer; } +/** + * Finds the reference in the document context + * @param {object} documentContext The document context from root + * @param {object} mainKeyInTrace - The key to find + * @returns {string} The reference value + */ +function findReferenceByMainKeyInTraceFromContext(documentContext, mainKeyInTrace) { + let relatedRef = '', + globalRef; + globalRef = Object.values(documentContext.globalReferences).find((item) => { + return item.mainKeyInTrace === mainKeyInTrace; + }); + if (globalRef) { + relatedRef = globalRef.reference; + } + return relatedRef; +} + /** * Generates the components object from the documentContext data * @param {object} documentContext The document context from root @@ -476,6 +494,7 @@ function generateComponentsObject (documentContext, rootContent, refTypeResolver let notInLine = Object.entries(documentContext.globalReferences).filter(([, value]) => { return value.keyInComponents.length !== 0; }); + const { COMPONENTS_KEYS } = getBundleRulesDataByVersion(version); notInLine.forEach(([key, value]) => { let [, partial] = key.split(localPointer); if (documentContext.globalReferences[key].refHasContent) { @@ -483,7 +502,7 @@ function generateComponentsObject (documentContext, rootContent, refTypeResolver value.keyInComponents, components, getContentFromTrace(documentContext.nodeContents[key], partial), - version + COMPONENTS_KEYS ); } }); @@ -533,7 +552,7 @@ function generateComponentsObject (documentContext, rootContent, refTypeResolver _.merge(referenceSiblings, refData.nodeContent) : refData.nodeContent; documentContext.globalReferences[property.$ref].reference = - resolveJsonPointerInlineNodes(this.parents, this.key); + resolveJsonPointerInlineNodes(this.parents, this.key); } this.update(refData.node); if (!refData.inline) { @@ -542,7 +561,7 @@ function generateComponentsObject (documentContext, rootContent, refTypeResolver refData.keyInComponents, components, refData.nodeContent, - version + COMPONENTS_KEYS ); } } @@ -552,13 +571,17 @@ function generateComponentsObject (documentContext, rootContent, refTypeResolver }); return { resRoot: traverseUtility(rootContent).map(function () { + let relatedRef = ''; if (this.circular) { - this.update({ [this.key]: '- Circular' }); + relatedRef = findReferenceByMainKeyInTraceFromContext(documentContext, this.circular.key); + this.update({ $ref: relatedRef, [CIRCULAR_REF_EXT_PROP]: true }); } }), newComponents: traverseUtility(components).map(function () { + let relatedRef = ''; if (this.circular) { - this.update({ [this.key]: '- Circular' }); + relatedRef = findReferenceByMainKeyInTraceFromContext(documentContext, this.circular.key); + this.update({ $ref: relatedRef, [CIRCULAR_REF_EXT_PROP]: true }); } }) }; @@ -567,18 +590,28 @@ function generateComponentsObject (documentContext, rootContent, refTypeResolver /** * Generates the components object wrapper * @param {object} parsedOasObject The parsed root - * @param {string} nodesContent - The content from all nodes + * @param {string} version - The current version + * @param {object} nodesContent - The nodes content * @returns {object} The components object wrapper */ -function generateComponentsWrapper(parsedOasObject, nodesContent = {}) { +function generateComponentsWrapper(parsedOasObject, version, nodesContent = {}) { let components = _.isNil(parsedOasObject.components) ? {} : parsedOasObject.components, componentsAreReferenced = components.$ref !== undefined && !_.isEmpty(nodesContent); - if (componentsAreReferenced) { - components = _.merge(parsedOasObject.components, nodesContent[components.$ref]); - delete components.$ref; + if (isSwagger(version)) { + getBundleRulesDataByVersion(version).COMPONENTS_KEYS.forEach((property) => { + if (parsedOasObject.hasOwnProperty(property)) { + components[property] = parsedOasObject[property]; + } + }); + } + else if (parsedOasObject.hasOwnProperty('components')) { + if (componentsAreReferenced) { + components = _.merge(parsedOasObject.components, nodesContent[components.$ref]); + delete components.$ref; + } } return components; @@ -640,7 +673,8 @@ module.exports = { path = pathBrowserify; } const initialComponents = generateComponentsWrapper( - specRoot.parsed.oasObject + specRoot.parsed.oasObject, + version ), initialMainKeys = getMainKeysFromComponents(initialComponents, version); let algorithm = new DFS(), @@ -664,6 +698,7 @@ module.exports = { }); components = generateComponentsWrapper( specRoot.parsed.oasObject, + version, rootContextData.nodeContents ); finalElements = generateComponentsObject( diff --git a/lib/bundleRules/spec20.js b/lib/bundleRules/spec20.js new file mode 100644 index 0000000..79154c2 --- /dev/null +++ b/lib/bundleRules/spec20.js @@ -0,0 +1,35 @@ +const SCHEMA_CONTAINERS = [ + 'schema', + 'items', + 'allOf', + 'additionalProperties' + ], + CONTAINERS = { + definitions: SCHEMA_CONTAINERS + }, + DEFINITIONS = { + properties: 'definitions', + responses: 'responses' + }, + INLINE = [ + 'examples', + 'value', + 'example' + ], + COMPONENTS_KEYS = [ + 'definitions', + 'parameters', + 'responses', + 'securityDefinitions' + ], + ROOT_CONTAINERS_KEYS = COMPONENTS_KEYS; + +module.exports = { + RULES_20: { + CONTAINERS, + DEFINITIONS, + COMPONENTS_KEYS, + INLINE, + ROOT_CONTAINERS_KEYS + } +}; diff --git a/lib/common/versionUtils.js b/lib/common/versionUtils.js index 1d8b55e..f26e210 100644 --- a/lib/common/versionUtils.js +++ b/lib/common/versionUtils.js @@ -9,7 +9,8 @@ const _ = require('lodash'), VERSION_3_1 = VERSION_31.version, fs = require('fs'), { RULES_30 } = require('./../bundleRules/spec30'), - { RULES_31 } = require('./../bundleRules/spec31'); + { RULES_31 } = require('./../bundleRules/spec31'), + { RULES_20 } = require('./../bundleRules/spec20'); /** * gets the version key and the version and generates a regular expression that @@ -235,10 +236,8 @@ function getSpecVersion({ type, data, specificationVersion }) { */ function getConcreteSchemaUtils({ type, data, specificationVersion }) { const specVersion = getSpecVersion({ type, data, specificationVersion }); - if (!specVersion) { - return; - } let concreteUtils = {}; + if (specVersion === DEFAULT_SPEC_VERSION) { concreteUtils = require('../30XUtils/schemaUtils30X'); } @@ -270,11 +269,7 @@ function filterOptionsByVersion(options, version) { * @returns {boolean} True if the current spec is using swagger 2.0 spec */ function isSwagger(version) { - let isSwagger = false; - if (version === VERSION_20.version) { - isSwagger = true; - } - return isSwagger; + return compareVersion(version, VERSION_20.version); } /** @@ -286,7 +281,7 @@ function validateSupportedVersion(version) { if (!version) { return false; } - let isValid = [DEFAULT_SPEC_VERSION, VERSION_3_1].find((supportedVersion) => { + let isValid = [DEFAULT_SPEC_VERSION, VERSION_3_1, SWAGGER_VERSION].find((supportedVersion) => { return compareVersion(version, supportedVersion); }); return isValid !== undefined; @@ -298,8 +293,12 @@ function validateSupportedVersion(version) { * @returns {object} The bundling rules related with the spec */ function getBundleRulesDataByVersion(version) { - const is31 = compareVersion(version, VERSION_31.version); - if (is31) { + const is31 = compareVersion(version, VERSION_31.version), + is20 = compareVersion(version, VERSION_20.version); + if (is20) { + return RULES_20; + } + else if (is31) { return RULES_31; } else { @@ -308,10 +307,10 @@ function getBundleRulesDataByVersion(version) { } /** -* Gets the version of a parsed Spec -* @param {object} spec The parsed openapi spec -* @returns {object} The bundling rules related with the spec -*/ + * Gets the version of a parsed Spec + * @param {object} spec The parsed openapi spec + * @returns {object} The bundling rules related with the spec + */ function getVersionFromSpec(spec) { if (!_.isNil(spec) && _.has(spec, 'swagger')) { return spec.swagger; diff --git a/lib/jsonPointer.js b/lib/jsonPointer.js index 75f0d4e..e289616 100644 --- a/lib/jsonPointer.js +++ b/lib/jsonPointer.js @@ -6,7 +6,7 @@ const slashes = /\//g, escapedTilde = /~0/g, jsonPointerLevelSeparator = '/', escapedTildeString = '~0', - { getBundleRulesDataByVersion } = require('./common/versionUtils'), + { isSwagger, getBundleRulesDataByVersion } = require('./common/versionUtils'), { resolveFirstLevelChild, resolveSecondLevelChild @@ -108,7 +108,7 @@ function getKeyInComponents(traceFromParent, mainKey, version, commonPathFromDat * @returns {string} - the concatenated json pointer */ function concatJsonPointer(traceFromParent, targetInRoot) { - const traceFromParentAsString = traceFromParent.join('/'); + const traceFromParentAsString = traceFromParent.join(jsonPointerLevelSeparator); return localPointer + targetInRoot + jsonPointerLevelSeparator + traceFromParentAsString; } @@ -120,8 +120,8 @@ function concatJsonPointer(traceFromParent, targetInRoot) { * @param {string} version - The version we are working on * @returns {string} - the concatenated json pointer */ -function getJsonPointerRelationToRoot(refValue, traceFromKey) { - let targetInRoot = '/components'; +function getJsonPointerRelationToRoot(refValue, traceFromKey, version) { + let targetInRoot = isSwagger(version) ? '' : '/components'; if (refValue.startsWith(localPointer)) { return refValue; } diff --git a/lib/relatedEntities.js b/lib/relatedEntities.js deleted file mode 100644 index c6f0e70..0000000 --- a/lib/relatedEntities.js +++ /dev/null @@ -1,116 +0,0 @@ -const traverseUtility = require('traverse'), - { DFS } = require('./dfs'), - { jsonPointerDecodeAndReplace, isLocalRef, getEntityName } = require('./jsonPointer'), - deref = require('./deref.js'); - -/** - * verifies if the path has been added to the result - * @param {string} path - path to find - * @param {Array} referencesInNode - Array with the already added paths - * @returns {boolean} - wheter a node with the same path has been added - */ -function added(path, referencesInNode) { - return referencesInNode.find((reference) => { return reference.path === path; }) !== undefined; -} - -/** - * Gets the path from a referenced entity - * @param {object} property - current node in process - * @returns {string} - $ref value - */ -function pathSolver(property) { - return property.$ref; -} - -/** - * Gets all the $refs from an object - * @param {object} currentNode - current node in process - * @param {Function} refTypeResolver - function to resolve the ref according to type (local, external, web etc) - * @param {Function} pathSolver - function to resolve the Path - * @returns {object} - {path : $ref value} - */ -function getReferences (currentNode, refTypeResolver, pathSolver) { - let referencesInNode = []; - traverseUtility(currentNode).forEach((property) => { - if (property) { - let hasReferenceTypeKey; - hasReferenceTypeKey = Object.keys(property) - .find( - (key) => { - return refTypeResolver(property, key); - } - ); - if (hasReferenceTypeKey) { - if (!added(property.$ref, referencesInNode)) { - referencesInNode.push({ path: pathSolver(property) }); - } - } - } - }); - return referencesInNode; -} - -/** - * Locates a referenced node from the data input by path - * @param {string} referencePath - value from the $ref property - * @param {object} spec - parsed spec - * @returns {object} - Detect root files result object - */ -function findNodeFromPath(referencePath, spec) { - let found, - splitRef = referencePath.split('/'); - splitRef = splitRef.slice(1).map((elem) => { - return jsonPointerDecodeAndReplace(elem); - }); - found = deref._getEscaped(spec, splitRef); - return found; -} - -/** - * Maps the output from get root files to detect root files - * @param {object} currentNode - current { path, content} object - * @param {object} spec - the whole parsed spec - * @returns {object} - Detect root files result object - */ -function getAdjacentAndMissing(currentNode, spec) { - let currentNodeReferences = getReferences(currentNode, isLocalRef, pathSolver), - graphAdj = [], - missingNodes = []; - - currentNodeReferences.forEach((reference) => { - let referencePath = reference.path, - adjacentNode = findNodeFromPath(referencePath, spec); - if (adjacentNode) { - adjacentNode.$info = { $ref: referencePath, name: getEntityName(referencePath) }; - graphAdj.push(adjacentNode); - } - else { - missingNodes.push({ $ref: referencePath }); - } - - }); - return { graphAdj, missingNodes }; -} - -module.exports = { - - /** - * Maps the output from get root files to detect root files - * @param {object} entityRoot - root file information - * @param {Array} spec - array of { path, content} objects - * @returns {object} - Detect root files result object - */ - getRelatedEntities: function (entityRoot, spec) { - let algorithm = new DFS(), - { traverseOrder, missing } = - algorithm.traverse(entityRoot, (currentNode) => { - return getAdjacentAndMissing(currentNode, spec); - }); - return { relatedEntities: traverseOrder, missingRelatedEntities: missing }; - }, - getReferences, - getAdjacentAndMissing, - isLocalRef, - findNodeFromPath, - pathSolver -}; diff --git a/lib/relatedFiles.js b/lib/relatedFiles.js index 0790714..0856373 100644 --- a/lib/relatedFiles.js +++ b/lib/relatedFiles.js @@ -1,7 +1,7 @@ const parse = require('./parse.js'), + traverseUtility = require('traverse'), BROWSER = 'browser', { DFS } = require('./dfs'), - { getReferences } = require('./relatedEntities'), { isExtRef, removeLocalReferenceFromPath } = require('./jsonPointer'); let path = require('path'), pathBrowserify = require('path-browserify'); @@ -23,6 +23,9 @@ function comparePaths(path1, path2) { * @returns {object} - Detect root files result object */ function calculatePath(parentFileName, referencePath) { + if (path.isAbsolute(referencePath)) { + return referencePath; + } let currentDirName = path.dirname(parentFileName), refDirName = path.join(currentDirName, referencePath); return refDirName; @@ -61,6 +64,44 @@ function findNodeFromPath(referencePath, allData) { }); } +/** + * verifies if the path has been added to the result + * @param {string} path - path to find + * @param {Array} referencesInNode - Array with the already added paths + * @returns {boolean} - wheter a node with the same path has been added + */ +function added(path, referencesInNode) { + return referencesInNode.find((reference) => { return reference.path === path; }) !== undefined; +} + +/** + * Gets all the $refs from an object + * @param {object} currentNode - current node in process + * @param {Function} refTypeResolver - function to resolve the ref according to type (local, external, web etc) + * @param {Function} pathSolver - function to resolve the Path + * @returns {object} - {path : $ref value} + */ +function getReferences (currentNode, refTypeResolver, pathSolver) { + let referencesInNode = []; + traverseUtility(currentNode).forEach((property) => { + if (property) { + let hasReferenceTypeKey; + hasReferenceTypeKey = Object.keys(property) + .find( + (key) => { + return refTypeResolver(property, key); + } + ); + if (hasReferenceTypeKey) { + if (!added(property.$ref, referencesInNode)) { + referencesInNode.push({ path: pathSolver(property) }); + } + } + } + }); + return referencesInNode; +} + /** * Maps the output from get root files to detect root files * @param {object} currentNode - current { path, content} object diff --git a/lib/schemaUtils.js b/lib/schemaUtils.js index 86c47c6..58ed56b 100644 --- a/lib/schemaUtils.js +++ b/lib/schemaUtils.js @@ -6,7 +6,7 @@ const { ParseError } = require('./common/ParseError.js'); const { formatDataPath, checkIsCorrectType, isKnownType } = require('./common/schemaUtilsCommon.js'), - { getConcreteSchemaUtils, SWAGGER_VERSION, validateSupportedVersion } = require('./common/versionUtils.js'), + { getConcreteSchemaUtils, isSwagger, validateSupportedVersion } = require('./common/versionUtils.js'), async = require('async'), sdk = require('postman-collection'), schemaFaker = require('../assets/json-schema-faker.js'), @@ -4842,16 +4842,22 @@ module.exports = { /** * Maps the output for each bundled root file * @param {object} format - defined output format from options - * @param {string} parsedRootFiles - specified version of the process + * @param {string} parsedRootFiles - The parsed root files + * @param {string} version - specified version of the process * @param {object} options - a standard list of options that's globally passed around. Check options.js for more. * @returns {object} - { rootFile: { path }, bundledContent } */ - mapBundleOutput(format, parsedRootFiles, options = {}) { + mapBundleOutput(format, parsedRootFiles, version, options = {}) { return (contentAndComponents) => { let bundledFile = contentAndComponents.fileContent, bundleOutput; - if (!_.isEmpty(contentAndComponents.components)) { + if (isSwagger(version)) { + Object.entries(contentAndComponents.components).forEach(([key, value]) => { + bundledFile[key] = value; + }); + } + else if (!_.isEmpty(contentAndComponents.components)) { bundledFile.components = contentAndComponents.components; } if (!format) { @@ -4901,7 +4907,7 @@ module.exports = { return bundleData; }); - let bundleData = data.map(this.mapBundleOutput(format, parsedRootFiles, options)); + let bundleData = data.map(this.mapBundleOutput(format, parsedRootFiles, version, options)); return bundleData; }, @@ -4926,7 +4932,7 @@ module.exports = { let parsedContent = parseFileOrThrow(rootFile.content); return { fileName: rootFile.fileName, content: rootFile.content, parsed: parsedContent }; }).filter((rootWithParsedContent) => { - let fileVersion = version === SWAGGER_VERSION ? + let fileVersion = isSwagger(version) ? rootWithParsedContent.parsed.oasObject.swagger : rootWithParsedContent.parsed.oasObject.openapi; return compareVersion(version, fileVersion); @@ -4934,8 +4940,8 @@ module.exports = { data = toBundle ? this.getBundledFileData(parsedRootFiles, inputData, origin, bundleFormat, version, options) : this.getRelatedFilesData(parsedRootFiles, inputData, origin); - return data; + return data; }, /** diff --git a/lib/schemapack.js b/lib/schemapack.js index 1a9996e..9b24b86 100644 --- a/lib/schemapack.js +++ b/lib/schemapack.js @@ -634,7 +634,6 @@ class SchemaPack { if (!this.hasDefinedVersion && ('content' in input.data[0])) { return schemaUtils.mapGetRootFilesOutputToDetectRootFilesOutput([], input.specificationVersion); } - let files = {}, rootFiles, res, diff --git a/lib/swaggerUtils/inputValidationSwagger.js b/lib/swaggerUtils/inputValidationSwagger.js index 753cbbe..aaa8c34 100644 --- a/lib/swaggerUtils/inputValidationSwagger.js +++ b/lib/swaggerUtils/inputValidationSwagger.js @@ -1,4 +1,5 @@ +const _ = require('lodash'); module.exports = { /** @@ -8,6 +9,12 @@ module.exports = { * @return {Object} Validation result */ validateSpec: function (spec, options) { + if (_.isNil(spec)) { + return { + result: false, + reason: 'The Specification is null or undefined' + }; + } if (spec.swagger !== '2.0') { return { result: false, @@ -20,7 +27,7 @@ module.exports = { reason: 'The Swagger specification must have an "info" field' }; } - if (!(spec.info.title && spec.info.version) && !options.isFolder) { + if (!(_.get(spec, 'info.title') && _.get(spec, 'info.version')) && !options.isFolder) { return { result: false, reason: 'Title, and version fields are required for the Info Object' diff --git a/test/data/swaggerMultifile/basicExample/bundleExpected.json b/test/data/swaggerMultifile/basicExample/bundleExpected.json new file mode 100644 index 0000000..f7cc6f3 --- /dev/null +++ b/test/data/swaggerMultifile/basicExample/bundleExpected.json @@ -0,0 +1,29 @@ +{ + "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" + } + } + } + } + } +} \ No newline at end of file diff --git a/test/data/swaggerMultifile/petstore-separate-yaml/expectedBundle.json b/test/data/swaggerMultifile/petstore-separate-yaml/expectedBundle.json new file mode 100644 index 0000000..fe4fccb --- /dev/null +++ b/test/data/swaggerMultifile/petstore-separate-yaml/expectedBundle.json @@ -0,0 +1,223 @@ +{ + "swagger": "2.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": "#/parameters/_spec_parameters.yaml-_tagsParam" + }, + { + "$ref": "#/parameters/_spec_parameters.yaml-_limitsParam" + } + ], + "responses": { + "200": { + "description": "pet response", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/_spec_Pet.yaml" + } + } + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "#/definitions/_common_Error.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": "#/definitions/_spec_NewPet.yaml" + } + } + ], + "responses": { + "200": { + "description": "pet response", + "schema": { + "$ref": "#/definitions/_spec_Pet.yaml" + } + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "#/definitions/_common_Error.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": "#/definitions/_spec_Pet.yaml" + } + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "#/definitions/_common_Error.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": "#/definitions/_common_Error.yaml" + } + } + } + } + } + }, + "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" + } + }, + "definitions": { + "_spec_Pet.yaml": { + "type": "object", + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "tag": { + "type": "string" + } + } + }, + "_common_Error.yaml": { + "type": "object", + "required": [ + "code", + "message" + ], + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + } + } + }, + "_spec_NewPet.yaml": { + "type": "object", + "allOf": [ + { + "$ref": "#/definitions/_spec_Pet.yaml" + }, + { + "required": [ + "name" + ], + "properties": { + "description": { + "type": "integer", + "format": "int64" + } + } + } + ] + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/circular_reference/expected.json b/test/data/toBundleExamples/circular_reference/expected.json index b5d5cde..6cc400f 100644 --- a/test/data/toBundleExamples/circular_reference/expected.json +++ b/test/data/toBundleExamples/circular_reference/expected.json @@ -22,19 +22,17 @@ "operationId": "findPets", "responses": { "200": { - "description": "pet response", - "schema": { - "type": "array", - "items": { - "$ref\"": "./schemas/schemas.yaml" + "description": "An paged array of pets", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/_schemas_schemas.yaml-components_schemas_ErrorDetail" + } + } } } - }, - "default": { - "description": "unexpected error", - "schema": { - "$ref": "#/components/schemas/_schemas_schemas.yaml-components_schemas_ErrorDetail" - } } } } @@ -65,7 +63,8 @@ "readOnly": true, "type": "array", "items": { - "items": "- Circular" + "$ref": "#/components/schemas/_schemas_schemas.yaml-components_schemas_ErrorDetail", + "x-circularRef": true }, "description": "The error details." } diff --git a/test/data/toBundleExamples/circular_reference/root.yaml b/test/data/toBundleExamples/circular_reference/root.yaml index 329fa61..79fe8e2 100644 --- a/test/data/toBundleExamples/circular_reference/root.yaml +++ b/test/data/toBundleExamples/circular_reference/root.yaml @@ -12,22 +12,17 @@ info: license: name: Apache 2.0 url: https://www.apache.org/licenses/LICENSE-2.0.html - - paths: /pets: get: description: Returns all pets alesuada ac... operationId: findPets responses: - "200": - description: pet response - schema: - type: array - items: - $ref": "./schemas/schemas.yaml" - default: - description: unexpected error - schema: - $ref: "./schemas/schemas.yaml#components/schemas/ErrorDetail" - + '200': + description: An paged array of pets + content: + application/json: + schema: + type: array + items: + $ref: "./schemas/schemas.yaml#components/schemas/ErrorDetail" diff --git a/test/data/toBundleExamples/composite_anyOf/schemas/pet.yaml b/test/data/toBundleExamples/composite_anyOf/schemas/pet.yaml index 5db88f7..209926c 100644 --- a/test/data/toBundleExamples/composite_anyOf/schemas/pet.yaml +++ b/test/data/toBundleExamples/composite_anyOf/schemas/pet.yaml @@ -3,4 +3,4 @@ properties: petId: type: integer petName: - type: string \ No newline at end of file + type: string diff --git a/test/data/toBundleExamples/composite_anyOf/schemas/user.yaml b/test/data/toBundleExamples/composite_anyOf/schemas/user.yaml index 81370de..0874221 100644 --- a/test/data/toBundleExamples/composite_anyOf/schemas/user.yaml +++ b/test/data/toBundleExamples/composite_anyOf/schemas/user.yaml @@ -3,4 +3,4 @@ properties: id: type: integer userName: - type: string \ No newline at end of file + type: string diff --git a/test/data/toBundleExamples/composite_not/root.yaml b/test/data/toBundleExamples/composite_not/root.yaml index 8a9dfc4..267d705 100644 --- a/test/data/toBundleExamples/composite_not/root.yaml +++ b/test/data/toBundleExamples/composite_not/root.yaml @@ -26,6 +26,6 @@ paths: type: integer client: type: object - not: + not: $ref: "./schemas/user.yaml" - + diff --git a/test/data/toBundleExamples/composite_not/schemas/user.yaml b/test/data/toBundleExamples/composite_not/schemas/user.yaml index 81370de..0874221 100644 --- a/test/data/toBundleExamples/composite_not/schemas/user.yaml +++ b/test/data/toBundleExamples/composite_not/schemas/user.yaml @@ -3,4 +3,4 @@ properties: id: type: integer userName: - type: string \ No newline at end of file + type: string diff --git a/test/data/toBundleExamples/composite_oneOf/schemas/pet.yaml b/test/data/toBundleExamples/composite_oneOf/schemas/pet.yaml index 5db88f7..209926c 100644 --- a/test/data/toBundleExamples/composite_oneOf/schemas/pet.yaml +++ b/test/data/toBundleExamples/composite_oneOf/schemas/pet.yaml @@ -3,4 +3,4 @@ properties: petId: type: integer petName: - type: string \ No newline at end of file + type: string diff --git a/test/data/toBundleExamples/composite_oneOf/schemas/user.yaml b/test/data/toBundleExamples/composite_oneOf/schemas/user.yaml index 81370de..0874221 100644 --- a/test/data/toBundleExamples/composite_oneOf/schemas/user.yaml +++ b/test/data/toBundleExamples/composite_oneOf/schemas/user.yaml @@ -3,4 +3,4 @@ properties: id: type: integer userName: - type: string \ No newline at end of file + type: string diff --git a/test/data/toBundleExamples/example_value/example_value.yml b/test/data/toBundleExamples/example_value/example_value.yml index 3cee5d1..98ce373 100644 --- a/test/data/toBundleExamples/example_value/example_value.yml +++ b/test/data/toBundleExamples/example_value/example_value.yml @@ -12,4 +12,4 @@ "signalToNoiseRatio": 0 } ] -} \ No newline at end of file +} diff --git a/test/data/toBundleExamples/example_value/root.yml b/test/data/toBundleExamples/example_value/root.yml index 4155d21..5ecd0a2 100644 --- a/test/data/toBundleExamples/example_value/root.yml +++ b/test/data/toBundleExamples/example_value/root.yml @@ -283,4 +283,4 @@ components: type: integer format: int32 message: - type: string \ No newline at end of file + type: string diff --git a/test/data/toBundleExamples/nestedProperties/properties/prop.yaml b/test/data/toBundleExamples/nestedProperties/properties/prop.yaml index 1164054..f1c75c9 100644 --- a/test/data/toBundleExamples/nestedProperties/properties/prop.yaml +++ b/test/data/toBundleExamples/nestedProperties/properties/prop.yaml @@ -11,4 +11,4 @@ properties: country: $ref: "./country.yaml" warrior: - $ref: "./warrior.yaml" \ No newline at end of file + $ref: "./warrior.yaml" diff --git a/test/data/toBundleExamples/nestedProperties/properties/warrior.yaml b/test/data/toBundleExamples/nestedProperties/properties/warrior.yaml index 6434c31..0308186 100644 --- a/test/data/toBundleExamples/nestedProperties/properties/warrior.yaml +++ b/test/data/toBundleExamples/nestedProperties/properties/warrior.yaml @@ -3,4 +3,4 @@ properties: power: type: string weapon: - type: string \ No newline at end of file + type: string diff --git a/test/data/toBundleExamples/referenced_components/responses.yaml b/test/data/toBundleExamples/referenced_components/responses.yaml index bc0ee2d..238aa75 100644 --- a/test/data/toBundleExamples/referenced_components/responses.yaml +++ b/test/data/toBundleExamples/referenced_components/responses.yaml @@ -22,4 +22,4 @@ fromB: type: string addressFromB: - type: string \ No newline at end of file + type: string diff --git a/test/data/toBundleExamples/referenced_components/schemaA.yaml b/test/data/toBundleExamples/referenced_components/schemaA.yaml index 2121fb6..c868282 100644 --- a/test/data/toBundleExamples/referenced_components/schemaA.yaml +++ b/test/data/toBundleExamples/referenced_components/schemaA.yaml @@ -3,4 +3,4 @@ properties: fromA: type: string addressFromA: - type: string \ No newline at end of file + type: string diff --git a/test/data/toBundleExamples/referenced_components/schemas.yaml b/test/data/toBundleExamples/referenced_components/schemas.yaml index efd94eb..ff5840d 100644 --- a/test/data/toBundleExamples/referenced_components/schemas.yaml +++ b/test/data/toBundleExamples/referenced_components/schemas.yaml @@ -1,2 +1,2 @@ schemaB: - type: integer \ No newline at end of file + type: integer diff --git a/test/data/toBundleExamples/referenced_examples/examples.yaml b/test/data/toBundleExamples/referenced_examples/examples.yaml index 921c511..c01b2fd 100644 --- a/test/data/toBundleExamples/referenced_examples/examples.yaml +++ b/test/data/toBundleExamples/referenced_examples/examples.yaml @@ -2,4 +2,4 @@ foo: summary: sum value: code: 1 - message: test error message \ No newline at end of file + message: test error message diff --git a/test/data/toBundleExamples/referenced_examples/root.yaml b/test/data/toBundleExamples/referenced_examples/root.yaml index 2ac1c4a..afb13e9 100644 --- a/test/data/toBundleExamples/referenced_examples/root.yaml +++ b/test/data/toBundleExamples/referenced_examples/root.yaml @@ -57,4 +57,4 @@ components: type: integer format: int32 message: - type: string \ No newline at end of file + type: string diff --git a/test/data/toBundleExamples/referenced_properties/attributes.yaml b/test/data/toBundleExamples/referenced_properties/attributes.yaml index 84858f0..4d90787 100644 --- a/test/data/toBundleExamples/referenced_properties/attributes.yaml +++ b/test/data/toBundleExamples/referenced_properties/attributes.yaml @@ -7,4 +7,4 @@ load_balancer_droplet_ids: - 3164444 - 3164445 description: An array containing the IDs of the Droplets assigned to the - load balancer. \ No newline at end of file + load balancer. diff --git a/test/data/toBundleExamples/referenced_properties/op2.yaml b/test/data/toBundleExamples/referenced_properties/op2.yaml deleted file mode 100644 index 362653d..0000000 --- a/test/data/toBundleExamples/referenced_properties/op2.yaml +++ /dev/null @@ -1,21 +0,0 @@ -operationId: loadBalancers_remove_droplets - -summary: Remove Droplets from a Load Balancer - -description: | - To remove a.. - -requestBody: - required: true - - content: - application/json: - schema: - properties: - testProp: - $ref: './test.yaml' - -responses: - default: - description: ok - diff --git a/test/data/toBundleExamples/referenced_properties/root.yaml b/test/data/toBundleExamples/referenced_properties/root.yaml index cb98989..8d105f0 100644 --- a/test/data/toBundleExamples/referenced_properties/root.yaml +++ b/test/data/toBundleExamples/referenced_properties/root.yaml @@ -7,4 +7,4 @@ info: paths: /users/{userId}: get: - $ref: 'operation.yaml' \ No newline at end of file + $ref: 'operation.yaml' diff --git a/test/data/toBundleExamples/schema_from_response_with_headers/expected.json b/test/data/toBundleExamples/schema_from_response_with_headers/expected.json new file mode 100644 index 0000000..46c7d7f --- /dev/null +++ b/test/data/toBundleExamples/schema_from_response_with_headers/expected.json @@ -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" + } + } + } + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/schema_from_response_with_headers/expected.yaml b/test/data/toBundleExamples/schema_from_response_with_headers/expected.yaml new file mode 100644 index 0000000..e405d31 --- /dev/null +++ b/test/data/toBundleExamples/schema_from_response_with_headers/expected.yaml @@ -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 diff --git a/test/data/toBundleExamples/schema_from_response_with_headers/headers/headers.yaml b/test/data/toBundleExamples/schema_from_response_with_headers/headers/headers.yaml new file mode 100644 index 0000000..5d1da1b --- /dev/null +++ b/test/data/toBundleExamples/schema_from_response_with_headers/headers/headers.yaml @@ -0,0 +1,6 @@ +headerTest: + schema: + type: integer + example: 5000 + description: >- + The test header \ No newline at end of file diff --git a/test/data/toBundleExamples/schema_from_response_with_headers/root.yaml b/test/data/toBundleExamples/schema_from_response_with_headers/root.yaml new file mode 100644 index 0000000..0529fe4 --- /dev/null +++ b/test/data/toBundleExamples/schema_from_response_with_headers/root.yaml @@ -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" \ No newline at end of file diff --git a/test/data/toBundleExamples/schema_from_response_with_headers/schemas/user.yaml b/test/data/toBundleExamples/schema_from_response_with_headers/schemas/user.yaml new file mode 100644 index 0000000..81370de --- /dev/null +++ b/test/data/toBundleExamples/schema_from_response_with_headers/schemas/user.yaml @@ -0,0 +1,6 @@ +type: object +properties: + id: + type: integer + userName: + type: string \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/additionalProperties/additionalProperties.yaml b/test/data/toBundleExamples/swagger20/additionalProperties/additionalProperties.yaml new file mode 100644 index 0000000..f80e915 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/additionalProperties/additionalProperties.yaml @@ -0,0 +1,9 @@ +type: + object +properties: + color: + type: string + weight: + type: integer + height: + type: integer \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/additionalProperties/expected.json b/test/data/toBundleExamples/swagger20/additionalProperties/expected.json new file mode 100644 index 0000000..2eff55e --- /dev/null +++ b/test/data/toBundleExamples/swagger20/additionalProperties/expected.json @@ -0,0 +1,69 @@ +{ + "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": { + "/pets": { + "get": { + "description": "Returns all pets from the system that the user has access to,", + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "A list of pets.,", + "schema": { + "$ref": "#/definitions/_pet.yaml" + } + } + } + } + } + }, + "definitions": { + "_pet.yaml": { + "type": "object", + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "tag": { + "type": "string" + }, + "additionalProperties": { + "$ref": "#/definitions/_additionalProperties.yaml" + } + } + }, + "_additionalProperties.yaml": { + "type": "object", + "properties": { + "color": { + "type": "string" + }, + "weight": { + "type": "integer" + }, + "height": { + "type": "integer" + } + } + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/additionalProperties/pet.yaml b/test/data/toBundleExamples/swagger20/additionalProperties/pet.yaml new file mode 100644 index 0000000..4d5a473 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/additionalProperties/pet.yaml @@ -0,0 +1,14 @@ +type: object +required: + - id + - name +properties: + id: + type: integer + format: int64 + name: + type: string + tag: + type: string + additionalProperties: + $ref: "./additionalProperties.yaml" \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/additionalProperties/root.yaml b/test/data/toBundleExamples/swagger20/additionalProperties/root.yaml new file mode 100644 index 0000000..e435b0e --- /dev/null +++ b/test/data/toBundleExamples/swagger20/additionalProperties/root.yaml @@ -0,0 +1,20 @@ +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: + /pets: + get: + description: Returns all pets from the system that the user has access to, + produces: + - application/json + responses: + 200: + description: A list of pets., + schema: + $ref: "./pet.yaml" diff --git a/test/data/toBundleExamples/swagger20/basicExample/bundleExpected.json b/test/data/toBundleExamples/swagger20/basicExample/bundleExpected.json new file mode 100644 index 0000000..f7cc6f3 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/basicExample/bundleExpected.json @@ -0,0 +1,29 @@ +{ + "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" + } + } + } + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/basicExample/index.yaml b/test/data/toBundleExamples/swagger20/basicExample/index.yaml new file mode 100644 index 0000000..f2f08fa --- /dev/null +++ b/test/data/toBundleExamples/swagger20/basicExample/index.yaml @@ -0,0 +1,9 @@ +swagger: "2.0" +info: + $ref: ./info.yaml +host: api.example.com +basePath: /v1 +schemes: + - https +paths: + $ref: ./paths.yaml \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/basicExample/info.yaml b/test/data/toBundleExamples/swagger20/basicExample/info.yaml new file mode 100644 index 0000000..19565f9 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/basicExample/info.yaml @@ -0,0 +1,3 @@ +title: Sample API +description: API description in Markdown. +version: 1.0.0 diff --git a/test/data/toBundleExamples/swagger20/basicExample/paths.yaml b/test/data/toBundleExamples/swagger20/basicExample/paths.yaml new file mode 100644 index 0000000..ab1b648 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/basicExample/paths.yaml @@ -0,0 +1,9 @@ +/users: + get: + summary: Returns a list of users. + description: Optional extended description in Markdown. + produces: + - application/json + responses: + 200: + description: OK \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternal/bundleExpected.json b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternal/bundleExpected.json new file mode 100644 index 0000000..1841277 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternal/bundleExpected.json @@ -0,0 +1,73 @@ +{ + "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/_pet.yaml-_Pet" + } + } + } + } + } + } + }, + "definitions": { + "_pet.yaml-_Pet": { + "type": "object", + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "tag": { + "type": "string" + }, + "Color": { + "$ref": "#/definitions/_pet.yaml-_Color" + } + } + }, + "_pet.yaml-_Color": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "uses": { + "type": "string" + }, + "color": { + "type": "string" + } + } + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternal/index.yaml b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternal/index.yaml new file mode 100644 index 0000000..1042333 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternal/index.yaml @@ -0,0 +1,10 @@ +swagger: "2.0" +info: + $ref: ./info.yaml +host: api.example.com +basePath: /v1 +schemes: + - https +paths: + $ref: "./paths.yaml" + \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternal/info.yaml b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternal/info.yaml new file mode 100644 index 0000000..19565f9 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternal/info.yaml @@ -0,0 +1,3 @@ +title: Sample API +description: API description in Markdown. +version: 1.0.0 diff --git a/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternal/paths.yaml b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternal/paths.yaml new file mode 100644 index 0000000..9531244 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternal/paths.yaml @@ -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: "./pet.yaml#/Pet" \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternal/pet.yaml b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternal/pet.yaml new file mode 100644 index 0000000..61c94b1 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternal/pet.yaml @@ -0,0 +1,25 @@ +Pet: + type: object + required: + - id + - name + properties: + id: + type: integer + format: int64 + name: + type: string + tag: + type: string + Color: + $ref: "#/Color" + +Color: + type: object + properties: + name: + type: string + uses: + type: string + color: + type: string diff --git a/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalMultiple/bundleExpected.json b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalMultiple/bundleExpected.json new file mode 100644 index 0000000..e6508db --- /dev/null +++ b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalMultiple/bundleExpected.json @@ -0,0 +1,136 @@ +{ + "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.", + "parameters": [ + { + "$ref": "#/parameters/_parameters_parameters.yaml-_Parameter1" + }, + { + "$ref": "#/parameters/_parameters_parameters.yaml-_Parameter2" + } + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/_pet.yaml-_Pet" + } + } + } + } + } + } + }, + "parameters": { + "_parameters_parameters.yaml-_Parameter1": { + "name": "tags", + "in": "query", + "description": "tags to filter by", + "required": false, + "type": "array", + "collectionFormat": "csv", + "items": { + "type": "string" + } + }, + "_parameters_parameters.yaml-_Parameter2": { + "name": "limit", + "in": "query", + "description": "maximum number of results to return", + "required": false, + "type": "integer", + "format": "int32" + } + }, + "definitions": { + "_pet.yaml-_Pet": { + "type": "object", + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "tag": { + "type": "string" + }, + "Color": { + "$ref": "#/definitions/_pet.yaml-_Color" + }, + "FavoriteFood": { + "$ref": "#/definitions/_food.yaml-_Food" + } + } + }, + "_pet.yaml-_Color": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "uses": { + "type": "string" + }, + "color": { + "type": "string" + } + } + }, + "_food.yaml-_Food": { + "type": "object", + "properties": { + "brand": { + "$ref": "#/definitions/_food.yaml-_Brand" + }, + "benefits": { + "type": "array", + "items": { + "$ref": "#/definitions/_food.yaml-_Benefit" + } + }, + "cost": { + "type": "string" + } + } + }, + "_food.yaml-_Brand": { + "type": "string" + }, + "_food.yaml-_Benefit": { + "type": "object", + "properties": { + "benefit": { + "type": "string" + }, + "detail": { + "type": "string" + } + } + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalMultiple/food.yaml b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalMultiple/food.yaml new file mode 100644 index 0000000..a7db36f --- /dev/null +++ b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalMultiple/food.yaml @@ -0,0 +1,22 @@ +Food: + type: object + properties: + brand: + $ref: "#/Brand" + benefits: + type: array + items: + $ref: "#/Benefit" + cost: + type: string + +Brand: + type: string + +Benefit: + type: object + properties: + benefit: + type: string + detail: + type: string \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalMultiple/index.yaml b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalMultiple/index.yaml new file mode 100644 index 0000000..1042333 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalMultiple/index.yaml @@ -0,0 +1,10 @@ +swagger: "2.0" +info: + $ref: ./info.yaml +host: api.example.com +basePath: /v1 +schemes: + - https +paths: + $ref: "./paths.yaml" + \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalMultiple/info.yaml b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalMultiple/info.yaml new file mode 100644 index 0000000..19565f9 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalMultiple/info.yaml @@ -0,0 +1,3 @@ +title: Sample API +description: API description in Markdown. +version: 1.0.0 diff --git a/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalMultiple/parameters/parameters.yaml b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalMultiple/parameters/parameters.yaml new file mode 100644 index 0000000..b6a3840 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalMultiple/parameters/parameters.yaml @@ -0,0 +1,16 @@ +Parameter1: + name: tags + in: query + description: tags to filter by + required: false + type: array + collectionFormat: csv + items: + type: string +Parameter2: + name: limit + in: query + description: maximum number of results to return + required: false + type: integer + format: int32 \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalMultiple/paths.yaml b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalMultiple/paths.yaml new file mode 100644 index 0000000..57e8f5d --- /dev/null +++ b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalMultiple/paths.yaml @@ -0,0 +1,16 @@ +/users: + get: + summary: Returns a list of users. + description: Optional extended description in Markdown. + parameters: + - $ref: "./parameters/parameters.yaml#/Parameter1" + - $ref: "./parameters/parameters.yaml#/Parameter2" + produces: + - application/json + responses: + 200: + description: OK + schema: + type: array + items: + $ref: "./pet.yaml#/Pet" \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalMultiple/pet.yaml b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalMultiple/pet.yaml new file mode 100644 index 0000000..6dbe34e --- /dev/null +++ b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalMultiple/pet.yaml @@ -0,0 +1,29 @@ +Pet: + type: object + required: + - id + - name + properties: + id: + type: integer + format: int64 + name: + type: string + tag: + type: string + Color: + $ref: "#/Color" + FavoriteFood: + $ref: "./food.yaml#/Food" + + + +Color: + type: object + properties: + name: + type: string + uses: + type: string + color: + type: string diff --git a/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalWithItems/bundleExpected.json b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalWithItems/bundleExpected.json new file mode 100644 index 0000000..d2395ea --- /dev/null +++ b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalWithItems/bundleExpected.json @@ -0,0 +1,76 @@ +{ + "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/_pet.yaml-_Pet" + } + } + } + } + } + } + }, + "definitions": { + "_pet.yaml-_Pet": { + "type": "object", + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "tag": { + "type": "string" + }, + "Colors": { + "type": "array", + "items": { + "$ref": "#/definitions/_pet.yaml-_Color" + } + } + } + }, + "_pet.yaml-_Color": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "uses": { + "type": "string" + }, + "color": { + "type": "string" + } + } + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalWithItems/index.yaml b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalWithItems/index.yaml new file mode 100644 index 0000000..1042333 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalWithItems/index.yaml @@ -0,0 +1,10 @@ +swagger: "2.0" +info: + $ref: ./info.yaml +host: api.example.com +basePath: /v1 +schemes: + - https +paths: + $ref: "./paths.yaml" + \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalWithItems/info.yaml b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalWithItems/info.yaml new file mode 100644 index 0000000..19565f9 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalWithItems/info.yaml @@ -0,0 +1,3 @@ +title: Sample API +description: API description in Markdown. +version: 1.0.0 diff --git a/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalWithItems/paths.yaml b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalWithItems/paths.yaml new file mode 100644 index 0000000..9531244 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalWithItems/paths.yaml @@ -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: "./pet.yaml#/Pet" \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalWithItems/pet.yaml b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalWithItems/pet.yaml new file mode 100644 index 0000000..b158bf0 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/bringLocalDependenciesFromExternalWithItems/pet.yaml @@ -0,0 +1,27 @@ +Pet: + type: object + required: + - id + - name + properties: + id: + type: integer + format: int64 + name: + type: string + tag: + type: string + Colors: + type: array + items: + $ref: "#/Color" + +Color: + type: object + properties: + name: + type: string + uses: + type: string + color: + type: string diff --git a/test/data/toBundleExamples/swagger20/multipleRefFromRootComponents/bundleExpected.json b/test/data/toBundleExamples/swagger20/multipleRefFromRootComponents/bundleExpected.json new file mode 100644 index 0000000..f8046e8 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/multipleRefFromRootComponents/bundleExpected.json @@ -0,0 +1,95 @@ +{ + "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": { + "/pets": null, + "get": { + "description": "Returns all pets from the system that the user has access to", + "operationId": "findPets", + "parameters": [ + { + "$ref": "#/parameters/Parameter1" + }, + { + "$ref": "#/parameters/Parameter2" + } + ], + "responses": { + "200": { + "description": "pet response", + "schema": { + "$ref": "#/definitions/Pet" + } + } + } + } + }, + "definitions": { + "Pet": { + "type": "object", + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "tag": { + "type": "string" + }, + "Color": { + "$ref": "#/definitions/_pet.yaml-_Color" + } + } + }, + "_pet.yaml-_Color": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "uses": { + "type": "string" + }, + "color": { + "type": "string" + } + } + } + }, + "parameters": { + "Parameter1": { + "name": "tags", + "in": "query", + "description": "tags to filter by", + "required": false, + "type": "array", + "collectionFormat": "csv", + "items": { + "type": "string" + } + }, + "Parameter2": { + "name": "limit", + "in": "query", + "description": "maximum number of results to return", + "required": false, + "type": "integer", + "format": "int32" + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/multipleRefFromRootComponents/index.yaml b/test/data/toBundleExamples/swagger20/multipleRefFromRootComponents/index.yaml new file mode 100644 index 0000000..259a70f --- /dev/null +++ b/test/data/toBundleExamples/swagger20/multipleRefFromRootComponents/index.yaml @@ -0,0 +1,28 @@ +swagger: "2.0" +info: + $ref: ./info.yaml +host: api.example.com +basePath: /v1 +schemes: + - https +paths: + /pets: + get: + description: Returns all pets from the system that the user has access to + operationId: findPets + parameters: + - $ref: "#/parameters/Parameter1" + - $ref: "#/parameters/Parameter2" + responses: + 200: + description: pet response + schema: + $ref: "#/definitions/Pet" +definitions: + Pet: + $ref: "./pet.yaml#/Pet" +parameters: + Parameter1: + $ref: "./parameters/parameters.yaml#/Parameter1" + Parameter2: + $ref: "./parameters/parameters.yaml#/Parameter2" diff --git a/test/data/toBundleExamples/swagger20/multipleRefFromRootComponents/info.yaml b/test/data/toBundleExamples/swagger20/multipleRefFromRootComponents/info.yaml new file mode 100644 index 0000000..19565f9 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/multipleRefFromRootComponents/info.yaml @@ -0,0 +1,3 @@ +title: Sample API +description: API description in Markdown. +version: 1.0.0 diff --git a/test/data/toBundleExamples/swagger20/multipleRefFromRootComponents/parameters/parameters.yaml b/test/data/toBundleExamples/swagger20/multipleRefFromRootComponents/parameters/parameters.yaml new file mode 100644 index 0000000..b6a3840 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/multipleRefFromRootComponents/parameters/parameters.yaml @@ -0,0 +1,16 @@ +Parameter1: + name: tags + in: query + description: tags to filter by + required: false + type: array + collectionFormat: csv + items: + type: string +Parameter2: + name: limit + in: query + description: maximum number of results to return + required: false + type: integer + format: int32 \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/multipleRefFromRootComponents/paths.yaml b/test/data/toBundleExamples/swagger20/multipleRefFromRootComponents/paths.yaml new file mode 100644 index 0000000..ab1b648 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/multipleRefFromRootComponents/paths.yaml @@ -0,0 +1,9 @@ +/users: + get: + summary: Returns a list of users. + description: Optional extended description in Markdown. + produces: + - application/json + responses: + 200: + description: OK \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/multipleRefFromRootComponents/pet.yaml b/test/data/toBundleExamples/swagger20/multipleRefFromRootComponents/pet.yaml new file mode 100644 index 0000000..61c94b1 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/multipleRefFromRootComponents/pet.yaml @@ -0,0 +1,25 @@ +Pet: + type: object + required: + - id + - name + properties: + id: + type: integer + format: int64 + name: + type: string + tag: + type: string + Color: + $ref: "#/Color" + +Color: + type: object + properties: + name: + type: string + uses: + type: string + color: + type: string diff --git a/test/data/toBundleExamples/swagger20/nestedLocalRef/bundleExpected.json b/test/data/toBundleExamples/swagger20/nestedLocalRef/bundleExpected.json new file mode 100644 index 0000000..a84aa62 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/nestedLocalRef/bundleExpected.json @@ -0,0 +1,72 @@ +{ + "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": { + "/pets": { + "get": { + "description": "Returns all pets from the system that the user has access to,", + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "A list of pets.,", + "schema": { + "$ref": "#/definitions/_schemas_pet.yaml" + } + } + } + } + } + }, + "definitions": { + "_schemas_pet.yaml": { + "type": "object", + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "tag": { + "type": "string" + }, + "favoriteFood": { + "$ref": "#/definitions/_schemas_favorite_food.yaml-_FavoriteFood" + }, + "foodPrice": { + "$ref": "#/definitions/_schemas_favorite_food.yaml-_Price" + } + } + }, + "_schemas_favorite_food.yaml-_FavoriteFood": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "brand": { + "type": "string" + } + } + }, + "_schemas_favorite_food.yaml-_Price": { + "type": "integer" + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/nestedLocalRef/index.yaml b/test/data/toBundleExamples/swagger20/nestedLocalRef/index.yaml new file mode 100644 index 0000000..75cbdc0 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/nestedLocalRef/index.yaml @@ -0,0 +1,18 @@ +swagger: "2.0" +info: + $ref: ./info.yaml +host: api.example.com +basePath: /v1 +schemes: + - https +paths: + /pets: + get: + description: Returns all pets from the system that the user has access to, + produces: + - application/json + responses: + 200: + description: A list of pets., + schema: + $ref: "./schemas/pet.yaml" diff --git a/test/data/toBundleExamples/swagger20/nestedLocalRef/info.yaml b/test/data/toBundleExamples/swagger20/nestedLocalRef/info.yaml new file mode 100644 index 0000000..19565f9 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/nestedLocalRef/info.yaml @@ -0,0 +1,3 @@ +title: Sample API +description: API description in Markdown. +version: 1.0.0 diff --git a/test/data/toBundleExamples/swagger20/nestedLocalRef/paths.yaml b/test/data/toBundleExamples/swagger20/nestedLocalRef/paths.yaml new file mode 100644 index 0000000..ab1b648 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/nestedLocalRef/paths.yaml @@ -0,0 +1,9 @@ +/users: + get: + summary: Returns a list of users. + description: Optional extended description in Markdown. + produces: + - application/json + responses: + 200: + description: OK \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/nestedLocalRef/schemas/favorite_food.yaml b/test/data/toBundleExamples/swagger20/nestedLocalRef/schemas/favorite_food.yaml new file mode 100644 index 0000000..331fbe2 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/nestedLocalRef/schemas/favorite_food.yaml @@ -0,0 +1,11 @@ +FavoriteFood: + type: object + properties: + name: + type: + string + brand: + type: + string +Price: + type: integer \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/nestedLocalRef/schemas/pet.yaml b/test/data/toBundleExamples/swagger20/nestedLocalRef/schemas/pet.yaml new file mode 100644 index 0000000..c34b1ef --- /dev/null +++ b/test/data/toBundleExamples/swagger20/nestedLocalRef/schemas/pet.yaml @@ -0,0 +1,16 @@ +type: object +required: + - id + - name +properties: + id: + type: integer + format: int64 + name: + type: string + tag: + type: string + favoriteFood: + $ref: "./favorite_food.yaml#/FavoriteFood" + foodPrice: + $ref: "./favorite_food.yaml#/Price" \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/nestedProperties20/bundleExpected.json b/test/data/toBundleExamples/swagger20/nestedProperties20/bundleExpected.json new file mode 100644 index 0000000..2013c18 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/nestedProperties20/bundleExpected.json @@ -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/_schemas_user.yaml" + } + } + } + } + } + } + }, + "definitions": { + "_schemas_user.yaml": { + "type": "object", + "properties": { + "age": { + "$ref": "#/definitions/_schemas_age.yaml" + }, + "hobbies": { + "$ref": "#/definitions/_schemas_hobbies.yaml" + } + } + }, + "_schemas_age.yaml": { + "type": "string" + }, + "_schemas_hobbies.yaml": { + "type": "array", + "items": { + "$ref": "#/definitions/_schemas_hobby.yaml" + } + }, + "_schemas_hobby.yaml": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "position": { + "type": "integer" + } + } + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/nestedProperties20/index.yaml b/test/data/toBundleExamples/swagger20/nestedProperties20/index.yaml new file mode 100644 index 0000000..f2f08fa --- /dev/null +++ b/test/data/toBundleExamples/swagger20/nestedProperties20/index.yaml @@ -0,0 +1,9 @@ +swagger: "2.0" +info: + $ref: ./info.yaml +host: api.example.com +basePath: /v1 +schemes: + - https +paths: + $ref: ./paths.yaml \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/nestedProperties20/info.yaml b/test/data/toBundleExamples/swagger20/nestedProperties20/info.yaml new file mode 100644 index 0000000..19565f9 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/nestedProperties20/info.yaml @@ -0,0 +1,3 @@ +title: Sample API +description: API description in Markdown. +version: 1.0.0 diff --git a/test/data/toBundleExamples/swagger20/nestedProperties20/paths.yaml b/test/data/toBundleExamples/swagger20/nestedProperties20/paths.yaml new file mode 100644 index 0000000..1a7dc22 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/nestedProperties20/paths.yaml @@ -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" \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/nestedProperties20/schemas/age.yaml b/test/data/toBundleExamples/swagger20/nestedProperties20/schemas/age.yaml new file mode 100644 index 0000000..2d8bb0e --- /dev/null +++ b/test/data/toBundleExamples/swagger20/nestedProperties20/schemas/age.yaml @@ -0,0 +1 @@ +type: string \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/nestedProperties20/schemas/hobbies.yaml b/test/data/toBundleExamples/swagger20/nestedProperties20/schemas/hobbies.yaml new file mode 100644 index 0000000..1b4d1b3 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/nestedProperties20/schemas/hobbies.yaml @@ -0,0 +1,3 @@ +type: array +items: + $ref: "./hobby.yaml" \ No newline at end of file diff --git a/test/data/toBundleExamples/referenced_properties/test.yaml b/test/data/toBundleExamples/swagger20/nestedProperties20/schemas/hobby.yaml similarity index 74% rename from test/data/toBundleExamples/referenced_properties/test.yaml rename to test/data/toBundleExamples/swagger20/nestedProperties20/schemas/hobby.yaml index f035fe4..8545a7b 100644 --- a/test/data/toBundleExamples/referenced_properties/test.yaml +++ b/test/data/toBundleExamples/swagger20/nestedProperties20/schemas/hobby.yaml @@ -1,6 +1,6 @@ type: object properties: - prop1: + name: type: string - prop2: + position: type: integer \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/nestedProperties20/schemas/user.yaml b/test/data/toBundleExamples/swagger20/nestedProperties20/schemas/user.yaml new file mode 100644 index 0000000..8c13a61 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/nestedProperties20/schemas/user.yaml @@ -0,0 +1,6 @@ +type: object +properties: + age: + $ref: "./age.yaml" + hobbies: + $ref: "./hobbies.yaml" \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/nestedRefs/bundleExpected.json b/test/data/toBundleExamples/swagger20/nestedRefs/bundleExpected.json new file mode 100644 index 0000000..69dc891 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/nestedRefs/bundleExpected.json @@ -0,0 +1,66 @@ +{ + "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": { + "/pets": { + "get": { + "description": "Returns all pets from the system that the user has access to,", + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "A list of pets.,", + "schema": { + "$ref": "#/definitions/_schemas_pet.yaml" + } + } + } + } + } + }, + "definitions": { + "_schemas_pet.yaml": { + "type": "object", + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "tag": { + "type": "string" + }, + "favoriteFood": { + "$ref": "#/definitions/_schemas_favorite_food.yaml" + } + } + }, + "_schemas_favorite_food.yaml": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "brand": { + "type": "string" + } + } + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/nestedRefs/index.yaml b/test/data/toBundleExamples/swagger20/nestedRefs/index.yaml new file mode 100644 index 0000000..75cbdc0 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/nestedRefs/index.yaml @@ -0,0 +1,18 @@ +swagger: "2.0" +info: + $ref: ./info.yaml +host: api.example.com +basePath: /v1 +schemes: + - https +paths: + /pets: + get: + description: Returns all pets from the system that the user has access to, + produces: + - application/json + responses: + 200: + description: A list of pets., + schema: + $ref: "./schemas/pet.yaml" diff --git a/test/data/toBundleExamples/swagger20/nestedRefs/info.yaml b/test/data/toBundleExamples/swagger20/nestedRefs/info.yaml new file mode 100644 index 0000000..19565f9 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/nestedRefs/info.yaml @@ -0,0 +1,3 @@ +title: Sample API +description: API description in Markdown. +version: 1.0.0 diff --git a/test/data/toBundleExamples/swagger20/nestedRefs/paths.yaml b/test/data/toBundleExamples/swagger20/nestedRefs/paths.yaml new file mode 100644 index 0000000..ab1b648 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/nestedRefs/paths.yaml @@ -0,0 +1,9 @@ +/users: + get: + summary: Returns a list of users. + description: Optional extended description in Markdown. + produces: + - application/json + responses: + 200: + description: OK \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/nestedRefs/schemas/favorite_food.yaml b/test/data/toBundleExamples/swagger20/nestedRefs/schemas/favorite_food.yaml new file mode 100644 index 0000000..32b48e5 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/nestedRefs/schemas/favorite_food.yaml @@ -0,0 +1,8 @@ +type: object +properties: + name: + type: + string + brand: + type: + string \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/nestedRefs/schemas/pet.yaml b/test/data/toBundleExamples/swagger20/nestedRefs/schemas/pet.yaml new file mode 100644 index 0000000..41e7d3c --- /dev/null +++ b/test/data/toBundleExamples/swagger20/nestedRefs/schemas/pet.yaml @@ -0,0 +1,14 @@ +type: object +required: + - id + - name +properties: + id: + type: integer + format: int64 + name: + type: string + tag: + type: string + favoriteFood: + $ref: "./favorite_food.yaml" \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/referenced_example/examples.yaml b/test/data/toBundleExamples/swagger20/referenced_example/examples.yaml new file mode 100644 index 0000000..972a8ef --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_example/examples.yaml @@ -0,0 +1,2 @@ +application/json: + name: Puma diff --git a/test/data/toBundleExamples/swagger20/referenced_example/expected.json b/test/data/toBundleExamples/swagger20/referenced_example/expected.json new file mode 100644 index 0000000..da7e196 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_example/expected.json @@ -0,0 +1,88 @@ +{ + "swagger": "2.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" + } + }, + "paths": { + "/pets": { + "get": { + "description": "Returns all pets alesuada ac...", + "operationId": "findPets", + "responses": { + "200": { + "description": "pet response", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Pet" + } + }, + "examples": { + "application/json": { + "name": "Puma" + } + } + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "#/definitions/Error" + }, + "examples": { + "application/json": { + "name": "Puma" + } + } + } + } + } + } + }, + "definitions": { + "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" + } + } + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/referenced_example/root.yaml b/test/data/toBundleExamples/swagger20/referenced_example/root.yaml new file mode 100644 index 0000000..844351a --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_example/root.yaml @@ -0,0 +1,57 @@ +swagger: '2.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 +paths: + /pets: + get: + description: Returns all pets alesuada ac... + operationId: findPets + responses: + '200': + description: pet response + schema: + type: array + items: + $ref: '#/definitions/Pet' + examples: + $ref: "examples.yaml" + default: + description: unexpected error + schema: + $ref: '#/definitions/Error' + examples: + application/json: + $ref: "examples.yaml#/application~1json" +definitions: + 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 diff --git a/test/data/toBundleExamples/swagger20/referenced_example_key/example.yaml b/test/data/toBundleExamples/swagger20/referenced_example_key/example.yaml new file mode 100644 index 0000000..871af42 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_example_key/example.yaml @@ -0,0 +1,3 @@ +id: 1 +name: Puma +tag: Test diff --git a/test/data/toBundleExamples/swagger20/referenced_example_key/expected.json b/test/data/toBundleExamples/swagger20/referenced_example_key/expected.json new file mode 100644 index 0000000..6d41686 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_example_key/expected.json @@ -0,0 +1,83 @@ +{ + "swagger": "2.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" + } + }, + "paths": { + "/pets": { + "get": { + "description": "Returns all pets alesuada ac...", + "operationId": "findPets", + "responses": { + "200": { + "description": "pet response", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Pet" + }, + "example": { + "id": 1, + "name": "Puma", + "tag": "Test" + } + } + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + } + }, + "definitions": { + "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" + } + } + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/referenced_example_key/root.yaml b/test/data/toBundleExamples/swagger20/referenced_example_key/root.yaml new file mode 100644 index 0000000..7f40d15 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_example_key/root.yaml @@ -0,0 +1,54 @@ +swagger: '2.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 +paths: + /pets: + get: + description: Returns all pets alesuada ac... + operationId: findPets + responses: + '200': + description: pet response + schema: + type: array + items: + $ref: '#/definitions/Pet' + example: + $ref: "example.yaml" + default: + description: unexpected error + schema: + $ref: '#/definitions/Error' +definitions: + 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 diff --git a/test/data/toBundleExamples/swagger20/referenced_paths/expected.json b/test/data/toBundleExamples/swagger20/referenced_paths/expected.json new file mode 100644 index 0000000..16927f5 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_paths/expected.json @@ -0,0 +1,107 @@ +{ + "swagger": "2.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" + } + }, + "paths": { + "/pets": { + "get": { + "description": "Returns all pets alesuada ac...", + "operationId": "findPets", + "responses": { + "200": { + "description": "pet response", + "content": { + "application/json": { + "schema": { + "required": [ + "code", + "message" + ], + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + } + } + } + } + } + }, + "default": { + "description": "unexpected error", + "content": { + "application/json": { + "schema": { + "required": [ + "code", + "message" + ], + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + } + } + } + } + } + } + } + } + } + }, + "definitions": { + "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" + } + } + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/referenced_paths/paths/path.yaml b/test/data/toBundleExamples/swagger20/referenced_paths/paths/path.yaml new file mode 100644 index 0000000..dab6ca5 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_paths/paths/path.yaml @@ -0,0 +1,31 @@ +description: Returns all pets alesuada ac... +operationId: findPets +responses: + "200": + description: pet response + content: + application/json: + schema: + required: + - code + - message + properties: + code: + type: integer + format: int32 + message: + type: string + default: + description: unexpected error + content: + application/json: + schema: + required: + - code + - message + properties: + code: + type: integer + format: int32 + message: + type: string diff --git a/test/data/toBundleExamples/swagger20/referenced_paths/paths/paths.yaml b/test/data/toBundleExamples/swagger20/referenced_paths/paths/paths.yaml new file mode 100644 index 0000000..e826f5c --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_paths/paths/paths.yaml @@ -0,0 +1,3 @@ +/pets: + get: + "$ref": "./path.yaml" diff --git a/test/data/toBundleExamples/swagger20/referenced_paths/root.yaml b/test/data/toBundleExamples/swagger20/referenced_paths/root.yaml new file mode 100644 index 0000000..6652cb6 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_paths/root.yaml @@ -0,0 +1,38 @@ +swagger: '2.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 +paths: + "$ref": "./paths/paths.yaml" +definitions: + 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 diff --git a/test/data/toBundleExamples/swagger20/referenced_paths_local_schema/expected.json b/test/data/toBundleExamples/swagger20/referenced_paths_local_schema/expected.json new file mode 100644 index 0000000..649315c --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_paths_local_schema/expected.json @@ -0,0 +1,85 @@ +{ + "swagger": "2.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" + } + }, + "paths": { + "/pets": { + "get": { + "description": "Returns all pets", + "content": { + "application/json": { + "schema": { + "$ref": "#/definitions/_paths_path.yaml-_definitions_Error" + } + }, + "description": "Returns all pets from the system that the user has access to,", + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "A list of pets.,", + "schema": { + "$ref": "#/definitions/_paths_path.yaml-_definitions_Pet" + } + } + } + } + } + } + }, + "definitions": { + "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-_definitions_Error": { + "$ref": "#/definitions/Error" + }, + "_paths_path.yaml-_definitions_Pet": { + "$ref": "#/definitions/Pet" + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/referenced_paths_local_schema/paths/path.yaml b/test/data/toBundleExamples/swagger20/referenced_paths_local_schema/paths/path.yaml new file mode 100644 index 0000000..ef92b58 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_paths_local_schema/paths/path.yaml @@ -0,0 +1,13 @@ +description: Returns all pets +content: + application/json: + schema: + $ref: "#/definitions/Error" + description: Returns all pets from the system that the user has access to, + produces: + - application/json + responses: + 200: + description: A list of pets., + schema: + $ref: "#/definitions/Pet" diff --git a/test/data/toBundleExamples/swagger20/referenced_paths_local_schema/paths/paths.yaml b/test/data/toBundleExamples/swagger20/referenced_paths_local_schema/paths/paths.yaml new file mode 100644 index 0000000..e826f5c --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_paths_local_schema/paths/paths.yaml @@ -0,0 +1,3 @@ +/pets: + get: + "$ref": "./path.yaml" diff --git a/test/data/toBundleExamples/swagger20/referenced_paths_local_schema/root.yaml b/test/data/toBundleExamples/swagger20/referenced_paths_local_schema/root.yaml new file mode 100644 index 0000000..6652cb6 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_paths_local_schema/root.yaml @@ -0,0 +1,38 @@ +swagger: '2.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 +paths: + "$ref": "./paths/paths.yaml" +definitions: + 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 diff --git a/test/data/toBundleExamples/swagger20/referenced_response/expected.json b/test/data/toBundleExamples/swagger20/referenced_response/expected.json new file mode 100644 index 0000000..06175a3 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_response/expected.json @@ -0,0 +1,74 @@ +{ + "swagger": "2.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" + } + }, + "paths": { + "/pets": { + "get": { + "description": "Returns all pets alesuada ac...", + "operationId": "findPets", + "responses": { + "200": { + "$ref": "#/responses/_response.yaml" + } + } + } + } + }, + "definitions": { + "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" + } + } + } + }, + "responses": { + "_response.yaml": { + "description": "A simple string response", + "schema": { + "type": "string" + } + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/referenced_response/response.yaml b/test/data/toBundleExamples/swagger20/referenced_response/response.yaml new file mode 100644 index 0000000..30e4662 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_response/response.yaml @@ -0,0 +1,3 @@ +description: A simple string response +schema: + type: string diff --git a/test/data/toBundleExamples/swagger20/referenced_response/root.yaml b/test/data/toBundleExamples/swagger20/referenced_response/root.yaml new file mode 100644 index 0000000..dbcc120 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_response/root.yaml @@ -0,0 +1,44 @@ +swagger: '2.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 +paths: + /pets: + get: + description: Returns all pets alesuada ac... + operationId: findPets + responses: + '200': + $ref: "./response.yaml" +definitions: + 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 diff --git a/test/data/toBundleExamples/swagger20/referenced_root_components/definitions.yaml b/test/data/toBundleExamples/swagger20/referenced_root_components/definitions.yaml new file mode 100644 index 0000000..7ec0b9c --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_root_components/definitions.yaml @@ -0,0 +1,22 @@ +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 \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/referenced_root_components/expected.json b/test/data/toBundleExamples/swagger20/referenced_root_components/expected.json new file mode 100644 index 0000000..654b54d --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_root_components/expected.json @@ -0,0 +1,141 @@ +{ + "swagger": "2.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" + } + }, + "paths": { + "/pets": { + "get": { + "description": "Returns all pets alesuada ac...", + "operationId": "findPets", + "responses": { + "200": { + "description": "pet response", + "content": { + "application/json": { + "schema": { + "required": [ + "code", + "message" + ], + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + } + } + } + } + } + }, + "default": { + "description": "unexpected error", + "content": { + "application/json": { + "schema": { + "required": [ + "code", + "message" + ], + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + } + } + } + } + } + } + } + } + } + }, + "definitions": { + "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" + } + } + } + }, + "securityDefinitions": { + "type": "oauth2", + "authorizationUrl": "http://swagger.io/api/oauth/dialog", + "flow": "implicit", + "scopes": { + "write:pets": "modify pets in your account", + "read:pets": "read your pets" + } + }, + "tags": [ + { + "name": "Authorization", + "x-bx-tag": "authorization", + "x-bx-priority": true + }, + { + "name": "Bx Sign", + "x-bx-tag": "sign_requests" + } + ], + "responses": { + "200": { + "description": "A simple string response", + "schema": { + "type": "string" + } + }, + "400": { + "description": "A simple string response from 400 code", + "schema": { + "type": "string" + } + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/referenced_root_components/info.yaml b/test/data/toBundleExamples/swagger20/referenced_root_components/info.yaml new file mode 100644 index 0000000..2ddd567 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_root_components/info.yaml @@ -0,0 +1,11 @@ +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 \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/referenced_root_components/paths/path.yaml b/test/data/toBundleExamples/swagger20/referenced_root_components/paths/path.yaml new file mode 100644 index 0000000..dab6ca5 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_root_components/paths/path.yaml @@ -0,0 +1,31 @@ +description: Returns all pets alesuada ac... +operationId: findPets +responses: + "200": + description: pet response + content: + application/json: + schema: + required: + - code + - message + properties: + code: + type: integer + format: int32 + message: + type: string + default: + description: unexpected error + content: + application/json: + schema: + required: + - code + - message + properties: + code: + type: integer + format: int32 + message: + type: string diff --git a/test/data/toBundleExamples/swagger20/referenced_root_components/paths/paths.yaml b/test/data/toBundleExamples/swagger20/referenced_root_components/paths/paths.yaml new file mode 100644 index 0000000..e826f5c --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_root_components/paths/paths.yaml @@ -0,0 +1,3 @@ +/pets: + get: + "$ref": "./path.yaml" diff --git a/test/data/toBundleExamples/swagger20/referenced_root_components/responses.yaml b/test/data/toBundleExamples/swagger20/referenced_root_components/responses.yaml new file mode 100644 index 0000000..0fa534b --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_root_components/responses.yaml @@ -0,0 +1,8 @@ +'200': + description: A simple string response + schema: + type: string +'400': + description: A simple string response from 400 code + schema: + type: string diff --git a/test/data/toBundleExamples/swagger20/referenced_root_components/root.yaml b/test/data/toBundleExamples/swagger20/referenced_root_components/root.yaml new file mode 100644 index 0000000..8cd48a6 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_root_components/root.yaml @@ -0,0 +1,13 @@ +swagger: '2.0' +info: + $ref: './info.yaml' +paths: + "$ref": "./paths/paths.yaml" +definitions: + $ref: './definitions.yaml' +securityDefinitions: + $ref: './securitySchemes.yaml' +tags: + $ref: './tags.yaml' +responses: + $ref: './responses.yaml' \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/referenced_root_components/securitySchemes.yaml b/test/data/toBundleExamples/swagger20/referenced_root_components/securitySchemes.yaml new file mode 100644 index 0000000..68a4da3 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_root_components/securitySchemes.yaml @@ -0,0 +1,6 @@ +type: oauth2 +authorizationUrl: http://swagger.io/api/oauth/dialog +flow: implicit +scopes: + write:pets: modify pets in your account + read:pets: read your pets diff --git a/test/data/toBundleExamples/swagger20/referenced_root_components/tags.yaml b/test/data/toBundleExamples/swagger20/referenced_root_components/tags.yaml new file mode 100644 index 0000000..a123fd4 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_root_components/tags.yaml @@ -0,0 +1,6 @@ +- name: Authorization + x-bx-tag: authorization + x-bx-priority: true + +- name: Bx Sign + x-bx-tag: sign_requests diff --git a/test/data/toBundleExamples/swagger20/referenced_security_schemes/expected.json b/test/data/toBundleExamples/swagger20/referenced_security_schemes/expected.json new file mode 100644 index 0000000..f003055 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_security_schemes/expected.json @@ -0,0 +1,91 @@ +{ + "swagger": "2.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" + } + }, + "paths": { + "/pets": { + "get": { + "description": "Returns all pets alesuada ac...", + "operationId": "findPets", + "responses": { + "200": { + "description": "pet response", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Pet" + } + } + } + }, + "security": [ + { + "petstore_auth": [ + "write:pets", + "read:pets" + ] + } + ] + } + } + }, + "definitions": { + "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" + } + } + } + }, + "securityDefinitions": { + "petstore_auth": { + "type": "oauth2", + "authorizationUrl": "http://swagger.io/api/oauth/dialog", + "flow": "implicit", + "scopes": { + "write:pets": "modify pets in your account", + "read:pets": "read your pets" + } + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/referenced_security_schemes/root.yaml b/test/data/toBundleExamples/swagger20/referenced_security_schemes/root.yaml new file mode 100644 index 0000000..cfef5e9 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_security_schemes/root.yaml @@ -0,0 +1,55 @@ +swagger: '2.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 +paths: + /pets: + get: + description: Returns all pets alesuada ac... + operationId: findPets + responses: + '200': + description: pet response + schema: + type: array + items: + $ref: '#/definitions/Pet' + security: + - petstore_auth: + - 'write:pets' + - 'read:pets' +definitions: + 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 +securityDefinitions: + petstore_auth: + $ref: "./sschemes.yaml" diff --git a/test/data/toBundleExamples/swagger20/referenced_security_schemes/sschemes.yaml b/test/data/toBundleExamples/swagger20/referenced_security_schemes/sschemes.yaml new file mode 100644 index 0000000..68a4da3 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_security_schemes/sschemes.yaml @@ -0,0 +1,6 @@ +type: oauth2 +authorizationUrl: http://swagger.io/api/oauth/dialog +flow: implicit +scopes: + write:pets: modify pets in your account + read:pets: read your pets diff --git a/test/data/toBundleExamples/swagger20/referenced_tags/expected.json b/test/data/toBundleExamples/swagger20/referenced_tags/expected.json new file mode 100644 index 0000000..cd62dc5 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_tags/expected.json @@ -0,0 +1,89 @@ +{ + "swagger": "2.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" + } + }, + "paths": { + "/pets": { + "get": { + "description": "Returns all pets alesuada ac...", + "operationId": "findPets", + "responses": { + "200": { + "description": "pet response", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/Pet" + } + } + }, + "default": { + "description": "unexpected error", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + } + }, + "tags": [ + { + "name": "Authorization", + "x-bx-tag": "authorization", + "x-bx-priority": true + }, + { + "name": "Bx Sign", + "x-bx-tag": "sign_requests" + } + ], + "definitions": { + "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" + } + } + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/referenced_tags/root.yaml b/test/data/toBundleExamples/swagger20/referenced_tags/root.yaml new file mode 100644 index 0000000..5eec1ae --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_tags/root.yaml @@ -0,0 +1,54 @@ +swagger: '2.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 +paths: + /pets: + get: + description: Returns all pets alesuada ac... + operationId: findPets + responses: + '200': + description: pet response + schema: + type: array + items: + $ref: '#/definitions/Pet' + default: + description: unexpected error + schema: + $ref: '#/definitions/Error' +tags: + "$ref": "./tags/tags.yaml" +definitions: + 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 diff --git a/test/data/toBundleExamples/swagger20/referenced_tags/tags/tags.yaml b/test/data/toBundleExamples/swagger20/referenced_tags/tags/tags.yaml new file mode 100644 index 0000000..a123fd4 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/referenced_tags/tags/tags.yaml @@ -0,0 +1,6 @@ +- name: Authorization + x-bx-tag: authorization + x-bx-priority: true + +- name: Bx Sign + x-bx-tag: sign_requests diff --git a/test/data/toBundleExamples/swagger20/sameRefDifferentSource/bundleExpected.json b/test/data/toBundleExamples/swagger20/sameRefDifferentSource/bundleExpected.json new file mode 100644 index 0000000..f749d5f --- /dev/null +++ b/test/data/toBundleExamples/swagger20/sameRefDifferentSource/bundleExpected.json @@ -0,0 +1,117 @@ +{ + "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": { + "$ref": "#/definitions/_schemas_user.yaml-User" + } + } + } + } + }, + "/clients": { + "get": { + "summary": "Returns a list of users.", + "description": "Optional extended description in Markdown.", + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/_otherSchemas_client.yaml-Client" + } + } + } + } + } + }, + "definitions": { + "_schemas_user.yaml-User": { + "type": "object", + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer" + }, + "detail": { + "type": "array", + "items": { + "$ref": "#/definitions/_schemas_detail.yaml-_Detail" + } + } + } + }, + "_otherSchemas_client.yaml-Client": { + "type": "object", + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer" + }, + "details": { + "type": "array", + "items": { + "$ref": "#/definitions/_otherSchemas_detail.yaml-_Detail" + } + } + } + }, + "_otherSchemas_detail.yaml-_Detail": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "clientName": { + "type": "string" + }, + "clientDescription": { + "type": "string" + } + } + }, + "_schemas_detail.yaml-_Detail": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "userName": { + "type": "string" + }, + "userDescription": { + "type": "string" + } + } + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/sameRefDifferentSource/index.yaml b/test/data/toBundleExamples/swagger20/sameRefDifferentSource/index.yaml new file mode 100644 index 0000000..f2f08fa --- /dev/null +++ b/test/data/toBundleExamples/swagger20/sameRefDifferentSource/index.yaml @@ -0,0 +1,9 @@ +swagger: "2.0" +info: + $ref: ./info.yaml +host: api.example.com +basePath: /v1 +schemes: + - https +paths: + $ref: ./paths.yaml \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/sameRefDifferentSource/info.yaml b/test/data/toBundleExamples/swagger20/sameRefDifferentSource/info.yaml new file mode 100644 index 0000000..19565f9 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/sameRefDifferentSource/info.yaml @@ -0,0 +1,3 @@ +title: Sample API +description: API description in Markdown. +version: 1.0.0 diff --git a/test/data/toBundleExamples/swagger20/sameRefDifferentSource/otherSchemas/client.yaml b/test/data/toBundleExamples/swagger20/sameRefDifferentSource/otherSchemas/client.yaml new file mode 100644 index 0000000..7a2d1f5 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/sameRefDifferentSource/otherSchemas/client.yaml @@ -0,0 +1,12 @@ +Client: + type: object + required: + - id + - name + properties: + id: + type: integer + details: + type: array + items: + $ref: "./detail.yaml#/Detail" \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/sameRefDifferentSource/otherSchemas/detail.yaml b/test/data/toBundleExamples/swagger20/sameRefDifferentSource/otherSchemas/detail.yaml new file mode 100644 index 0000000..2898012 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/sameRefDifferentSource/otherSchemas/detail.yaml @@ -0,0 +1,10 @@ +Detail: + type: object + properties: + id: + type: integer + format: int64 + clientName: + type: string + clientDescription: + type: string \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/sameRefDifferentSource/paths.yaml b/test/data/toBundleExamples/swagger20/sameRefDifferentSource/paths.yaml new file mode 100644 index 0000000..cd37e5f --- /dev/null +++ b/test/data/toBundleExamples/swagger20/sameRefDifferentSource/paths.yaml @@ -0,0 +1,22 @@ +/users: + get: + summary: Returns a list of users. + description: Optional extended description in Markdown. + produces: + - application/json + responses: + 200: + description: OK + schema: + $ref: "./schemas/user.yaml#User" +/clients: + get: + summary: Returns a list of users. + description: Optional extended description in Markdown. + produces: + - application/json + responses: + 200: + description: OK + schema: + $ref: "./otherSchemas/client.yaml#Client" \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/sameRefDifferentSource/schemas/detail.yaml b/test/data/toBundleExamples/swagger20/sameRefDifferentSource/schemas/detail.yaml new file mode 100644 index 0000000..5a0406e --- /dev/null +++ b/test/data/toBundleExamples/swagger20/sameRefDifferentSource/schemas/detail.yaml @@ -0,0 +1,10 @@ +Detail: + type: object + properties: + id: + type: integer + format: int64 + userName: + type: string + userDescription: + type: string \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/sameRefDifferentSource/schemas/user.yaml b/test/data/toBundleExamples/swagger20/sameRefDifferentSource/schemas/user.yaml new file mode 100644 index 0000000..fe4c4ad --- /dev/null +++ b/test/data/toBundleExamples/swagger20/sameRefDifferentSource/schemas/user.yaml @@ -0,0 +1,12 @@ +User: + type: object + required: + - id + - name + properties: + id: + type: integer + detail: + type: array + items: + $ref: "./detail.yaml#/Detail" \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/schema_collision_from_responses/expected.json b/test/data/toBundleExamples/swagger20/schema_collision_from_responses/expected.json new file mode 100644 index 0000000..1c30fa8 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/schema_collision_from_responses/expected.json @@ -0,0 +1,109 @@ +{ + "swagger": 2, + "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": "#/definitions/_schemas___user.yaml" + } + } + } + } + } + } + }, + "/users/weird": { + "get": { + "summary": "Get a user by ID", + "responses": { + "200": { + "description": "A single user.", + "content": { + "application/json": { + "schema": { + "$ref": "#/definitions/_schemas___user.yaml_RQm8" + } + } + } + } + } + } + }, + "/users/other": { + "get": { + "summary": "Get a user by ID", + "responses": { + "200": { + "description": "A single user.", + "content": { + "application/json": { + "schema": { + "$ref": "#/definitions/_schemas___user.yaml_mvS0" + } + } + } + } + } + } + } + }, + "definitions": { + "_schemas___user.yaml": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "userName": { + "type": "string" + } + } + }, + "_schemas___user.yaml_RQm8": { + "type": "object", + "properties": { + "otherCollisionedId": { + "type": "integer" + }, + "someData": { + "type": "string" + } + } + }, + "_schemas___user.yaml_mvS0": { + "type": "object", + "properties": { + "aCollisionedItem": { + "type": "integer" + }, + "userName": { + "type": "string" + }, + "randomString": { + "type": "string" + } + } + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/schema_collision_from_responses/root.yaml b/test/data/toBundleExamples/swagger20/schema_collision_from_responses/root.yaml new file mode 100644 index 0000000..60ebad2 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/schema_collision_from_responses/root.yaml @@ -0,0 +1,43 @@ +swagger: 2.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" + /users/weird: + get: + summary: Get a user by ID + responses: + 200: + description: A single user. + content: + application/json: + schema: + $ref: "./schemas_/_user.yaml" + /users/other: + get: + summary: Get a user by ID + responses: + 200: + description: A single user. + content: + application/json: + schema: + $ref: "./schemas/__user.yaml" \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/schema_collision_from_responses/schemas/__user.yaml b/test/data/toBundleExamples/swagger20/schema_collision_from_responses/schemas/__user.yaml new file mode 100644 index 0000000..46d4750 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/schema_collision_from_responses/schemas/__user.yaml @@ -0,0 +1,8 @@ +type: object +properties: + aCollisionedItem: + type: integer + userName: + type: string + randomString: + type: string \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/schema_collision_from_responses/schemas_/_user.yaml b/test/data/toBundleExamples/swagger20/schema_collision_from_responses/schemas_/_user.yaml new file mode 100644 index 0000000..b63536e --- /dev/null +++ b/test/data/toBundleExamples/swagger20/schema_collision_from_responses/schemas_/_user.yaml @@ -0,0 +1,6 @@ +type: object +properties: + otherCollisionedId: + type: integer + someData: + type: string \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/schema_collision_from_responses/schemas__/user.yaml b/test/data/toBundleExamples/swagger20/schema_collision_from_responses/schemas__/user.yaml new file mode 100644 index 0000000..81370de --- /dev/null +++ b/test/data/toBundleExamples/swagger20/schema_collision_from_responses/schemas__/user.yaml @@ -0,0 +1,6 @@ +type: object +properties: + id: + type: integer + userName: + type: string \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/schema_collision_w_root_components/expected.json b/test/data/toBundleExamples/swagger20/schema_collision_w_root_components/expected.json new file mode 100644 index 0000000..141900f --- /dev/null +++ b/test/data/toBundleExamples/swagger20/schema_collision_w_root_components/expected.json @@ -0,0 +1,78 @@ +{ + "swagger": 2, + "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": "#/definitions/_schemas_user.yaml_zfNS" + } + } + } + } + } + } + }, + "/users/other": { + "get": { + "summary": "Get a user by ID", + "responses": { + "200": { + "description": "A single user.", + "content": { + "application/json": { + "schema": { + "$ref": "#/definitions/_schemas_user.yaml" + } + } + } + } + } + } + } + }, + "definitions": { + "_schemas_user.yaml": { + "type": "object", + "properties": { + "componentInRootId": { + "type": "string" + } + } + }, + "_schemas_user.yaml_zfNS": { + "type": "object", + "properties": { + "aCollisionedItem": { + "type": "integer" + }, + "userName": { + "type": "string" + }, + "randomString": { + "type": "string" + } + } + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/schema_collision_w_root_components/root.yaml b/test/data/toBundleExamples/swagger20/schema_collision_w_root_components/root.yaml new file mode 100644 index 0000000..b9ca19a --- /dev/null +++ b/test/data/toBundleExamples/swagger20/schema_collision_w_root_components/root.yaml @@ -0,0 +1,39 @@ +swagger: 2.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" + /users/other: + get: + summary: Get a user by ID + responses: + 200: + description: A single user. + content: + application/json: + schema: + $ref: "#/definitions/_schemas_user.yaml" +definitions: + "_schemas_user.yaml": + type: object + properties: + componentInRootId: + type: string \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/schema_collision_w_root_components/schemas/user.yaml b/test/data/toBundleExamples/swagger20/schema_collision_w_root_components/schemas/user.yaml new file mode 100644 index 0000000..46d4750 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/schema_collision_w_root_components/schemas/user.yaml @@ -0,0 +1,8 @@ +type: object +properties: + aCollisionedItem: + type: integer + userName: + type: string + randomString: + type: string \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/simpleRef/bundleExpected.json b/test/data/toBundleExamples/swagger20/simpleRef/bundleExpected.json new file mode 100644 index 0000000..9977af4 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/simpleRef/bundleExpected.json @@ -0,0 +1,52 @@ +{ + "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": { + "/pets": { + "get": { + "description": "Returns all pets from the system that the user has access to,", + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "A list of pets.,", + "schema": { + "$ref": "#/definitions/_pet.yaml" + } + } + } + } + } + }, + "definitions": { + "_pet.yaml": { + "type": "object", + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "tag": { + "type": "string" + } + } + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/simpleRef/index.yaml b/test/data/toBundleExamples/swagger20/simpleRef/index.yaml new file mode 100644 index 0000000..466509a --- /dev/null +++ b/test/data/toBundleExamples/swagger20/simpleRef/index.yaml @@ -0,0 +1,18 @@ +swagger: "2.0" +info: + $ref: ./info.yaml +host: api.example.com +basePath: /v1 +schemes: + - https +paths: + /pets: + get: + description: Returns all pets from the system that the user has access to, + produces: + - application/json + responses: + 200: + description: A list of pets., + schema: + $ref: "./pet.yaml" diff --git a/test/data/toBundleExamples/swagger20/simpleRef/info.yaml b/test/data/toBundleExamples/swagger20/simpleRef/info.yaml new file mode 100644 index 0000000..19565f9 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/simpleRef/info.yaml @@ -0,0 +1,3 @@ +title: Sample API +description: API description in Markdown. +version: 1.0.0 diff --git a/test/data/toBundleExamples/swagger20/simpleRef/paths.yaml b/test/data/toBundleExamples/swagger20/simpleRef/paths.yaml new file mode 100644 index 0000000..ab1b648 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/simpleRef/paths.yaml @@ -0,0 +1,9 @@ +/users: + get: + summary: Returns a list of users. + description: Optional extended description in Markdown. + produces: + - application/json + responses: + 200: + description: OK \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/simpleRef/pet.yaml b/test/data/toBundleExamples/swagger20/simpleRef/pet.yaml new file mode 100644 index 0000000..dcdc8a0 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/simpleRef/pet.yaml @@ -0,0 +1,12 @@ +type: object +required: + - id + - name +properties: + id: + type: integer + format: int64 + name: + type: string + tag: + type: string \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/withParametersAndItems/bundleExpected.json b/test/data/toBundleExamples/swagger20/withParametersAndItems/bundleExpected.json new file mode 100644 index 0000000..756036b --- /dev/null +++ b/test/data/toBundleExamples/swagger20/withParametersAndItems/bundleExpected.json @@ -0,0 +1,82 @@ +{ + "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": { + "/pets": { + "get": { + "description": "Returns all pets from the system that the user has access to", + "operationId": "findPets", + "parameters": [ + { + "$ref": "#/parameters/_parameters_parameters.yaml-_Parameter1" + }, + { + "$ref": "#/parameters/_parameters_parameters.yaml-_Parameter2" + } + ], + "responses": { + "200": { + "description": "pet response", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/_pet.yaml" + } + } + } + } + } + } + }, + "parameters": { + "_parameters_parameters.yaml-_Parameter1": { + "name": "tags", + "in": "query", + "description": "tags to filter by", + "required": false, + "type": "array", + "collectionFormat": "csv", + "items": { + "type": "string" + } + }, + "_parameters_parameters.yaml-_Parameter2": { + "name": "limit", + "in": "query", + "description": "maximum number of results to return", + "required": false, + "type": "integer", + "format": "int32" + } + }, + "definitions": { + "_pet.yaml": { + "type": "object", + "required": [ + "id", + "name" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + }, + "tag": { + "type": "string" + } + } + } + } +} \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/withParametersAndItems/index.yaml b/test/data/toBundleExamples/swagger20/withParametersAndItems/index.yaml new file mode 100644 index 0000000..f2f08fa --- /dev/null +++ b/test/data/toBundleExamples/swagger20/withParametersAndItems/index.yaml @@ -0,0 +1,9 @@ +swagger: "2.0" +info: + $ref: ./info.yaml +host: api.example.com +basePath: /v1 +schemes: + - https +paths: + $ref: ./paths.yaml \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/withParametersAndItems/info.yaml b/test/data/toBundleExamples/swagger20/withParametersAndItems/info.yaml new file mode 100644 index 0000000..19565f9 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/withParametersAndItems/info.yaml @@ -0,0 +1,3 @@ +title: Sample API +description: API description in Markdown. +version: 1.0.0 diff --git a/test/data/toBundleExamples/swagger20/withParametersAndItems/parameters/parameters.yaml b/test/data/toBundleExamples/swagger20/withParametersAndItems/parameters/parameters.yaml new file mode 100644 index 0000000..b6a3840 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/withParametersAndItems/parameters/parameters.yaml @@ -0,0 +1,16 @@ +Parameter1: + name: tags + in: query + description: tags to filter by + required: false + type: array + collectionFormat: csv + items: + type: string +Parameter2: + name: limit + in: query + description: maximum number of results to return + required: false + type: integer + format: int32 \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/withParametersAndItems/paths.yaml b/test/data/toBundleExamples/swagger20/withParametersAndItems/paths.yaml new file mode 100644 index 0000000..d67649e --- /dev/null +++ b/test/data/toBundleExamples/swagger20/withParametersAndItems/paths.yaml @@ -0,0 +1,14 @@ +/pets: + get: + description: Returns all pets from the system that the user has access to + operationId: findPets + parameters: + - $ref: "./parameters/parameters.yaml#/Parameter1" + - $ref: "./parameters/parameters.yaml#/Parameter2" + responses: + 200: + description: pet response + schema: + type: array + items: + $ref: "./pet.yaml" \ No newline at end of file diff --git a/test/data/toBundleExamples/swagger20/withParametersAndItems/pet.yaml b/test/data/toBundleExamples/swagger20/withParametersAndItems/pet.yaml new file mode 100644 index 0000000..dcdc8a0 --- /dev/null +++ b/test/data/toBundleExamples/swagger20/withParametersAndItems/pet.yaml @@ -0,0 +1,12 @@ +type: object +required: + - id + - name +properties: + id: + type: integer + format: int64 + name: + type: string + tag: + type: string \ No newline at end of file diff --git a/test/unit/bundle.test.js b/test/unit/bundle.test.js index 662e885..f4702c0 100644 --- a/test/unit/bundle.test.js +++ b/test/unit/bundle.test.js @@ -250,7 +250,6 @@ describe('bundle files method - 3.0', function () { expect(res).to.not.be.empty; expect(res.result).to.be.true; expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); - }); it('Should return bundled file - petstore separated example', async function () { @@ -396,7 +395,6 @@ describe('bundle files method - 3.0', function () { expect(res).to.not.be.empty; expect(res.result).to.be.true; expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); - }); it('Should return bundled file - with_ref_in_items', async function () { @@ -434,7 +432,6 @@ describe('bundle files method - 3.0', function () { expect(res).to.not.be.empty; expect(res.result).to.be.true; expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); - }); it('Should return error data - with_ref_in_items - wrong root', async function () { @@ -466,7 +463,6 @@ describe('bundle files method - 3.0', function () { } ] }; - try { await Converter.bundle(input); } @@ -862,52 +858,6 @@ describe('bundle files method - 3.0', function () { expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); }); - it('Should take the root file from data array root file prop undefined', async function () { - let contentRootFile = fs.readFileSync(sameRefDiffSource + '/root.yaml', 'utf8'), - user = fs.readFileSync(sameRefDiffSource + '/schemas/user/user.yaml', 'utf8'), - client = fs.readFileSync(sameRefDiffSource + '/schemas/client/client.yaml', 'utf8'), - specialUser = fs.readFileSync(sameRefDiffSource + '/schemas/user/special.yaml', 'utf8'), - specialClient = fs.readFileSync(sameRefDiffSource + '/schemas/client/special.yaml', 'utf8'), - magic = fs.readFileSync(sameRefDiffSource + '/schemas/client/magic.yaml', 'utf8'), - expected = fs.readFileSync(sameRefDiffSource + '/expected.json', 'utf8'), - input = { - type: 'multiFile', - specificationVersion: '3.0', - data: [ - { - path: '/root.yaml', - content: contentRootFile - }, - { - path: '/schemas/user/user.yaml', - content: user - }, - { - path: '/schemas/user/special.yaml', - content: specialUser - }, - { - path: '/schemas/client/client.yaml', - content: client - }, - { - path: '/schemas/client/special.yaml', - content: specialClient - }, - { - path: '/schemas/client/magic.yaml', - content: magic - } - ], - options: {}, - bundleFormat: 'JSON' - }; - const res = await Converter.bundle(input); - expect(res).to.not.be.empty; - expect(res.result).to.be.true; - expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); - }); - it('Should throw error when root files is undefined and in data there is no root file', async function () { let user = fs.readFileSync(schemaFromResponse + '/schemas/user.yaml', 'utf8'), input = { @@ -976,7 +926,6 @@ describe('bundle files method - 3.0', function () { expect(res).to.not.be.empty; expect(res.result).to.be.true; expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); - }); it('Should throw error when root files is empty array and in data there is no root file', async function () { @@ -1558,6 +1507,53 @@ describe('bundle files method - 3.0', function () { expect(res.output.data[1].bundledContent).to.be.equal(expectedYAML); }); + it('Should take the root file from data array root file prop undefined', async function () { + let contentRootFile = fs.readFileSync(sameRefDiffSource + '/root.yaml', 'utf8'), + user = fs.readFileSync(sameRefDiffSource + '/schemas/user/user.yaml', 'utf8'), + client = fs.readFileSync(sameRefDiffSource + '/schemas/client/client.yaml', 'utf8'), + specialUser = fs.readFileSync(sameRefDiffSource + '/schemas/user/special.yaml', 'utf8'), + specialClient = fs.readFileSync(sameRefDiffSource + '/schemas/client/special.yaml', 'utf8'), + magic = fs.readFileSync(sameRefDiffSource + '/schemas/client/magic.yaml', 'utf8'), + expected = fs.readFileSync(sameRefDiffSource + '/expected.json', 'utf8'), + input = { + type: 'multiFile', + specificationVersion: '3.0', + data: [ + { + path: '/root.yaml', + content: contentRootFile + }, + { + path: '/schemas/user/user.yaml', + content: user + }, + { + path: '/schemas/user/special.yaml', + content: specialUser + }, + { + path: '/schemas/client/client.yaml', + content: client + }, + { + path: '/schemas/client/special.yaml', + content: specialClient + }, + { + path: '/schemas/client/magic.yaml', + content: magic + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); + }); + it('Should return bundled file - referenced response', async function () { let contentRoot = fs.readFileSync(referencedResponse + '/root.yaml', 'utf8'), contentRef = fs.readFileSync(referencedResponse + '/response.yaml', 'utf8'), @@ -1588,7 +1584,6 @@ describe('bundle files method - 3.0', function () { expect(res).to.not.be.empty; expect(res.result).to.be.true; expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); - }); it('Should return bundled file - referenced Parameter', async function () { @@ -1814,7 +1809,6 @@ describe('bundle files method - 3.0', function () { bundleFormat: 'JSON' }; const res = await Converter.bundle(input); - expect(res).to.not.be.empty; expect(res.result).to.be.true; expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); @@ -1924,7 +1918,6 @@ describe('bundle files method - 3.0', function () { expect(res).to.not.be.empty; expect(res.result).to.be.true; expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); - }); it('Should throw error when version is not correct', async function () { @@ -1955,7 +1948,6 @@ describe('bundle files method - 3.0', function () { } }); - it('Should return bundled file as json - schema_collision_from_responses', async function () { let contentRootFile = fs.readFileSync(schemaCollision + '/root.yaml', 'utf8'), user = fs.readFileSync(schemaCollision + '/schemas_/_user.yaml', 'utf8'), @@ -2088,7 +2080,6 @@ describe('bundle files method - 3.0', function () { expect(res.output.specification.version).to.equal('3.0'); expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); }); - it('should ignore reference when is empty content and no root is sent', async function () { let input = { @@ -2658,8 +2649,7 @@ describe('bundle files method - 3.0', function () { }); describe('getReferences method when node does not have any reference', function() { - it('Should return ' + - ' - schema_from_response', function() { + it('Should return reference data empty if there are not any reference', function() { const userData = 'type: object\n' + 'properties:\n' + ' id:\n' + @@ -2682,8 +2672,7 @@ describe('getReferences method when node does not have any reference', function( expect(Object.keys(result.nodeReferenceDirectory).length).to.equal(0); }); - it('Should return ' + - ' - schema_from_response', function() { + it('Should return the reference data - schema_from_response', function() { const userData = 'User:\n' + ' $ref: \"./user.yaml\"\n' + '\n' + @@ -2722,5 +2711,4 @@ describe('getReferences method when node does not have any reference', function( expect(result.referencesInNode[0].path).to.equal('./user.yaml'); expect(result.referencesInNode[0].newValue.$ref).to.equal('the/parent/user.yaml'); }); - }); diff --git a/test/unit/bundle20.test.js b/test/unit/bundle20.test.js new file mode 100644 index 0000000..451b8ae --- /dev/null +++ b/test/unit/bundle20.test.js @@ -0,0 +1,1009 @@ +let expect = require('chai').expect, + Converter = require('../../index.js'), + fs = require('fs'), + path = require('path'), + SWAGGER_MULTIFILE_FOLDER = '../data/toBundleExamples/swagger20', + refTags20 = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + '/referenced_tags'), + basicExample = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + '/basicExample'), + refPaths20 = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + '/referenced_paths'), + refPathsRefToLocalSchema20 = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + '/referenced_paths_local_schema'), + nestedRefs = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + '/nestedRefs'), + nestedLocalRef = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + '/nestedLocalRef'), + withParametersAndItems = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + '/withParametersAndItems'), + bringLocalFromExternal = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + '/bringLocalDependenciesFromExternal'), + bringLocalFromExternalWithItems = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + + '/bringLocalDependenciesFromExternalWithItems'), + bringLocalFromExternalMultiple = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + + '/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'), + SWAGGER_PETSTORE_FOLDER = path.join(__dirname, '../data/swaggerMultifile/petstore-separate-yaml'), + additionalProperties20 = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + '/additionalProperties'), + referencedSecuritySchemes20 = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + '/referenced_security_schemes'), + referencedResponse20 = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + '/referenced_response'), + schemaCollision = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + + '/schema_collision_from_responses'), + schemaCollisionWRootComponent = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + + '/schema_collision_w_root_components'), + referencedRootComponents = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + + '/referenced_root_components'), + referencedExampleKey = path.join(__dirname, SWAGGER_MULTIFILE_FOLDER + + '/referenced_example_key'); + +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(JSON.parse(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'), + paths = fs.readFileSync(sameRefDifferentSource + '/paths.yaml', 'utf8'), + user = fs.readFileSync(sameRefDifferentSource + '/schemas/user.yaml', 'utf8'), + userDetail = fs.readFileSync(sameRefDifferentSource + '/schemas/detail.yaml', 'utf8'), + client = fs.readFileSync(sameRefDifferentSource + '/otherSchemas/client.yaml', 'utf8'), + clientDetail = fs.readFileSync(sameRefDifferentSource + '/otherSchemas/detail.yaml', 'utf8'), + expected = fs.readFileSync(sameRefDifferentSource + '/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/detail.yaml', + content: userDetail + }, + { + path: '/otherSchemas/client.yaml', + content: client + }, + { + path: '/otherSchemas/detail.yaml', + content: clientDetail + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); + }); + + it('Should return bundled result from - multipleRefFromRootComponents', async function() { + let contentRootFile = fs.readFileSync(multipleRefFromRootComponents + '/index.yaml', 'utf8'), + info = fs.readFileSync(multipleRefFromRootComponents + '/info.yaml', 'utf8'), + paths = fs.readFileSync(multipleRefFromRootComponents + '/paths.yaml', 'utf8'), + pet = fs.readFileSync(multipleRefFromRootComponents + '/pet.yaml', 'utf8'), + parameters = fs.readFileSync(multipleRefFromRootComponents + '/parameters/parameters.yaml', 'utf8'), + expected = fs.readFileSync(multipleRefFromRootComponents + '/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: '/pet.yaml', + content: pet + }, + { + path: '/parameters/parameters.yaml', + content: parameters + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); + }); + + it('Should return bundled result from - bringLocalDependenciesFromExternalMultiple', async function() { + let contentRootFile = fs.readFileSync(bringLocalFromExternalMultiple + '/index.yaml', 'utf8'), + info = fs.readFileSync(bringLocalFromExternalMultiple + '/info.yaml', 'utf8'), + paths = fs.readFileSync(bringLocalFromExternalMultiple + '/paths.yaml', 'utf8'), + pet = fs.readFileSync(bringLocalFromExternalMultiple + '/pet.yaml', 'utf8'), + food = fs.readFileSync(bringLocalFromExternalMultiple + '/food.yaml', 'utf8'), + parameters = fs.readFileSync(bringLocalFromExternalMultiple + '/parameters/parameters.yaml', 'utf8'), + expected = fs.readFileSync(bringLocalFromExternalMultiple + '/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: '/pet.yaml', + content: pet + }, + { + path: '/food.yaml', + content: food + }, + { + path: '/parameters/parameters.yaml', + content: parameters + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); + }); + + it('Should return bundled result from - bringLocalDependenciesFromExternalWithItems', async function() { + let contentRootFile = fs.readFileSync(bringLocalFromExternalWithItems + '/index.yaml', 'utf8'), + info = fs.readFileSync(bringLocalFromExternalWithItems + '/info.yaml', 'utf8'), + paths = fs.readFileSync(bringLocalFromExternalWithItems + '/paths.yaml', 'utf8'), + pet = fs.readFileSync(bringLocalFromExternalWithItems + '/pet.yaml', 'utf8'), + expected = fs.readFileSync(bringLocalFromExternalWithItems + '/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: '/pet.yaml', + content: pet + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); + }); + + it('Should return bundled result from - bringLocalDependenciesFromExternal', async function() { + let contentRootFile = fs.readFileSync(bringLocalFromExternal + '/index.yaml', 'utf8'), + info = fs.readFileSync(bringLocalFromExternal + '/info.yaml', 'utf8'), + paths = fs.readFileSync(bringLocalFromExternal + '/paths.yaml', 'utf8'), + pet = fs.readFileSync(bringLocalFromExternal + '/pet.yaml', 'utf8'), + expected = fs.readFileSync(bringLocalFromExternal + '/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: '/pet.yaml', + content: pet + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); + }); + + it('Should return bundled result from - withParametersAndItems', async function() { + let contentRootFile = fs.readFileSync(withParametersAndItems + '/index.yaml', 'utf8'), + info = fs.readFileSync(withParametersAndItems + '/info.yaml', 'utf8'), + paths = fs.readFileSync(withParametersAndItems + '/paths.yaml', 'utf8'), + pet = fs.readFileSync(withParametersAndItems + '/pet.yaml', 'utf8'), + parameters = fs.readFileSync(withParametersAndItems + '/parameters/parameters.yaml', 'utf8'), + expected = fs.readFileSync(withParametersAndItems + '/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: '/pet.yaml', + content: pet + }, + { + path: '/parameters/parameters.yaml', + content: parameters + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); + }); + + it('Should return bundled result from - nestedLocalRef', async function() { + let contentRootFile = fs.readFileSync(nestedLocalRef + '/index.yaml', 'utf8'), + info = fs.readFileSync(nestedLocalRef + '/info.yaml', 'utf8'), + paths = fs.readFileSync(nestedLocalRef + '/paths.yaml', 'utf8'), + pet = fs.readFileSync(nestedLocalRef + '/schemas/pet.yaml', 'utf8'), + favoriteFood = fs.readFileSync(nestedLocalRef + '/schemas/favorite_food.yaml', 'utf8'), + expected = fs.readFileSync(nestedLocalRef + '/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/pet.yaml', + content: pet + }, + { + path: '/schemas/favorite_food.yaml', + content: favoriteFood + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); + }); + + it('Should return bundled result from - nestedRefs', async function() { + let contentRootFile = fs.readFileSync(nestedRefs + '/index.yaml', 'utf8'), + info = fs.readFileSync(nestedRefs + '/info.yaml', 'utf8'), + paths = fs.readFileSync(nestedRefs + '/paths.yaml', 'utf8'), + pet = fs.readFileSync(nestedRefs + '/schemas/pet.yaml', 'utf8'), + favoriteFood = fs.readFileSync(nestedRefs + '/schemas/favorite_food.yaml', 'utf8'), + expected = fs.readFileSync(nestedRefs + '/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/pet.yaml', + content: pet + }, + { + path: '/schemas/favorite_food.yaml', + content: favoriteFood + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); + }); + + it('Should return bundled result from - basicExample', async function() { + let contentRootFile = fs.readFileSync(basicExample + '/index.yaml', 'utf8'), + info = fs.readFileSync(basicExample + '/info.yaml', 'utf8'), + paths = fs.readFileSync(basicExample + '/paths.yaml', 'utf8'), + expected = fs.readFileSync(basicExample + '/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 + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); + }); + + it('Should return bundled result from - simpleRef', async function() { + let contentRootFile = fs.readFileSync(simpleRef + '/index.yaml', 'utf8'), + info = fs.readFileSync(simpleRef + '/info.yaml', 'utf8'), + paths = fs.readFileSync(simpleRef + '/paths.yaml', 'utf8'), + pet = fs.readFileSync(simpleRef + '/pet.yaml', 'utf8'), + expected = fs.readFileSync(simpleRef + '/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: '/pet.yaml', + content: pet + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); + }); + + it('Should return bundled file with referenced tags from root', async function () { + let contentRootFile = fs.readFileSync(refTags20 + '/root.yaml', 'utf8'), + tags = fs.readFileSync(refTags20 + '/tags/tags.yaml', 'utf8'), + expected = fs.readFileSync(refTags20 + '/expected.json', 'utf8'), + input = { + type: 'multiFile', + specificationVersion: '2.0', + rootFiles: [ + { + path: '/root.yaml' + } + ], + data: [ + { + path: '/root.yaml', + content: contentRootFile + }, + { + path: '/tags/tags.yaml', + content: tags + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); + }); + + it('Should return bundled file with referenced paths from root', async function () { + let contentRootFile = fs.readFileSync(refPaths20 + '/root.yaml', 'utf8'), + paths = fs.readFileSync(refPaths20 + '/paths/paths.yaml', 'utf8'), + path = fs.readFileSync(refPaths20 + '/paths/path.yaml', 'utf8'), + expected = fs.readFileSync(refPaths20 + '/expected.json', 'utf8'), + input = { + type: 'multiFile', + specificationVersion: '2.0', + rootFiles: [ + { + path: '/root.yaml' + } + ], + data: [ + { + path: '/root.yaml', + content: contentRootFile + }, + { + 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; + expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); + }); + + it('Should return bundled file with referenced paths from root - path references local schema', async function () { + let contentRootFile = fs.readFileSync(refPathsRefToLocalSchema20 + '/root.yaml', 'utf8'), + paths = fs.readFileSync(refPathsRefToLocalSchema20 + '/paths/paths.yaml', 'utf8'), + path = fs.readFileSync(refPathsRefToLocalSchema20 + '/paths/path.yaml', 'utf8'), + expected = fs.readFileSync(refPathsRefToLocalSchema20 + '/expected.json', 'utf8'), + input = { + type: 'multiFile', + specificationVersion: '2.0', + rootFiles: [ + { + path: '/root.yaml' + } + ], + data: [ + { + path: '/root.yaml', + content: contentRootFile + }, + { + 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; + expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); + }); + + it('Should return bundled file with referenced example', async function () { + let contentRootFile = fs.readFileSync(refExample20 + '/root.yaml', 'utf8'), + examples = fs.readFileSync(refExample20 + '/examples.yaml', 'utf8'), + expected = fs.readFileSync(refExample20 + '/expected.json', 'utf8'), + input = { + type: 'multiFile', + specificationVersion: '2.0', + rootFiles: [ + { + path: '/root.yaml' + } + ], + data: [ + { + path: '/root.yaml', + content: contentRootFile + }, + { + path: '/examples.yaml', + content: examples + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); + }); + + it('Should return bundled file from - petstore-separated-yaml (contains allOf)', async function() { + let contentRootFile = fs.readFileSync(SWAGGER_PETSTORE_FOLDER + '/spec/swagger.yaml', 'utf8'), + parameters = fs.readFileSync(SWAGGER_PETSTORE_FOLDER + '/spec/parameters.yaml', 'utf8'), + pet = fs.readFileSync(SWAGGER_PETSTORE_FOLDER + '/spec/Pet.yaml', 'utf8'), + newPet = fs.readFileSync(SWAGGER_PETSTORE_FOLDER + '/spec/NewPet.yaml', 'utf8'), + error = fs.readFileSync(SWAGGER_PETSTORE_FOLDER + '/common/Error.yaml', 'utf8'), + expected = fs.readFileSync(SWAGGER_PETSTORE_FOLDER + '/expectedBundle.json', 'utf8'), + input = { + type: 'multiFile', + specificationVersion: '2.0', + rootFiles: [ + { + path: '/spec/swagger.yaml' + } + ], + data: [ + { + path: '/spec/swagger.yaml', + content: contentRootFile + }, + { + path: '/spec/parameters.yaml', + content: parameters + }, + { + path: '/spec/Pet.yaml', + content: pet + }, + { + path: '/spec/NewPet.yaml', + content: newPet + }, + { + path: '/common/Error.yaml', + content: error + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); + }); + + it('Should bundle file from - additionalProperties 2.0', async function() { + let contentRootFile = fs.readFileSync(additionalProperties20 + '/root.yaml', 'utf8'), + pet = fs.readFileSync(additionalProperties20 + '/pet.yaml', 'utf8'), + additionalProps = fs.readFileSync(additionalProperties20 + '/additionalProperties.yaml', 'utf8'), + expected = fs.readFileSync(additionalProperties20 + '/expected.json', 'utf8'), + input = { + type: 'multiFile', + specificationVersion: '2.0', + rootFiles: [ + { + path: '/root.yaml' + } + ], + data: [ + { + path: '/root.yaml', + content: contentRootFile + }, + { + path: '/pet.yaml', + content: pet + }, + { + path: '/additionalProperties.yaml', + content: additionalProps + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); + }); + + it('Should return bundled file - referenced Security Schemes', async function () { + let contentRoot = fs.readFileSync(referencedSecuritySchemes20 + '/root.yaml', 'utf8'), + contentRef = fs.readFileSync(referencedSecuritySchemes20 + '/sschemes.yaml', 'utf8'), + expected = fs.readFileSync(referencedSecuritySchemes20 + '/expected.json', 'utf8'), + input = { + type: 'multiFile', + specificationVersion: '2.0', + rootFiles: [ + { + path: '/root.yaml' + } + ], + data: [ + { + path: '/root.yaml', + content: contentRoot + }, + { + path: '/sschemes.yaml', + content: contentRef + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); + }); + + it('Should bundle file from - referenced response 2.0', async function() { + let contentRootFile = fs.readFileSync(referencedResponse20 + '/root.yaml', 'utf8'), + referenced = fs.readFileSync(referencedResponse20 + '/response.yaml', 'utf8'), + expected = fs.readFileSync(referencedResponse20 + '/expected.json', 'utf8'), + input = { + type: 'multiFile', + specificationVersion: '2.0', + rootFiles: [ + { + path: '/root.yaml' + } + ], + data: [ + { + path: '/root.yaml', + content: contentRootFile + }, + { + path: '/response.yaml', + content: referenced + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); + }); + + it('Should return bundled file as json - schema_collision_from_responses', async function () { + let contentRootFile = fs.readFileSync(schemaCollision + '/root.yaml', 'utf8'), + user = fs.readFileSync(schemaCollision + '/schemas_/_user.yaml', 'utf8'), + user1 = fs.readFileSync(schemaCollision + '/schemas/__user.yaml', 'utf8'), + user2 = fs.readFileSync(schemaCollision + '/schemas__/user.yaml', 'utf8'), + expected = fs.readFileSync(schemaCollision + '/expected.json', 'utf8'), + input = { + type: 'multiFile', + specificationVersion: '2.0', + rootFiles: [ + { + path: '/root.yaml' + } + ], + data: [ + { + path: '/root.yaml', + content: contentRootFile + }, + { + path: '/schemas__/user.yaml', + content: user2 + }, + { + path: '/schemas_/_user.yaml', + content: user + }, + { + path: '/schemas/__user.yaml', + content: user1 + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(res.output.specification.version).to.equal('2.0'); + expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); + }); + + it('Should return bundled file as json - schema_collision_w_root_components', async function () { + let contentRootFile = fs.readFileSync(schemaCollisionWRootComponent + '/root.yaml', 'utf8'), + user = fs.readFileSync(schemaCollisionWRootComponent + '/schemas/user.yaml', 'utf8'), + expected = fs.readFileSync(schemaCollisionWRootComponent + '/expected.json', 'utf8'), + input = { + type: 'multiFile', + specificationVersion: '2.0', + rootFiles: [ + { + path: '/root.yaml' + } + ], + data: [ + { + path: '/root.yaml', + content: contentRootFile + }, + { + path: '/schemas/user.yaml', + content: user + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(res.output.specification.version).to.equal('2.0'); + expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); + }); + + it('Should return bundled file as json - referenced_root_components', async function () { + let contentRootFile = fs.readFileSync(referencedRootComponents + '/root.yaml', 'utf8'), + definitions = fs.readFileSync(referencedRootComponents + '/definitions.yaml', 'utf8'), + info = fs.readFileSync(referencedRootComponents + '/info.yaml', 'utf8'), + responses = fs.readFileSync(referencedRootComponents + '/responses.yaml', 'utf8'), + securitySchemes = fs.readFileSync(referencedRootComponents + '/securitySchemes.yaml', 'utf8'), + tags = fs.readFileSync(referencedRootComponents + '/tags.yaml', 'utf8'), + paths = fs.readFileSync(referencedRootComponents + '/paths/paths.yaml', 'utf8'), + singlePath = fs.readFileSync(referencedRootComponents + '/paths/path.yaml', 'utf8'), + expected = fs.readFileSync(referencedRootComponents + '/expected.json', 'utf8'), + input = { + type: 'multiFile', + specificationVersion: '2.0', + rootFiles: [ + { + path: '/root.yaml' + } + ], + data: [ + { + path: '/root.yaml', + content: contentRootFile + }, + { + path: '/definitions.yaml', + content: definitions + }, + { + path: '/info.yaml', + content: info + }, + { + path: '/responses.yaml', + content: responses + }, + { + path: '/securitySchemes.yaml', + content: securitySchemes + }, + { + path: '/tags.yaml', + content: tags + }, + { + path: '/paths/paths.yaml', + content: paths + }, + { + path: '/paths/path.yaml', + content: singlePath + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(res.output.specification.version).to.equal('2.0'); + expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); + }); + + it('Should return bundled file as json - referenced_example_key', async function () { + let contentRootFile = fs.readFileSync(referencedExampleKey + '/root.yaml', 'utf8'), + example = fs.readFileSync(referencedExampleKey + '/example.yaml', 'utf8'), + expected = fs.readFileSync(referencedExampleKey + '/expected.json', 'utf8'), + input = { + type: 'multiFile', + specificationVersion: '2.0', + rootFiles: [ + { + path: '/root.yaml' + } + ], + data: [ + { + path: '/root.yaml', + content: contentRootFile + }, + { + path: '/example.yaml', + content: example + } + ], + options: {}, + bundleFormat: 'JSON' + }; + const res = await Converter.bundle(input); + + expect(res).to.not.be.empty; + expect(res.result).to.be.true; + expect(res.output.specification.version).to.equal('2.0'); + expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected); + }); +}); diff --git a/test/unit/detectRoot.test.js b/test/unit/detectRoot.test.js index d7cc681..47192c1 100644 --- a/test/unit/detectRoot.test.js +++ b/test/unit/detectRoot.test.js @@ -263,7 +263,6 @@ describe('detectRoot method', function() { expect(res).to.not.be.empty; expect(res.result).to.be.true; expect(res.output.data.length).to.equal(0); - }); it('should return error when "type" parameter is not sent', async function () { diff --git a/test/unit/jsonPointer.test.js b/test/unit/jsonPointer.test.js index a7ccc9a..63c9cfd 100644 --- a/test/unit/jsonPointer.test.js +++ b/test/unit/jsonPointer.test.js @@ -8,17 +8,19 @@ const expect = require('chai').expect, describe('getKeyInComponents function', function () { it('should return [] when is pointing to an element in components', function () { - const result = getKeyInComponents(['components', 'schemas'], 'pet.yaml', '3.0', ''); + const result = getKeyInComponents(['components', 'schemas'], 'pet.yaml', '', '3.0'); + expect(result).to.be.an('array').with.length(0); }); it('should return [] when is pointing to a local ref in components', function () { - const result = getKeyInComponents(['components', 'schemas'], 'pet.yaml', '/definitions/world', '3.0', ''); + const result = getKeyInComponents(['components', 'schemas'], 'pet.yaml', '/definitions/world', '3.0'); + expect(result).to.be.an('array').with.length(0); }); - it('should return ["schemas", "_folder_pet.yaml"] when the filename is _folder_pet.yaml', function () { + it('should return ["schemas", "_folder_pet.yaml"] when the filename _folder_pet.yaml', function () { const result = getKeyInComponents(['path', 'schemas'], '_folder_pet.yaml', '3.0', ''); expect(result).to.be.an('array').with.length(2); expect(result[0]).to.equal('schemas'); @@ -26,27 +28,31 @@ describe('getKeyInComponents function', function () { }); }); - describe('getJsonPointerRelationToRoot function', function () { it('should return "#/components/schemas/Pets.yaml" no local path and schema', function () { let res = getJsonPointerRelationToRoot( 'Pets.yaml', ['schemas', 'Pets.yaml'] ); + expect(res).to.equal('#/components/schemas/Pets.yaml'); }); + it('should return "#/components/schemas/hello.yaml" no local path and schema', function () { let res = getJsonPointerRelationToRoot( 'hello.yaml#/definitions/world', ['schemas', 'hello.yaml'] ); + expect(res).to.equal('#/components/schemas/hello.yaml'); }); + it('should return "#/components/schemas/Error" no file path', function () { let res = getJsonPointerRelationToRoot( '#/components/schemas/Error', ['components', 'schemas', 'Error'] ); + expect(res).to.equal('#/components/schemas/Error'); }); }); @@ -57,6 +63,7 @@ describe('concatJsonPointer function ', function () { ['schemas', 'Pets.yaml'], '/components' ); + expect(res).to.equal('#/components/schemas/Pets.yaml'); }); @@ -65,8 +72,10 @@ describe('concatJsonPointer function ', function () { ['schemas', 'other_Pets.yaml'], '/components' ); + expect(res).to.equal('#/components/schemas/other_Pets.yaml'); }); + it('should return "#/components/schemas/some_Pet" no local path and schema folder in filename', function () { let res = concatJsonPointer( ['schemas', 'some_Pet.yaml'], @@ -74,11 +83,13 @@ describe('concatJsonPointer function ', function () { ); 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( ['schemas', 'hello.yaml'], '/components' ); + expect(res).to.equal('#/components/schemas/hello.yaml'); }); diff --git a/test/unit/relatedEntities.test.js b/test/unit/relatedEntities.test.js deleted file mode 100644 index da3a290..0000000 --- a/test/unit/relatedEntities.test.js +++ /dev/null @@ -1,220 +0,0 @@ -const { getReferences, - isLocalRef, - getAdjacentAndMissing, - findNodeFromPath, - getRelatedEntities, - pathSolver } = require('./../../lib/relatedEntities'), - { isExtRef, - removeLocalReferenceFromPath } = require('./../../lib/jsonPointer'), - path = require('path'), - expect = require('chai').expect, - PET_STORE_SEPARATED = '../data/petstore separate yaml/spec', - newPet = path.join(__dirname, PET_STORE_SEPARATED + '/NewPet.yaml'), - fs = require('fs'), - parse = require('./../../lib/parse.js'), - swaggerRoot = path.join(__dirname, PET_STORE_SEPARATED + '/swagger.yaml'), - mockedInputPetstore = { - 'components': { - 'schemas': { - 'Pet': { - 'required': [ - 'id', - 'name' - ], - 'properties': { - 'id': { - 'type': 'integer', - 'format': 'int64' - }, - 'name': { - 'type': 'string' - }, - 'tag': { - 'type': 'string' - } - } - }, - 'Pets': { - 'type': 'array', - 'items': { - '$ref': '#/components/schemas/Pet' - } - }, - 'Error': { - 'required': [ - 'code', - 'message' - ], - 'properties': { - 'code': { - 'type': 'integer', - 'format': 'int32' - }, - 'message': { - 'type': 'string' - } - } - } - } - } - }; - - -describe('getReferences function', function () { - it('should return 1 local reference from input', function () { - const inputNode = { - type: 'array', - items: { - $ref: '#/components/schemas/Pet' - } - }, - result = getReferences(inputNode, isLocalRef, pathSolver); - expect(result.length).to.equal(1); - expect(result[0].path).to.equal('#/components/schemas/Pet'); - - }); - - it('should return 1 local reference from input, even when repeated', function () { - const inputNode = { - type: 'object', - properties: { - pet: { $ref: '#/components/schemas/Pet' }, - newPet: { $ref: '#/components/schemas/Pet' } - } - }, - result = getReferences(inputNode, isLocalRef, pathSolver); - expect(result.length).to.equal(1); - expect(result[0].path).to.equal('#/components/schemas/Pet'); - }); - - it('should not identify an external ref as local ref', function () { - const inputNode = { - type: 'object', - properties: { - pet: { $ref: 'Pet.yaml' }, - newPet: { $ref: 'Pet.yaml' } - } - }, - result = getReferences(inputNode, isLocalRef, pathSolver); - expect(result.length).to.equal(0); - }); - - - it('should return 1 reference from input', function () { - const parsedContentFile = parse.getOasObject(fs.readFileSync(newPet, 'utf8')), - result = getReferences(parsedContentFile, isExtRef, removeLocalReferenceFromPath); - expect(result.length).to.equal(1); - expect(result[0].path).to.equal('Pet.yaml'); - - }); - - it('should return unique references from input', function () { - const parsedContentFile = parse.getOasObject(fs.readFileSync(swaggerRoot, 'utf8')), - result = getReferences(parsedContentFile, isExtRef, removeLocalReferenceFromPath); - expect(result.length).to.equal(5); - expect(result[0].path).to.equal('parameters.yaml'); - expect(result[1].path).to.equal('parameters.yaml'); - expect(result[2].path).to.equal('Pet.yaml'); - expect(result[3].path).to.equal('../common/Error.yaml'); - expect(result[4].path).to.equal('NewPet.yaml'); - - }); - - -}); - -describe('findNodeFromPath method', function () { - it('should return the node by the json pointer', function () { - const res = findNodeFromPath('#/components/schemas/Pet', mockedInputPetstore); - expect(res).to.not.be.undefined; - }); -}); - -describe('getAdjacentAndMissing function', function () { - it('should return 1 adjacent reference from input', function () { - const inputNode = { - type: 'array', - items: { - $ref: '#/components/schemas/Pet' - } - }, - { graphAdj, missingNodes } = getAdjacentAndMissing(inputNode, mockedInputPetstore); - expect(graphAdj.length).to.equal(1); - expect(missingNodes.length).to.equal(0); - - }); - - it('should return 1 missing reference from input', function () { - const inputNode = { - type: 'array', - items: { - $ref: '#/components/schemas/Dog' - } - }, - { graphAdj, missingNodes } = getAdjacentAndMissing(inputNode, mockedInputPetstore); - expect(graphAdj.length).to.equal(0); - expect(missingNodes.length).to.equal(1); - expect(missingNodes[0].$ref).to.equal('#/components/schemas/Dog'); - }); -}); - -describe('getRelatedEntities function', function () { - it('should return 1 adjacent and the root', function () { - const inputNode = { - type: 'array', - items: { - $ref: '#/components/schemas/Pet' - } - }, - { relatedEntities, missingRelatedEntities } = getRelatedEntities(inputNode, mockedInputPetstore); - expect(relatedEntities.length).to.equal(2); - expect(relatedEntities[1].$info.$ref).to.equal('#/components/schemas/Pet'); - expect(relatedEntities[1].$info.name).to.equal('Pet'); - expect(missingRelatedEntities.length).to.equal(0); - - }); - - it('should return 1 adjacent and the root even with 2 refs', function () { - const inputNode = { - type: 'object', - properties: { - pet: { $ref: '#/components/schemas/Pet' }, - newPet: { $ref: '#/components/schemas/Pets' } - } - }, - { relatedEntities, missingRelatedEntities } = getRelatedEntities(inputNode, mockedInputPetstore); - expect(relatedEntities.length).to.equal(3); - expect(relatedEntities[1].$info.$ref).to.equal('#/components/schemas/Pets'); - expect(relatedEntities[1].$info.name).to.equal('Pets'); - expect(relatedEntities[2].$info.$ref).to.equal('#/components/schemas/Pet'); - expect(relatedEntities[2].$info.name).to.equal('Pet'); - expect(missingRelatedEntities.length).to.equal(0); - - }); - - it('should return 1 missing reference from input', function () { - const inputNode = { - type: 'array', - items: { - $ref: '#/components/schemas/Dog' - } - }, - { relatedEntities, missingRelatedEntities } = getRelatedEntities(inputNode, mockedInputPetstore); - expect(relatedEntities.length).to.equal(1); - expect(missingRelatedEntities.length).to.equal(1); - expect(missingRelatedEntities[0].$ref).to.equal('#/components/schemas/Dog'); - }); - - it('should ignore external references', function () { - const inputNode = { - type: 'array', - items: { - $ref: 'pet.yaml' - } - }, - { relatedEntities, missingRelatedEntities } = getRelatedEntities(inputNode, mockedInputPetstore); - expect(relatedEntities.length).to.equal(1); - expect(missingRelatedEntities.length).to.equal(0); - }); - -}); diff --git a/test/unit/versionUtils.test.js b/test/unit/versionUtils.test.js index d93924d..90b956c 100644 --- a/test/unit/versionUtils.test.js +++ b/test/unit/versionUtils.test.js @@ -340,9 +340,9 @@ describe('validateSupportedVersion method', function () { expect(result).to.be.true; }); - it('should return false with version 2.0', function () { + it('should return true with version 2.0', function () { const result = validateSupportedVersion('2.0'); - expect(result).to.be.false; + expect(result).to.be.true; }); it('should return true with version 3.1', function () { @@ -366,4 +366,3 @@ describe('validateSupportedVersion method', function () { }); }); -