SwaggerUI not displaying Model Schema

2019-05-23 18:23发布

问题:

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)