Skip to content

Path Templating: is there a restriction on the path parameter name? #1969

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
jmini opened this issue Jul 7, 2019 · 2 comments
Closed

Path Templating: is there a restriction on the path parameter name? #1969

jmini opened this issue Jul 7, 2019 · 2 comments

Comments

@jmini
Copy link

jmini commented Jul 7, 2019

According to the specification, each defined path parameter must correspond to a same-named variable placeholder in the path:

name: If in is "path", the name field MUST correspond to the associated path segment from the path field in the Paths Object. See Path Templating for further information.

There is no information about what is a valid name. Is there any restriction/recommendation about the characters that should or must be used?

For example, for:

GET <server>/api/231

231 corresponds to the path parameter.

In the following example with the name is todoID:

openapi: 3.0.1
info:
    title: Todo Backend
    version: '1.0'
paths:
    '/api/{todoID}':
        get:
            parameters:
                -  name: todoID
                   description: The id of the todo
                   schema:
                        format: int64
                        type: integer
                   in: path
                   required: true
            responses:
                '200':
                    description: OK
            summary: Get one todo

An other example with todo-id:

openapi: 3.0.1
info:
    title: Todo Backend
    version: '1.0'
paths:
    '/api/{todo-id}':
        get:
            parameters:
                -  name: todo-id
                   description: The id of the todo
                   schema:
                        format: int64
                        type: integer
                   in: path
                   required: true
            responses:
                '200':
                    description: OK
            summary: Get one todo

Are both names (todoID and todo-id) allowed?

@MikeRalphson
Copy link
Member

OAS 3.0 imposes no restrictions on parameter names, whether in: path or not. Even the empty string should be valid.

That said, use of { and } characters in path parameter names could lead to confusion, so you might want to avoid this.

Certainly your two examples are both fine.

@handrews
Copy link
Member

This was answered with no further questions, so closing as resolved. For improving the requirements of path templating, see issue #3256.

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