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

3
  • Which language/framework are you using - Springfox, Swashbuckle, etc.?
    – Helen
    Sep 13, 2018 at 20:54
  • I am using java without any framework,
    – MIKEL
    Sep 13, 2018 at 21:01
  • The @OpenAPIDefinition annotation, which is the most general, does not contain the host or basePath properties
    – MIKEL
    Sep 13, 2018 at 21:12

1 Answer 1

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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.