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

Commit

Permalink
refactor: little refactor to follow our code style and 100% coverage.…
Browse files Browse the repository at this point in the history
… Support for file types
  • Loading branch information
joolfe committed Jul 24, 2021
1 parent 91ce1a9 commit b569785
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
15 changes: 7 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,14 @@ function parseBody (body = {}, method) {
'multipart/form-data': {
schema: {
type: 'object',
properties: body.formdata.reduce((acc, v) => {
acc[v.key] = { type: v.type === 'text' ? 'string' : v.type }
if (Object.prototype.hasOwnProperty.call(v, 'description')) {
acc[v.key].description = v.description === '' ? 'Description' : v.description
properties: body.formdata.reduce((obj, { key, type, description, value }) => {
obj[key] = {
type: 'string',
...(description ? { description } : {}),
...(value ? { example: value } : {}),
...(type === 'file' ? { format: 'binary' } : {})
}
if (Object.prototype.hasOwnProperty.call(v, 'value') && v.value !== '') {
acc[v.key].example = v.value
};
return acc
return obj
}, {})
}
}
Expand Down
13 changes: 9 additions & 4 deletions test/resources/input/v2/FormData.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"info": {
"_postman_id": "1eaa74c4-2d76-45f0-bd34-bff5d96f0ba8",
"_postman_id": "66fd929e-c84f-4bc5-970a-60231fe16f5b",
"name": "Form Data",
"description": "Just a collection with a form data post for test",
"description": "Just a collection with a form data post for test",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
},
"item": [
Expand All @@ -29,8 +29,13 @@
{
"key": "password",
"value": "pasword123",
"description": "password (to be used for logging in)",
"type": "text"
},
{
"key": "profileImage",
"description": "User avatar",
"type": "file",
"src": []
}
]
},
Expand All @@ -39,4 +44,4 @@
"response": []
}
]
}
}
13 changes: 9 additions & 4 deletions test/resources/input/v21/FormData.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"info": {
"_postman_id": "1eaa74c4-2d76-45f0-bd34-bff5d96f0ba8",
"_postman_id": "66fd929e-c84f-4bc5-970a-60231fe16f5b",
"name": "Form Data",
"description": "Just a collection with a form data post for test",
"description": "Just a collection with a form data post for test",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
Expand All @@ -29,8 +29,13 @@
{
"key": "password",
"value": "pasword123",
"description": "password (to be used for logging in)",
"type": "text"
},
{
"key": "profileImage",
"description": "User avatar",
"type": "file",
"src": []
}
]
},
Expand All @@ -49,4 +54,4 @@
"response": []
}
]
}
}
5 changes: 4 additions & 1 deletion test/resources/output/FormData.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ paths:
example: newuser@example.com
password:
type: string
description: password (to be used for logging in)
example: pasword123
profileImage:
type: string
description: User avatar
format: binary
responses:
'200':
description: Successful response
Expand Down

0 comments on commit b569785

Please sign in to comment.