我使用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的对象中:
{
"schema": {
"title": "SchemaModel",
"type": "object",
"additionalProperties": false,
"properties": {
"caseId": {
"title": "Case Id",
"type": [
"null",
"string"
],
"description": "desc.",
}
}
}
}如何通过NJsonSchema c#模式生成器执行此操作?
发布于 2021-03-30 20:27:45
我不确定这是否是最好的解决方案,但我最终还是这么做了:
return new JObject
{
{ "schema", JToken.Parse(schema.ToJson()) }
};https://stackoverflow.com/questions/66862830
复制相似问题