RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.72k stars 1.29k forks source link

Generated class name might be lower case in 14.0 #4837

Open WolfgangHG opened 6 months ago

WolfgangHG commented 6 months ago

I have a yaml file (unfortunately is not public, so I cannot post it here). With 14.0.4, some of the generated class names start with a lowercase letter, while they had before uppercase names.

Here is a yaml snippet:

  VariableDatenStandalone:
    type: "object"
    properties:
      dienstnehmer:
        $ref: "#/definitions/DienstnehmerRef"
      variableDaten:
        type: "array"
        items:
          type: "object"
          properties:
            validFrom:
              type: "string"
              format: "date"
              example: "2019-01-15"
            data:
              $ref: "#/definitions/VariableDaten"

"definitions/VariableDaten" is defined like this:

  VariableDaten:
    type: "object"
    properties:
      validFrom:
        type: "string"
        format: "date"
        example: "2019-01-15"
      dnGruppe:
        type: "object"
        properties:
          kz:
            type: "string"
            example: "ANG"
          name:
            type: "string"
            example: "Angestellter"
      lohnsteuer:
        type: "object"
        properties:
           ...

The generated code looks like this:

    [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.0.4.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))")]
    public partial class VariableDatenStandalone
    {
        [Newtonsoft.Json.JsonProperty("dienstnehmer", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
        public DienstnehmerRef Dienstnehmer { get; set; }

        [Newtonsoft.Json.JsonProperty("variableDaten", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
        public System.Collections.Generic.ICollection<variableDaten> VariableDaten { get; set; }

    }

    [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.0.4.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))")]
    public partial class variableDaten
    {
        [Newtonsoft.Json.JsonProperty("validFrom", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
        [Newtonsoft.Json.JsonConverter(typeof(DateFormatConverter))]
        public System.DateTimeOffset? ValidFrom { get; set; }

        [Newtonsoft.Json.JsonProperty("data", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
        public VariableDaten Data { get; set; }

    }

    [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.0.4.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))")]
    public partial class VariableDaten
    {
        [Newtonsoft.Json.JsonProperty("validFrom", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
        [Newtonsoft.Json.JsonConverter(typeof(DateFormatConverter))]
        public System.DateTimeOffset? ValidFrom { get; set; }

        [Newtonsoft.Json.JsonProperty("dnGruppe", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
        public DnGruppe DnGruppe { get; set; }

        [Newtonsoft.Json.JsonProperty("lohnsteuer", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
        public Lohnsteuer Lohnsteuer { get; set; }

        .....

I don't like the situation that a class name exists in a lower and upper case version. With 13.0.20, the class "variableDaten" was named "VariableDaten3" - not much better, but at least it didn't look strange ;-).

This might be a problem with VB.NET I think - here casing does not matter as far as I know.

If you don't consider it relevant enough to look at, please close this issue.

RicoSuter commented 6 months ago

Please retry with v14.0.7

WolfgangHG commented 6 months ago

@RicoSuter Did not change in 14.0.7, I deleted the generated cs file after updating, and the regenerated file still has lower case class names.