Skip to content

Equivalent paths are not allowed even thogh the path + verb combination is different #1677

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
cskru opened this issue Feb 14, 2018 · 10 comments

Comments

@cskru
Copy link

cskru commented Feb 14, 2018

Paste this spec in https://editor.swagger.io:

info:
  title: Server
  version: 1.0.0

host: 'localhost:8000'
basePath: /
produces:
  - application/json

schemes:
  - http

swagger: '2.0'
paths:
  
  '/path/{paramName}':
    get:
      summary: Get paramName
      parameters:
        - name: paramName
          in: path
          required: true
          type: string
      responses:
        '200':
          description: Success
  '/path/{someOtherParamNameButTheVerbIsPut}':
    put:
      summary: Update paramName
      parameters:
        - name: someOtherParamNameButTheVerbIsPut
          in: path
          required: true
          type: string
      responses:
        '200':
          description: Success

Though path+verb combinations are different, it throws error.
This is not expected at all!

@cskru cskru changed the title Equivalent paths are not allowed Equivalent paths are not allowed even thogh the path + verb combination is different Feb 14, 2018
@hkosova
Copy link
Contributor

hkosova commented Feb 14, 2018

TL;DR: This is a limitation of the OpenAPI Specification and not a Swagger Editor issue.


The error means that these paths
/path/{paramName}
/path/{someOtherParamNameButTheVerbIsPut}

are considered identical and therefore invalid. They are identical because there's no way to tell if /path/foo corresponds to /path/{paramName} or /path/{someOtherParamName}. The parameter name alone does not make the path unique.

What you can do is define a single path /path/{paramName} with 2 operations get and put:

paths:
  /path/{paramName}:
    get:
      ...
    put:
      ...

This limitation has been previously discussed in the OpenAPI Specification repository here:
OAI/OpenAPI-Specification#576
OAI/OpenAPI-Specification#788


If you want to change the path matching behavior, file an enhancement request with OpenAPI Specification:
https://github.com/OAI/OpenAPI-Specification/issues

@webron
Copy link
Contributor

webron commented Feb 15, 2018

What @hkosova said.

@webron webron closed this as completed Feb 15, 2018
@cskru
Copy link
Author

cskru commented Feb 15, 2018

I understand what you have to say @hkosova and thank you for the response.

Regarding your comment:

there's no way to tell if /path/foo corresponds to /path/{paramName} or /path/{someOtherParamName}

There sure is a way and that is why I created this issue. We can differentiate them by specifying different verbs: put and get say.

It is fair to have ['/path/{paramName}' get] and [/path/{someOtherParamNameButTheVerbIsPut}' put]

I mean, the key should be path + verb combination, not the path alone.

I am not asking for something like this:
['/path/{paramName}' get] and [/path/{someOtherParamNameButTheVerbIsPut}' get]
This definitely causes conflict.

But I don't understand why there is an issue when the verb + path combinations are different.

My server is happy and has no qualms about it. Then why should the documentation have issues? :-)
Hope you understand the point.

#854
@webron , please refer this comment where you mention verb + path uniquely identifies an operation:
#854 (comment)

Swagger already is awesome. If these constraints are solved, it'll be more awesome to use. :-)

I strongly encourage you to reopen this issue.

@webron
Copy link
Contributor

webron commented Feb 15, 2018

They are not different. /path/{pathName} and /path/{whatever} are equivalent not matter what. That's how the spec regards it, and that's pretty much it. The fact that your server doesn't have issues with it, doesn't mean the spec doesn't. The spec doesn't allow plenty of things different server implementations do.

@nickdnk
Copy link

nickdnk commented Dec 10, 2018

I have this problem as well. Consider this:

I want to add multiple entries all under a specific date:

POST /something/{date}

Each entry gets and ID, which means I can delete or update individual entries like this:

DELETE /something/{id}
PATCH /something/{id}

{id} needs to be validated as an integer, {date} as a date string, and I cannot just put them under the same path, because then the variable needs to be named something like {dateOrId}, which is super ugly and misleading (but works!).

Given that the methods don't overlap because of different verbs, there's no way this can ever cause a conflict, and it works fine in the real world as well.

Please reconsider this limitation in the future.

@shockey
Copy link
Contributor

shockey commented Jan 4, 2019

@nickdnk interesting point - I see where you're coming from.

Consider opening an issue over at https://github.com/OAI/OpenAPI-Specification - they're the folks in charge of what's allowed in Swagger/OpenAPI documents 😄

@Ashikpaul
Copy link

Any updates?

@5-k
Copy link

5-k commented Jun 16, 2023

It does weird behavior even if the prefix is different

Semantic error at paths.

/dependency/{project}/{component}/{installation}/{name}
Equivalent paths are not allowed.
Semantic error at paths.

/installation/{project}/{component}/{name}
Equivalent paths are not allowed.

@WahidBitar
Copy link

Is there any hope to consider the verb as part of the path uniqueness??
I just wanted to mention this before the end of 2023 ^_^

@Harushii18
Copy link

Harushii18 commented Feb 22, 2024

Is there any hope to consider the verb as part of the path uniqueness?? I just wanted to mention this before the end of 2023 ^_^

I would also like to ask about the progress of using the verb for path uniqueness.

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

9 participants