Path templating, multiple segments, and RFC 6570?
I'm trying to write swagger docs for APIs like dropbox where the number of path segments isn't known ahead of time. For example, the path template will look something like:
/api/metadata/{filePath}
And the following urls should all match this path:
/api/metadata/file1.txt
/api/metadata/dir1/file2.txt
/api/metadata/dir1/dir2/file3.txt
If we were using RFC 6570, I'd represent this as:
/api/metadata/{/filePath*}
but the swagger v2 spec doesn't say if this syntax is acceptable or not.
If it is acceptable/correct, could you please let me know in this item? If it's not, what is the expected way to model APIs like this with runtime variable URI paths?
Currently, Swagger 2.0 doesn't support it. It's been discussed in the workgroup but we have decided to exclude it. I imagine it has a very good chance of being included in the next version of the spec though.
Thanks, please then consider this a vote for some solution to this problem in the next rev of the spec.
:+1:
👍🏻
Does this bug imply that it is not possible to have multiple REST-API "Search" operations for same resource?
"/rest/resource?param1"
"/rest/resource?param2¶m3"
...
This would be a big problem for us to use swagger!
It's not a bug, it's a feature request (can't believe I just said that).
If your query parameters are mutually exclusive, you can't define that, but that's not related to this feature but another one here. If you're just looking to describe multiple parameters, there's no problem with that.
Okay let`s name it feature ^^ I´m exactly referencing to the springfox-swagger "feature" dilipkrish linked above. Can u please tell me the issue number of the "other feature" u wrote about, so I can track it?
It actually relates to #164, not this one. We can't treat RFC 6570 as a single feature. Not saying it won't all be implemented, but we need to have separate issues for separate sections of it so we know we cover it properly.
+1 and curious about how to track/participate in the workgroup on this issue?
+1 to include this in the next spec.
+1 for adding at least partial RFC 6570 support from me as well. We already use these local extensions:
{/optionalSegment}{+optionalReservedSuffix}
I'm trying to implement :
{/path}{path*}- and
{/path*}
maybe soon a PR :)
+1
Parent: #574
+1 for adding RFC 6570 support from me as well.
:+1:
I need it at two different places:
- FS-like path:
/fs/dir1/dir2 - Access to a sub API, referenced somewhere else:
/subapi/resource/id/...
In an attempt to move this discussion forward in one direction or the other, here are questions that need to be addressed before we could move ahead with 6570 support.
- 6570 defines templates for the entire URI. Should the paths object still only include a template for the path portion of the URI, or do we consider adding the query string to allow different operations based on query string parameters?
- What features of 6570 templates should we not support? Do we need to support the + operator that allows parameters to not be escaped? Do we allow the * expansion operator and if so does that mean we need to introduce a new parameter type
map? Optional path parameters? Prefix operator? - If a parameter appears in a template, must it also have a parameter object in the operation?
- If a parameter is defined in the operation that is in the URL, must it appear in the template?
I'm sure there are more, but this gives us a place to start.
@darrelmiller At the very least, it needs to support the * expansion operator. Without it there are an entire class of APIs (i.e. Dropbox) that cannot be represented. As per the original bug report.
I propose merging the functionality of the current path and query parameter types under a new type called uri which would allow the parameter to apply to the URI template according to 6570.
@christav I think the reserved character (+) operator is what you're looking for. I, too, require this for an API I manage that presents an arbitrary hierarchy.
I also need support for the explode (*) modifier to support passing arbitrary name/value pairs in query params.
@emattheis Either + or * could be used. + would work if the parameter was a string with a set of segments predefined. * would work if you passed an array of segment values.
As the path is currently used as the key for operations, it is not as simple as creating a new property with a new name. It would require changing the specification of the key value that appears in the paths object. I have no objection to heading in that direction, but I suspect other people might. That's what I'm hoping we can surface here.