小编sch*_*s0x的帖子

Swagger/OpenApi 模型示例值

我正在尝试在 Swagger/OpenApi 中插入我自己的值,目前在模型示例值中我有以下值:

现在的情况

期望的情况如下图:

在此输入图像描述

我研究过它并尝试了多种方法来实现此目的,例如我尝试添加如下 XMLComments:

第一种方法

然而这不起作用。然后我尝试使用提供此功能的 MapType 函数,我使用以下代码完成了此操作:

c.MapType<Student>(() => new Schema()
                    {
                        example = new Student()
                        {
                            StudentName = "John Doe",
                            Age = 28
                        }
                    });
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试这种方式时,我得到以下结果: 结果

有任何解决这个问题的方法吗 ?

.net c# swagger

3
推荐指数
1
解决办法
3138
查看次数

标签 统计

.net ×1

c# ×1

swagger ×1