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

Commit

Permalink
refactor: form data drop encoding section from and removed require code
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
devNoiseConsulting committed Jul 25, 2021
1 parent a85eef6 commit 9994c8d
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 29 deletions.
17 changes: 2 additions & 15 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ function parseBody (body = {}, method) {
'multipart/form-data': {
schema: {
type: 'object',
properties: body.formdata.reduce(mapFormData(), {}),
encoding: body.formdata.reduce(mapFormDataEencoding(), {})
properties: body.formdata.reduce(mapFormData(), {})
}
}
}
Expand All @@ -193,23 +192,11 @@ function parseBody (body = {}, method) {
/* Accumulator function for form data values */
function mapFormData () {
return (obj, { key, type, description, value }) => {
const required = /\[required\]/gi.test(description)
obj[key] = {
type: inferType(value),
...(description ? { description: description.replace(/ ?\[required\] ?/gi, '') } : {}),
...(value ? { example: value } : {}),
...(type === 'file' ? { format: 'binary' } : {}),
...(required ? { required } : {})
}
return obj
}
}

/* Accumulator function for form data value encodings */
function mapFormDataEencoding () {
return (obj, { key, contentType }) => {
obj[key] = {
...(contentType ? { contentType: contentType } : { contentType: 'text/plain' })
...(type === 'file' ? { format: 'binary' } : {})
}
return obj
}
Expand Down
11 changes: 0 additions & 11 deletions test/resources/output/FormData.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,17 @@ paths:
type: string
description: full name of the user (accepts spaces)
example: New User
required: true
email:
type: string
description: email of the user (for notifications and login)
example: newuser@example.com
required: true
password:
type: string
example: pasword123
profileImage:
type: string
description: User avatar
format: binary
encoding:
name:
contentType: text/plain
email:
contentType: text/plain
password:
contentType: text/plain
profileImage:
contentType: application/octet-stream
responses:
'200':
description: Successful response
Expand Down
3 changes: 0 additions & 3 deletions test/resources/output/WwwFormUrlencoded.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@ paths:
type: string
description: full name of the user (accepts spaces)
example: New User
required: true
email:
type: string
description: email of the user (for notifications and login)
example: newuser@example.com
required: true
password:
type: string
description: password (to be used for logging in)
example: pasword123
required: true
responses:
'200':
description: Successful response
Expand Down

0 comments on commit 9994c8d

Please sign in to comment.