asyncapi / saunter

Saunter is a code-first AsyncAPI documentation generator for dotnet.
https://www.asyncapi.com/
MIT License
205 stars 57 forks source link

[FEATURE] Generate classes based on AsyncAPI document #207

Open thompson-tomo opened 6 months ago

thompson-tomo commented 6 months ago

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?

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue?

Yes I am willing to submit a PR!

yurvon-screamo commented 6 months ago

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

Can you describe your idea in more detail?

thompson-tomo commented 6 months ago

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 commented 6 months ago

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:

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 commented 6 months ago

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.