0

I'm using swagger YAML for documenting few APIs. The APIs that I have are as follows:

  • POST: /customers/id
  • GET: /customers/id
  • PUT: /customers/id
  • DELETE: /customers/id

I'm using the same name for the APIs but I'm differentiating it based on the type of http call as per the REST URI naming convention. But when documenting this using swagger, I'm getting "Map keys must be unique" error.

How can I overcome this error?

Suganth
  • 35
  • 1
  • 7
  • Can your post your OpenAPI YAML file? – Helen Feb 14 '23 at 08:57
  • Does this answer your question - [Can I write same path names for different methods in REST API?](https://stackoverflow.com/a/45519050/113116) – Helen Feb 14 '23 at 09:01

1 Answers1

0

If you use OpenAPI (Swagger) you should write it like this:

paths:
  /customers/id:
    post:
      ...
    get:
      ...
    put:
      ...
    delete:

Unfortunately, OpenAPI is not convenient in this case, because usually there are many lines of code between method names (post, get, put, etc.). So when you look at some specific place in your code, it is not easy to say, what endpoint you are actually looking at. Thus I understand your wish to write it like this: POST: /customer/id: it is more natural and user-friendly, but not possible in OpenAPI.

However, you can use JSight, which does just the thing you want. Look, it is much easier to grasp:

JSIGHT 0.3

POST /customers/{id}

GET /customers/{id}

PUT /customers/{id}

DELETE /customers/{id}

I have written a more detailed example for you here: https://editor.jsight.io/r/aL952LZ/1