How to define 2 different endpoints for variable path parameter and specific path parameter in swagger

Viewed 257

I want to define 2 rest endpoints:

  1. POST on /a/{id}/c
  2. POST on /a/b/c

b here being a specific keyword. The reason I need separate endpoints is payloads are different for both

The problem is when I do a POST on /a/b/c, the request is going to the first and due to mismatch of payloads, failing

Can this be done in swagger? Is there better way to do this?

1 Answers

Based on your comment, you could create two new POST endpoints and separate their functionality a little. Separating the functionality in the endpoint itself also makes it easier to read and to work with, as it immediately states what the endpoint is there for. Whether it be for a single user, or a whole batch of users, but still performing the same action. For example:

Adding a role to a specific user.

POST /system/roles/user/{userid} 

Adding roles to a batch of users at once.

POST /system/roles/batch

Would that work for you?

Related