ApiOperation.response takes a class, so why doesn't ApiImplicitParam.dataType?
Not really sure why it was created like that (long time ago), however changing that now would be a breaking change which is something we'd probably want to avoid.
If it's too painful to straight up change it or you wanted to ease the migration path, you could deprecate it and create a new field that's a Class
@benmccann agreed, we can support both constructs in the annotation.
You might want to keep dataType="string"
and to create a new field named enum
(accepting a enum Class), coherently with the type and enum fields generated in the swagger docs when you annotate with ApiParam a request param declared with that enum Class type.
Accepting a class would be very helpful as I have several endpoints that accept an InputStream parameter (@ApiParam(hidden=true)) for deserialization performance, but want to document them as the actual class expected.
Also, no matter what I add for "datatype=xxxx", the schema.type value is always the literal value "string"
It would be pretty neat if atleast enums would be taken. Even in the official documentation it says that class names can be taken.
http://docs.swagger.io/swagger-core/current/apidocs/index.html?io/swagger/annotations/ApiImplicitParam.html
Hopefully this will be added in the near future ;)
Agree with @todd-richmond . I am facing the same situation, and now have to look for alternatives wherein i use jackson serialization and de-serialization instead of using InputStream, so that i can at-least have a documentation available for my parameters.
It does work if you specify the full path to the class, e.g. "com.example.project.entities.MyEntity".
I am doing the same InputStream method that @todd-richmond is doing and running into the same problems. @stoffus I tried the full class path name and it still didn't work for me. In which version were you using that this was working? Thanks!
@jmacauley I'm using the latest and greatest - 1.5.10.
@stoffus , did it allow you to define body type parameters?
@lloyd31 Sure. Here's an example:
@ApiImplicitParams({
@ApiImplicitParam(
required = true,
dataType = "com.example.project.entities.MyEntity",
paramType = "body"
)
})
I to am running into this same problem when I attempt to workaround the InputStream issue as I mentionned in 1531. In fact the proposed solution there, which I prefer, is to allow ApiParam to specify dataType= to override the datatype of the actual parameter
@fehguy can you explain why this was closed?
duplicate issue here: https://github.com/swagger-api/swagger-core/issues/1564
pull request here: https://github.com/swagger-api/swagger-core/pull/2068
@benmccann Because we can specify type
and format
in the @ApiImplicitParam
which effectively lets you set the type to _anything_. If you think that accepting a class would be dramatically better, we can look at that.
Accepting a class is critical for us, because we're in an OSGI environment and Class.forName() or even Thread.getContextClassloader().findClass() doesn't work for us as the class might be in neither of the related classloaders.
I'm about to attempt the change on my own.
OK I'll reopen this and we can look at merging the PR.
Hey @pjfanning - I noticed that you've already started on this at https://github.com/pjfanning/swagger-core/commit/c25171974c19ae256918eda7c95ca2ea398305fb
Is it close ?
N00b here, so if there's another forum where we should be talking about this let me know.
@RadicalQuiver https://github.com/swagger-api/swagger-core/pull/2068 was merged a few hours ago
tried to use springfox version 2.6.1 with the latest swagger-annotations 1.5.13 and it didn't work
@ApiImplicitParams({
@ApiImplicitParam(name = "test", required = true, paramType = "header")
})
public class Test {
.
.
.
doesn't appear in the documentation
@renannprado that's an issue with Springfox.
@webron you're right, I posted in the wrong repo
@webron can we close this? https://github.com/swagger-api/swagger-core/pull/2068 was merged a while ago.
@stoffus - It's not working. any clue?
https://github.com/springfox/springfox/issues/2183
+1
Any updates on how to resolve it?
ApiImplicitParam can map a parameter to a correct type, but the type must be detected by swagger, so must be a valid reference. The only way I could make this working is by using additionalModels method.
Example in spring-boot:
configure swagger
import springfox.documentation.spring.web.plugins.Docket;
import com.fasterxml.classmate.TypeResolver;
...
@Bean
public Docket api(TypeResolver typeResolver) {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("your-group-rest-api")
.select()
.apis(RequestHandlerSelectors.basePackage("your.package"))
.paths(PathSelectors.any())
.build()
.additionalModels(typeResolver.resolve(YourModel.class))
.apiInfo(apiInfo());
}
controller
@ApiOperation...
@ApiImplicitParams(
@ApiImplicitParam(dataType = "YourModel", name = "requestJson", paramType = "body"))
@ApiResponses...
@RequestMapping...
public void yourMethod(@RequestBody String requestJson,...)
Of course you could have an InputStream parameter for the request and map that to your model.
Hi, the existing problems:
Error message:
Failed to convert value of type 'java.lang.String' to required type 'java.util.Map'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'java.util.Map': no matching editors or conversion strategy found
Skip swagger UI,this is working:
http://localhost:8080/api/v1/meta/User/list?sort=id,desc&sort=createDate,asc
Please help me !!!
Most helpful comment
Accepting a class would be very helpful as I have several endpoints that accept an InputStream parameter (@ApiParam(hidden=true)) for deserialization performance, but want to document them as the actual class expected.
Also, no matter what I add for "datatype=xxxx", the schema.type value is always the literal value "string"