From 0158130a8cf8a0e26e98faa434538e21572ca8ba Mon Sep 17 00:00:00 2001 From: Fabio Burzigotti Date: Tue, 14 Oct 2025 19:06:38 +0200 Subject: [PATCH] Adding a test to validate processing rules (@ExternalDocumentation ATM) --- .../tck/extra/ProcessingRulesTest.java | 52 +++++++++++++++++++ .../extra/procrules/OpenApiModelReader.java | 26 ++++++++++ .../WidgetResourceWithAnnotations.java | 9 ++++ .../resources/set-model-reader.properties | 1 + 4 files changed, 88 insertions(+) create mode 100644 testsuite/extra/src/test/java/io/smallrye/openapi/tck/extra/ProcessingRulesTest.java create mode 100644 testsuite/extra/src/test/java/io/smallrye/openapi/tck/extra/procrules/OpenApiModelReader.java create mode 100644 testsuite/extra/src/test/java/io/smallrye/openapi/tck/extra/procrules/WidgetResourceWithAnnotations.java create mode 100644 testsuite/extra/src/test/resources/set-model-reader.properties diff --git a/testsuite/extra/src/test/java/io/smallrye/openapi/tck/extra/ProcessingRulesTest.java b/testsuite/extra/src/test/java/io/smallrye/openapi/tck/extra/ProcessingRulesTest.java new file mode 100644 index 000000000..3e30fcc16 --- /dev/null +++ b/testsuite/extra/src/test/java/io/smallrye/openapi/tck/extra/ProcessingRulesTest.java @@ -0,0 +1,52 @@ +/* + * Copyright 2025 Red Hat, Inc. + * + * Licensed 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 io.smallrye.openapi.tck.extra; + +import org.eclipse.microprofile.openapi.tck.AppTestBase; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.testng.annotations.Test; + +import io.restassured.response.ValidatableResponse; +import test.io.smallrye.openapi.tck.ExtraSuiteTestBase; + +/** + * NOTE: It's not a TCK test, it only leverages the TCK test setup + */ +public class ProcessingRulesTest extends ExtraSuiteTestBase { + + public static class ProcessingRulesTestArquillian extends AppTestBase { + @Deployment(name = "processing-rules") + public static WebArchive createDeployment() { + return ShrinkWrap.create(WebArchive.class, "ProcessingRules.war") + .addPackages(true, new String[] { "io.smallrye.openapi.tck.extra.procrules" }) + .addAsManifestResource("set-model-reader.properties", "microprofile-config.properties"); + } + + @RunAsClient + @Test(dataProvider = "formatProvider") + public void testPathItems(String type) { + ValidatableResponse vr = this.callEndpoint(type); + vr.body("externalDocs.url", org.hamcrest.Matchers.notNullValue()); + vr.body("externalDocs.url", org.hamcrest.Matchers.is("http://widget-external-docs.org")); + vr.body("externalDocs.description", org.hamcrest.Matchers.notNullValue()); + vr.body("externalDocs.description", org.hamcrest.Matchers.is("Widget resource external documentation")); + } + + } +} diff --git a/testsuite/extra/src/test/java/io/smallrye/openapi/tck/extra/procrules/OpenApiModelReader.java b/testsuite/extra/src/test/java/io/smallrye/openapi/tck/extra/procrules/OpenApiModelReader.java new file mode 100644 index 000000000..78739148b --- /dev/null +++ b/testsuite/extra/src/test/java/io/smallrye/openapi/tck/extra/procrules/OpenApiModelReader.java @@ -0,0 +1,26 @@ +package io.smallrye.openapi.tck.extra.procrules; + +import org.eclipse.microprofile.openapi.OASFactory; +import org.eclipse.microprofile.openapi.OASModelReader; +import org.eclipse.microprofile.openapi.models.ExternalDocumentation; +import org.eclipse.microprofile.openapi.models.OpenAPI; + +/** + * Generates a base model to be used by the OpenAPI. + */ +public class OpenApiModelReader implements OASModelReader { + /** + * Creates a new {@link ExternalDocumentation} instance, modifying the output OpenAPI document. + * + * @return A new {@link OpenAPI} instance that will serve as base for generation + */ + @Override + public OpenAPI buildModel() { + OpenAPI api = OASFactory.createObject(OpenAPI.class); + ExternalDocumentation externalDocumentation = OASFactory.createExternalDocumentation(); + externalDocumentation.setUrl("http://oas-model-reader-based-external-docs.org"); + externalDocumentation.setDescription("Could be overridden by static files and/or annotations"); + api.setExternalDocs(externalDocumentation); + return api; + } +} diff --git a/testsuite/extra/src/test/java/io/smallrye/openapi/tck/extra/procrules/WidgetResourceWithAnnotations.java b/testsuite/extra/src/test/java/io/smallrye/openapi/tck/extra/procrules/WidgetResourceWithAnnotations.java new file mode 100644 index 000000000..43f187875 --- /dev/null +++ b/testsuite/extra/src/test/java/io/smallrye/openapi/tck/extra/procrules/WidgetResourceWithAnnotations.java @@ -0,0 +1,9 @@ +package io.smallrye.openapi.tck.extra.procrules; + +import org.eclipse.microprofile.openapi.annotations.ExternalDocumentation; + +import io.smallrye.openapi.tck.extra.jaxrs.WidgetResource; + +@ExternalDocumentation(url = "http://widget-external-docs.org", description = "Widget resource external documentation") +public class WidgetResourceWithAnnotations extends WidgetResource { +} diff --git a/testsuite/extra/src/test/resources/set-model-reader.properties b/testsuite/extra/src/test/resources/set-model-reader.properties new file mode 100644 index 000000000..acba0ac6d --- /dev/null +++ b/testsuite/extra/src/test/resources/set-model-reader.properties @@ -0,0 +1 @@ +mp.openapi.model.reader=io.smallrye.openapi.tck.extra.procrules.OpenApiModelReader \ No newline at end of file