简体   繁体   English

通过 NJsonSchema 为 .NET 或 Newtonsoft.Json.Schema 生成 swagger v2 模式

[英]Generate swagger v2 schema by NJsonSchema for .NET or Newtonsoft.Json.Schema

I need to use a tool, preferably NJsonSchema for .NET to generate schemas from c# classes.我需要使用一个工具,最好是 NJsonSchema for .NET 从 c# 类生成模式。 The requirement is to create schemas based on swagger version 2. For example I cannot have oneOf, anyOf, etc, which are new keywords in OAS3 in the schema.要求是基于 swagger 版本 2 创建模式。例如,我不能在模式中包含 OAS3 中的新关键字 oneOf、anyOf 等。 Can we specify the swagger/OAS version in the schema generator?我们可以在模式生成器中指定 swagger/OAS 版本吗? How can this be done?如何才能做到这一点?

I just found that there is a setting in NJsonSchema for choosing the version:我刚刚发现在NJsonSchema中有一个选择版本的设置:

var settings = new JsonSchemaGeneratorSettings
            {
                SchemaType = NJsonSchema.SchemaType.Swagger2,
            };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM