JsonSchemaDefinitionAppender
Appends a JSON Schema to the Definitions of another JSON Schema.
using System;
namespace NJsonSchema
{
public class JsonSchemaDefinitionAppender : ISchemaDefinitionAppender
{
public void Append(object root, JsonSchema4 objectToAppend)
{
JsonSchema4 jsonSchema = root as JsonSchema4;
if (jsonSchema != null && objectToAppend != null) {
if (!jsonSchema.Definitions.ContainsKey(objectToAppend.TypeName))
jsonSchema.Definitions[objectToAppend.TypeName] = objectToAppend;
else
jsonSchema.Definitions["ref_" + Guid.NewGuid().ToString().Replace("-", "_")] = objectToAppend;
return;
}
throw new InvalidOperationException("Could not find the JSON path of a child object.");
}
}
}