这里我只是匆忙列出来一些代码,还没看呢。先记录。
@Configuration
@EnableSwagger2
public class SwaggerConfig {
public static final Contact DEFAULT_CONTACT = new Contact(
"Ranga Karanam", "http://www.in28minutes.com", "in28minutes@gmail.com");
public static final ApiInfo DEFAULT_API_INFO = new ApiInfo(
"Awesome API Title", "Awesome API Description", "1.0",
"urn:tos", DEFAULT_CONTACT,
"Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0");
private static final Set<String> DEFAULT_PRODUCES_AND_CONSUMES =
new HashSet<String>(Arrays.asList("application/json",
"application/xml"));
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(DEFAULT_API_INFO)
.produces(DEFAULT_PRODUCES_AND_CONSUMES)
.consumes(DEFAULT_PRODUCES_AND_CONSUMES);
}
}
@SwaggerDefinition(
info = @Info(
description = "Awesome Resources",
version = "V12.0.12",
title = "Awesome Resource API",
contact = @Contact(
name = "Ranga Karanam",
email = "ranga@in28minutes.com",
url = "http://www.in28minutes.com"
),
license = @License(
name = "Apache 2.0",
url = "http://www.apache.org/licenses/LICENSE-2.0"
)
),
consumes = {"application/json", "application/xml"},
produces = {"application/json", "application/xml"},
schemes = {SwaggerDefinition.Scheme.HTTP, SwaggerDefinition.Scheme.HTTPS},
externalDocs = @ExternalDocs(value = "Read This For Sure", url = "http://in28minutes.com")
)
public interface ApiDocumentationConfig {
}
@GetMapping("/students/{id}")
@ApiOperation(value = "Find student by id",
notes = "Also returns a link to retrieve all students with rel - all-students")
public Resource<Student> retrieveStudent(@PathVariable long id) {
@Entity
@ApiModel(description="All details about the student. ")
public class Student {
@ApiModelProperty(notes="Name should have atleast 2 characters")
@Size(min=2, message="Name should have atleast 2 characters")
private String name;