0

我正在使用 NJsonSchema 从 c# 类生成 JasonSchema。我可以创建这个架构:

{
    "title": "SchemaModel",
    "type": "object",
    "additionalProperties": false,
    "properties": {
        "caseId": {
            "title": "Case Id",
            "type": [
                "null",
                "string"
            ],
            "description": "desc.",
        }
    }
}

通过使用:

var settings = new JsonSchemaGeneratorSettings
            {
                DefaultPropertyNameHandling = PropertyNameHandling.CamelCase
            };
            var generator = new JsonSchemaGenerator(settings);
            var schema = generator.Generate(typeof(SchemaModel));

但我需要将其包装在一个名为模式的对象中:

{
   "schema": {
       "title": "SchemaModel",
       "type": "object",
       "additionalProperties": false,
       "properties": {
           "caseId": {
               "title": "Case Id",
               "type": [
                   "null",
                   "string"
               ],
               "description": "desc.",
            }
       }
   }
}

我如何通过 NJsonSchema c# 模式生成器做到这一点?

4

1 回答 1

0

不确定这是否是最好的解决方案,但我最终这样做了:

return new JObject
            {
                { "schema", JToken.Parse(schema.ToJson()) }
            };
于 2021-03-30T12:27:44.823 回答