在Spring ROO项目上没有被swagger检测到的API

时间:2015-05-28 15:27:59

标签: swagger

我已经尝试了很多东西,但由于某种原因,没有被swagger检测到API。我是否必须指定swagger扫描包?或者一些网址包括模式?

我的Swager配置:

@Configuration
@EnableSwagger
@EnableWebMvc
public class SwaggerConfiguration {

private final Logger log = LoggerFactory
        .getLogger(SwaggerConfiguration.class);

/**
 * Swagger Spring MVC configuration.
 */
@Bean
public SwaggerSpringMvcPlugin swaggerSpringMvcPlugin(
        SpringSwaggerConfig springSwaggerConfig) {
    log.debug("Starting Swagger");
    StopWatch watch = new StopWatch();
    watch.start();
    SwaggerSpringMvcPlugin swaggerSpringMvcPlugin = new SwaggerSpringMvcPlugin(
            springSwaggerConfig).apiInfo(apiInfo())
            .genericModelSubstitutes(ResponseEntity.class);

    swaggerSpringMvcPlugin.build();
    watch.stop();
    log.debug("Started Swagger in {} ms", watch.getTotalTimeMillis());
    return swaggerSpringMvcPlugin;
}

/**
 * API Info as it appears on the swagger-ui page.
 */
private ApiInfo apiInfo() {
    return new ApiInfo("Title", "Description", "terms of service",
            "contact", "license", "licenseUrl");
}

}

样本控制器

@RequestMapping("/settings")
@Controller
@Api(value = "/settings", description = "Endpoint for settings management")
public class SettingsController {

@ApiOperation(value = "API Operation")
@RequestMapping(value = "/changepassword", method = RequestMethod.POST)
public @ResponseBody Map<String, Object> changePassword(@RequestParam Map<String, String> userProperties,
        Model model, HttpServletRequest httpServletRequest, Locale locale) {
    Map<String, Object> responseMap = new HashMap<String, Object>();
    return responseMap;
}

}

我得到一个空的回复

{

"apiVersion": "1.0",
"swaggerVersion": "1.2",
"apis": [ ],
"authorizations": [ ],
"info": 

{
    "title": "Title",
    "description": "Description",
    "termsOfServiceUrl": "terms of service",
    "contact": "contact",
    "license": "license",
    "licenseUrl": "licenseUrl"
}

}

我使用的是swagger-springmvc版本1.0.2和春季版本4.1.6.RELEASE

1 个答案:

答案 0 :(得分:1)

按照以下网址中的说明操作:

Here