【问题标题】:Providing multiple result types with NSwag使用 NSwag 提供多种结果类型
【发布时间】:2019-06-25 10:32:28
【问题描述】:

有没有办法在 Asp.net WebApi(不是核心)中为相同的状态代码提供多个 NSwag.Annotations.SwaggerResponse 类型?实际上,我有两种响应类型,都是同一个抽象类的后代。

我试图将基类指定为响应类型,这导致在生成的描述符中将该类作为响应模型。这有点正常。

我试图添加两个属性实例和两个后代。生成的模型仍然是基类,而不是指定的实际类,但描述被合并了。

[SwaggerResponse(HttpStatusCode.OK, typeof(DeliveryData), Description = "Provided PIN code belongs to a delivery")]
[SwaggerResponse(HttpStatusCode.OK, typeof(AdhocData), Description = "Provided PIN code belongs to an adhoc visitor")]

结果是:

有趣的是,在模型列表中,我看到了基类和两个后代。

有什么方法可以指示 NSwag 生成替代模型 (oneOf)?

【问题讨论】:

    标签: asp.net-web-api nswag


    【解决方案1】:

    本页介绍如何在序列化程序和规范中设置继承:

    https://github.com/RicoSuter/NJsonSchema/wiki/Inheritance

    【讨论】:

    • 嗯...看起来完全没有区别,可能是因为它需要在容器类中。地雷直接退回。
    猜你喜欢
    • 2014-06-08
    • 1970-01-01
    • 2011-09-21
    • 1970-01-01
    • 1970-01-01
    • 2012-10-10
    • 1970-01-01
    • 2020-01-17
    • 1970-01-01
    相关资源
    最近更新 更多