我正在使用Swagger api编写REST API。现在,我想以下列方式编写插入,更新和删除方法(我已在许多API上看到过这样的路径):
/生
/生/ {studentId}
/生/ {studentId}
现在,1可以,但2和3是相同的路径(但有不同的方法)。当我写这篇文章时,Swagger API给出了错误。这真的不允许吗?
如果不允许,有哪些最好的方法可以定义不同的路径,而不会让它们变长,看起来仍然很酷?
答案 0 :(得分:2)
要为同一路径定义不同的方法(GET / PUT / DELETE / etc。),只需在此路径下列出这些方法,如下所示:
paths:
/students/{studentId}:
# Common parameter for all methods on this path
parameters:
- name: studentId
in: path
...
get:
summary: Get a student by ID
...
put:
summary: Update a student
...
delete:
summary: Delete a student
...