Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
801 views
in Technique[技术] by (71.8m points)

rest - Setting the Api Version with Swagger UI

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 now trying to add versioning to the API.

The first step I'm taking is I'm trying to update the API version that is displayed by the dynamically generated swagger (html) page. I've traced the call flow all the way to the swagger-ui.js file but I can't figure out how to change the displayed API version at the bottom of the dynamically generated page.

The default that is currently displayed at the bottom is ' API VERSION: 1.0.0 '.

I've read something about a ServiceStack here but unfortunately the code base I'm working on doesn't use anything of the sort.

Could anyone please kindly point me to where/what I would need to change/update in order to update the displayed API version number?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...