-
-
Notifications
You must be signed in to change notification settings - Fork 187
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
Add enum for asyncapi message $id`s #181
Comments
Related to #188 |
@jonaslagoni Im not sure about it. I know that you introduced changes which allow to create enums and use it for values. |
@czlowiek488 no you right, the changes does not directly allow you to do this natively. However you can manually force it to generate it with the following somewhat pseudocode (not tested): import {CommonInputModel, CommonModel, TypeScriptGenerator} from '@asyncapi/modelina';
import {parse} from '@asyncapi/parser';
const parsedAsyncapiDocument = await parse(<Your asyncapi document>);
let messageEnumModel = new CommonModel();
messageEnumModel.$id = 'AsyncApiMessages';
for(const [,message] of parsedAsyncapiDocument.allMessages()){
messageEnumModel.addEnum(message.payload().$id);
}
let inputModel = new CommonInputModel();
inputModel.models = {'AsyncApiMessages': messageEnumModel}
const generator = new TypeScriptGenerator();
const outputModels = await generator.generate(inputModel); |
Ok its nice 👌. |
Yea I agree with you, there are also different kinds of enums that could be generated using the AsyncAPI file. I have no idea how to best enable such a feature though (as it is only related to AsyncAPI inputs). @czlowiek488 any suggestion on how you could see the API change to allow for such a feature? 🤔 |
@jonaslagoni I would see it this way. import { MessageIdsEnum } from "@asyncapi/modelina-plugins";
const generator = new TypeScriptGenerator({ plugins: [MessageIdsEnum] }); It support custom plugins so anyone would be able to modify generator in its own way. |
This issue has been automatically marked as stale because it has not had recent activity 😴 |
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 ❤️ |
Still relevant |
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 ❤️ |
As there are no specifics or suggestions on how to add something like plugins for input processors I am gonna close this one down. We have a specific example of creating custom MetaModels from any input you choose. So that can be done as a solution for this one https://github.com/asyncapi/modelina/blob/next/examples/meta-model/index.ts |
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 ❤️ |
Reason/Context
I created generator which generate types and Joi validators.
I generate validator with code like below.
As you can see I must pass string what is a little bit dirty solution.
This string is $id of message from asyncapi yaml file but there is no way to access it from generated types.
Description
I would like to have access to enum with all messages $id`s as key and value.
I guess it may look similar to this one.
The text was updated successfully, but these errors were encountered: