【发布时间】:2019-05-16 13:23:48
【问题描述】:
我正在使用官方文档逐步方法来配置 Swagger UI 并在我的 ASP.NET 核心 API 应用程序中生成 Swagger JSON 文件。
Get started with Swashbuckle and ASP.NET Core
如果我查看生成的 swagger.json 文件 - 它缺少三个重要属性 host、basePath 和 schemes
请帮助我了解我可以添加哪些代码,以便生成的 swagger.json 将具有以下提到的属性/值。
这是一个理想的 swagger.json - 如果我遵循应用程序中的文档代码,请注意 host、basePath 和 schemes 值
{
"swagger": "2.0",
"info": {
"version": "v1",
"title": "Demo API Title"
},
"host": "some-url-that-is-hosted-on-azure.azurewebsites.net",
"basePath": "/api",
"schemes": ["https"],
"paths": {
"/Account/Test": {
"post": {
"tags": [
"Admin"
],
"summary": "Account test method - POST",
"operationId": "AccountTest",
"consumes": [],
"produces": [
"text/plain",
"application/json",
"text/json"
],
"parameters": [],
"responses": {
"200": {
"description": "Success",
"schema": {
"type": "boolean"
}
}
}
}
}
},
"definitions": {
"NumberSearchResult": {
"type": "object",
"properties": {
"number": {
"type": "string"
},
"location": {
"type": "string"
}
}
}
},
"securityDefinitions": {
"Bearer": {
"name": "Authorization",
"in": "header",
"type": "apiKey",
"description": "Authorization. Example: \"Authorization: Bearer {token}\""
}
},
"security": [
{
"Bearer": []
}
]
}
【问题讨论】:
标签: c# json asp.net-core swagger swashbuckle