Search code examples
swaggerswagger-uiopenapi

How to migrate swagger 2.0 schemes field into openApi?


In our old swagger 2.0 definitions, we have the following line:

  "schemes" : [ "http", "https" ]

When deployed, we can see in swagger UI a select box that allows us to choose a scheme, which is quite useful when running locally.

Now, I'd like to convert our API to OpenApi. I tried doing so using the Swagger editor at https://swagger.io/ which has an automatic conversion tool, but the scheme line had disappeared. Is it deprecated in OpenApi? I couldn't find any guide on what to use instead. Any ideas what I should do to allow local developers to choose which scheme to use even using OpenApi definitions?


Solution

  • servers replaces the host, basePath and schemes keywords used in OpenAPI 2.0

    In this case, you'd want to define two servers (http and https).

    servers:
      - url: http://api.example.com/v1
      - url: https://api.example.com/v1
    

    Full documentation can be found here.