Skip to content
This repository has been archived by the owner on Dec 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #116 from joolfe/develop
Browse files Browse the repository at this point in the history
x-logo extension
  • Loading branch information
joolfe authored May 31, 2021
2 parents db76f0d + 76e8b94 commit c8b87d0
Show file tree
Hide file tree
Showing 10 changed files with 393 additions and 22 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## [1.11.0](https://github.com/joolfe/postman-to-openapi/compare/1.10.0...1.11.0) (2021-05-31)


### Features

* x-logo support Close [#18](https://github.com/joolfe/postman-to-openapi/issues/18) ([2e7358f](https://github.com/joolfe/postman-to-openapi/commit/2e7358f97e38bbaa25e4249b1019e97f36e4a8b5))


### Documentation

* update docs with new field ([3aa907f](https://github.com/joolfe/postman-to-openapi/commit/3aa907f2fc7b6a5a651bc595a58c3a3779d3cde9))

## [1.10.0](https://github.com/joolfe/postman-to-openapi/compare/1.9.2...1.10.0) (2021-05-27)


Expand Down
10 changes: 8 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ The basic information of the API is obtained from Postman collection as describe
| `termsOfService` | String. A URL to the Terms of Service for the API. MUST be in the format of a URL. |
| `contact` | Object. The contact information for the exposed API. See details in [License and Contact configuration](#license-and-contact-configuration) section. |
| `license` | Object. The license information for the exposed API.See details in [License and Contact configuration](#license-and-contact-configuration) section. |
| `xLogo` | Object. Contain the info for the `x-logo` extension defined by [redoc](https://github.com/Redocly/redoc/blob/master/docs/redoc-vendor-extensions.md#x-logo) |

Basically this are the required and relevant parameters defined in OpenAPI spec [info object](http://spec.openapis.org/oas/v3.0.3.html#info-object), an example of the option will be:

Expand All @@ -147,6 +148,11 @@ Basically this are the required and relevant parameters defined in OpenAPI spec
name: 'My Support',
url: 'http://www.api.com/support',
email: '[email protected]'
},
xLogo: {
url: 'https://github.com/joolfe/logoBanner.png',
backgroundColor: '#FFFFFF',
altText: 'Example logo'
}
}
}
Expand Down Expand Up @@ -355,9 +361,9 @@ const result = await postmanToOpenApi(postmanCollection, outputFile, { servers:

This will remove the `servers` field from the yml specification result.

## License and Contact configuration
## Pass data as postman collection variables

Inside the [info object](http://spec.openapis.org/oas/v3.0.3.html#info-object) of OpenAPI definition exist two Object fields called `contact` and `license`, this fields are very useful for provide information to developers, but inside a Postman collection not exist any "standard" way to save this information, for this reason we use [Postman collection variables](https://learning.postman.com/docs/sending-requests/variables/) to define this options.
Inside the [info object](http://spec.openapis.org/oas/v3.0.3.html#info-object) of OpenAPI definition exist some Object fields as `contact`, `license` or `xLogo`, this fields are very useful for provide information to developers, but inside a Postman collection not exist any "standard" way to save this information, for this reason we use [Postman collection variables](https://learning.postman.com/docs/sending-requests/variables/) to define this options and maintain this info indie the postman collection.

Is as easy as define the values in the "Edit Collection" form page inside the tab "Variables", as showed in the next image:

Expand Down
15 changes: 14 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,31 @@ function compileInfo (postmanJson, optsInfo) {
const ver = getVarValue(variable, 'version', '1.0.0')
const {
title = name, description = desc, version = ver,
termsOfService, license, contact
termsOfService, license, contact, xLogo
} = optsInfo
return {
title,
description,
version,
...parseXLogo(variable, xLogo),
...(termsOfService ? { termsOfService } : {}),
...parseContact(variable, contact),
...parseLicense(variable, license)
}
}

function parseXLogo (variables, xLogo = {}) {
const urlVar = getVarValue(variables, 'x-logo.urlVar')
const backgroundColorVar = getVarValue(variables, 'x-logo.backgroundColorVar')
const altTextVar = getVarValue(variables, 'x-logo.altTextVar')
const hrefVar = getVarValue(variables, 'x-logo.hrefVar')
const {
url = urlVar, backgroundColor = backgroundColorVar,
altText = altTextVar, href = hrefVar
} = xLogo
return (url != null) ? { 'x-logo': { url, backgroundColor, altText, href } } : {}
}

function parseLicense (variables, optsLicense = {}) {
const nameVar = getVarValue(variables, 'license.name')
const urlVar = getVarValue(variables, 'license.url')
Expand Down
35 changes: 19 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postman-to-openapi",
"version": "1.10.0",
"version": "1.11.0",
"description": "Convert postman collection to OpenAPI spec",
"main": "lib/index.js",
"types": "types/index.d.ts",
Expand Down Expand Up @@ -50,10 +50,10 @@
"conventional-changelog-cli": "^2.1.1",
"eslint": "^7.27.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.23.3",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.0",
"execa": "^5.0.0",
"execa": "^5.0.1",
"husky": "^6.0.0",
"mocha": "^8.4.0",
"nyc": "^15.1.0",
Expand Down
35 changes: 35 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const EXPECTED_EXTERNAL_DOCS = readFileSync('./test/resources/output/ExternalDoc
const EXPECTED_EXTERNAL_DOCS_OPTS = readFileSync('./test/resources/output/ExternalDocsOpts.yml', 'utf8')
const EXPECTED_EXTERNAL_DOCS_OPTS_PARTIAL = readFileSync('./test/resources/output/ExternalDocsOptsPartial.yml', 'utf8')
const EXPECTED_EMPTY_URL = readFileSync('./test/resources/output/EmptyUrl.yml', 'utf8')
const EXPECTED_X_LOGO = readFileSync('./test/resources/output/XLogo.yml', 'utf8')
const EXPECTED_X_LOGO_VAR = readFileSync('./test/resources/output/XLogoVar.yml', 'utf8')

describe('Library specs', function () {
afterEach('remove file', function () {
Expand Down Expand Up @@ -70,6 +72,7 @@ describe('Library specs', function () {
const COLLECTION_URL_WITH_PORT = `./test/resources/input/${version}/UrlWithPort.json`
const COLLECTION_EXTERNAL_DOCS = `./test/resources/input/${version}/ExternalDocs.json`
const COLLECTION_EMPTY_URL = `./test/resources/input/${version}/EmptyUrl.json`
const COLLECTION_XLOGO = `./test/resources/input/${version}/XLogo.json`

it('should work with a basic transform', async function () {
const result = await postmanToOpenApi(COLLECTION_BASIC, OUTPUT_PATH, {})
Expand Down Expand Up @@ -319,6 +322,38 @@ describe('Library specs', function () {
const result = await postmanToOpenApi(COLLECTION_EMPTY_URL, OUTPUT_PATH)
equal(result, EXPECTED_EMPTY_URL)
})

it('should accept "x-logo" extension by option', async function () {
const result = await postmanToOpenApi(COLLECTION_XLOGO, OUTPUT_PATH, {
info: {
xLogo: {
url: 'https://github.com/joolfe/logoBanner.png',
backgroundColor: '#FFFFFF',
altText: 'Example logo'
}
}
})
equal(result, EXPECTED_X_LOGO)
})

it('should use only "x-logo" standard fields', async function () {
const result = await postmanToOpenApi(COLLECTION_XLOGO, OUTPUT_PATH, {
info: {
xLogo: {
url: 'https://github.com/joolfe/logoBanner.png',
backgroundColor: '#FFFFFF',
altText: 'Example logo',
incorrect: 'field'
}
}
})
equal(result, EXPECTED_X_LOGO)
})

it('should use "x-logo" from variables', async function () {
const result = await postmanToOpenApi(COLLECTION_XLOGO, OUTPUT_PATH, {})
equal(result, EXPECTED_X_LOGO_VAR)
})
})
})

Expand Down
90 changes: 90 additions & 0 deletions test/resources/input/v2/XLogo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"info": {
"_postman_id": "e223ab3f-2683-4759-9e41-8167a7caaf99",
"name": "Simple Post",
"description": "Just a simple collection for test",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
},
"item": [
{
"name": "Create new User",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"example\": \"field\",\n \"other\": {\n \"data1\": \"yes\",\n \"data2\": \"no\"\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": "https://api.io/users",
"description": "Create a new user into your amazing API"
},
"response": []
},
{
"name": "Post empty raw",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "",
"options": {
"raw": {
"language": "json"
}
}
},
"url": "https://api.io/raw",
"description": "Create a new user into your amazing API"
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
],
"variable": [
{
"key": "version",
"value": "2.3.0"
},
{
"key": "x-logo.urlVar",
"value": "https://github.com/joolfe/mylogo.png"
},
{
"key": "x-logo.backgroundColorVar",
"value": "#000FFF"
},
{
"key": "x-logo.altTextVar",
"value": "Othert text for logo"
},
{
"key": "x-logo.hrefVar",
"value": "https://github.com/joolfe/here.html"
}
]
}
Loading

0 comments on commit c8b87d0

Please sign in to comment.