RicoSuter / NJsonSchema

JSON Schema reader, generator and validator for .NET
http://NJsonSchema.org
MIT License
1.4k stars 535 forks source link

Source Code Generation creates empty file #1417

Open writeameer opened 3 years ago

writeameer commented 3 years ago

Hi there,

I was testing out the C# source code generation for the following schema:

https://schema.management.azure.com/schemas/2017-03-01/Microsoft.Network.json#

I used the following code:

using NJsonSchema;
using NJsonSchema.CodeGeneration.CSharp;
using System;
using System.Net;

var schemaUrl = "https://schema.management.azure.com/schemas/2017-03-01/Microsoft.Network.json#";
var schemaTxt = new WebClient().DownloadString(schemaUrl);
var jsonSchema = JsonSchema.FromJsonAsync(schemaTxt).Result;
var generator = new CSharpGenerator(jsonSchema);
generator.Settings.Namespace = "MyNameSpace";
var code = generator.GenerateFile();

Console.WriteLine(code);

I get an empty name space as the generated code:

//----------------------
// <auto-generated>
//     Generated using the NJsonSchema v10.5.2.0 (Newtonsoft.Json v9.0.0.0) (http://NJsonSchema.org)
// </auto-generated>
//----------------------

namespace MyNameSpace
{
    #pragma warning disable // Disable all warnings

}

Am I doing something wrong ? Any ideas/help to generate the correct C# code would be greatly appreciated. Thank you.

RodneyRichardson commented 2 years ago

The schema you're using doesn't have a "properties" or "type" keys, so everything ends up in the ExtensionData property.

try adding "type" : "object", and renaming "resourceDefinitions" to "properties".