Skip to content

Definining URL-encoded JSON value #290

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

Closed
marcus-maws opened this issue Mar 2, 2015 · 19 comments
Closed

Definining URL-encoded JSON value #290

marcus-maws opened this issue Mar 2, 2015 · 19 comments

Comments

@marcus-maws
Copy link

Hi,

Is it possible to define a URL-encoded JSON value that has a name. e.g. the sent data is of type

multipart/form-data

And the POST data is a URL-encoded version of the following code (in PHP):

request=json_encode(array(...))

If it's not possible in the main spec, is there a hack to allow such forms?

Thanks.

@webron
Copy link
Member

webron commented Mar 2, 2015

Can you give an explicit example of what it would look like (not in a given language, but a raw request)?

@marcus-maws
Copy link
Author

webron - thanks for your quick resonse. The POST data would be an encoded form of

request={"key":"value"}

which I believe would be

request=3D%7B%22key%22%3A%22value%22%7D

Thanks.

@marcus-maws
Copy link
Author

Note that the object that is passed can be quite complex, and I have various definitions for the parameters that can be passed, it´s just that the json data is not passes as application/json, it´s multipart/form-data, with a key before the JSON value.

@webron
Copy link
Member

webron commented Mar 2, 2015

The only way I can think of doing that is using the format property to say that is URL encoded. It's not that the various tools will add support for it internally, but you can use that to add support in them.

@marcus-maws
Copy link
Author

OK, thanks. I´ll look into that. And the parameters, how would I define them? I´m thinking about something like:

parameters:
  request:
    (what goes here?)

@webron
Copy link
Member

webron commented Mar 2, 2015

You can take a look at the petstore (http://petstore.swagger.io/v2/swagger.json) or the ones provides with the editor. There are plenty examples on how to define parameters, though if you have any problem let me know and I'll be happy to assist.

@marcus-maws
Copy link
Author

Thanks. I had a look before, but couldn't manage it for this specific example - hence the post. I'll try again, though, and if I really can't, I'll come back to you.

Thanks for your help.

@webron
Copy link
Member

webron commented Mar 2, 2015

Perhaps I didn't understand the question there. Do you ask how to define a parameter in general or something more specific?

@marcus-maws
Copy link
Author

It's specific to this example. There are two possible parameters, each of which are URL-encoded JSON objects/arrays. The objects/arrays have specific formats, and themselves have parameters defined for them, but are not at the 'top level', as would be the case if they were sent in application/json format. As such the two top-level parameters (json or requests) each take URL-encoded JSON objects/arrays, which themselves have parameters defined for them. Specifically, the 'json' parameter takes a single JSON object (which defines a single API action), whereas 'requests' takes an array of objects (i.e. a list of API actions). The issue I'm having is how to define this hierarchy of parameters.

Is that any clearer?

@webron
Copy link
Member

webron commented Mar 2, 2015

I should have picked up on it earlier, but you can't define a model for a form parameter. The most you can do is define it as a string. I believe this is one thing we may change in future versions of the spec, for form parameters only.

@marcus-maws
Copy link
Author

Hmm, OK. Thanks. That's kind of what I thought might be the case. I guess I'm going to have to hack some existing tools.

@marcus-maws
Copy link
Author

Is it not possible to define a schema for the inputs that themselves define schemas? (I'm guessing not from your response, I just wanted to check.)

@webron
Copy link
Member

webron commented Mar 2, 2015

Only body parameters can define a schema.

If you're asking whether you can define a schema that allows the definitions of schemas as a model, then you may be able to do that within some limitations.

@marcus-maws
Copy link
Author

I'm not sure if I should put this in a different question, since it's not quite the same thing, but is it not possible then to define a schema and use $ref when the parameters are query or path parameters?

@webron
Copy link
Member

webron commented Mar 5, 2015

No. You can't use schemas for query or path parameters. The reason is that you can't really define a mime type for these parameters. The mime type of the request affects the body of the request, but not anything around it.

@marcus-maws
Copy link
Author

OK, thanks.

@webron
Copy link
Member

webron commented Mar 5, 2015

Can we close this issue?

@marcus-maws
Copy link
Author

Yeah - done.

@alecthomas
Copy link

Is this still the case?

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

No branches or pull requests

3 participants