RicoSuter / NSwag

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

Is DataContract(Name="Override") supported? #1938

Open abbotware opened 5 years ago

abbotware commented 5 years ago

Is DataContract(Name="Override") supported?

This is similar to #1302 and #6, but at the class name level.

abbotware commented 5 years ago

Interestingly enough, Swashbuckle seems to not support this directly either, but there is a mechanism to at least override the behavior: https://github.com/domaindrivendev/Swashbuckle/issues/457

abbotware commented 5 years ago

Maybe this is more for NJsonSchema ?

I just came across this doc page: https://github.com/RSuter/NJsonSchema/wiki/JsonSchemaGenerator and it seems like what I am asking about is not supported?

abbotware commented 5 years ago

As an FYI - [JsonSchema(Name = "Override")] is definitely working for me

RicoSuter commented 5 years ago

NJS/NSwag uses the newtonsoft.json contract resolver to get property names so that the schema matches the actual serialization.. if there is a DataContract attribute on the class and a DataMember on the property i’d say this should work

abbotware commented 5 years ago

hmm.. so you mean this could be Newtonsoft issue then?

This is what I have discovered:

[DataContract(Name="Override")] - Class level - doesn't work [DataMember(Name="Override")] - Property level - works

[JsonSchema(Name = "Override")] - Class or Property - works

RicoSuter commented 5 years ago

[DataContract(Name="Override")] - Class level - doesn't work

Ah yes, this is probably something which has to be handled by NJsonSchema manually to be supported...