0

I'm using NJsonSchema to generate JasonSchema from c# classes. 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:

{
   "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?

CageE
  • 419
  • 4
  • 13

1 Answers1

0

not sure if this is the best solution but I ended up doing this:

return new JObject
            {
                { "schema", JToken.Parse(schema.ToJson()) }
            };
CageE
  • 419
  • 4
  • 13