如何用安全性标记路径但不进行操作?

时间:2020-01-23 02:55:49

标签: openapi

我的api被分为一些公共路由和一些安全路由。所有安全路径都是/secured/的子级,因此我想将其标记一次,而不是将每个操作路径标记为安全。

所以我有

之类的路线
/ // nothing here
/healthcheck //open route, can be used to make sure API is up
/login              //generates the cookie and tokens
/secured/users      //requires login and lists users
/secured/resources  //requires login and lists resources
/secured/others     //etc.

我的API在secured路径上具有用于登录检查的中间件,因此,下面的所有内容都必须检查Cookie和令牌。所以我想我的文档匹配。我知道我可以在根或每个端点上标记安全性,但是如何在secured路径中仅对其标记一次?

我正在尝试类似的事情:

paths:
  /healthcheck:
    get:
      [the get activity]
  /login:
    post:
      [yada yada yada]
 /secured:
    security:
      [security rules]
 /secured/users:
    get:
    post:
    put:
    delete:

但是这似乎会引发错误。除了将安全性放在每条路线和操作上之外,还有什么想法可以实现?

1 个答案:

答案 0 :(得分:1)

我知道我可以在根或每个端点上标记安全性,但是如何在<queryCompoundEmployeeResponse> <CompoundEmployee> <id>11111</id> <person> <employment_information> <job_information> <end_date>9999-12-31</end_date> <start_date>2017-05-17</start_date> </job_information> </employment_information> </person> </CompoundEmployee> </queryCompoundEmployeeResponse>路径中仅对其标记一次?

这是不可能的,主要是因为OpenAPI没有子路径的概念。用OpenAPI术语,您的API实际上没有secured路径-它有/secured/secured/users等。

如果您的API具有比非安全操作更多的安全操作,则可以全局定义/secured/resources,为不使用它的操作定义disable security

security