RicoSuter / NSwag

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

Property Name "System" conflicts with Namespace in C# #4389

Open marcobudde opened 1 year ago

marcobudde commented 1 year ago

We are using NSwagStudio 13.18.2 to generate a C# client for our backend.

One of our data types contains a property called "System":

 "PositionMatched": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "System",
          "X",
          "Y",
          "Z"
        ],
        "properties": {
          "System": {
            "type": "boolean",
            "nullable": true
          },
          "X": {
            "type": "boolean",
            "nullable": true
          },
          "Y": {
            "type": "boolean",
            "nullable": true
          },
          "Z": {
            "type": "boolean",
            "nullable": true
          }
        }
      },

This results into a conflict with the "System" namespace of the generated JsonIgnore statement:

    [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v13.0.0.0))")]
    public partial class PositionMatched
    {
        [System.Text.Json.Serialization.JsonPropertyName("System ")]
        [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)]   
        public bool? System { get; set; }

As the generated code already contains the following statement:

using System = global::System;

it would be better to reference the System namespace within the generated code with

System::Text.Json.Serialization.JsonIgnoreCondition.Never

instead of

System.Text.Json.Serialization.JsonIgnoreCondition.Never

MichaelGoulding commented 1 year ago

I'm running into this as well.

aunikitin commented 8 months ago

Hello, faced with it on 13.20.0

image image