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

Accommodate legacy APIs by allowing query parameters in the path #84

Closed
earth2marsh opened this issue Aug 1, 2014 · 6 comments
Closed

Comments

@earth2marsh
Copy link

There are real APIs where a query string may determine the structure of the response, for example verbose=true, metadata=1, action=reboot.

However, Those cannot be expressed in Swagger 2.0 today because the path/verb maps onto a response model 1:1.

While it may be a bit of a kludge, consider a unique path where the query string is hard-wired into the path:
"path":"/me?metadata=1"

The order of the query params may not be determined in real situations, but for the purpose of defining methods in the spec, this may be an acceptable compromise to accommodate legacy services.

@fehguy
Copy link

fehguy commented Aug 1, 2014

Hi @earth2marsh I think the driver here will be the tooling. Having a query param in what should be a path might lead to nasty /me?metadata=1?foo=bar side effects.

@earth2marsh
Copy link
Author

Yes, the tooling would have to check for the ? when building the query
string. But having a spec that can accommodate more APIs is a good thing,
even if the pattern itself is bad. #goingPostel

@fehguy
Copy link

fehguy commented Aug 1, 2014

Marsh I know you want to support all apis, but I worry that it would be at the expense of others. Perhaps you can use anchors? /me#hack1 I don't know how they would fit into the design but I know they're not explicitly forbidden

@BSalita
Copy link

BSalita commented Aug 2, 2014

Perhaps Swagger 3.0 can address such legacy APIs using conditionals.

"path" : "/me ? verbose==false && metadata==0"

@maxlinc
Copy link

maxlinc commented Aug 4, 2014

@BSalita you'd need to write another specification just for how the conditionals are processed.

I still think the answer to those sorts of problems is still RFC 6570, because it's the closest thing to that specification.

At this point I think we should just ask tools to handle "path" as "the path portion of a URI template", and to consider an "x-query" extension for the "query portion of a URI template". I think it's better to have projects like swagger-js get started with basic URI template support before we try to extend it to cover query.

If they decide it isn't difficult to support it, here's how I'd expect it to work:

The default:

path: "/me?metadata=1"
# x-query: "{?parameters*}"

would produce: http://example.com/me?metadata=1?foo=oof&bar=rab&baz=zab, which has the problem @fehguy mentioned.

A simple override tells the tool how you want it handled:

path: "/me?metadata=1"
x-query: "{&parameters*}" # changed the prefix to &

That produces http://example.com/me?metadata=1&foo=oof&bar=rab&baz=zab, which is correct.

Even more complex patterns are possible, for example:

path: "/me?metadata=1"
x-query: "{&foo,bar}{;baz}"

Produces http://example.com/me?metadata=1&foo=oof&bar=rab;baz=zab.

The only thing I don't like about this is that path is a misnomer now. route would be a more appropriate name if it can include (some of) the query.

@webron
Copy link

webron commented Sep 21, 2014

Moved here - OAI#123.

@webron webron closed this as completed Sep 21, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants