CSharpGenerator not generating C# Class

63 Views Asked by At

I have a JSON schema

 {
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "ghkvhjhvh",
  "title": "gffghfjhg",
  "description": "zzzzzx",
  "type": "object",
  "properties": {
    "wbNumber": {
      "description": "fjhgfhg ",
      "type": "string"
    },
    "documents": {
      "description": "ghfcg",
      "type": "object",
      "properties": {
        "documentType": {
          "description": "sdzfdgfxhg",
          "type": "integer"
        },
        "file": {
          "description": "gdxfghfhgj",
          "type": "string",
          "contentEncoding": "base64"
        },
        "fileName": {
          "description": "dgfrhg",
          "type": "string"
        }
      },
      "required": [ "documentType", "file", "fileName" ]
    }
  },
  "required": [ "wbNumber", "documents" ]
}

Im trying to generate C# class from it with following:

  var json = File.ReadAllText(schemaDestination);
  var schema = await JsonSchema.FromJsonAsync(json);

  var genSettings = new CSharpGeneratorSettings
  {
      ClassStyle = CSharpClassStyle.Poco,
      JsonLibrary = CSharpJsonLibrary.SystemTextJson,
 
  };

  var generator = new CSharpGenerator(schema, genSettings);
  var res = generator.GenerateFile();

  await File.WriteAllTextAsync($"{destinationDir}/{Path.GetFileNameWithoutExtension(schemaDestination)
      .Humanize().Pascalize()}.cs", res);

Now I see that schema variable is filled in and I can see the actual values from json schema, but afterwards it`s goes to writing file I see this:

   // <auto-generated>
  //     Generated using the NSwag toolchain v11.0.0.0 (Newtonsoft.Json v13.0.0.0) (http://NSwag.org)
// </auto-generated>
//----------------------
namespace BusMesssage
{
    using System = global::System;
}

Can anyone tell me what I'm doing wrong?

1

There are 1 best solutions below

0
Oleg Pro On

Hi i found out that the problem is that i have a nSwag NjsonSchema generator and it`s appears that it cannot generate normally c# class, he think that I generate a controller and generating stuff like this:

// <auto-generated>
//     Generated using the NSwag toolchain v11.0.0.0 (Newtonsoft.Json v13.0.0.0) (http://NSwag.org)
// </auto-generated>
//----------------------

But when i moved to a sepparate console application it`s generated normally

//----------------------
// <auto-generated>
//     Generated using the NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0) (http://NJsonSchema.org)
// </auto-generated>
//----------------------

When I started to generate it a json schema first in my app, I couldn't to generate my controllers from CSharpClientGeneratorSettings, so it`s appears some bug in this library that cannot run both on same app.