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

Commit

Permalink
fix: Avoid error when some versions of postman export response header…
Browse files Browse the repository at this point in the history
… with null value. close #152
  • Loading branch information
joolfe committed Oct 3, 2021
1 parent f6be79d commit 8eb6861
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ function parseResponseHeaders (headerArray, responseHeaders) {
if (!responseHeaders) {
return {}
}
headerArray = headerArray || []
const headers = headerArray.reduce((acc, { key, value }) => {
acc[key] = {
schema: {
Expand Down
7 changes: 7 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { version } = require('../package.json')
const OUTPUT_PATH = path.join(__dirname, '/openAPIRes.yml')

const COLLECTION_NO_OPTIONS = './test/resources/input/NoOptionsInBody.json'
const COLLECTION_NULL_HEADERS = './test/resources/input/NullHeaders.json'

const EXPECTED_BASIC = readFileSync('./test/resources/output/Basic.yml', 'utf8')
const EXPECTED_INFO_OPTS = readFileSync('./test/resources/output/InfoOpts.yml', 'utf8')
Expand Down Expand Up @@ -54,6 +55,7 @@ const EXPECTED_VARIABLES = readFileSync('./test/resources/output/Variables.yml',
const EXPECTED_VARIABLES_ADDITIONAL = readFileSync('./test/resources/output/VariablesAdditional.yml', 'utf8')
const EXPECTED_BASEPATH_VAR = readFileSync('./test/resources/output/BasepathVar.yml', 'utf8')
const EXPECTED_RAW_BODY = readFileSync('./test/resources/output/RawBody.yml', 'utf8')
const EXPECTED_NULL_HEADER = readFileSync('./test/resources/output/NullHeader.yml', 'utf8')

const AUTH_DEFINITIONS = {
myCustomAuth: {
Expand Down Expand Up @@ -469,4 +471,9 @@ describe('Library specs', function () {
it('should expose the version of the library', async function () {
equal(postmanToOpenApi.version, version)
})

it('should work if header is equals to "null" in response', async function () {
const result = await postmanToOpenApi(COLLECTION_NULL_HEADERS, OUTPUT_PATH, {})
equal(result, EXPECTED_NULL_HEADER)
})
})
145 changes: 145 additions & 0 deletions test/resources/input/NullHeaders.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
{
"info": {
"_postman_id": "4b33ade6-60b3-48e7-a441-c723b9c8b8bb",
"name": "Information sociétaire",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Authentification",
"item": [
{
"name": "Récupération token",
"event": [
{
"listen": "test",
"script": {
"exec": [
"const jsonData = pm.response.json();\r",
"\r",
"pm.test(\"Réponse OK\", function () \r",
"{\r",
" postman.setNextRequest(null);\r",
" pm.expect(jsonData.codeErreur).to.eq(0);\r",
" pm.response.to.have.status(200);\r",
" postman.setNextRequest(\"Associer distributeur au token\");\r",
"});\r",
"\r",
"pm.collectionVariables.set(\"token\", jsonData.contenu.token);"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"contenu\":\r\n {\r\n \"compte\": \"{{compte}}\",\r\n \"motDePasse\": \"{{motDePasse}}\",\r\n \"identifiant\": \"{{identifiant}}\"\r\n }\r\n}"
},
"url": {
"raw": "{{url}}/{{webApp}}/token",
"host": [
"{{url}}"
],
"path": [
"{{webApp}}",
"token"
]
},
"description": "Méthode d'authentification \nRetourne un token en cas de succès"
},
"response": [
{
"name": "Récupération token",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"contenu\": {\r\n \"compte\": \"\",\r\n \"motDePasse\": \"\",\r\n \"identifiant\": \"\"\r\n }\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{url}}/{{webApp}}/token",
"host": [
"{{url}}"
],
"path": [
"{{webApp}}",
"token"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": null,
"cookie": [],
"body": "{\n \"erreur\": null,\n \"codeErreur\": 0,\n \"contenu\": {\n \"token\": \"ct54q7uoidffg2z661afigu98ix476s8\"\n }\n}"
}
]
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
"pm.variables.set(\"webApp\", \"auth/web\");"
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
]
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
],
"variable": []
}
50 changes: 50 additions & 0 deletions test/resources/output/NullHeader.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
openapi: 3.0.0
info:
title: Information sociétaire
version: 1.0.0
servers:
- url: http://{{url}}
tags:
- name: Authentification
paths:
/{webApp}/token:
post:
tags:
- Authentification
summary: Récupération token
description: |-
Méthode d'authentification
Retourne un token en cas de succès
requestBody:
content:
application/json:
schema:
type: object
example:
contenu:
compte: '{{compte}}'
motDePasse: '{{motDePasse}}'
identifiant: '{{identifiant}}'
parameters:
- name: Content-Type
in: header
schema:
type: string
example: application/json
- name: webApp
in: path
schema:
type: string
required: true
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
example:
erreur: null
codeErreur: 0
contenu:
token: ct54q7uoidffg2z661afigu98ix476s8

0 comments on commit 8eb6861

Please sign in to comment.