I'm trying to use NJsonSchema to generate C# classes, but it's naming the classes for objects in an array "anonymous_".
For example, this json schema snippet
"Identifiers": { "type": "array", "items": { "type": "object", "properties": { "ID": { "type": "string" }, "IDType": { "type": "string" } }, "required": [ "ID", "IDType" ] }
Generates this C# property and class
[Newtonsoft.Json.JsonProperty("Identifiers", Required = Newtonsoft.Json.Required.Always)] [System.ComponentModel.DataAnnotations.Required] public System.Collections.ObjectModel.ObservableCollection<Anonymous> Identifiers { get; set; } = new System.Collections.ObjectModel.ObservableCollection<Anonymous>();
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "9.3.0.0")] public partial class Anonymous { [Newtonsoft.Json.JsonProperty("ID", Required = Newtonsoft.Json.Required.Always)] [System.ComponentModel.DataAnnotations.Required] public string ID { get; set; } [Newtonsoft.Json.JsonProperty("IDType", Required = Newtonsoft.Json.Required.Always)] [System.ComponentModel.DataAnnotations.Required] public string IDType { get; set; } public string ToJson() { return Newtonsoft.Json.JsonConvert.SerializeObject(this); } public static Anonymous FromJson(string data) { return Newtonsoft.Json.JsonConvert.DeserializeObject<Anonymous>(data); } }
Wondering if there's a way to force NJsonSchema to name objects in a collection according to a singularized version of the collection name (e.g. in this case I'd want the anonymous
class to be named something like Identifier
since the class describes objects in a collection called Identifiers
). I've tried using a custom TypeNameGenerator for this but the name of the collection isn't provided to the Generate
function.