SwaggerUI不显示模型架构 [英] SwaggerUI not displaying Model Schema

查看:204
本文介绍了SwaggerUI不显示模型架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有Swagger和Swashbuckle的C#Web.API项目.

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

我有一个模特:

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

我有一个带有方法的控制器:

I have a controller with methods:

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

在构建期间,我期望Swashbuckle生成一个SwaggerUI,该SwaggerUI在UI中显示TimeZoneName类型的JSON表示形式.

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

那没有发生.

如何设置方法和模型,以便在SwaggerUI中显示模型模式"?

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

推荐答案

Swashbuckle在Action名称的开头解释Get,并假定您没有在请求的正文中发送复杂的数据.

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.

您可以通过添加装饰器来强制Swashbuckle将Action解释为POST.

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

[HttpPost]
public string GetLocalTimeByTimeZone(TimeZoneName timezone)

这篇关于SwaggerUI不显示模型架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆