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

Commit

Permalink
refactor: merge from upstream/master
Browse files Browse the repository at this point in the history
  • Loading branch information
devNoiseConsulting committed Jul 25, 2021
2 parents 8311563 + 9cc56b0 commit 0a0f849
Show file tree
Hide file tree
Showing 11 changed files with 509 additions and 447 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
2 changes: 1 addition & 1 deletion docs/assets/css/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ $header-bg-color-secondary: #5f5278 !default;
$body-link-color: #3b95ef !default;
$section-headings-color: #ff6b37 !default;

@import "{{ site.theme }}";
@import "jekyll-theme-cayman";

strong {
color: #788286;
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
52 changes: 26 additions & 26 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ function parseContact (variables, optsContact = {}) {
const { name = nameVar, url = urlVar, email = emailVar } = optsContact
return [name, url, email].some(e => e != null)
? {
contact: {
...(name ? { name } : {}),
...(url ? { url } : {}),
...(email ? { email } : {})
contact: {
...(name ? { name } : {}),
...(url ? { url } : {}),
...(email ? { email } : {})
}
}
}
: {}
}

Expand Down Expand Up @@ -166,45 +166,45 @@ function parseBody (body = {}, method) {
'text/plain': {}
}
break
case "formdata":
case 'formdata':
content = {
"multipart/form-data": {
'multipart/form-data': {
schema: {
type: "object",
type: 'object',
properties: body.formdata.reduce(mapFormData(), {}),
encoding: body.formdata.reduce(mapFormDataEencoding(), {})
}
}
};
break;
case "urlencoded":
}
break
case 'urlencoded':
content = {
"application/x-www-form-urlencoded": {
'application/x-www-form-urlencoded': {
schema: {
properties: body.urlencoded.reduce(mapFormData(), {})
}
}
};
break;
}
break
}
return { requestBody: { content } }
}

function mapFormData () {
return (data, { key, value, description, type }) => {
data[key] = { type: inferType (value) };
if (type == "file") {
data[key].type = "string";
data[key].format = "base64";
data[key] = { type: inferType(value) }
if (type === 'file') {
data[key].type = 'string'
data[key].format = 'base64'
}
if (description && description !== '') {
data[key].description = description;
data[key].description = description
}
if (value && value !== '') {
data[key].example = value;
data[key].example = value
};
if (/\[required\]/gi.test(description)) {
data[key].require = true;
data[key].require = true
}
return data
}
Expand All @@ -213,9 +213,9 @@ function mapFormData () {
function mapFormDataEencoding () {
return (data, { key, contentType }) => {
if (contentType) {
data[key] = { contentType: contentType };
data[key] = { contentType: contentType }
} else {
data[key] = { contentType: 'text/plain' };
data[key] = { contentType: 'text/plain' }
}
return data
}
Expand Down Expand Up @@ -339,9 +339,9 @@ function parseOptsAuth (optAuth) {
return Object.keys(securitySchemes).length === 0
? {}
: {
components: { securitySchemes },
security
}
components: { securitySchemes },
security
}
}

/* From the path array compose the real path for OpenApi specs */
Expand Down
Loading

0 comments on commit 0a0f849

Please sign in to comment.