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

Commit

Permalink
Merge pull request #127 from joolfe/develop
Browse files Browse the repository at this point in the history
form-data fetaure
  • Loading branch information
joolfe authored Jul 24, 2021
2 parents 8289a98 + e8283c1 commit a5793e1
Show file tree
Hide file tree
Showing 11 changed files with 637 additions and 406 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"cSpell.words": [
"execa"
"execa",
"formdata"
]
}
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
## [1.14.0](https://github.com/joolfe/postman-to-openapi/compare/1.13.0...1.14.0) (2021-07-24)


### Features

* adding support for formdata ([547b137](https://github.com/joolfe/postman-to-openapi/commit/547b137a52277d029e7b4c022311faf79161fccf))


### Bug Fixes

* fix lint problems ([91ce1a9](https://github.com/joolfe/postman-to-openapi/commit/91ce1a92c4994237236a1af9f99471bf07c54c99))


### Tests

* form data testing ([8a26c69](https://github.com/joolfe/postman-to-openapi/commit/8a26c691cadd36db46151a35f15517bdc57129db))


### Code Refactoring

* little refactor to follow our code style and 100% coverage. Support for file types ([b569785](https://github.com/joolfe/postman-to-openapi/commit/b569785acde50530cc5a7ca9135143380b3b1371))


### Documentation

* update new feature for parse "form-data" ([4699d50](https://github.com/joolfe/postman-to-openapi/commit/4699d5007c214c2a6347faee9b0a2a91eb1fcee9))


### Build System

* update version ([2855f10](https://github.com/joolfe/postman-to-openapi/commit/2855f1086e113685f1d0d0034eee14e24cd12cf1))

## [1.13.0](https://github.com/joolfe/postman-to-openapi/compare/1.12.1...1.13.0) (2021-07-16)


Expand Down
Binary file added docs/assets/img/formDataOptions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 10 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* Transform query, headers and path parameters (description, required...).
* Postman variables as Path parameters.
* Automatic infer types from query and headers parameters.
* Support Json and Text body formats.
* Support postman "raw" body for `Json` and `Text` formats and also postman body "form-data".
* Postman Authorization parse or by configuration (Basic and Bearer).
* Contact and License from variables or by configuration.
* Provide meta-information as a markdown table.
Expand Down Expand Up @@ -320,7 +320,7 @@ The default value is `true`, so headers are by default added to the response def

## Basic conversion

This library support the transformation from Postman collection to all the basic HTTP method as GET, POST, PUT... and also parse the body request of type raw `Json` or `Text` type. [Query parameters](#parameters-parsing) are also supported.
This library support the transformation from Postman collection to all the basic HTTP method as GET, POST, PUT... parse the body request of type "raw" (`Json` and `Text`) and "form-data" (see ["form-data" body](#form-data-body) section for more info about this mode). [Query parameters](#parameters-parsing) are also supported.

Have a look to the [PostmantoOpenAPI collection](https://github.com/joolfe/postman-to-openapi/blob/master/test/resources/input/v21/PostmantoOpenAPI.json) file for an example of how to use this feature.

Expand Down Expand Up @@ -439,6 +439,14 @@ Take into account that this feature has priority over the [Response status code

If there are more than one example at request level the used headers will be the ones that appear in the last example in the postman collection.

## "form-data" Body

Library `postman-to-openapi` is able to parse the Postman collection body request of type "form-data", as Postman only support the parameter types `Text` and `File` (as you can see in next image) this are the only supported types for the Library.

![form-data options](assets/img/formDataOptions.png)

A "form-data" request body will be describe as a `multipart/form-data` content with schema of type `object`. For `Text` parameter `postman-to-openapi` will parse just as a `type: string` parameter and for type `File` following OpenAPI specs is parsed as `type: string, format: binary`

</div></div>
<div class="tilted-section"><div markdown="1">

Expand Down
18 changes: 18 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,24 @@ function parseBody (body = {}, method) {
'text/plain': {}
}
break
case 'formdata':
content = {
'multipart/form-data': {
schema: {
type: 'object',
properties: body.formdata.reduce((obj, { key, type, description, value }) => {
obj[key] = {
type: 'string',
...(description ? { description } : {}),
...(value ? { example: value } : {}),
...(type === 'file' ? { format: 'binary' } : {})
}
return obj
}, {})
}
}
}
break
}
return { requestBody: { content } }
}
Expand Down
Loading

0 comments on commit a5793e1

Please sign in to comment.