quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.64k stars 2.64k forks source link

[Extension Proposal] AsyncAPI generator #41207

Open rquinio1A opened 3 months ago

rquinio1A commented 3 months ago

Description

Interested in this extension, please +1 via the emoji/reaction feature of GitHub (top right).

The go-to library to generare Java model classes from an AsyncAPI document is modelina However, as it's a typscript library, using it in a Maven project requires a lot of boilerplate (frontend-maven-plugin + npm package.json + generator.ts).

There are probably 2 questions to answer for such an extension:

  1. Where to host the extension ?

  2. Which Java generator to use ?

I have a PoC that generates an intermediate OpenAPI document and calls quarkus-openapi-generator on it, but it brings "quarkus-rest-client" dependencies, which don't make sense for event-driven microservices.

Ideally I'd want the same capibilities and user experience for schema-first developement with Quarkus, whether it is for REST server, REST client or event processors.

/cc @hbelmiro @ChMThiel @fjtirado

Repository name

quarkus-asyncapi-generator

Short description

Generate Java POJO from AsyncAPI components

Repository Homepage URL

https://quarkiverse.github.io/quarkiverse-docs/quarkus-asyncapi-generator/dev/

Repository Topics

No response

Team Members

No response

Additional context

No response

quarkus-bot[bot] commented 3 months ago

/cc @aloubyansky (extension-proposal), @gastaldi (extension-proposal), @gsmet (extension-proposal), @maxandersen (extension-proposal)

ChMThiel commented 3 months ago

I think that's a question mainly for @fjtirado since it's for the contract-first part of the extension...

maxandersen commented 3 months ago

on first hunch this feels like a thing the asyncapi extension could/should do - but I honestly know too little about asyncapi to say which generator to use.

maxandersen commented 3 months ago

completely out-of-box thinking...would a modelina extension make sense?

one that allows generation using modelina?

similar to how done for kiota?

maxandersen commented 3 months ago

btw. modelina does not seem to implement/generate a client just generate the model do I read that right?

rquinio1A commented 3 months ago

btw. modelina does not seem to implement/generate a client just generate the model do I read that right?

Indeed it generates only the payload model class, in v3 it's components.schemas.* referenced from components.messages.[eventName].payload.$ref. I've seen requests to also generate wrappers for components.messages.[eventName] containing event metadata (cloud events, headers, ...), but smallrye-reactive-message has its own APIs to manipulate such metadata so I think it doesn't matter.

completely out-of-box thinking...would a modelina extension make sense? one that allows generation using modelina? similar to how done for kiota?

Here's an example of calling it from a Maven project: https://github.com/asyncapi/modelina/tree/master/examples/integrate-with-maven Do you mean Quarkus could hide this boilerplate by packaging nodejs + npm pre-requisites into an extension ?

maxandersen commented 3 months ago

Do you mean Quarkus could hide this boilerplate by packaging nodejs + npm pre-requisites into an extension ?

kinda - we have quinoa that does that for webapp usage and webbundler that bundles esbuild to enable interesting usecases.

not sure if it suffices for modelina - personally I'm not a fan of dragging nodejs ecosystem in just to generate some classes - but if that's what is available ...

andreaTP commented 3 months ago

Hi @rquinio1A ! It's pretty straightforward to hide some setup in a Quarkus Extension, and you have various alternatives, in quarkus-kiota we are wrapping a CLI.

In no particular order, things that can work:

andreaTP commented 2 months ago

I quickly hacked around a POC: https://github.com/andreaTP/quarkus-modelina-poc

You can check the basic usage in the integration-tests.

It uses eirslett/frontend-maven-plugin behind the scenes to setup Node, NPM and install Modelina etc.

Not sure if there is any better recommendation on how to implement this kind of automation cc. @ia3andy

radcortez commented 1 month ago

We did some prototype work for AsyncAPI in SmallRye: https://github.com/smallrye/smallrye-async-api