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

Commit 9994c8d

Browse files
refactor: form data drop encoding section from and removed require code
Removed encoding section based on feedback. required for form data was implemented as it is used in parameters. This was removed and not refactored based on feedback.
1 parent a85eef6 commit 9994c8d

3 files changed

Lines changed: 2 additions & 29 deletions

File tree

lib/index.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,7 @@ function parseBody (body = {}, method) {
171171
'multipart/form-data': {
172172
schema: {
173173
type: 'object',
174-
properties: body.formdata.reduce(mapFormData(), {}),
175-
encoding: body.formdata.reduce(mapFormDataEencoding(), {})
174+
properties: body.formdata.reduce(mapFormData(), {})
176175
}
177176
}
178177
}
@@ -193,23 +192,11 @@ function parseBody (body = {}, method) {
193192
/* Accumulator function for form data values */
194193
function mapFormData () {
195194
return (obj, { key, type, description, value }) => {
196-
const required = /\[required\]/gi.test(description)
197195
obj[key] = {
198196
type: inferType(value),
199197
...(description ? { description: description.replace(/ ?\[required\] ?/gi, '') } : {}),
200198
...(value ? { example: value } : {}),
201-
...(type === 'file' ? { format: 'binary' } : {}),
202-
...(required ? { required } : {})
203-
}
204-
return obj
205-
}
206-
}
207-
208-
/* Accumulator function for form data value encodings */
209-
function mapFormDataEencoding () {
210-
return (obj, { key, contentType }) => {
211-
obj[key] = {
212-
...(contentType ? { contentType: contentType } : { contentType: 'text/plain' })
199+
...(type === 'file' ? { format: 'binary' } : {})
213200
}
214201
return obj
215202
}

test/resources/output/FormData.yml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,17 @@ paths:
2121
type: string
2222
description: full name of the user (accepts spaces)
2323
example: New User
24-
required: true
2524
email:
2625
type: string
2726
description: email of the user (for notifications and login)
2827
example: newuser@example.com
29-
required: true
3028
password:
3129
type: string
3230
example: pasword123
3331
profileImage:
3432
type: string
3533
description: User avatar
3634
format: binary
37-
encoding:
38-
name:
39-
contentType: text/plain
40-
email:
41-
contentType: text/plain
42-
password:
43-
contentType: text/plain
44-
profileImage:
45-
contentType: application/octet-stream
4635
responses:
4736
'200':
4837
description: Successful response

test/resources/output/WwwFormUrlencoded.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,14 @@ paths:
1919
type: string
2020
description: full name of the user (accepts spaces)
2121
example: New User
22-
required: true
2322
email:
2423
type: string
2524
description: email of the user (for notifications and login)
2625
example: newuser@example.com
27-
required: true
2826
password:
2927
type: string
3028
description: password (to be used for logging in)
3129
example: pasword123
32-
required: true
3330
responses:
3431
'200':
3532
description: Successful response

0 commit comments

Comments
 (0)