raml-spec icon indicating copy to clipboard operation
raml-spec copied to clipboard

Repeatable URL parameters

Open petrochenko-pavel-a opened this issue 9 years ago • 4 comments

Some APIs allows infinite nesting of URL parameter. As a canonical sample lets imagine API reprenting information about hierarchical file system and less use url parameters to represent structure of parent folders. Currently I see no good way to represent this pattern in the raml.

The possible way to solve it is to specify that resource path segments that are fully represented by URL parameter and has some special symbol at the end of the pattern (for example +) may be indefinitely repeated.

/files/{folderId+}/{fileId}
   get:
     .....

Regards, Pavel

petrochenko-pavel-a avatar Oct 12 '16 13:10 petrochenko-pavel-a

I have a use for something like this.

If the type of the repeatable parameter is an array of something that can be in a uriParameter, that seems sufficient, given language in the RAML spec that provides this interpretation. API specifications that use this would be more readable with an annotation as you describe, with * and + as allowable modifiers.

Being more specific in the type would allow additional constraints to be applied:

types:
   segment:
      type: string
      pattern: "[a-z][a-z0-9]*"

/files/{folderId+}/{fileId}:
   uriParameters:
      folderId:
        type: segment[]
        minLength: 1
        maxLength: 7
   get:
     .....

freddrake avatar Oct 12 '16 13:10 freddrake

Yep

petrochenko-pavel-a avatar Oct 12 '16 15:10 petrochenko-pavel-a

A refinement: including * or + at the end of the uri parameter name in the resource entry should be required when the type is an array, and should match in number. (* if an empty array is allowed, + if not.) More elaborate RE-like notations should not be allowed:

/files/{folderId{1,5}}/{fileId}:
  ...

would be unreadable.

freddrake avatar Oct 12 '16 17:10 freddrake

Is RAML still being extended? OpenAPI is also lacking a "Repeated path parameters" feature, and it would be nice to see it added to either spec :-)

jypma avatar Jun 15 '21 13:06 jypma