-
-
Notifications
You must be signed in to change notification settings - Fork 185
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
[FEATURE] Support marshal / unmarshal enum values to target types in Go generator #2043
Comments
Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request. |
@condorcet |
Have you tried using the |
Yes, it works, but as I mentioned before it's impossible to marshal type "as is", because underlying type is For example, we can't do something like that
|
@jonaslagoni For my project I extend generator with MarshalJSON / UnmarshalJSON. Maybe I can make PR with proposal? |
Please do yea ✌️ Make sure you target |
This issue has been automatically marked as stale because it has not had recent activity 😴 It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation. There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model. Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here. Thank you for your patience ❤️ |
Why do we need this improvement?
For now, generated enums in Go generator represents as
uint
https://github.com/asyncapi/modelina/blob/master/src/generators/go/renderers/EnumRenderer.ts#L28This also covered by docstring here
For example, if we have string type enum like this
Generated code will be:
It becomes blocker to use generated type "as is", because when we need marshal / unmarshal this type to JSON, we can't rely on string type (underlying
Status
type is uint).Of course, we have
Value()
method to use actual values of enum, but it forces to make some additional wrappers on original type. We can't make something like this:How will this change help?
This change unlocks using of generated enum types "as is" with different types (e.g. string) to satisfy original JSON schema.
Screenshots
No response
How could it be implemented/designed?
One of the solution is to add methods MarshalText / UnmarshalText to generated type.
It helps json codec to serialize data to target type according JSON schema.
In scope of the example very simplified solution for string enum values may look this:
and
This solution aims not to change internal representation of enum value, but only JSON serialization. So, this change can be considered backward compatible.
🚧 Breaking changes
No
👀 Have you checked for similar open issues?
🏢 Have you read the Contributing Guidelines?
Are you willing to work on this issue?
None
The text was updated successfully, but these errors were encountered: