jomin7 commented on code in PR #8883:
URL: https://github.com/apache/camel-quarkus/pull/8883#discussion_r3608493397


##########
extensions/openapi-validator/deployment/src/main/java/org/apache/camel/quarkus/component/openapi/validator/deployment/OpenapiValidatorProcessor.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.openapi.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.NativeImageResourceBuildItem;
+import 
io.quarkus.deployment.builditem.nativeimage.NativeImageResourceDirectoryBuildItem;
+import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
+import 
io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
+import org.jboss.jandex.ClassInfo;
+import org.jboss.jandex.DotName;
+
+class OpenapiValidatorProcessor {
+
+    private static final String FEATURE = "camel-openapi-validator";
+    private static final DotName ABSTRACT_KEYWORD_VALIDATOR = DotName
+            
.createSimple("com.github.fge.jsonschema.keyword.validator.AbstractKeywordValidator");
+
+    @BuildStep
+    FeatureBuildItem feature() {
+        return new FeatureBuildItem(FEATURE);
+    }
+
+    @BuildStep
+    void indexDependencies(BuildProducer<IndexDependencyBuildItem> 
indexDependency) {
+        indexDependency.produce(new 
IndexDependencyBuildItem("com.atlassian.oai", 
"swagger-request-validator-core"));
+        indexDependency.produce(new 
IndexDependencyBuildItem("com.github.java-json-tools", 
"json-schema-validator"));
+        indexDependency.produce(new 
IndexDependencyBuildItem("com.github.java-json-tools", "json-schema-core"));
+    }
+
+    @BuildStep
+    void registerReflectiveClasses(
+            CombinedIndexBuildItem combinedIndex,
+            BuildProducer<ReflectiveClassBuildItem> reflectiveClasses) {
+
+        // Keyword validators are instantiated via 
ReflectionKeywordValidatorFactory using Constructor.newInstance()
+        String[] keywordValidators = combinedIndex.getIndex()
+                .getAllKnownSubclasses(ABSTRACT_KEYWORD_VALIDATOR)
+                .stream()
+                .map(ClassInfo::name)
+                .map(DotName::toString)
+                .toArray(String[]::new);
+        
reflectiveClasses.produce(ReflectiveClassBuildItem.builder(keywordValidators).constructors(true).build());
+
+        // Message bundles are instantiated via MessageBundles.getBundle() 
using Constructor.newInstance()
+        reflectiveClasses.produce(ReflectiveClassBuildItem.builder(
+                
"com.atlassian.oai.validator.schema.SwaggerV20Library$ValidationBundle",
+                
"com.atlassian.oai.validator.schema.SwaggerV20Library$SyntaxBundle",
+                
"com.github.fge.jsonschema.core.messages.JsonSchemaCoreMessageBundle",
+                
"com.github.fge.jsonschema.core.messages.JsonSchemaSyntaxMessageBundle",
+                
"com.github.fge.jsonschema.messages.JsonSchemaConfigurationBundle",
+                
"com.github.fge.jsonschema.messages.JsonSchemaValidationBundle").constructors(true).build());
+    }
+
+    @BuildStep
+    void 
runtimeInitializedClasses(BuildProducer<RuntimeInitializedClassBuildItem> 
runtimeInitializedClasses) {
+        runtimeInitializedClasses
+                .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"));

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



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to