Example Swagger/OpenAPI definition:
{
"openapi": "3.0.0",
"info": {
"title": "API",
"version": "0.1"
},
"servers": [
{
"url": "\/api",
"description": "Default API Server"
}
],
"paths": {
"\/account\/current": {
"get": {
"operationId": "Current::index",
"responses": {
"200": {
"content": {
"application\/json": {
"schema": {
"$ref": "#\/components\/schemas\/Account"
}
}
}
},
"401": {
"$ref": "#\/components\/responses\/Unauthorized"
}
},
"security": [
{
"default": []
}
]
}
},
"\/v2\/swagger.json": {
"get": {
"operationId": "Swagger_json::index",
"responses": {
"200": {
"description": "Swagger API Definition"
}
}
}
}
},
"components": {
"schemas": {
"Account": {
"properties": {
"id": {
"type": "integer"
}
},
"type": "object"
}
},
"responses": {
"Unauthorized": {
"description": "Unauthorized"
}
},
"securitySchemes": {
"default": {
"type": "apiKey",
"name": "ci_session",
"in": "cookie"
}
}
}
}
Swagger-UI configuration options:
const ui = SwaggerUIBundle({
url: "api/v2/swagger.json",
dom_id: '#swagger-ui',
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIBundle.SwaggerUIStandalonePreset
]
})
api/v2/swagger.json
Cannot auth the request with cookie auth method.
Steps to reproduce the behavior:
The execute function in Try it out not working as excepted,it ignored the cookie sitting in Security requirement and caused the auth failed and get 401 from my server
I try to track the stack and found swagger-ui have set the cookie in the request but the fetch function ignored it or using the brower's cookie instead.


Cookie authentication currently does not work in Swagger UI and Swagger Editor because of browser security restrictions that prevent web pages from modifying certain headers (such as Cookie) programmatically. Please see swagger-api/swagger-js#1163 for details and future updates regarding this issue.
A possible workaround is to use the withCredentials option and rely on browser-supplied cookies instead.
Thanks for reply :3
well I understand the problem now.swagger cannot function properly with cookie auth until somebody set up a extension to help with such cookie setting. for now on I login manually at login api and let brower deal the cookie instead as workaround
Closing as resolved — we'll continue tracking this generally in swagger-api/swagger-js#1163.
Most helpful comment
Thanks for reply :3
well I understand the problem now.swagger cannot function properly with cookie auth until somebody set up a extension to help with such cookie setting. for now on I login manually at login api and let brower deal the cookie instead as workaround