diff --git a/lib/index.js b/lib/index.js index 4de18bb..0473e0b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -99,7 +99,7 @@ function parseContact (variables, optsContact = {}) { function parseBody (body = {}, method) { // Swagger validation return an error if GET has body if (['GET'].includes(method)) return {} - const { mode, raw, options } = body + const { mode, raw, options = { raw: { language: 'json' } } } = body let content = {} switch (mode) { case 'raw': { diff --git a/test/index.spec.js b/test/index.spec.js index 7288293..61e46b6 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -22,6 +22,7 @@ const COLLECTION_LICENSE_CONTACT = './test/resources/input/LicenseContact.json' const COLLECTION_DEPTH_PATH_PARAMS = './test/resources/input/DepthPathParams.json' const COLLECTION_PARSE_STATUS_CODE = './test/resources/input/ParseStatusCode.json' const COLLECTION_NO_PATH = './test/resources/input/NoPath.json' +const COLLECTION_NO_OPTIONS = './test/resources/input/NoOptionsInBody.json' const EXPECTED_BASIC = readFileSync('./test/resources/output/Basic.yml', 'utf8') const EXPECTED_INFO_OPTS = readFileSync('./test/resources/output/InfoOpts.yml', 'utf8') @@ -226,8 +227,13 @@ describe('Library specs', function () { equal(result, EXPECTED_PARSE_STATUS_CODE) }) - it.only('should parse operation when no path (only domain)', async function () { + it('should parse operation when no path (only domain)', async function () { const result = await postmanToOpenApi(COLLECTION_NO_PATH) equal(result, EXPECTED_NO_PATH) }) + + it('should work if no options in request body', async function () { + const result = await postmanToOpenApi(COLLECTION_NO_OPTIONS, OUTPUT_PATH, {}) + equal(result, EXPECTED_BASIC) + }) }) diff --git a/test/resources/input/NoOptionsInBody.json b/test/resources/input/NoOptionsInBody.json new file mode 100644 index 0000000..05d1102 --- /dev/null +++ b/test/resources/input/NoOptionsInBody.json @@ -0,0 +1,121 @@ +{ + "info": { + "_postman_id": "2a45baa5-352f-4831-8483-1a0fcbc7da37", + "name": "Postman to OpenAPI", + "description": "Mi super test collection from postman", + "schema": "https://schema.getpostman.com/json/collection/v2.1.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}" + }, + "url": { + "raw": "https://api.io/users", + "protocol": "https", + "host": [ + "api", + "io" + ], + "path": [ + "users" + ] + }, + "description": "Create a new user into your amazing API" + }, + "response": [] + }, + { + "name": "Create a post", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "file", + "file": {}, + "options": { + "raw": { + "language": "text" + } + } + }, + "url": { + "raw": "https://api.io/posts", + "protocol": "https", + "host": [ + "api", + "io" + ], + "path": [ + "posts" + ] + } + }, + "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": [ + { + "listen": "prerequest", + "script": { + "id": "ef248fcc-2944-4cba-837f-680b10a45b30", + "type": "text/javascript", + "exec": [ + "" + ] + } + }, + { + "listen": "test", + "script": { + "id": "8e7453aa-5712-4a90-bc32-965c7d47906a", + "type": "text/javascript", + "exec": [ + "" + ] + } + } + ], + "variable": [ + { + "id": "d04439bd-c604-4758-bde2-3c873140f38c", + "key": "version", + "value": "1.1.0" + } + ], + "protocolProfileBehavior": {} +} \ No newline at end of file