Skip to content

Commit 6e99c16

Browse files
authored
Merge pull request #779 from postmanlabs/fix/OAS-3.0-yaml-spec-bundling-error
[FIX] OAS 3.0 yaml spec bundling error
2 parents 2b06ebd + d1e6378 commit 6e99c16

File tree

21 files changed

+171
-107
lines changed

21 files changed

+171
-107
lines changed

assets/json-schema-faker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10919,7 +10919,7 @@ module.exports = {
1091910919
*/
1092010920
parse: function yamlParse (text, reviver) {
1092110921
try {
10922-
return yaml.safeLoad(text);
10922+
return yaml.load(text);
1092310923
}
1092410924
catch (e) {
1092510925
if (e instanceof Error) {

examples/sampleswagger.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ info:
1414
email: apiteam@wordnik.com
1515
license:
1616
name: Apache 2.0
17-
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
17+
url: http://www.apache.org/licenses/LICENSE-2.0.html
1818
tags:
1919
- name: pet
2020
description: Everything about your Pets
2121
externalDocs:
2222
description: Find out more
23-
url: 'http://swagger.io'
23+
url: http://swagger.io
2424
- name: store
2525
description: Operations about user
2626
- name: user
2727
description: Access to Petstore orders
2828
externalDocs:
2929
description: Find out more about our store
30-
url: 'http://swagger.io'
30+
url: http://swagger.io
3131
paths:
3232
/pet:
3333
post:
@@ -542,7 +542,7 @@ paths:
542542
description: User not found
543543
externalDocs:
544544
description: Find out more about Swagger
545-
url: 'http://swagger.io'
545+
url: http://swagger.io
546546
components:
547547
requestBodies:
548548
UserArray:
@@ -688,4 +688,4 @@ components:
688688
message:
689689
type: string
690690
xml:
691-
name: '##default'
691+
name: '##default'

lib/bundle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,12 +701,12 @@ function generateComponentsObject(documentContext, rootContent,
701701
circularRefsSet = new Set();
702702
const { COMPONENTS_KEYS } = getBundleRulesDataByVersion(version);
703703
notInLine.forEach(([key, value]) => {
704-
let [, partial] = key.split(localPointer);
704+
let [nodeRef, partial] = key.split(localPointer);
705705
if (documentContext.globalReferences[key].refHasContent) {
706706
setValueInComponents(
707707
value.keyInComponents,
708708
components,
709-
getContentFromTrace(documentContext.nodeContents[key], partial),
709+
getContentFromTrace(documentContext.nodeContents[nodeRef], partial),
710710
COMPONENTS_KEYS
711711
);
712712
}

lib/parse.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ module.exports = {
3333

3434
asYaml: function (spec) {
3535
try {
36-
let obj = yaml.safeLoad(spec, {
36+
let obj = yaml.load(spec, {
3737
schema: yaml.JSON_SCHEMA
3838
});
3939
// yaml.safeLoad does not throw errors for most of the cases in invalid yaml
40+
// yaml.safeLoad is removed in js-yaml 4. Hence Using yaml.load instead, which is now safe by default.
4041
// hence check if it returned an object
4142
if (typeof obj !== 'object') {
4243
throw new Error('');

package-lock.json

Lines changed: 76 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
"ajv-formats": "2.1.1",
122122
"async": "3.2.4",
123123
"commander": "2.20.3",
124-
"js-yaml": "3.14.1",
124+
"js-yaml": "4.1.0",
125125
"json-schema-merge-allof": "0.8.1",
126126
"lodash": "4.17.21",
127127
"oas-resolver-browser": "2.5.6",

0 commit comments

Comments
 (0)