bruno
bruno copied to clipboard
feat: OpenAPI import: create a default environment
Description
Fixes #1239
The previous solution constructed a default server baseUrl and directly concatenated it into each request of the collection. This makes it difficult to change it later through the UI if it is wrong or if the same OpenAPI spec can be used in multiple environments.
This solution instead creates a default environment with two variables "protocol" and "host", which are filled according to the previously constructed default baseUrl. This makes it very easy to change for all requests while preserving the server information extracted from the spec.
Contribution Checklist:
- [x] The pull request only addresses one issue or adds one feature.
- [x] The pull request does not introduce any breaking changes
- [ ] I have added screenshots or gifs to help explain the change if applicable.
- [x] I have read the contribution guidelines.
- [x] Create an issue and link to the pull request.
Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.
Publishing to New Package Managers
Please see here for more information.
Any updates on getting this merged...?
This is a pain when working with large APIs with different environments...
Right, but this way you can change it through the UI, that's better than writing a script, if you ask me. Would you be happy with this PR if the whole base url was a single variable?
Hello,
Maybe we can use vars and define an OpenAPI extension for describe envrionments
https://spec.openapis.org/oas/latest.html#specification-extensions
If OpenAPI spec file contain x-bruno-environments, we can use it for environments generation
"servers": [
{
"url": "https://{{hostApim}}{{pathSites}}"
}
],
"x-bruno-environments": [
{
"name": "dev",
"vars": [
{
"name": "hostApim",
"value": "gatewayapi-dev.com",
"enabled": true
},
{
"name": "pathSites",
"value": "/myapi",
"enabled": true
},
{
"name": "apiKey",
"value": "9ef58158-0235-4a75-821d-51a12256b0ku",
"enabled": true
}
]
},
{
"name": "prd",
"vars": [
{
"name": "hostApim",
"value": "gatewayapi-prd.com",
"enabled": true
},
{
"name": "pathSites",
"value": "/myapi",
"enabled": true
},
{
"name": "apiKey",
"value": "",
"enabled": true
}
]
}
]