diff --git a/docs/index.md b/docs/index.md index beffccc..9220b2f 100644 --- a/docs/index.md +++ b/docs/index.md @@ -235,7 +235,7 @@ Is as easy as define the values in the "Edit Collection" form page inside the ta ![contact and license variables](images/variables.png) -The variables names will be in dot notation, for example for `contact` fields will be as `contact.name`, `contact.url`... Take into account that some of this fields are required as described in OpenAPI specs if not provided all the section will be ignored. +The variables names will be in dot notation, for example for `contact` fields will be as `contact.name`, `contact.url`... Take into account that fields that are required by OpenAPI specs, as `contact.name`, if not provided then all the section will be ignored. You can also customize this information using the [Info option](#info-(object)), note that info provided by options will overwrite the variables inside the Postman collection (has more priority) but values will be merged from both sources (postman variables and options). diff --git a/test/index.spec.js b/test/index.spec.js index 67a11fa..583952a 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -36,6 +36,8 @@ const EXPECTED_SERVERS_OPTIONS = readFileSync('./test/resources/output/ServersOp const EXPECTED_NO_SERVERS = readFileSync('./test/resources/output/NoServers.yml', 'utf8') const EXPECTED_LICENSE_CONTACT = readFileSync('./test/resources/output/LicenseContact.yml', 'utf8') const EXPECTED_LICENSE_CONTACT_OPT = readFileSync('./test/resources/output/LicenseContactOpts.yml', 'utf8') +const EXPECTED_LICENSE_CONTACT_PARTIAL = readFileSync('./test/resources/output/LicenseContactPartial.yml', 'utf8') +const EXPECTED_LICENSE_CONTACT_PARTIAL_2 = readFileSync('./test/resources/output/LicenseContactPartial2.yml', 'utf8') describe('Library specs', function () { afterEach('remove file', function () { @@ -160,7 +162,7 @@ describe('Library specs', function () { equal(result, EXPECTED_LICENSE_CONTACT) }) - it('should use license from options', async function () { + it('should use license and contact from options', async function () { const result = await postmanToOpenApi(COLLECTION_LICENSE_CONTACT, OUTPUT_PATH, { info: { @@ -177,4 +179,34 @@ describe('Library specs', function () { }) equal(result, EXPECTED_LICENSE_CONTACT_OPT) }) + + it('should support optional params in license and contact options', async function () { + const result = await postmanToOpenApi(COLLECTION_BASIC, OUTPUT_PATH, + { + info: { + license: { + name: 'MIT' + }, + contact: { + name: 'My Support' + } + } + }) + equal(result, EXPECTED_LICENSE_CONTACT_PARTIAL) + }) + + it('should support optional params in license and contact options (2)', async function () { + const result = await postmanToOpenApi(COLLECTION_BASIC, OUTPUT_PATH, + { + info: { + license: { + name: 'MIT' + }, + contact: { + url: 'http://www.api.com/support' + } + } + }) + equal(result, EXPECTED_LICENSE_CONTACT_PARTIAL_2) + }) }) diff --git a/test/resources/output/LicenseContactPartial.yml b/test/resources/output/LicenseContactPartial.yml new file mode 100644 index 0000000..30482f2 --- /dev/null +++ b/test/resources/output/LicenseContactPartial.yml @@ -0,0 +1,63 @@ +openapi: 3.0.0 +info: + title: Postman to OpenAPI + description: Mi super test collection from postman + version: 1.1.0 + contact: + name: My Support + license: + name: MIT +servers: + - url: 'https://api.io' +paths: + /users: + post: + tags: + - default + summary: Create new User + description: Create a new user into your amazing API + requestBody: + content: + application/json: + schema: + type: object + example: + example: field + other: + data1: 'yes' + data2: 'no' + responses: + '200': + description: Successful response + content: + application/json: {} + /posts: + post: + tags: + - default + summary: Create a post + requestBody: + content: + text/plain: {} + responses: + '200': + description: Successful response + content: + application/json: {} + /note: + post: + tags: + - default + summary: Create a note + description: Just an example of text raw body + requestBody: + content: + application/json: + schema: + type: string + example: This is an example Note + responses: + '200': + description: Successful response + content: + application/json: {} diff --git a/test/resources/output/LicenseContactPartial2.yml b/test/resources/output/LicenseContactPartial2.yml new file mode 100644 index 0000000..0e45fc8 --- /dev/null +++ b/test/resources/output/LicenseContactPartial2.yml @@ -0,0 +1,63 @@ +openapi: 3.0.0 +info: + title: Postman to OpenAPI + description: Mi super test collection from postman + version: 1.1.0 + contact: + url: 'http://www.api.com/support' + license: + name: MIT +servers: + - url: 'https://api.io' +paths: + /users: + post: + tags: + - default + summary: Create new User + description: Create a new user into your amazing API + requestBody: + content: + application/json: + schema: + type: object + example: + example: field + other: + data1: 'yes' + data2: 'no' + responses: + '200': + description: Successful response + content: + application/json: {} + /posts: + post: + tags: + - default + summary: Create a post + requestBody: + content: + text/plain: {} + responses: + '200': + description: Successful response + content: + application/json: {} + /note: + post: + tags: + - default + summary: Create a note + description: Just an example of text raw body + requestBody: + content: + application/json: + schema: + type: string + example: This is an example Note + responses: + '200': + description: Successful response + content: + application/json: {}