NJsonSchema
NJsonSchema copied to clipboard
CSharp Generated class name
Hi There,
A question rather than an issue. When I generate C# from a json schema, the resulting class is called 'Anonymous', is there a way to specify the name of the generated class please?
Cheers Jonathan
Set the “title” attribute of the given schema
Set the “title” attribute of the given schema
That worked. We did have it set, but it contained spaces.
Thank you!
And what if title contains dots (namespace.class)? Should the title be used as a class name? I suppose it should be but is not (#1131).
I think the title is only used if it matches [a-zA-Z0-9] (or similar) - this is because the namespace should not be part of the schema (leaky abstraction).
Regarding this point, I am using the NJsonSchema v10.6.10.0 (Newtonsoft.Json v13.0.0.0) but setting the Title is not changing the title of the class, still getting:
public partial class Anonymous
I am doing it like:
JsonSchema schema = JsonSchema.FromSampleJson(json);
schema.Title = className;
CSharpGeneratorSettings genSettings = new CSharpGeneratorSettings { Namespace = "Veronica.JsonClasses", ClassStyle = CSharpClassStyle.Poco };
CSharpGenerator generator = new CSharpGenerator(schema, genSettings);
var file = generator.GenerateFile();