OpenAPI-Specification icon indicating copy to clipboard operation
OpenAPI-Specification copied to clipboard

Path templating, multiple segments, and RFC 6570?

Open christav opened this issue 11 years ago • 39 comments

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?

christav avatar Mar 02 '15 23:03 christav

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.

webron avatar Mar 02 '15 23:03 webron

Thanks, please then consider this a vote for some solution to this problem in the next rev of the spec.

christav avatar Mar 03 '15 00:03 christav

:+1:

igr avatar Apr 27 '15 05:04 igr

👍🏻

dilipkrish avatar May 25 '15 16:05 dilipkrish

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&param3" ... This would be a big problem for us to use swagger!

GitVhaos avatar Jun 18 '15 06:06 GitVhaos

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.

webron avatar Jun 18 '15 06:06 webron

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?

GitVhaos avatar Jun 18 '15 07:06 GitVhaos

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.

webron avatar Jun 18 '15 07:06 webron

+1 and curious about how to track/participate in the workgroup on this issue?

chrisdostert avatar Oct 09 '15 22:10 chrisdostert

+1 to include this in the next spec.

nikhiljindal avatar Nov 04 '15 01:11 nikhiljindal

+1 for adding at least partial RFC 6570 support from me as well. We already use these local extensions:

  • {/optionalSegment}
  • {+optionalReservedSuffix}

gwicke avatar Dec 01 '15 01:12 gwicke

I'm trying to implement :

  • {/path}
  • {path*}
  • and {/path*}

maybe soon a PR :)

harobed avatar Jan 01 '16 14:01 harobed

+1

rajeshkamal5050 avatar Jan 21 '16 10:01 rajeshkamal5050

Parent: #574

webron avatar Feb 22 '16 00:02 webron

+1 for adding RFC 6570 support from me as well.

drobri avatar Mar 01 '16 23:03 drobri

:+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/...

Tronix117 avatar Mar 07 '16 14:03 Tronix117

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 avatar Apr 08 '16 15:04 darrelmiller

@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.

christav avatar Apr 08 '16 17:04 christav

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 avatar Apr 08 '16 18:04 emattheis

@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.

darrelmiller avatar Apr 08 '16 18:04 darrelmiller