dimanche 1 mars 2015

Does Swagger UI support @PathVariable binding?

Currently when I'm testing the Swagger UI for a GET request that binds the "id" path variable to a data object, the dataType of the "id" field is Model, instead of a Long.


For instance, here is the method in the RestController:



@RequestMapping(value = "/{id}", method = GET)
public AwardVO getAwardById(@PathVariable("id") Award award) {
LOG.info("inside the get award method: "+award);
if (award == null) {
throw new AwardNotFoundException();
}

return new AwardVO(award);
}


Here is the resulting documentation:


swagger ui example


So when I pass a Long to the input field, I don't receive the desired record. Is this type of binding supported in Swagger, or do I need to just need to do a lookup for the record and pass the PathVariable as a Long?


Version of Swagger: compile "com.mangofactory:swagger-springmvc:0.9.5"


SwaggerConfig:



@Configuration
@EnableSwagger
public class SwaggerConfig extends WebMvcConfigurerAdapter {

private SpringSwaggerConfig springSwaggerConfig;

@Autowired
public void setSpringSwaggerConfig(SpringSwaggerConfig springSwaggerConfig) {
this.springSwaggerConfig = springSwaggerConfig;
}

@Bean
public SwaggerSpringMvcPlugin customImplementation() {
return new SwaggerSpringMvcPlugin(this.springSwaggerConfig).apiInfo(
apiInfo())
.genericModelSubstitutes(ResponseEntity.class)
.includePatterns("/v1/.*", "/register/.*");
}

private ApiInfo apiInfo() {
ApiInfo apiInfo = new ApiInfo("API", "API",
"API terms of service", "email@gmail.com",
"API Licence Type", "API License URL");
return apiInfo;
}

@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}


Thanks.


Aucun commentaire:

Enregistrer un commentaire