Search results

Step 3: The servers object (OpenAPI tutorial)

Keep current with the latest trends in technical communication by subscribing to the I'd Rather Be Writing newsletter. 5,000+ subscribers

I'm giving an API documentation workshop in Los Angeles, California, on January 23, 2020. Check it out on EventBrite and register today to receive a $100 early bird discount.

In the servers object, you specify the basepath used in your API requests. The basepath is the part of the URL that appears before the endpoint.

Sample servers object

The following is a sample servers object:

- url:

Each of your endpoints (called “paths” in the spec) will be appended to the server URL when users make “Try it out” requests. For example, if one of the paths is /weather, when Swagger UI submits the request, it will submit the path to {server URL}{path} or

Options with the server URL

You have some flexibility and configuration options for your server URL. You can specify multiple server URLs that might relate to different environments (test, beta, production). If you have multiple server URLs, users can select the environment from a servers drop-down box. For example, you can specify multiple server URLs like this:

  - url:
    description: Production server
  - url:
    description: Beta server
  - url:
    description: Some other server

In Swagger UI, the multiple servers appear as options users can select in a drop-down list:

If you have just one URL, you still see a drop-down box but with just one option.

You can also incorporate variables into the server URL that can be populated at runtime by your server. Additionally, if different paths (endpoints) require different server URLs, you can add the servers object as a property in the path object’s operation object. The locally declared servers URL will override the global servers URL.

See “Overriding Servers” in “API Server and Base URL” (Swagger’s docs) for more details.

View the Appearance in Swagger UI

Paste the servers object (the first code sample above showing just one url) into your Swagger Editor, adding to the code you already have there. Swagger UI will look as follows.

Swagger UI with the servers object
Swagger UI with the servers object
68% Complete

68/150 pages complete. Only 82 more pages to go.


Want to buy me lunch? Click the Donate button below to donate any amount through Paypal.