Li-*_* Yu 7 cookies swagger swagger-ui swagger-2.0
我的Web服务API将检查请求中是否包含特定的cookie,但是我不知道如何在我的swagger doc api调用中包含cookie。
我尝试了两种方法:
在我的.yaml文件中像这样添加cookie作为可编辑字段。
paths:
/myApi/create:
parameters:
- name: Cookie
in: header
description: cookie
required: true
type: string
Run Code Online (Sandbox Code Playgroud)在swagger ui的html文件中,添加
window.authorizations.add(
"Cookie",
new ApiKeyAuthorization("Cookie", 'Name=Val', 'header')
)
Run Code Online (Sandbox Code Playgroud)但是在我的api都没有获得cookie的两种方法中,我想知道如何做到这一点?谢谢!
OpenAPI / Swagger spec 2.0不支持cookie身份验证。对于下一个版本(3.0),可以在下面找到支持它的讨论:
https://github.com/OAI/OpenAPI-Specification/issues/15
更新:OpenAPI spec 3.0将支持cookie:https : //github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/versions/3.0.md#parameter-locations
也许为时已晚,但您应该检查以下示例:
swagger: '2.0'
info:
version: '1'
title: With Cookie Authentication
description: With Cookie Authentication
securityDefinitions:
myCookie:
type: apiKey
name: Cookie
in: header
paths:
/say-hi:
get:
summary: Say Hello
description: Say Hello
responses:
200:
description: OK
security:
- myCookie: []
Run Code Online (Sandbox Code Playgroud)