-
-
Notifications
You must be signed in to change notification settings - Fork 183
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
Constants are compiled as enums #1471
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. |
@Ksisa try and switch over to the |
@jonaslagoni for Typescript, I get this, which is invalid interface TradePayloadClient {
operation: 'Trade' = 'Trade';
data: TradeClient;
} And for C#, it doesn't retain the constant's value public class TradePayloadClient
{
public string Operation { get; set; }
public TradeClient Data { get; set; }
} |
How is that input invalid? 🤔
Yea C# still need a few things |
@jonaslagoni It's an interface, variables can't be initialized. |
Ahh yea 😅 So it's part of https://github.com/asyncapi/modelina/blob/042b45e38ae6a08c6a3ef7df9feb1a724eb63969/src/generators/typescript/TypeScriptObjectRenderer.ts#L49C70-L49C75 that is called by
@Ksisa wanna provide a fix for it? |
Yeah, I can take a look tomorrow evening. |
@Ksisa wanna have a look at the c# generator as well? It is slightly more complicated than your last PR. First part is implementing the constant constrainer for C#: https://github.com/asyncapi/modelina/blob/next/src/generators/csharp/constrainer/ConstantConstrainer.ts you can use the TypeScript constant constrainer as a guideline. Then in the generator, you just need to adapt the property rendering using the
|
@jonaslagoni what is the constant constrainer used for? I can see the Java ConstantConstrainer is identical to the TypeScript one, so I'm tempted to just copy paste it, especially since Java is syntactically very similar to C#. |
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 ❤️ |
It renders the constant value in language at hand. Some languages will overlap in that others will be unique. So it's vary possible that the implementation is gonna be the same or very similar between them 🙂 |
@jonaslagoni Is const only implemented for strings? 🤔 If so, should there be a check on the property type in the generator so we don't generate junk (e.g. |
🎉 This issue has been resolved in version 4.0.0-next.4 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Describe the bug
If I have a value that's a constant on an object, it will get compiled into an anonymous schema. This overcomplicates things by a lot.
Input:
Expected TypeScript output:
Actual Typescript Output:
Expected C# output:
Actual C# output:
The text was updated successfully, but these errors were encountered: