Skip to content
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

feat: OpenAPI import: create a default environment #1240

Closed

Conversation

AndrejsK
Copy link

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:

  • The pull request only addresses one issue or adds one feature.
  • The pull request does not introduce any breaking changes
  • I have added screenshots or gifs to help explain the change if applicable.
  • I have read the contribution guidelines.
  • 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.

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.
@nikolaihen
Copy link

Any updates on getting this merged...?

This is a pain when working with large APIs with different environments...

Copy link

@bSolt bSolt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your solution is not any better than the way it currently works. I need the whole host to come from a variable, and your solution would break that. You can just replace your hosts in your collection this way with your own script if you need it. That's what I ended up doing anyway

@AndrejsK
Copy link
Author

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?

@TheBlackReverand
Copy link

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
            }
        ]
    }
]

@TheBlackReverand
Copy link

I make a PR with my proposition #2088 with that you can create and describe multiple environment.

@helloanoop
Copy link
Contributor

Closing this PR as this has been addressed in #3267

@helloanoop helloanoop closed this Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] OpenAPI Import: make server protocol and host easily changeable
6 participants