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

Commit

Permalink
fix: avoid fail body.raw is empty string Close #101
Browse files Browse the repository at this point in the history
  • Loading branch information
joolfe committed Apr 24, 2021
1 parent 1d85167 commit 1c376cf
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function parseBody (body = {}, method) {
'application/json': {
schema: {
type: 'object',
example: JSON.parse(raw)
example: raw ? JSON.parse(raw) : ''
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postman-to-openapi",
"version": "1.7.2",
"version": "1.7.3",
"description": "Convert postman collection to OpenAPI spec",
"main": "lib/index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ describe('Library specs', function () {
termsOfService: 'http://tos.myweb.com'
}
})
console.log(result)
equal(result, EXPECTED_INFO_OPTS)
})

Expand Down
25 changes: 21 additions & 4 deletions test/resources/input/v2/SimplePost.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info": {
"_postman_id": "56e38043-4473-4faa-a735-1815ca79ee04",
"_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"
Expand All @@ -24,14 +24,31 @@
"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": []
}
],
"variable": [
{
"id": "a1b68638-d65e-4ee8-9a91-4d5749e9c2f2",
"key": "version",
"value": "2.3.0"
}
],
"protocolProfileBehavior": {}
]
}
35 changes: 31 additions & 4 deletions test/resources/input/v21/SimplePost.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info": {
"_postman_id": "3ad7e1b4-f3a1-4a8f-8bd0-56ff18f53339",
"_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.1.0/collection.json"
Expand Down Expand Up @@ -34,14 +34,41 @@
"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": {
"raw": "https://api.io/raw",
"protocol": "https",
"host": [
"api",
"io"
],
"path": [
"raw"
]
},
"description": "Create a new user into your amazing API"
},
"response": []
}
],
"variable": [
{
"id": "a1b68638-d65e-4ee8-9a91-4d5749e9c2f2",
"key": "version",
"value": "2.3.0"
}
],
"protocolProfileBehavior": {}
]
}
17 changes: 17 additions & 0 deletions test/resources/output/CustomTag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,20 @@ paths:
description: Successful response
content:
application/json: {}
/raw:
post:
tags:
- Custom Tag
summary: Post empty raw
description: Create a new user into your amazing API
requestBody:
content:
application/json:
schema:
type: object
example: ''
responses:
'200':
description: Successful response
content:
application/json: {}
17 changes: 17 additions & 0 deletions test/resources/output/InfoOpts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,20 @@ paths:
description: Successful response
content:
application/json: {}
/raw:
post:
tags:
- default
summary: Post empty raw
description: Create a new user into your amazing API
requestBody:
content:
application/json:
schema:
type: object
example: ''
responses:
'200':
description: Successful response
content:
application/json: {}

0 comments on commit 1c376cf

Please sign in to comment.