Added code for BAEL-4095
This commit is contained in:
parent
d175ff0b7d
commit
97252050f4
|
@ -61,6 +61,7 @@
|
|||
<module>spring-boot-runtime</module>
|
||||
<module>spring-boot-security</module>
|
||||
<module>spring-boot-springdoc</module>
|
||||
<module>spring-boot-swagger</module>
|
||||
<module>spring-boot-testing</module>
|
||||
<module>spring-boot-vue</module>
|
||||
<module>spring-boot-xml</module>
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung.spring-boot-modules</groupId>
|
||||
<artifactId>spring-boot-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>spring-boot-swagger</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>spring-boot-swagger</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<description>Module For Spring Boot Swagger</description>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-boot-starter</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,13 @@
|
|||
package com.baeldung.swagger2boot;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class SpringBootSwaggerApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringBootSwaggerApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package com.baeldung.swagger2boot.configuration;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.service.Contact;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger.web.DocExpansion;
|
||||
import springfox.documentation.swagger.web.ModelRendering;
|
||||
import springfox.documentation.swagger.web.OperationsSorter;
|
||||
import springfox.documentation.swagger.web.TagsSorter;
|
||||
import springfox.documentation.swagger.web.UiConfiguration;
|
||||
import springfox.documentation.swagger.web.UiConfigurationBuilder;
|
||||
|
||||
@Configuration
|
||||
public class SwaggerConfiguration {
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfo("My REST API", "Some custom description of API.", "API TOS", "Terms of service", new Contact("Umang Budhwar", "www.baeldung.com", "umangbudhwar@gmail.com"), "License of API", "API license URL", Collections.emptyList());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Docket api() {
|
||||
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.any())
|
||||
.paths(PathSelectors.any())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* SwaggerUI information
|
||||
*/
|
||||
|
||||
@Bean
|
||||
UiConfiguration uiConfig() {
|
||||
return UiConfigurationBuilder.builder()
|
||||
.deepLinking(true)
|
||||
.displayOperationId(false)
|
||||
.defaultModelsExpandDepth(1)
|
||||
.defaultModelExpandDepth(1)
|
||||
.defaultModelRendering(ModelRendering.EXAMPLE)
|
||||
.displayRequestDuration(false)
|
||||
.docExpansion(DocExpansion.NONE)
|
||||
.filter(false)
|
||||
.maxDisplayedTags(null)
|
||||
.operationsSorter(OperationsSorter.ALPHA)
|
||||
.showExtensions(false)
|
||||
.tagsSorter(TagsSorter.ALPHA)
|
||||
.supportedSubmitMethods(UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS)
|
||||
.validatorUrl(null)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.baeldung.swagger2boot.controller;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
@ApiIgnore
|
||||
@RestController
|
||||
public class RegularRestController {
|
||||
|
||||
@ApiIgnore
|
||||
@ApiOperation(value = "This method is used to get the author name.")
|
||||
@GetMapping("/getAuthor")
|
||||
public String getAuthor() {
|
||||
return "Umang Budhwar";
|
||||
}
|
||||
|
||||
@ApiOperation(value = "This method is used to get the current date.", hidden = true)
|
||||
@GetMapping("/getDate")
|
||||
public LocalDate getDate() {
|
||||
return LocalDate.now();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "This method is used to get the current time.")
|
||||
@GetMapping("/getTime")
|
||||
public LocalTime getTime() {
|
||||
return LocalTime.now();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue