2.100. REST OpenApi


To call REST services using OpenAPI specification as contract.

2.100.1. What’s inside

Refer to the above link for usage and configuration details.

2.100.2. Maven coordinates

Create a new project with this extension on code.camel.redhat.com

Or add the coordinates to your existing project:

<dependency>
    <groupId>org.apache.camel.quarkus</groupId>
    <artifactId>camel-quarkus-rest-openapi</artifactId>
</dependency>

2.100.3. Usage

2.100.3.1. Required Dependencies

A RestProducerFactory implementation must be available when using the rest-openapi extension. The currently known extensions are:

  • camel-quarkus-http
  • camel-quarkus-netty-http

Maven users will need to add one of these dependencies to their pom.xml, for example:

<dependency>
    <groupId>org.apache.camel.quarkus</groupId>
    <artifactId>camel-quarkus-http</artifactId>
</dependency>

Depending on which mechanism is used to load the OpenApi specification, additional dependencies may be required. When using the file resource locator, the org.apache.camel.quarkus:camel-quarkus-file extension must be added as a project dependency. When using ref or bean to load the specification, not only must the org.apache.camel.quarkus:camel-quarkus-bean dependency be added, but the bean itself must be annotated with @RegisterForReflection.

When using the classpath resource locator with native code, the path to the OpenAPI specification must be specified in the quarkus.native.resources.includes property of the application.properties file. For example:

quarkus.native.resources.includes=openapi.json

2.100.3.2. Contract First Development

The model classes generation has been integrated with the quarkus-maven-plugin. So there’s no need to use the swagger-codegen-maven-plugin, instead put your contract files in src/main/openapi with a .json suffix. And add the generate-code goal to the quarkus-maven-plugin like:

<plugin>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-maven-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>generate-code</goal>
            </goals>
        </execution>
    </executions>
</plugin>

It requires a specific package name for the model classes by using the quarkus.camel.openapi.codegen.model-package property of the application.properties file. For example:

quarkus.camel.openapi.codegen.model-package=org.acme

This package name should be added in camel.rest.bindingPackageScan as well.

The contract files in src/main/openapi needs to be added in the classpath since they could be used in Camel Rest DSL. So you can add src/main/openapi in pom.xml

<build>
    <resources>
        <resource>
            <directory>src/main/openapi</directory>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
    </resources>
</build>

When running in the native mode, the contract files must be specified the quarkus.native.resources.include like

quarkus.native.resources.includes=contract.json

2.100.4. Additional Camel Quarkus configuration

Expand
Configuration propertyTypeDefault

quarkus.camel.openapi.codegen.enabled

If true, Camel Quarkus OpenAPI code generation is run for .json files discovered from the openapi directory. When false, code generation for .json files is disabled.

boolean

true

quarkus.camel.openapi.codegen.model-package

The package to use for generated model classes.

string

org.apache.camel.quarkus

quarkus.camel.openapi.codegen.models

A comma separated list of models to generate. All models is the default.

string

 

quarkus.camel.openapi.codegen.use-bean-validation

If true, use bean validation annotations in the generated model classes.

boolean

false

quarkus.camel.openapi.codegen.not-null-jackson

If true, use NON_NULL Jackson annotation in the generated model classes.

boolean

false

Configuration property fixed at build time. All other configuration properties are overridable at runtime.

Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

Red Hat ドキュメントについて

Legal Notice

Theme

© 2026 Red Hat
トップに戻る