asyncapi / modelina

A library for generating typed models based on inputs such as AsyncAPI, OpenAPI, and JSON Schema documents with high customization
https://modelina.org
Apache License 2.0
295 stars 170 forks source link

[BUG] Generated JsonConverter tries to Deserialize enums as dynamic in the C# generator #2063

Closed jespitae closed 3 weeks ago

jespitae commented 2 months ago

Describe the bug.

The C# generator generates a JsonConverter using SystemTextJson, that tries to deserialize the enums as dynamic. The enum looks like this: image Next to the enum an extension method is generated: image The json converter tries to deserialize the enum as follows: image This results in the following error when trying to deserialize the enum: The best overloaded method match for 'CBS.Viewer.Integration.Events.EnvironmentExtensions.ToEnvironment(string)' has some invalid arguments

Expected behavior

We would expect the resulting json converter to look like this: image

Screenshots

Screenshot provided throughout.

How to Reproduce

Our asyncapi spec for the enum looks like this: image The property on one of our events: image

We used version 2.0.2 of the asyncapi cli and version 3.5.3 of modelina and ran the following command: asyncapi generate models csharp ./asyncapi.json --namespace=Test --output=Models --csharpSystemJson Our async api specification is defined in version 2.4.0.

🥦 Browser

Mozilla Firefox

👀 Have you checked for similar open issues?

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue ?

Yes I am willing to submit a PR!

jonaslagoni commented 2 months ago

@jespitae feel free to provide a PR :v: I don't think the next version has this solved 🤔 Just remember that enums can be any valid JSON value 🙂

jespitae commented 2 months ago

@jonaslagoni In that case maybe it's better to change the parameter type of the To... extension method to dynamic. I'll provide a PR.