-
Notifications
You must be signed in to change notification settings - Fork 23
feat: adding support for server variables into oas-to-har #1241
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"openapi": "3.0.3", | ||
"info": { | ||
"version": "1.0.0", | ||
"title": "Server variables" | ||
}, | ||
"servers": [ | ||
{ | ||
"url": "https://{name}.example.com:{port}/{basePath}", | ||
"variables": { | ||
"name": { | ||
"default": "demo" | ||
}, | ||
"port": { | ||
"default": "443" | ||
}, | ||
"basePath": { | ||
"default": "v2" | ||
} | ||
} | ||
}, | ||
{ | ||
"url": "http://{name}.local/{basePath}", | ||
"variables": { | ||
"name": { | ||
"default": "demo" | ||
}, | ||
"basePath": { | ||
"default": "v2" | ||
} | ||
} | ||
} | ||
], | ||
"paths": { | ||
"/": { | ||
"post": { | ||
"summary": "Should fetch variables from defaults and user values", | ||
"responses": { | ||
"200": { | ||
"description": "OK" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,7 +97,21 @@ module.exports = ( | |
operation = new Operation(oas, operationSchema.path, operationSchema.method, operationSchema); | ||
} | ||
|
||
const formData = { ...defaultFormDataTypes, ...values }; | ||
const formData = { | ||
...defaultFormDataTypes, | ||
server: { | ||
selected: 0, | ||
variables: oas.defaultVariables(0), | ||
}, | ||
...values, | ||
}; | ||
|
||
// If the incoming `server.variables` is missing variables let's pad it out with defaults. | ||
formData.server.variables = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: should we just move up into the object above or was this done to improve readability? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since I'm loading |
||
...oas.defaultVariables(formData.server.selected), | ||
...formData.server.variables, | ||
}; | ||
|
||
const har = { | ||
cookies: [], | ||
headers: [], | ||
|
@@ -106,7 +120,7 @@ module.exports = ( | |
postData: {}, | ||
bodySize: 0, | ||
method: operation.method.toUpperCase(), | ||
url: `${oas.url()}${operation.path}`.replace(/\s/g, '%20'), | ||
url: `${oas.url(formData.server.selected, formData.server.variables)}${operation.path}`.replace(/\s/g, '%20'), | ||
httpVersion: 'HTTP/1.1', | ||
}; | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mdash 👏