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

Commit

Permalink
feat: support DELETE operations #66
Browse files Browse the repository at this point in the history
Close #66
  • Loading branch information
joolfe committed Aug 25, 2020
1 parent ea1671e commit 38eb357
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function parseContact (variables, optsContact = {}) {

function parseBody (body = {}, method) {
// Swagger validation return an error if GET has body
if (['GET'].includes(method)) return {}
if (['GET', 'DELETE'].includes(method)) return {}
const { mode, raw, options = { raw: { language: 'json' } } } = body
let content = {}
switch (mode) {
Expand Down
7 changes: 7 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const COLLECTION_DEPTH_PATH_PARAMS = './test/resources/input/DepthPathParams.jso
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 COLLECTION_DELETE = './test/resources/input/DeleteOperation.json'

const EXPECTED_BASIC = readFileSync('./test/resources/output/Basic.yml', 'utf8')
const EXPECTED_INFO_OPTS = readFileSync('./test/resources/output/InfoOpts.yml', 'utf8')
Expand All @@ -45,6 +46,7 @@ const EXPECTED_LICENSE_CONTACT_PARTIAL_2 = readFileSync('./test/resources/output
const EXPECTED_DEPTH_PATH_PARAMS = readFileSync('./test/resources/output/DepthPathParams.yml', 'utf8')
const EXPECTED_PARSE_STATUS_CODE = readFileSync('./test/resources/output/ParseStatus.yml', 'utf8')
const EXPECTED_NO_PATH = readFileSync('./test/resources/output/NoPath.yml', 'utf8')
const EXPECTED_DELETE = readFileSync('./test/resources/output/DeleteOperation.yml', 'utf8')

describe('Library specs', function () {
afterEach('remove file', function () {
Expand Down Expand Up @@ -236,4 +238,9 @@ describe('Library specs', function () {
const result = await postmanToOpenApi(COLLECTION_NO_OPTIONS, OUTPUT_PATH, {})
equal(result, EXPECTED_BASIC)
})

it('should support "DELETE" operations', async function () {
const result = await postmanToOpenApi(COLLECTION_DELETE)
equal(result, EXPECTED_DELETE)
})
})
60 changes: 60 additions & 0 deletions test/resources/input/DeleteOperation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"info": {
"_postman_id": "469344e4-4c85-45fe-b0a6-246575a018bc",
"name": "Delete Operation",
"description": "Mi super test collection from postman",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Delete all users",
"request": {
"method": "DELETE",
"header": [],
"url": {
"raw": "https://api.io/users",
"protocol": "https",
"host": [
"api",
"io"
],
"path": [
"users"
]
},
"description": "Delete all the existing users"
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"id": "9f8baaad-642e-48c6-b5d3-6ec59d2df6b1",
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"id": "61df081f-afb8-4e8a-8a32-66db8b22f887",
"type": "text/javascript",
"exec": [
""
]
}
}
],
"variable": [
{
"id": "b8ff9254-81e3-432f-9e5a-aea92cf34d7c",
"key": "version",
"value": "1.1.0"
}
],
"protocolProfileBehavior": {}
}
19 changes: 19 additions & 0 deletions test/resources/output/DeleteOperation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
openapi: 3.0.0
info:
title: Delete Operation
description: Mi super test collection from postman
version: 1.1.0
servers:
- url: 'https://api.io'
paths:
/users:
delete:
tags:
- default
summary: Delete all users
description: Delete all the existing users
responses:
'200':
description: Successful response
content:
application/json: {}

0 comments on commit 38eb357

Please sign in to comment.