Skip to content

Commit

Permalink
Merge pull request #45 from RolphH/feature/add-example-uri-values
Browse files Browse the repository at this point in the history
Replace path parameters with example values
  • Loading branch information
ErikWittern authored Jun 22, 2020
2 parents 8784611 + db6288f commit 73d996c
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion openapi-to-har.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const createHar = function (openApi, path, method, queryParamValues) {

const har = {
method: method.toUpperCase(),
url: baseUrl + path,
url: baseUrl + getFullPath(openApi, path),
headers: getHeadersArray(openApi, path, method),
queryString: getQueryStrings(openApi, path, method, queryParamValues),
httpVersion: 'HTTP/1.1',
Expand Down Expand Up @@ -176,6 +176,33 @@ const getQueryStrings = function (openApi, path, method, values) {
return queryStrings
}

/**
* Return the path with the parameters example values used if specified.
*
* @param {Object} openApi OpenApi document
* @param {string} path Key of the path
* @return {string} Full path including example values
*/
const getFullPath = function (openApi, path) {
let fullPath = path

if (typeof openApi.paths[path].parameters !== 'undefined') {
for (let i in openApi.paths[path].parameters) {
let param = openApi.paths[path].parameters[i]
if (typeof param['$ref'] === 'string' &&
/^#/.test(param['$ref'])) {
param = resolveRef(openApi, param['$ref'])
}
if (typeof param.in !== 'undefined' && param.in.toLowerCase() === 'path') {
if (typeof param.example !== 'undefined') { // only if the schema has an example value
fullPath = fullPath.replace("{" + param.name + "}", param.example)
}
}
}
}
return fullPath
}

/**
* Get an array of objects describing the header for a path and method pair
* described in the given OpenAPI document.
Expand Down

0 comments on commit 73d996c

Please sign in to comment.