[英]Add a root object to NJsonSchema schema generator
I'm using NJsonSchema to generate JasonSchema from c# classes.我正在使用 NJsonSchema 从 c# 类生成 JasonSchema。 I can create this schema:我可以创建这个架构:
{
"title": "SchemaModel",
"type": "object",
"additionalProperties": false,
"properties": {
"caseId": {
"title": "Case Id",
"type": [
"null",
"string"
],
"description": "desc.",
}
}
}
by using:通过使用:
var settings = new JsonSchemaGeneratorSettings
{
DefaultPropertyNameHandling = PropertyNameHandling.CamelCase
};
var generator = new JsonSchemaGenerator(settings);
var schema = generator.Generate(typeof(SchemaModel));
but the I need to wrap this in an object called schema:但我需要将它包装在一个名为架构的 object 中:
{
"schema": {
"title": "SchemaModel",
"type": "object",
"additionalProperties": false,
"properties": {
"caseId": {
"title": "Case Id",
"type": [
"null",
"string"
],
"description": "desc.",
}
}
}
}
How can I do this by NJsonSchema c# schema generator? NJsonSchema c# 模式生成器如何做到这一点?
not sure if this is the best solution but I ended up doing this:不确定这是否是最好的解决方案,但我最终这样做了:
return new JObject
{
{ "schema", JToken.Parse(schema.ToJson()) }
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.