How to define basePath in swagger 2.0
Asked Answered
K

1

5

Reviewing the swagger documentation specifically the annotations I did not find how to define the host and basePath properties. Any idea where to set them?

documentation consulted: Swagger-2.X---Annotations

Here is a json generated with the variables: petstore.swagger.io/v2/swagger.json

Ketchum answered 13/9, 2018 at 20:34 Comment(3)
Which language/framework are you using - Springfox, Swashbuckle, etc.?Tirpitz
I am using java without any framework,Ketchum
The @OpenAPIDefinition annotation, which is the most general, does not contain the host or basePath propertiesKetchum
C
6

Swagger 2.x supports OpenAPI Specification 3.0 (see here for reference), where host, basePath and schemes keywords have been replaced by the server element.

In OpenAPI 3.0, you can use an array of server elements to specify one or more base URLs for your API.

A server URL has the following structure:

    scheme://host[:port][/basePath]

You can register the servers using the annotation @Server:

Alternatively you can define the servers in your Swagger configuration file e.g:

YAML

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

JSON

  "servers" : [ {
    "url" : "https://api.example.com/v1",
    "description" : "example"
  } ]
Carbylamine answered 4/7, 2019 at 14:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.