postmanlabs / swagger2-postman2

Module and library to convert Swagger 2.0 to a Postman Collection (v2.0)
Apache License 2.0
81 stars 42 forks source link

Fixed issue where module threw exception when anchors are used in YAML document. #78

Closed VShingala closed 3 years ago

VShingala commented 3 years ago

RCA:

We use swagger2openapi module to first convert Swagger 2.0 document to OpenAPI v3 and then use OpenAPI-to-Postman module for conversion.

In this flow, when there are YAML anchors used in Swagger document. swagger2openapi module throws the following exception for the attached file in issue.

S2OError: YAML anchor or merge key at #/paths/~1client/post/produces
    at throwError (/Users/vishal/swagger2-postman2/node_modules/swagger2openapi/index.js:39:15)
    at /Users/vishal/swagger2-postman2/node_modules/swagger2openapi/index.js:1369:21
    at recurse (/Users/vishal/swagger2-postman2/node_modules/reftools/lib/recurse.js:38:13)
    at recurse (/Users/vishal/swagger2-postman2/node_modules/reftools/lib/recurse.js:53:13)
    at recurse (/Users/vishal/swagger2-postman2/node_modules/reftools/lib/recurse.js:53:13)
    at recurse (/Users/vishal/swagger2-postman2/node_modules/reftools/lib/recurse.js:53:13)

Fix:

Upon deep dive into swagger2openapi module, we found that we have to specifically specify option to enable anchor cloning while using API provided by module. Here is reference.

Enabling this option solves the corresponding issue.