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

3) Ajout d'annotations swagger pour détailler la documentation générée #1

Open
wants to merge 2 commits into
base: springfox-configured
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/greetings/Application.java
Expand Up @@ -5,6 +5,8 @@
import org.springframework.context.annotation.Bean;
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.swagger2.annotations.EnableSwagger2;
Expand All @@ -24,6 +26,7 @@ public Docket api() {
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.regex("/greeting.*"))
.build()
.apiInfo(new ApiInfo("Greetings Api Documentation", "Documentation of the awesome greetings API.", "1.0", "urn:tos", new Contact("", "", ""), "Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0"))
.useDefaultResponseMessages(false);
}
}
5 changes: 5 additions & 0 deletions src/main/java/greetings/Greeting.java
@@ -1,8 +1,13 @@
package greetings;

import io.swagger.annotations.ApiModelProperty;

public class Greeting {

@ApiModelProperty(value = "The request number", position = 0)
private final long id;

@ApiModelProperty(value = "The greeting content", position = 1)
private final String content;

public Greeting(long id, String content) {
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/greetings/GreetingController.java
@@ -1,5 +1,8 @@
package greetings;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
Expand All @@ -8,14 +11,16 @@

import java.util.concurrent.atomic.AtomicLong;

@Api(tags = "Greetings", description = "Greets the user by it's name")
@RestController
public class GreetingController {

private static final String TEMPLATE = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();

@ApiOperation(notes = "A longer description of this greeting method. \n\nIt may use `markdown` notation.", value = "greeting")
@RequestMapping(value = "/greeting", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public Greeting greeting(@RequestParam(value = "name", defaultValue = "World") String name) {
public Greeting greeting(@ApiParam("The name to greet") @RequestParam(value = "name", defaultValue = "World") String name) {
return new Greeting(counter.incrementAndGet(),
String.format(TEMPLATE, name));
}
Expand Down