Skip to content

Commit

Permalink
Bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikWittern committed Jun 4, 2021
1 parent 373514c commit b999cd0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
31 changes: 18 additions & 13 deletions openapi-to-har.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,22 +157,27 @@ const getBaseUrl = function (openApi, path, method) {
* @param {Object} values Optional: query parameter values to use in the snippet if present
* @returns {Object} Object describing the parameters in a given OpenAPI method
*/
const getParameterValues = function (param, values) {
let value = 'SOME_' + (param.type || param.schema.type).toUpperCase() + '_VALUE'
const getParameterValues = function (param, values) {
let value =
'SOME_' + (param.type || param.schema.type).toUpperCase() + '_VALUE';
if (values && typeof values[param.name] !== 'undefined') {
value = values[param.name] + '' /* adding a empty string to convert to string */
value =
values[param.name] + ''; /* adding a empty string to convert to string */
} else if (typeof param.default !== 'undefined') {
value = param.default + ''
} else if (typeof param.schema !== 'undefined' && typeof param.schema.example !== 'undefined') {
value = param.schema.example + ''
} else if (typeof param.example !== 'undefined'){
value = param.example + ''
value = param.default + '';
} else if (
typeof param.schema !== 'undefined' &&
typeof param.schema.example !== 'undefined'
) {
value = param.schema.example + '';
} else if (typeof param.example !== 'undefined') {
value = param.example + '';
}
return {
name: param.name,
value: value
}
}
value: value,
};
};

/**
* Get array of objects describing the query parameters for a path and method
Expand Down Expand Up @@ -214,7 +219,7 @@ const getQueryStrings = function (openApi, path, method, values) {
typeof param.in !== 'undefined' &&
param.in.toLowerCase() === 'query'
) {
queryStrings.push(getParameterValues(param, values))
queryStrings.push(getParameterValues(param, values));
}
}
}
Expand Down Expand Up @@ -308,7 +313,7 @@ const getHeadersArray = function (openApi, path, method) {
typeof param.in !== 'undefined' &&
param.in.toLowerCase() === 'header'
) {
headers.push(getParameterValues(param))
headers.push(getParameterValues(param));
}
}
}
Expand Down
6 changes: 3 additions & 3 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.9.3",
"version": "0.10.0",
"description": "Generates code snippets from Open API (previously Swagger) documents.",
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const IBMOpenAPI = require('./ibm_watson_alchemy_data_news_api.json');
const PetStoreOpenAPI = require('./petstore_swagger.json');
const PetStoreOpenAPI3 = require('./petstore_oas.json');
const ParameterSchemaReferenceAPI = require('./parameter_schema_reference');
const ParameterExampleReferenceAPI = require('./parameter_example_swagger.json')
const ParameterExampleReferenceAPI = require('./parameter_example_swagger.json');

test('Getting snippets should not result in error or undefined', function (t) {
t.plan(1);
Expand Down Expand Up @@ -195,4 +195,4 @@ test('Testing the case when an example is provided, use the provided example val
t.true(/ {tags: 'dog,cat', limit: '10'}/.test(snippet));
t.false(/SOME_INTEGER_VALUE/.test(snippet));
t.end();
});
});

0 comments on commit b999cd0

Please sign in to comment.