Skip to content

Fixes #6169. Add OpenAPI Validator extension#8883

Merged
jamesnetherton merged 1 commit into
apache:mainfrom
jomin7:issue-6169-openapi-validator-extension
Jul 21, 2026
Merged

Fixes #6169. Add OpenAPI Validator extension#8883
jamesnetherton merged 1 commit into
apache:mainfrom
jomin7:issue-6169-openapi-validator-extension

Conversation

@jomin7

@jomin7 jomin7 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Fixes #6169. Add OpenAPI Validator extension

  • Add camel-quarkus-openapi-validator extension providing native image support for the camel-openapi-validator
    component
  • Register reflective classes for JSON Schema keyword validators, native image resources for draft schema directories, and
    runtime-initialized classes for the Atlassian swagger-request-validator library
  • Integration test uses REST DSL consumer with clientRequestValidation to exercise the full JSON Schema validation path
    (required fields, type checking, missing body)
  • Added a servers section with /api basePath to the integration test OpenAPI spec and updated test URLs accordingly, to work around a Camel 4.21 contract-first routing issue where a root basePath (/) produces double-slash paths (e.g. //fruits) that don't match incoming requests

@jomin7
jomin7 force-pushed the issue-6169-openapi-validator-extension branch 2 times, most recently from b7c8360 to d3926bc Compare July 14, 2026 21:13
Comment on lines +8 to +9
cqJvmSince: 3.37.0
cqNativeSince: 3.37.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it will be since 3.38.0, isn't it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right — it should be 3.38.0. Fixed in the latest push, thanks for catching that

Comment on lines +12 to +13
:cq-jvm-since: 3.37.0
:cq-native-since: 3.37.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it will be since 3.38.0, isn't it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above — updated to 3.38.0. Thanks!

Comment on lines +76 to +80
.produce(new RuntimeInitializedClassBuildItem("com.github.fge.jackson.JsonNodeReader"));
runtimeInitializedClasses
.produce(new RuntimeInitializedClassBuildItem("com.github.fge.jackson.JsonLoader"));
runtimeInitializedClasses
.produce(new RuntimeInitializedClassBuildItem("com.github.fge.jsonschema.core.util.RegexECMA262Helper"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use the Java method JsonNodeReader.class.getName() ?

it allows to detect deprecation and removal more easily when there are upgrades of the library dependency

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great suggestion .updated all three RuntimeInitializedClassBuildItem entries to use class references. This will make it easier to catch breakages on dependency upgrades.

@apupier

apupier commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

PR check failures are due to the usage of 3.38.0-SNAPSHOT version instead of 3.38.0-SNAPSHOT

@jomin7
jomin7 force-pushed the issue-6169-openapi-validator-extension branch from d3926bc to c631889 Compare July 18, 2026 13:57
@jomin7

jomin7 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

@apupier Thanks for flagging.Updated all to 3.38.0-SNAPSHOT in the latest push.

@jomin7
jomin7 force-pushed the issue-6169-openapi-validator-extension branch 2 times, most recently from 601e9a4 to 3398ced Compare July 20, 2026 07:05
@jomin7

jomin7 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

The earlier failure was due to the generated flattened BOM files (poms/bom/src/main/generated/flattened-*.xml) still carrying 3.37.0-SNAPSHOT versions , a leftover from the rebase conflict resolution. I've since regenerated them with the correct 3.38.0-SNAPSHOT versions and force pushed. The CI check should pass now.

Comment on lines +1 to +15
=== Enabling Request Validation

To validate incoming requests against an OpenAPI specification, use the REST DSL with `clientRequestValidation` enabled:

[source,java]
----
rest().clientRequestValidation(true).openApi().specification("openapi.json");

// Handler route — auto-wired by operationId from the spec
from("direct:addFruit")
.setBody(constant("Fruit created"));
----

Invalid requests are rejected with HTTP 400 and a validation report describing the errors.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably remove this. It's a duplication of the Camel component documentation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.removed. Kept only the Native Mode section since that's Quarkus-specific.Thanks

@jamesnetherton jamesnetherton Jul 20, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are uncommitted changes
HEAD detached at pull/8883/merge
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   docs/modules/ROOT/pages/reference/extensions/openapi-validator.adoc

You'll need to run mvn clean install in the openapi-validator extension module to regenerate the docs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that . Fixed now by running mvn process-classes on the deployment module and pushed the update.

@jomin7
jomin7 force-pushed the issue-6169-openapi-validator-extension branch from 3398ced to 070161c Compare July 20, 2026 11:12
Add a Camel Quarkus extension for the camel-openapi-validator component,
providing native image support for JSON Schema validation of REST API
requests against OpenAPI specifications.

The extension registers reflective classes for keyword validators,
native image resources for JSON Schema draft directories, and
runtime-initialized classes required by the underlying Atlassian
swagger-request-validator library.

The integration test uses the REST DSL consumer with
clientRequestValidation enabled to exercise the full validation path,
including JSON Schema keyword validation for required fields and type
checking.
@jomin7
jomin7 force-pushed the issue-6169-openapi-validator-extension branch from 070161c to 39ebfb9 Compare July 20, 2026 12:49
@jomin7
jomin7 requested a review from apupier July 20, 2026 14:23
@jamesnetherton
jamesnetherton merged commit cad57ff into apache:main Jul 21, 2026
10 checks passed
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

Successfully merging this pull request may close these issues.

Camel 4.7 - camel-openapi-validator extension

3 participants