NJsonSchema
NJsonSchema copied to clipboard
Empty file being generated...
Hello!
I'm trying to use this sample code to generate classes from a given json schema:
static void Main(string[] args)
{
var schema = JsonSchema4.FromJsonAsync(GetJsonSchema()).Result;
var settings = new CSharpGeneratorSettings { ClassStyle = CSharpClassStyle.Poco, Namespace = "ns" };
var generator = new CSharpGenerator(schema, settings);
var output = generator.GenerateFile("Foo");
Console.WriteLine("Hello World!");
}
static string GetJsonSchema()
{
var url = "https://raw.githubusercontent.com/Microsoft/vscode-debugadapter-node/master/debugProtocol.json";
var client = new HttpClient();
return client.GetStringAsync(url).Result;
}
output
is always an empty class with #pragma
and some auto-generated xxx comment.
What is wrong with it?
Thanks!
I have the same issue. I can see in Fiddler that it downloads all the JSON schemas and no exceptions are thrown at any stage but the output is empty. What am I missing?
var schema = await NJsonSchema.JsonSchema.FromUrlAsync("https://bdp-service.sageone.com/schema/ukie/v1/provision.json");
var generator = new CSharpGenerator(schema);
var output = generator.GenerateFile();
Output
//----------------------
// <auto-generated>
// Generated using the NJsonSchema v10.3.3.0 (Newtonsoft.Json v9.0.0.0) (http://NJsonSchema.org)
// </auto-generated>
//----------------------
namespace MyNamespace
{
#pragma warning disable // Disable all warnings
}
We eventually discovered that this was down to having some OneOf
elements in the top level. I'm assuming it's a bug in the way it's handled in the library but our workaround is just to remove them for now