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

Commit

Permalink
feat: Add support for POST with text #36
Browse files Browse the repository at this point in the history
Only text body added
  • Loading branch information
joolfe committed Jul 26, 2020
1 parent 05fd1e8 commit af0d452
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 14 deletions.
27 changes: 20 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,32 @@ function compileInfo (postmanJson, optsInfo) {
function parseBody (body = {}, method) {
// Swagger validation return an error if GET has body
if (['GET'].includes(method)) return {}
const { mode, raw } = body
const { mode, raw, options } = body
let content = {}
switch (mode) {
case 'raw':
content = {
'application/json': {
schema: {
type: 'object',
example: JSON.parse(raw)
case 'raw': {
const { raw: { language } } = options
if (language === 'json') {
content = {
'application/json': {
schema: {
type: 'object',
example: JSON.parse(raw)
}
}
}
} else {
content = {
'application/json': {
schema: {
type: 'string',
example: raw
}
}
}
}
break
}
case 'file':
content = {
'text/plain': {}
Expand Down
37 changes: 33 additions & 4 deletions test/resources/input/PostmantoOpenAPI.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"info": {
"_postman_id": "2a45baa5-352f-4831-8483-1a0fcbc7da37",
"name": "Postman to OpenAPI",
"description": "Mi super test collection from postman ",
"description": "Mi super test collection from postman",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Create a user",
"name": "Create new User",
"request": {
"method": "POST",
"header": [],
Expand All @@ -31,7 +31,7 @@
"users"
]
},
"description": "This is a post request with json body"
"description": "Create a new user into your amazing API"
},
"response": []
},
Expand Down Expand Up @@ -62,6 +62,35 @@
}
},
"response": []
},
{
"name": "Create a note",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "This is an example Note",
"options": {
"raw": {
"language": "text"
}
}
},
"url": {
"raw": "https://api.io/note",
"protocol": "https",
"host": [
"api",
"io"
],
"path": [
"note"
]
},
"description": "Just an example of text raw body"
},
"response": []
}
],
"event": [
Expand All @@ -88,7 +117,7 @@
],
"variable": [
{
"id": "cfcda50b-827a-4a48-8059-1344d044cba7",
"id": "d04439bd-c604-4758-bde2-3c873140f38c",
"key": "version",
"value": "1.1.0"
}
Expand Down
23 changes: 20 additions & 3 deletions test/resources/output/Basic.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
openapi: 3.0.0
info:
title: Postman to OpenAPI
description: 'Mi super test collection from postman '
description: Mi super test collection from postman
version: 1.1.0
paths:
/users:
post:
tags:
- default
summary: Create a user
description: This is a post request with json body
summary: Create new User
description: Create a new user into your amazing API
requestBody:
content:
application/json:
Expand Down Expand Up @@ -38,3 +38,20 @@ paths:
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: {}

0 comments on commit af0d452

Please sign in to comment.