New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Honor variable defaults from servers declaration during OpenAPI3 import #2151
Honor variable defaults from servers declaration during OpenAPI3 import #2151
Conversation
Deploy preview for insomnia-storybook ready! Built with commit ec2e8d5 |
* @param {Object} api - openapi3 object | ||
* @returns {UrlWithStringQuery} the resolved server URL | ||
*/ | ||
function getDefaultServerUrl(api) { |
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.
Curious why you used a different approach than openapi-2-kong
does. Is it so you could replace vars with a default value if they don't have one defined? If so, can we make sure the fixture defined handles the case where there is no default?
export function fillServerVariables(server: OA3Server): string { |
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.
There are two approaches (there should be a unified one) to fill server variables in openapi-2-kong
:
- iterates over
server.variables
, throws if default missing, and replaces items in the url - iterates over variables in the url, searches for a default in
server.variables
, defaults tohttp
or.*
if missing
I used a hybrid approach for the openapi3 importer, for several reasons:
- To successfully parse the URL, we need a valid, resolved URL, and smart defaults are much more involved,
- A truly valid OpenAPI spec should have variable defaults defined for a server url
o2k
(kubernetes) can handle missing defaults (as per the requirements) using.*
fallback
The openapi3 importer honors variable defaults, but if a variable exists in the URL and is missing in server.variables
, an error is thrown and presented to the user.
0afb781
to
ae894dd
Compare
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.
This PR adds functionality to honor variable defaults from the servers declaration during an OpenAPI3 spec import.
The
openapi-2-kong
package already does this, the functionality is simply adapted forinsomnia-importers
.The openapi3 importer honors variable defaults, but if a variable exists in the URL and is missing in
server.variables
, an error is thrown and presented to the user.Example spec
Insomnia Core
Insomnia Designer
Doesn't do anything during design -> debug navigation, silently swallows any errors caused by parsing an invalid spec. This is existing behavior, which we should improve.
Closes #1640