Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a bug where incorrect ref in Paths was not being handled correctly #777

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ function generateComponentsObject(documentContext, rootContent,
});

if (isMissingNode) {
refData.nodeContent = refData.node;
refData.refHasContent && (refData.nodeContent = refData.node);
refData.local = false;
}
else if (!refData) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"openapi": "3.1.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": "[email protected]",
"url": "http://swagger.io"
},
"license": {
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
}
},
"components": {
"schemas": {
"Pet": {
"required": [
"id",
"name"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},
"tag": {
"type": "string"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

openapi: "3.1.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: [email protected]
url: http://swagger.io
license:
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
paths:
"$ref": "./path"
components:
schemas:
Pet:
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
31 changes: 31 additions & 0 deletions test/unit/bundle31.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const expect = require('chai').expect,
path = require('path'),
BUNDLES_FOLDER = '../data/toBundleExamples',
pathItem31 = path.join(__dirname, BUNDLES_FOLDER + '/referenced_paths_31'),
invalidPathRef31 = path.join(__dirname, BUNDLES_FOLDER + '/referenced_invalid_paths_31'),
webhookItem31 = path.join(__dirname, BUNDLES_FOLDER + '/referenced_webhook_31');


Expand Down Expand Up @@ -73,4 +74,34 @@ describe('bundle files method - 3.1', function () {
expect(res.output.specification.version).to.equal('3.1');
expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected);
});

it('Should return bundled file where path has an invalid $ref', async function () {
let contentRootFile = fs.readFileSync(invalidPathRef31 + '/invalid_reference_at_path.yaml', 'utf8'),
expected = fs.readFileSync(invalidPathRef31 + '/expected.json', 'utf8'),
input = {
origin: 'browser',
type: 'multiFile',
specificationVersion: '3.1',
options: { includeReferenceMap: true },
bundleFormat: 'JSON',
rootFiles: [
{
path: 'root.yaml',
content: contentRootFile
}
],
data: [
{
path: 'root.yaml',
content: contentRootFile
}
]
};
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('3.1');
expect(JSON.stringify(JSON.parse(res.output.data[0].bundledContent), null, 2)).to.be.equal(expected);
});
});
Loading