Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@ApiImplicitParam: "array" dataType is getting resolved into "type":"ref" #902

Closed
anny-ts opened this issue Aug 10, 2015 · 11 comments
Closed
Labels
Milestone

Comments

@anny-ts
Copy link

anny-ts commented Aug 10, 2015

Hi,
i have rest method where one of the implicit parameters is an array.
When i use @ApiImplicitParam annotation with dataType = "array" it is resolved into

  • "type":"ref" in api docs
  • "undefined" in swagger-ui
@ApiImplicitParam(name = "status_ids", required = false, allowMultiple = true, paramType = "query", dataType = "array")
public List<App> listApps(@ApiIgnore HttpServletRequest request) {
//some code here
}

i'm using springfox-swagger2 2.1.2.

Could you please advise what is the correct way to document implicit array parameter?

Thank you.

@dilipkrish
Copy link
Member

Just fyi here is the documentation on the expectation of overriding types like you have.

Also it should be defined as a child of the implicit params collection

@ApiImplicitParams({
    @ApiImplicitParam(name = "status_ids", required = false, allowMultiple = true, paramType = "query", dataType = "array")
})

@dilipkrish dilipkrish added this to the 2.2.0 milestone Aug 10, 2015
@anny-ts
Copy link
Author

anny-ts commented Aug 11, 2015

Thank you for quick response,
I'm using @ApiImplicitParam as a child of @ApiImplicitParams.

What i need is to describe all possible query parameters, where one of the parameters is an array.

@ApiImplicitParams({
            @ApiImplicitParam(name = "app_id", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "status_ids", required = false, allowMultiple = true, paramType = "query", dataType = "array"),
            @ApiImplicitParam(name = "limit", required = false, dataType = "int", paramType = "query")
    })
    @RequestMapping(method = GET)
    public List<App> listApps(@ApiIgnore HttpServletRequest request, @ApiIgnore HttpSession httpSession) {
        String query = request.getQueryString();
        //some code here
    }

My question is: what dataType value should i use for implicit parameter to be resolved into "array" type.

@dilipkrish
Copy link
Member

Change allowMultiple = true, paramType = "query", dataType = "array" to allowMultiple = true, paramType = "query", dataType = "string".

dataType as descibed in the link ☝️ the value should be able to resolve to a valid type in the ClassLoader

@vivin
Copy link

vivin commented Feb 11, 2016

I apologize for reopening this issue (didn't want to create a duplicate one).

Based on the swagger specification, one of the allowed types for a query parameter is "array". However, I can't seem to set this for an array of enums through the @ApiImplicitParam annotation for an object annotated with @ModelAttribute:

@ApiImplicitParams({
    @ApiImplicitParam(name = "classifications", allowMultiple = true, paramType = "query", allowableValues = "ONE, TWO, THREE")
})

This seems to generate a swagger model with the type set to "ref". As originally mentioned in this issue, I can't set the type to "array" because dataType needs to be a class that can be instantiated. I did set the type to "string", but this simply sets dataType to "string", and there is no "items" entry even though allowMultiple is true. I basically end up with this:

{
    "enum": [
        "ONE",
        "TWO",
        "THREE"
    ],
    "in": "query",
    "name": "classifications",
    "required": false,
    "type": "string"
}

The enum itself is called Classification, and the type of the classifications field within the @ModelAttribute-annotated class is Classification[].

I tried adding rules (using resolver.arrayType) to resolve arrays of type Classification to arrays of type String, but I still end up with ref. Removing the @ApiImplicitParams annotation completely ends up giving me this:

{
    "name": "classifications",
    "in": "query",
    "required": false,
    "type": "array",
    "items": {
        "$ref": "#/definitions/"
    },
    "collectionFormat": "multi"
}

But this doesn't have the list of enum values or the item type I want ("string"). What is the correct way to accomplish this?

@dilipkrish dilipkrish added bug and removed question labels Feb 11, 2016
@dilipkrish dilipkrish modified the milestones: 2.4.0, 2.2.0 Feb 11, 2016
@dilipkrish dilipkrish reopened this Feb 11, 2016
@dilipkrish
Copy link
Member

@vivin I fixed a subtle bug with it, but it should be available when we release 2.4.0. details in the commit ☝️ Thanks for reporting!

@vivin
Copy link

vivin commented Feb 11, 2016

@dilipkrish Thanks Dilip!

@vivin
Copy link

vivin commented Feb 11, 2016

@dilipkrish One more question - I can't seem to find 2.4.x snapshot versions on the snapshot repo. Am I looking in the right place? Or should I try building directly from the source?

@dilipkrish
Copy link
Member

Haven't upped the version yet. So u should find it @ 2.3.2-Snapshot. Details on how to get it it at http://springfox.io

@vivin
Copy link

vivin commented Feb 11, 2016

@dilipkrish Thank you!

@smagellan
Copy link

strange results for Pojos:

  • swagger produces cool Model Schema for Data Type if @ApiParam(hidden=false) is applied
  • swagger produces ordinary string for Data Type if @ApiParam(hidden=true) and @ApiImplicitParam(name = "user", value = "user", required = true, dataType = "User") is applied
    How can I configure Swagger to produce Model Schema (not ordinary string!) ?

@sumit1488
Copy link

I wanted to do the same using openapi 3. but there is no allowMultiple = true.
Any Idea how to get the same things done in open api 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants