Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I generate Quarkus rest JX-RS service based on given openapi 3.0.3 yaml file

Currently I am developing an application using quarkus. I have an openapi yaml file that describes everything. I wanted to know if there are quarkus extensions or tool with which I can generate the rest end points that would produce and consume same file format.

like image 785
Sandra Avatar asked Jan 27 '26 08:01

Sandra


2 Answers

As long as you dont need any Quarkus specific features(e.g reactive, @Cached,..), then the REST endpoints are standard JAXRS endpoints and you can use the openapi generator to generate the interfaces and model POJOs for you. After that you simply implement the generated interface:

openapi-cli generate -i url_or_path_to_your_api_schema.yml -g jaxrs-spec --skip-validate-spec --additional-properties=interfaceOnly=true,useSwaggerAnnotations=false

The above command will generate only JAXRS endpoint interface any POJO classes for any models defined in API. You can copy them to your project and implement the iface.

Instead of manual cli invocation, you could integrate this in your maven build, using the openapi generator plugin:

<plugin>
    <groupId>org.openapitools</groupId>
    <artifactId>openapi-generator-maven-plugin</artifactId>
       <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>${project.basedir}/src/main/resources/yourapi.yaml</inputSpec>
                <generatorName>jaxrs-spec</generatorName>
                <additionalProperties>interfaceOnly=true,useSwaggerAnnotations=false</additionalProperties>
                <configOptions>
                   <sourceFolder>src/gen/java/main</sourceFolder>
                </configOptions>
            </configuration>
        </execution>
    </executions>
</plugin>

There is also a complete project stub generator for Quarkus if thats something you fancy: (as --library=quarkus option for jaxrs-spec generator)

There are many more options you may wish to configure described in the docs of OpenApi generators. You can also customize the code templates(moustache) in case the built in ones miss sth you need, though at that point you might look into creating your own generator.

If you need a client and you are ok with the standard Microprofile REST client approach, then the Openapi generator will also work fine:

openapi-cli generate -i path_to_your_openapi_schema.yml -g java --library microprofile

The OpenApi generator is a complex project and not without issues, so it would be best if Quarkus community adopted a custom optimized tooling for server and client code generators, to fully utilise all features e.g. reactive client...

like image 145
yntelectual Avatar answered Jan 29 '26 13:01

yntelectual


We are currently working on an official OpenAPI Generator extension: https://github.com/quarkiverse/quarkus-openapi-generator#readme

Please take a look if you're interested. We'd love to hear feedback from the community.

like image 21
Ricardo Zanini Avatar answered Jan 29 '26 12:01

Ricardo Zanini



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!