Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use springdoc as default library for swagger-ui #1191

Merged
merged 1 commit into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
{{^springBootV2}}
springfox.documentation.swagger.v2.path=/api-docs
{{/springBootV2}}
{{#springBootV2}}
{{#useOas2}}
springfox.documentation.swagger.v2.path=/api-docs
server.contextPath={{^contextPath}}/{{/contextPath}}{{#contextPath}}{{contextPath}}{{/contextPath}}
{{/useOas2}}
{{^useOas2}}
springfox.documentation.open-api.v3.path=/api-docs
springdoc.api-docs.path=/api-docs
{{/useOas2}}
{{/springBootV2}}
server.servlet.contextPath={{^contextPath}}/{{/contextPath}}{{#contextPath}}{{contextPath}}{{/contextPath}}
server.port={{serverPort}}
spring.jackson.date-format={{basePackage}}.RFC3339DateFormat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
springfox.documentation.swagger.v2.path=/api-docs
{{/useOas2}}
{{^useOas2}}
springfox.documentation.open-api.v3.path=/api-docs
springdoc.api-docs.path=/api-docs
{{/useOas2}}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ public class HomeController {
@RequestMapping(value = "/")
public String index() {
{{#useOas2}}
System.out.println("swagger-ui.html");
return "redirect:swagger-ui.html";
{{/useOas2}}
{{^useOas2}}
System.out.println("/swagger-ui/index.html");
return "redirect:/swagger-ui/";
{{/useOas2}}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@
<springfox-version>2.9.2</springfox-version>
{{/useOas2}}
{{^useOas2}}
{{^springBootV2}}
<springdoc-version>1.2.9</springdoc-version>
{{/springBootV2}}
{{#springBootV2}}
<springfox-version>3.0.0</springfox-version>
{{/springBootV2}}
<springdoc-version>1.7.0</springdoc-version>
{{/useOas2}}
</properties>
<parent>
Expand Down Expand Up @@ -79,37 +74,19 @@
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-version}</version>
</dependency>
{{/useOas2}}
{{^useOas2}}
{{#springBootV2}}
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-oas</artifactId>
<version>${springfox-version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-version}</version>
</dependency>
{{/springBootV2}}
{{/useOas2}}
{{#useOas2}}
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-version}</version>
</dependency>
{{/useOas2}}
{{^useOas2}}
{{^springBootV2}}
<!-- SpringDoc dependencies -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>${springdoc-version}</version>
</dependency>
{{/springBootV2}}
{{/useOas2}}

{{#withXml}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import org.springframework.context.annotation.ComponentScan;
{{#useOas2}}
import springfox.documentation.swagger2.annotations.EnableSwagger2;
{{/useOas2}}
{{^useOas2}}
import springfox.documentation.oas.annotations.EnableOpenApi;
{{/useOas2}}

import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
Expand All @@ -24,9 +21,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
{{#useOas2}}
@EnableSwagger2
{{/useOas2}}
{{^useOas2}}
@EnableOpenApi
{{/useOas2}}
@ComponentScan(basePackages = { "{{basePackage}}", "{{apiPackage}}" , "{{configPackage}}"})
public class Swagger2SpringBoot implements CommandLineRunner {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,27 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
{{>generatedAnnotation}}
@Configuration
public class SwaggerUiConfiguration implements WebMvcConfigurer {

@Override
{{#useOas2}}
public void addResourceHandlers(ResourceHandlerRegistry registry) {
{{#useOas2}}

registry
.addResourceHandler("/swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");

registry
.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
{{/useOas2}}
{{^useOas2}}
registry.
addResourceHandler("/swagger-ui/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
.resourceChain(false);
{{/useOas2}}
}

@Override
{{/useOas2}}
{{^useOas2}}
public void addViewControllers(ViewControllerRegistry registry) {
{{^useOas2}}
registry.addViewController("/swagger-ui/").setViewName("forward:/swagger-ui/index.html");
{{/useOas2}}
}
{{/useOas2}}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
springfox.documentation.open-api.v3.path=/api-docs
springdoc.api-docs.path=/api-docs
server.servlet.contextPath={{^contextPath}}/{{/contextPath}}{{#contextPath}}{{contextPath}}{{/contextPath}}
server.port={{serverPort}}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<maven.compiler.release>17</maven.compiler.release>
<springboot-version>3.1.1</springboot-version>
<swagger-annotations-version>2.2.14</swagger-annotations-version>
<springdoc-version>1.7.0</springdoc-version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -74,6 +75,12 @@
<version>2.10.1</version>
</dependency>
{{/notNullJacksonAnnotation}}
<!-- SpringDoc dependencies -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>${springdoc-version}</version>
</dependency>

<dependency>
<groupId>io.swagger.core.v3</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
{{>generatedAnnotation}}
@Configuration
public class SwaggerUiConfiguration implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.
addResourceHandler("/swagger-ui/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
.resourceChain(false);
}

@Override
public void addViewControllers(ViewControllerRegistry registry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package {{configPackage}};
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

{{#useOas2}}
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
{{/useOas2}}
{{^useOas2}}
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
Expand All @@ -22,14 +24,11 @@ import java.util.Optional;
@Configuration
public class SwaggerDocumentationConfig {

{{#useOas2}}
@Bean
public Docket customImplementation(){
{{#useOas2}}

return new Docket(DocumentationType.SWAGGER_2)
{{/useOas2}}
{{^useOas2}}
return new Docket(DocumentationType.OAS_30)
{{/useOas2}}
.select()
.apis(RequestHandlerSelectors.basePackage("{{apiPackage}}"))
.build()
Expand Down Expand Up @@ -62,8 +61,8 @@ public class SwaggerDocumentationConfig {
.contact(new Contact("","", "{{infoEmail}}"))
.build();
}

{{^useOas2}}
{{/useOas2}}
{{^useOas2}}
@Bean
public OpenAPI openApi() {
return new OpenAPI()
Expand All @@ -78,6 +77,6 @@ public class SwaggerDocumentationConfig {
.contact(new io.swagger.v3.oas.models.info.Contact()
.email("{{infoEmail}}")));
}
{{/useOas2}}
{{/useOas2}}

}