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

Commit

Permalink
feat: x-logo support Close #18
Browse files Browse the repository at this point in the history
  • Loading branch information
joolfe committed May 31, 2021
1 parent a0a6436 commit 2e7358f
Show file tree
Hide file tree
Showing 8 changed files with 373 additions and 20 deletions.
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 2e7358f

Please sign in to comment.