我正在使用官方文档分步方法来配置 Swagger UI 并在我的 ASP.NET core API 应用程序中生成 Swagger JSON 文件。
如果我查看生成的 swagger.json 文件 - 它缺少三个重要属性host
, basePath
and schemes
请帮助我了解我可以添加哪一段代码,以便生成的 swagger.json 将具有以下提到的属性/值。
这是一个理想的 swagger.json - 注意host
, basePath
and 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": []
}
]
}