问题描述
Swagger UI 已创建,看起来很像下降,但我的方法无法获得描述。
c# 控制器
[Authorize]
[ApiController]
[ApiVersion("1.0")]
[Route("v{version:apiVersion}/me")]
[SwaggerTag("Me")]
public class MeController : ControllerBase
{
[HttpGet(Name = "GetMe")]
[Produces("application/json")]
[SwaggerResponse(400,ControllerConstants.Http400Description,typeof(BadRequestMessage))]
[SwaggerOperation("Retrieve the profile of the user","test",OperationId = "test")]
public async Task<IActionResult> Get()
{
//code
}
}
startup.cs
services
.AddSwaggerGen(swagger =>
{
swagger.SwaggerDoc("v1",new OpenApiInfo
{
Title = "<title>",Version = "1.0",Contact = new OpenApiContact()
{
Email = "<email>",Name = "<name>",},Description = "<description>",});
swagger.AddServer(new OpenApiServer() { Url = "http://example.com" });
};
services
.AddApiVersioning(options => options.ReportApiVersions = true);
services
.AddVersionedApiExplorer(
options =>
{
options.GroupNameFormat = "'v'VVV";
options.SubstituteApiVersionInUrl = true;
});
services
.AddSwaggerGenNewtonsoftSupport();
swagger.json(已删除)
我希望 GetMe 操作具有 https://swagger.io/docs/specification/paths-and-operations/
中所述的摘要/描述{
"openapi": "3.0.1","paths": {
"/v1/me": {
"get": {
"tags": [
"Me"
],"operationId": "GetMe","responses": {
"400": {
"description": "Bad Request","content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BadRequestMessage"
}
}
}
},"200": {
"description": "Success","content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Me"
}
}
}
}
}
},}
更新
我忽略了 EnableAnnotation 方法。 RTFM
的简单案例swagger.EnableAnnotations();
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)