I am building a Spring Boot application and documenting it using a Swagger UI using the Springfox Swagger UI. I've got everything documented, but want to customize the title and description but can't figure out how. For example, in this image: https://springfox.github.io/springfox/docs/current/images/springfox-swagger-ui.png the title is "Springfox petstore API" and the description is Lorem Ipsum. But in my Swagger UI, both the title and the description say "API Documentation". I have tried using the @SwaggerDefinition annotation, but it does not seem to do anything.
Asked
Active
Viewed 2.2k times
11
-
For swagger 2.0 and later, see this answer: https://stackoverflow.com/questions/54185836/beanconfig-or-similar-in-swagger-2-0-openapi-3-0/54216142?noredirect=1#comment122346942_54216142 – Matthew Sep 17 '21 at 10:54
1 Answers
16
I recommend you to use swagger editor, then you can auto generate Spring Boot server from the API docs, using "Generate Server" option from Top Menu. It is really great for generating an API for the first time.
If you want to set from the YAML you must provide this fields at the info section:
info:
version: "1.0.0"
title: My API title
description: "Awesome description"
From the code, check the generated classes from Swagger editor and compare it with your code. You could set description and title, setting the corresponding attributes on the ApiInfo Builder object, which is inside the class SwaggerDocumentationConfig.
Here you have the code:
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2017-10-05T14:03:51.916-03:00")
@EnableSwagger2
@Configuration
public class SwaggerDocumentationConfig {
ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("My API Title")
.description("Awesome description")
.license("Apache 2.0")
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
.termsOfServiceUrl("")
.version("1.0.0")
.contact(new Contact("", "", "contact@contact.com.uy"))
.build();
}
@Bean
public Docket customImplementation() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.mypackage.api"))
.build()
.apiInfo(apiInfo());
}
}
If none of this makes sense to you, show me a little more of your code to know how you are using Springfox and I can help you better.
Bests regards!

Emiliano Viotti
- 1,619
- 2
- 16
- 30
-
I tried to generate a Spring server from the example given, but nothing happened. What is supposed to happen? – faiuwle Nov 09 '17 at 21:16
-
Make sure your browser is not blocking pop-ups. By selecting the option "Generate-Server-> spring" from the main menu, you will download a zip with a SpringBoot project. Then you can undo it and compare it against your code. Keep in mind that much of the autogenerated code may not be useful for your particular case. – Emiliano Viotti Nov 09 '17 at 21:20
-
-
-
Could you please give more details about how you are actually tagging your code, in order to enable Swagger? For example how your SpringBoot Main application looks? – Emiliano Viotti Nov 10 '17 at 17:01
-
Swagger editor online with the code generator option gives you a complete example about tagging your code but it is not the only code generator. Check [this](https://github.com/swagger-api/swagger-codegen) other code gen. If you still can not download the code you could generate the server using the Petstore JSON specification as an example. – Emiliano Viotti Nov 10 '17 at 17:02
-
Also [this](http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api) example about configure springfox in SpringBoot may be usefull for you. – Emiliano Viotti Nov 10 '17 at 17:07
-
I got it to work, I just needed to add a version. Thanks! Unfortunately the swagger editor still doesn't work. – faiuwle Nov 10 '17 at 20:44
-
As I see it, the title gets set on the OpenAPI but the title of the SwaggerUI HTML page is still "Swagger UI" – Niccolò Sep 18 '19 at 08:33