Skip to content

Commit

Permalink
Added Json Validator support apache#1367
Browse files Browse the repository at this point in the history
  • Loading branch information
aldettinger committed Jun 22, 2020
1 parent 9a138c7 commit e8d9473
Show file tree
Hide file tree
Showing 20 changed files with 749 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/test-categories.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,5 @@ social:
- twitter
validation:
- bean-validator
- json-validator
- validator
47 changes: 47 additions & 0 deletions docs/modules/ROOT/pages/extensions/json-validator.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Do not edit directly!
// This file was generated by camel-quarkus-package-maven-plugin:update-extension-doc-page

[[json-validator]]
= JSON Schema Validator

[.badges]
[.badge-key]##Since Camel Quarkus##[.badge-version]##1.0.0-CR3## [.badge-key]##JVM##[.badge-supported]##supported## [.badge-key]##Native##[.badge-supported]##supported##

Validate JSON payloads using NetworkNT JSON Schema.

== What's inside

* https://camel.apache.org/components/latest/json-validator-component.html[JSON Schema Validator component], URI syntax: `json-validator:resourceUri`

Please refer to the above link for usage and configuration details.

== Maven coordinates

[source,xml]
----
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-json-validator</artifactId>
</dependency>
----

Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.

== Additional Camel Quarkus configuration

Beyond standard usages described above, a trick is needed when using json-validator templates from classpath resources in native mode. In such a situation, one needs to explicitly embed the resources in the native executable by specifying the `include-patterns` option.

For instance, the route below would load the json-validator template from a classpath resource named _schema.json_:
[source,java]
----
from("direct:start").to("json-validator:schema.json");
----

In order to work in native mode the `include-patterns` configuration should be set. For instance, in the `application.properties` file as below :
[source,properties]
----
quarkus.camel.native.resources.include-patterns = schema.json
----

More information about selecting resources for inclusion in the native executable could be found at xref:user-guide/native-mode.adoc#embedding-resource-in-native-executable[Embedding resource in native executable].

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ In case you are missing some Camel feature in the list:
== Camel Components

// components: START
Number of Camel components: 150 in 115 JAR artifacts (0 deprecated)
Number of Camel components: 151 in 116 JAR artifacts (0 deprecated)

[width="100%",cols="4,1,1,1,5",options="header"]
|===
Expand Down Expand Up @@ -186,6 +186,8 @@ Number of Camel components: 150 in 115 JAR artifacts (0 deprecated)

| xref:extensions/jms.adoc[JMS] | camel-quarkus-jms | Native + Stable | 1.2.0 | Sent and receive messages to/from a JMS Queue or Topic.

| xref:extensions/json-validator.adoc[JSON Schema Validator] | camel-quarkus-json-validator | Native + Stable | 1.0.0-CR3 | Validate JSON payloads using NetworkNT JSON Schema.

| xref:extensions/kafka.adoc[Kafka] | camel-quarkus-kafka | Native + Stable | 1.0.0-M1 | Sent and receive messages to/from an Apache Kafka broker.

| xref:extensions/kubernetes.adoc[Kubernetes ConfigMap] | camel-quarkus-kubernetes | Native + Stable | 1.0.0-M6 | Perform operations on Kubernetes ConfigMaps and get notified on ConfigMaps changes.
Expand Down
79 changes: 79 additions & 0 deletions extensions/json-validator/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-json-validator-parent</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>camel-quarkus-json-validator-deployment</artifactId>
<name>Camel Quarkus :: JSON Schema Validator :: Deployment</name>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-bom-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-direct-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-json-validator</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${quarkus.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.component.json.validator.deployment;

import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.IndexDependencyBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import org.jboss.jandex.DotName;

class JsonValidatorProcessor {

private static final String FEATURE = "camel-json-validator";
private static final DotName VALIDATOR_INTERFACE = DotName.createSimple("com.networknt.schema.JsonValidator");

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

@BuildStep
IndexDependencyBuildItem addNetworkNtJsonValidatorArtifactToIndex() {
return new IndexDependencyBuildItem("com.networknt", "json-schema-validator");
}

/**
* Keywords used in schema ("required", "type"...) need matching classes ("RequiredValidator", "TypeValidator"...).
* So, let's register all the known JsonValidator implementations for reflective access in native mode.
*/
@BuildStep
void registerReflectiveClasses(CombinedIndexBuildItem combinedIndex,
BuildProducer<ReflectiveClassBuildItem> reflectiveProducer) {
combinedIndex.getIndex().getAllKnownImplementors(VALIDATOR_INTERFACE).stream()
.forEach(c -> reflectiveProducer.produce(new ReflectiveClassBuildItem(false, false, c.name().toString())));
}
}
39 changes: 39 additions & 0 deletions extensions/json-validator/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-build-parent</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../../poms/build-parent/pom.xml</relativePath>
</parent>

<artifactId>camel-quarkus-json-validator-parent</artifactId>
<name>Camel Quarkus :: JSON Schema Validator</name>
<packaging>pom</packaging>

<modules>
<module>deployment</module>
<module>runtime</module>
</modules>
</project>
98 changes: 98 additions & 0 deletions extensions/json-validator/runtime/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-json-validator-parent</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>camel-quarkus-json-validator</artifactId>
<name>Camel Quarkus :: JSON Schema Validator :: Runtime</name>
<description>Validate JSON payloads using NetworkNT JSON Schema.</description>

<properties>
<firstVersion>1.0.0-CR3</firstVersion>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-bom</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-direct</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-json-validator</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-package-maven-plugin</artifactId>
<executions>
<execution>
<id>update-extension-doc-page</id>
<goals><goal>update-extension-doc-page</goal></goals>
<phase>process-resources</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bootstrap-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${quarkus.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
15 changes: 15 additions & 0 deletions extensions/json-validator/runtime/src/main/doc/configuration.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Beyond standard usages described above, a trick is needed when using json-validator templates from classpath resources in native mode. In such a situation, one needs to explicitly embed the resources in the native executable by specifying the `include-patterns` option.

For instance, the route below would load the json-validator template from a classpath resource named _schema.json_:
[source,java]
----
from("direct:start").to("json-validator:schema.json");
----

In order to work in native mode the `include-patterns` configuration should be set. For instance, in the `application.properties` file as below :
[source,properties]
----
quarkus.camel.native.resources.include-patterns = schema.json
----

More information about selecting resources for inclusion in the native executable could be found at xref:user-guide/native-mode.adoc#embedding-resource-in-native-executable[Embedding resource in native executable].
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# This is a generated file. Do not edit directly!
# To re-generate, run the following command from the top level directory:
#
# mvn -N cq:update-quarkus-metadata
#
---
name: "Camel JSON Schema Validator"
description: "Validate JSON payloads using NetworkNT JSON Schema"
metadata:
guide: "https://camel.apache.org/camel-quarkus/latest/extensions/json-validator.html"
categories:
- "integration"
1 change: 1 addition & 0 deletions extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
<module>jira</module>
<module>jms</module>
<module>johnzon</module>
<module>json-validator</module>
<module>jsonpath</module>
<module>kafka</module>
<module>kotlin</module>
Expand Down

0 comments on commit e8d9473

Please sign in to comment.