# Setting {{baseUrl}} when generating a collection from an OpenAPI spec

**URL:** <https://community.postman.com/t/setting-baseurl-when-generating-a-collection-from-an-openapi-spec/35168>\
**Category:** Help Hub\
**Tags:** collections, openapi\
**Created:** [May 10, 2022, 3:30am UTC](https://community.postman.com/t/setting-baseurl-when-generating-a-collection-from-an-openapi-spec/35168 "2022-05-10T03:30:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![telecoms-specialist2](https://avatars.discourse-cdn.com/v4/letter/t/85f322/32.png) [@telecoms-specialist2](https://community.postman.com/u/telecoms-specialist2)\
**Post date:** [May 10, 2022, 3:30am UTC](https://community.postman.com/t/setting-baseurl-when-generating-a-collection-from-an-openapi-spec/35168/1 "2022-05-10T03:30:10Z")

</div>

# Context

I’m working on consolidating our OpenAPI spec to Postman.

# Problem

Currently, when generating a new collection from an OpenAPI spec, all the new APIs within such collection has `{{baseUrl}}` in their request URL. This presents a slight inconvenience, since we already have environments setup with an appropriate endpoint.

I’ve looked around, but it does not seem like it is possible to change this variable to that we already have.

# Question

What is the best/recommended way to approach this, aside from manually changing every API to use the correct variable?

Thank you.

---

<div class="post-metadata">

**Author:** ![grantavery](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/grantavery/32/15135_2.png) [@grantavery](https://community.postman.com/u/grantavery)\
**Post date:** [March 8, 2023, 2:20pm UTC](https://community.postman.com/t/setting-baseurl-when-generating-a-collection-from-an-openapi-spec/35168/2 "2023-03-08T14:20:22Z")

</div>

I ran into this same issue trying to convert our manually-built Postman collections and environments to OpenAPI-generated ones, and ended up solving it like this in my Spring Java application (where we use the `io.swagger.v3.oas` library for OpenAPI generation):

 ![Screen Shot 2023-03-08 at 9.08.21 AM](https://us1.discourse-cdn.com/getpostman/original/3X/b/7/b72216947ed5e690553c9a8fe5b399defb747b41.png)

This shows up like this in the Swagger UI, with each of the ServerVariables below that heading:

 ![Screen Shot 2023-03-08 at 9.12.20 AM](https://us1.discourse-cdn.com/getpostman/original/3X/0/7/07ad939000ee6dc5d7e0050257142e906ee5f1f7.png)

And then when we import the api-docs.json into Postman, it makes an API (or Collection if you use the [GitHub - postmanlabs/openapi-to-postman: Plugin for converting OpenAPI 3.0 specs to the Postman Collection (v2) format](https://github.com/postmanlabs/openapi-to-postman) library), which has these Collection variables:

 ![Screen Shot 2023-03-08 at 9.13.54 AM](https://us1.discourse-cdn.com/getpostman/original/3X/b/8/b886fb0409aaec68dd666d975ae738f6da50cc0b.png)

(see the next comment for more, there is a limit on file uploads)

---

<div class="post-metadata">

**Author:** ![grantavery](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/grantavery/32/15135_2.png) [@grantavery](https://community.postman.com/u/grantavery)\
**Post date:** [March 8, 2023, 2:21pm UTC](https://community.postman.com/t/setting-baseurl-when-generating-a-collection-from-an-openapi-spec/35168/3 "2023-03-08T14:21:15Z")

</div>

(pt. 2)

Then, as long as your environments in Postman have this variable setup:

 ![Screen Shot 2023-03-08 at 9.16.02 AM](https://us1.discourse-cdn.com/getpostman/original/3X/f/e/fe74b4488c83ff1d5b3a202058ebd3a9b3e1e14f.png)

You can make requests like this and it all works, regardless of which environment you have selected:  
 ![Screen Shot 2023-03-08 at 9.17.19 AM](https://us1.discourse-cdn.com/getpostman/original/3X/f/a/fa74e4178c05868c253f87506b377b3e3fe8a772.png)

Hope that helps!

The next issue I’m trying to work through is having URL params get auto-populated from examples in the OpenAPI definition (instead of these `<string>` placeholders), but I’m having struggles with that so reach out if you get further than me 🙂  
 ![Screen Shot 2023-03-08 at 9.19.14 AM](https://us1.discourse-cdn.com/getpostman/original/3X/8/d/8d097ed0990d81bc87de9df2a7a443b0084f179a.png)
