Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
822 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...