Per quanto riguarda l'integrazione di Swagger in Spring MVC:Swagger per il progetto Spring MVC
Swagger non visualizza la documentazione GET/PUT/POST
per @RequestMapping
Nella mia applicazione webservice Spring MVC Resto, ho un regolatore di accesso e un controller per studenti. Ho appena configurato Swagger per generare la documentazione dell'API Rest. Riferimento: http://java.dzone.com/articles/how-configure-swagger-generate
Domanda: Tuttavia, Swagger sta visualizzando solo il percorso a livello di classe, e credo che la sua non wven la visualizzazione del livello di classe @RequestMapping
. , I mapping del livello del metodo vengono ignorati. Qualche motivo per cui?
@Controller
@RequestMapping(value = "/login")
public class LoginController {
@RestController
@RequestMapping(value = "/students/")
public class StudentController {
@RequestMapping(value = "{departmentID}", method = RequestMethod.GET)
public MyResult getStudents(@PathVariable String departmentID) {
// code
}
@RequestMapping(value = "student", method = RequestMethod.GET)
public MyResult getStudentInfo(
@RequestParam(value = "studentID") String studentID,
@RequestParam(value = "studentName") String studentName) {
//code
}
@RequestMapping(value = "student", method = RequestMethod.POST)
public ResponseEntity<Student> updateStudentInfo(@RequestBody Student student) {
//code
}
Swagger Configurazione:
@Configuration
@EnableSwagger
public class SwaggerConfiguration {
private SpringSwaggerConfig swaggerConfig;
@Autowired
public void setSpringSwaggerConfig(SpringSwaggerConfig swaggerConfig) {
this.swaggerConfig = swaggerConfig;
}
@Bean
// Don't forget the @Bean annotation
public SwaggerSpringMvcPlugin customImplementation() {
return new SwaggerSpringMvcPlugin(this.swaggerConfig).apiInfo(
apiInfo()).includePatterns("/.*");
}
private ApiInfo apiInfo() {
ApiInfo apiInfo = new ApiInfo("my API", "API for my app", "", "[email protected]", "License type",
"something like a License URL");
return apiInfo;
}
uscita:
http://localhost:8080/studentapplication/api-docs
{
apiVersion: "1.0",
swaggerVersion: "1.2",
apis: [
{
path: "/default/login-controller",
description: "Login Controller"
},
{
path: "/default/student-controller",
description: "Student Controller"
}
],
info: {
title: "Student API",
description: "API for Student",
termsOfServiceUrl: "StudentApp API terms of service",
contact: "[email protected]",
license: "sometext",
licenseUrl: "License URL"
}
}
Aggiornamento:
è necessario anche il config di seguito nel file XML primavera di configurazione, come accennato in https://github.com/martypitt/swagger-springmvc
<!-- to enable the default documentation controller-->
<context:component-scan base-package="com.mangofactory.swagger.controllers"/>
<!-- to pick up the bundled spring configuration-->
<context:component-scan base-package="com.mangofactory.swagger.configuration"/>
<!-- Direct static mappings -->
<mvc:resources mapping="*.html" location="/, classpath:/swagger-ui"/>
<!-- Serve static content-->
<mvc:default-servlet-handler/>
controllare l'output di http: // localhost: 8080/studentapplication/API-docs/default/login-controller e http: // localhost: 8080/studentapplication/api-docs // default/studente-controller – Ron
Stato HTTP 404 – spiderman
OK. Non so quanto gli sviluppatori di swagger-springmvc guardino in SO, quindi se non si ottiene una risposta in modo tempestivo, suggerirei di aprire solo il problema sul loro repository. – Ron