Skip to content

Commit

Permalink
Bump version; fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikWittern committed Aug 13, 2021
1 parent 52b9e66 commit 284aeeb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
37 changes: 23 additions & 14 deletions openapi-to-har.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ const getPayload = function (openApi, path, method) {
openApi.paths[path][method].requestBody &&
openApi.paths[path][method].requestBody.content
) {
if (openApi.paths[path][method].requestBody.content['application/json'] &&
if (
openApi.paths[path][method].requestBody.content['application/json'] &&
openApi.paths[path][method].requestBody.content['application/json'].schema
) {
const sample = OpenAPISampler.sample(
Expand All @@ -118,34 +119,42 @@ const getPayload = function (openApi, path, method) {
);
return {
mimeType: 'application/json',
text: JSON.stringify(sample)
text: JSON.stringify(sample),
};
}

if (openApi.paths[path][method].requestBody.content['application/x-www-form-urlencoded'] &&
openApi.paths[path][method].requestBody.content['application/x-www-form-urlencoded'].schema
if (
openApi.paths[path][method].requestBody.content[
'application/x-www-form-urlencoded'
] &&
openApi.paths[path][method].requestBody.content[
'application/x-www-form-urlencoded'
].schema
) {
const sample = OpenAPISampler.sample(openApi.paths[path][method].requestBody.content['application/x-www-form-urlencoded']
.schema,
{skipReadOnly: true},
const sample = OpenAPISampler.sample(
openApi.paths[path][method].requestBody.content[
'application/x-www-form-urlencoded'
].schema,
{ skipReadOnly: true },
openApi
);

if (sample === undefined) return null;

const params = [];
Object.keys(sample).map(
key => params.push({
'name': encodeURIComponent(key).replace(/\%20/g, '+'),
'value': encodeURIComponent(sample[key]).replace(/\%20/g, '+')
})
}
Object.keys(sample).map((key) =>
params.push({
name: encodeURIComponent(key).replace(/\%20/g, '+'),
value: encodeURIComponent(sample[key]).replace(/\%20/g, '+'),
})
);

return {
mimeType: 'application/x-www-form-urlencoded',
params: params,
text: Object.keys(params).map(key => key + '=' + sample[key]).join('&')
text: Object.keys(params)
.map((key) => key + '=' + sample[key])
.join('&'),
};
}
}
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openapi-snippet",
"version": "0.10.0",
"version": "0.11.0",
"description": "Generates code snippets from Open API (previously Swagger) documents.",
"repository": {
"type": "git",
Expand Down

0 comments on commit 284aeeb

Please sign in to comment.