-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SpringFox and query params to HelloController
- Loading branch information
1 parent
31e3ba4
commit 2bcd083
Showing
6 changed files
with
74 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 9 additions & 4 deletions
13
src/main/java/com/raf/springbootcamp/demo/HelloController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
package com.raf.springbootcamp.demo; | ||
|
||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@Api(tags = "Hello") | ||
public class HelloController { | ||
|
||
@RequestMapping("/") | ||
public String index() { | ||
return "Greetings from Spring Boot!"; | ||
@GetMapping("/") | ||
@ApiOperation("Says 'Hello'") | ||
public String getHello(@RequestParam(value = "name", defaultValue = "World", required = false) String name) { | ||
return String.format("Hello, %s!", name); | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/com/raf/springbootcamp/demo/SpringFoxConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.raf.springbootcamp.demo; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.info.BuildProperties; | ||
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 java.util.Collections; | ||
|
||
@Configuration | ||
public class SpringFoxConfig { | ||
|
||
@Autowired | ||
private BuildProperties buildProperties; | ||
|
||
@Bean | ||
public Docket apiDocket() { | ||
return new Docket(DocumentationType.OAS_30) | ||
.select() | ||
.apis(RequestHandlerSelectors.basePackage(buildProperties.getGroup())) | ||
.paths(PathSelectors.any()) | ||
.build() | ||
.apiInfo(getApiInfo()); | ||
} | ||
|
||
private ApiInfo getApiInfo() { | ||
return new ApiInfo( | ||
"Spring Boot Demo", | ||
"OpenAPI Documentation", | ||
buildProperties.getVersion(), | ||
"", | ||
new Contact("","",""), | ||
"", | ||
"", | ||
Collections.emptyList() | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters