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

[FEATURE] Generate classes based on AsyncAPI document #207

Open
2 tasks done
thompson-tomo opened this issue May 16, 2024 · 4 comments
Open
2 tasks done

[FEATURE] Generate classes based on AsyncAPI document #207

thompson-tomo opened this issue May 16, 2024 · 4 comments

Comments

@thompson-tomo
Copy link

Why do we need this improvement?

Allow for less boiler plate to code to be prepared.

How will this change help?

Enable classes to be generated at build time based on AsyncAPI document.

Screenshots

No response

How could it be implemented/designed?

By using dotnet source generators and provide a standalone package

🚧 Breaking changes

No

👀 Have you checked for similar open issues?

  • I checked and didn't find a similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue?

Yes I am willing to submit a PR!

@thompson-tomo thompson-tomo changed the title [FEATURE] <description> [FEATURE] Generate classes based on AsyncAPI document May 16, 2024
@yurvon-screamo
Copy link
Collaborator

To be honest, I didn't understand anything, sorry)

Can you describe your idea in more detail?

@thompson-tomo
Copy link
Author

thompson-tomo commented May 22, 2024

So the idea would be to package a source generator as a standalone nuget package which a user can install. As part of the csproj the user specifies the yaml file and on build/compile time classes are generated as per the asyncapi spec.

This approach would enable asyncapi to be the source of truth for schema ie contract first rather than code first.

@smoerijf
Copy link
Contributor

smoerijf commented Jun 1, 2024

I'm implementing a Roslyn source generator for a PoC on a work project. This will be my first source generator, so I'm also playing with it in my personal time.

My idea is two-fold:

  • fully AsyncApi-contract first: Generate data classes (NJsonSchema/NSwag), generate interfaces, generate classes using scriban as templating engine
  • Interface definitions in code: Generate boiler plate code by source generator using scriban as templating engine

I'm also planning of implementing Swagger (IApiDescriptionProvider) on top of on AsyncApi schema for the "Try it out" functionality for easy message creation for testing and debugging.

@smoerijf
Copy link
Contributor

smoerijf commented Jun 5, 2024

Update: I've both code generators working for our project. Not in a state yet it will be generally usable, but all necessary components are working. But it highly depends on #213, since I first generate interfaces decorated with the AsyncApi attributes based of AsyncApi spec file(s). (Using NSwag for the data-types + custom code gen for the asyncApi channels using the Lego.asyncApi.reader for parsing the spec files)
And then a second source code generator to generate the actual class implementation of those generated interfaces. (Which is just forwarding the data to MediatR for further handling)

I'm willing to make it production ready if this saunter project starts moving again.

smoerijf pushed a commit to smoerijf/saunter that referenced this issue Jul 14, 2024
smoerijf pushed a commit to smoerijf/saunter that referenced this issue Jul 14, 2024
smoerijf pushed a commit to smoerijf/saunter that referenced this issue Jul 14, 2024
smoerijf pushed a commit to smoerijf/saunter that referenced this issue Jul 20, 2024
smoerijf pushed a commit to smoerijf/saunter that referenced this issue Jul 20, 2024
smoerijf pushed a commit to smoerijf/saunter that referenced this issue Jul 20, 2024
smoerijf pushed a commit to smoerijf/saunter that referenced this issue Jul 20, 2024
smoerijf pushed a commit to smoerijf/saunter that referenced this issue Jul 21, 2024
smoerijf pushed a commit to smoerijf/saunter that referenced this issue Jul 21, 2024
smoerijf pushed a commit to smoerijf/saunter that referenced this issue Jul 21, 2024
smoerijf pushed a commit to smoerijf/saunter that referenced this issue Jul 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants