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

Commit b569785

Browse files
committed
refactor: little refactor to follow our code style and 100% coverage. Support for file types
1 parent 91ce1a9 commit b569785

4 files changed

Lines changed: 29 additions & 17 deletions

File tree

lib/index.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,14 @@ function parseBody (body = {}, method) {
171171
'multipart/form-data': {
172172
schema: {
173173
type: 'object',
174-
properties: body.formdata.reduce((acc, v) => {
175-
acc[v.key] = { type: v.type === 'text' ? 'string' : v.type }
176-
if (Object.prototype.hasOwnProperty.call(v, 'description')) {
177-
acc[v.key].description = v.description === '' ? 'Description' : v.description
174+
properties: body.formdata.reduce((obj, { key, type, description, value }) => {
175+
obj[key] = {
176+
type: 'string',
177+
...(description ? { description } : {}),
178+
...(value ? { example: value } : {}),
179+
...(type === 'file' ? { format: 'binary' } : {})
178180
}
179-
if (Object.prototype.hasOwnProperty.call(v, 'value') && v.value !== '') {
180-
acc[v.key].example = v.value
181-
};
182-
return acc
181+
return obj
183182
}, {})
184183
}
185184
}

test/resources/input/v2/FormData.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"info": {
3-
"_postman_id": "1eaa74c4-2d76-45f0-bd34-bff5d96f0ba8",
3+
"_postman_id": "66fd929e-c84f-4bc5-970a-60231fe16f5b",
44
"name": "Form Data",
5-
"description": "Just a collection with a form data post for test",
5+
"description": "Just a collection with a form data post for test",
66
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
77
},
88
"item": [
@@ -29,8 +29,13 @@
2929
{
3030
"key": "password",
3131
"value": "pasword123",
32-
"description": "password (to be used for logging in)",
3332
"type": "text"
33+
},
34+
{
35+
"key": "profileImage",
36+
"description": "User avatar",
37+
"type": "file",
38+
"src": []
3439
}
3540
]
3641
},
@@ -39,4 +44,4 @@
3944
"response": []
4045
}
4146
]
42-
}
47+
}

test/resources/input/v21/FormData.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"info": {
3-
"_postman_id": "1eaa74c4-2d76-45f0-bd34-bff5d96f0ba8",
3+
"_postman_id": "66fd929e-c84f-4bc5-970a-60231fe16f5b",
44
"name": "Form Data",
5-
"description": "Just a collection with a form data post for test",
5+
"description": "Just a collection with a form data post for test",
66
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
77
},
88
"item": [
@@ -29,8 +29,13 @@
2929
{
3030
"key": "password",
3131
"value": "pasword123",
32-
"description": "password (to be used for logging in)",
3332
"type": "text"
33+
},
34+
{
35+
"key": "profileImage",
36+
"description": "User avatar",
37+
"type": "file",
38+
"src": []
3439
}
3540
]
3641
},
@@ -49,4 +54,4 @@
4954
"response": []
5055
}
5156
]
52-
}
57+
}

test/resources/output/FormData.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ paths:
2727
example: newuser@example.com
2828
password:
2929
type: string
30-
description: password (to be used for logging in)
3130
example: pasword123
31+
profileImage:
32+
type: string
33+
description: User avatar
34+
format: binary
3235
responses:
3336
'200':
3437
description: Successful response

0 commit comments

Comments
 (0)