RicoSuter / NSwag

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

NSwag 14 - Swagger.json Tuple includes internal and private properties #4717

Closed jochenjonc closed 2 months ago

jochenjonc commented 7 months ago

When trying to upgrade to NSwag 14 (on a dotnet 7 project) I noticed that the swagger.json and thus all code generated based on that specification includes internal and private properties on classes that are being used.

I have noticed that other people have reported similar things but as a solution added [JsonIgnore] to these properties. See #4681 and some comments on #4524.

But for some types that isn't a solution, for instance for a Tuple that is part of dotnet.

NSwag 13 generated the following for a Tuple:

  "TupleOfStringAndString": {
    "type": "object",
    "additionalProperties": false,
    "properties": {
      "item1": {
        "type": "string"
      },
      "item2": {
        "type": "string"
      }
    }
  },

NSwag 14 includes 2 private properties:

"TupleOfStringAndString": {
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "item1": {
      "type": "string",
      "nullable": true
    },
    "item2": {
      "type": "string",
      "nullable": true
    },
    "system.Runtime.CompilerServices.ITuple.Length": {
      "type": "integer",
      "format": "int32"
    },
    "system.Runtime.CompilerServices.ITuple.Item": {
      "nullable": true
    }
  }
},

Is there any idea on how to fix this? What has changed between NSwag 13 and 14 that changes this behavior? If someone can point me in some direction I could have a look myself.

simeyla commented 6 months ago

It seems that property1 below will be added to the API but property2 will not.

 // Why does this get added to the API? It is private!
 private string Property1 { get; }

 // This does not get added to the API
 private string Property2 { get; set; }

I believe this could be the same 'bug' that causes https://github.com/RicoSuter/NJsonSchema/issues/1661 and https://github.com/RicoSuter/NSwag/issues/4572

I clearly have no ability to add [JsonIgnore] to the Exception property serializationWatsonBuckets !!!

jochenjonc commented 2 months ago

Tuple got fixed by https://github.com/RicoSuter/NJsonSchema/pull/1701