SwaggerUI not displaying Model Schema

喜欢而已 提交于 2019-12-22 18:01:42

问题


I have a C# Web.API project with Swagger and Swashbuckle.

I have a model:

    public class TimeZoneName
    {
        public string zoneName { get; }
    }

I have a controller with methods:

public string GetLocalTimeByTimeZone(TimeZoneName timezone)
{
     //Stuff Happens here
     return "12:00";
}

During a build I was expecting Swashbuckle to generate a SwaggerUI that shows a JSON representation of the TimeZoneName type in the UI.

That didn't occur.

How do I set up my methods and models so that the Model Schema is shown in the SwaggerUI?


回答1:


Swashbuckle interprets the Get at the start of the Action name and assumes you are not sending complex data in the body of the request.

You can force Swashbuckle to interpret the Action as a POST by adding a decorator.

[HttpPost]
public string GetLocalTimeByTimeZone(TimeZoneName timezone)


来源:https://stackoverflow.com/questions/40888207/swaggerui-not-displaying-model-schema

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!