Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 tasks done
jespitae opened this issue Jun 26, 2024 · 2 comments
Closed
2 tasks done
Labels
bug Something isn't working

Comments

@jespitae
Copy link

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?

  • I checked and didn't find similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue ?

Yes I am willing to submit a PR!

@jespitae jespitae added the bug Something isn't working label Jun 26, 2024
@jonaslagoni
Copy link
Member

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

@jespitae
Copy link
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants