swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

"click to set as parameter value" does not work when json-object is a form parameter

Open gaffa opened this issue 13 years ago • 10 comments

These methods (swagger-jersey-jaxrs):

    @POST
    @Path("/works")
    @Consumes(MediaType.APPLICATION_JSON)
    @ApiOperation("working")
    public String working(@ApiParam("translation") Translation translation){
        return new Gson().toJson(translation);
    }

    @POST
    @Path("/oops")
    @Consumes(MediaType.APPLICATION_JSON)
    @ApiOperation("oops")
    public String oops(@ApiParam("translation") @FormParam("translation") Translation translation){
        return new Gson().toJson(translation);
    }

result in the following documentation:

[
{
        "path": "/translation/oops",
        "description": "RESTful API for translations",
        "operations": [
            {
                "httpMethod": "POST",
                "summary": "oops",
                "responseClass": "void",
                "nickname": "oops",
                "parameters": [
                    {
                        "name": "translation",
                        "description": "translation",
                        "paramType": "form",
                        "required": false,
                        "allowMultiple": false,
                        "dataType": "Translation"
                    }
                ]
            }
        ]
    },

{
        "path": "/translation/works",
        "description": "RESTful API for translations",
        "operations": [
            {
                "httpMethod": "POST",
                "summary": "working",
                "responseClass": "void",
                "nickname": "working",
                "parameters": [
                    {
                        "description": "translation",
                        "paramType": "body",
                        "required": false,
                        "allowMultiple": false,
                        "dataType": "Translation"
                    }
                ]
            }
        ]
    }
]



result in swagger-ui:

image

As you can see in "oops" its single-line and also the model does not get copied into the input when i click the link that says so. In "works" everything works.

gaffa avatar May 15 '13 06:05 gaffa

seems to be fixed now!

gaffa avatar Aug 22 '13 12:08 gaffa

I am seeing the same problem, but with "query" parameters. Everything around the execution of the call works, except (1) the value entry is a text field instead of a text area and (2) the "click to set" option doesn't work.

ttamulewicz avatar Nov 02 '13 19:11 ttamulewicz

@ttamulewicz are you trying to send complex objects as query params? If so, that's not supported by swagger.

fehguy avatar Nov 04 '13 18:11 fehguy

Yes, that’s it exactly. That’s unfortunate, but thanks for the response.

I’m surprised that it’s not supported because it does work! If I manually type in the JSON block for my complex query parameter, it passes to the server properly. It’s really just a convenience to have the field as a text area (so it can be more easily read) and to populate the structure more readily.

From: Tony Tam [mailto:[email protected]] Sent: Monday, November 04, 2013 1:52 PM To: wordnik/swagger-ui Cc: Tom Tamulewicz Subject: Re: [swagger-ui] "click to set as parameter value" does not work when json-object is a form parameter (#208)

@ttamulewiczhttps://github.com/ttamulewicz are you trying to send complex objects as query params? If so, that's not supported by swagger.

— Reply to this email directly or view it on GitHubhttps://github.com/wordnik/swagger-ui/issues/208#issuecomment-27711559.

ttamulewicz avatar Nov 04 '13 18:11 ttamulewicz

We are sending complex objects in query params. However, we do it by overriding OurComplexObject.fromString( String ourCustomSerializedObject ) as per jaxrs documentation. And call it a string in the Swagger config.

rage-shadowman avatar Nov 04 '13 19:11 rage-shadowman

Yes, as @rage-shadowman said, it's definitely doable, the challenge for supporting this in swagger is, we're trying to stay as server-independent as possible in the spec and tooling. It seems every REST framework has it's own way of using the query params for arrays, complex types, etc.

So in this case, I suggest forking swagger-ui to support serializing and setting the value in the UI. It should be pretty easy to support that

fehguy avatar Nov 04 '13 19:11 fehguy

Is there a way to get the JSON object string from swagger directly and parse it myself?

tpietsch avatar Jun 13 '14 16:06 tpietsch

get it where?

webron avatar Jun 13 '14 16:06 webron

https://github.com/wordnik/swagger-ui/issues/474

i just posted another ticket since this one is closed...

POJO

class my{ public string myKey; public string myValu; }

apiparam(my thisismyparam)

generates

{ "my key" : "my value", "my key" : "my value", "key" : "value", "key" : "value" }

i want to be able to accept the added key values and parse them myself

tpietsch avatar Jun 13 '14 16:06 tpietsch

okay, let's take it to that issue.

webron avatar Jun 13 '14 16:06 webron