Setting the Api Version with Swagger UI

后端 未结 3 928
醉酒成梦
醉酒成梦 2020-12-19 22:21

I have a REST API developed through the use of Jersey and we document the REST API through swagger-ui. Unfortunately, we did not start versioning the API from day 1. We are

3条回答
  •  甜味超标
    2020-12-19 23:11

    API version displayed at the bottom of the Swagger UI is coming from the Swagger document.

    Here is an example Swagger document:

    {
        "swagger": "2.0",
        "info": {
            "description": "This is a sample server Petstore server.",
            "version": "1.0.0",
            "title": "Swagger Petstore",
        ...
    

    "version": "1.0.0" is the default value but you can change it using the Swagger @Info annotation:

    @SwaggerDefinition(
        info = @Info(
            description = "This is a sample server Petstore server.",
            version = "1.0.1",
            title = "Swagger Petstore"
    

    This document can be added to any class scanned during the Swagger auto-configuration process as per the Swagger Wiki page:

    The annotation can be on any class scanned during the Swagger auto-configuration process, i.e. it does not have to be on a JAX-RS API class but could just be on a marker/config interface

    You can find some samples here: https://github.com/swagger-api/swagger-samples/tree/master/java. Some are using Jersey and setting the API version.

提交回复
热议问题