Skip to content

Commit

Permalink
Consider 'mp.openapi.scan.disable' value when scanning annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
jmini committed Jul 29, 2019
1 parent b01bcfc commit 36501c8
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.eclipse.microprofile.openapi.OASConfig;
import org.eclipse.microprofile.openapi.OASFilter;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
Expand Down Expand Up @@ -208,8 +209,11 @@ public void build(ApplicationArchivesBuildItem archivesBuildItem,

feature.produce(new FeatureBuildItem(FeatureBuildItem.SMALLRYE_OPENAPI));
OpenAPI staticModel = generateStaticModel(archivesBuildItem);

OpenAPI annotationModel;
if (resteasyJaxrsConfig.isPresent()) {
Config config = ConfigProvider.getConfig();
boolean scanDisable = config.getOptionalValue(OASConfig.SCAN_DISABLE, Boolean.class).orElse(false);
if (resteasyJaxrsConfig.isPresent() && !scanDisable) {
annotationModel = generateAnnotationModel(index, resteasyJaxrsConfig.get());
} else {
annotationModel = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkus.smallrye.openapi.test;

import org.hamcrest.Matchers;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -29,6 +30,10 @@ public void testOpenApiPathAccessResource() {
.then().header("Content-Type", "application/json;charset=UTF-8");
RestAssured.given().queryParam("format", "JSON")
.when().get(OPEN_API_PATH)
.then().header("Content-Type", "application/json;charset=UTF-8");
.then()
.header("Content-Type", "application/json;charset=UTF-8")
.body("openapi", Matchers.startsWith("3.0"))
.body("info.title", Matchers.equalTo("Generated API"))
.body("paths", Matchers.hasKey("/resource"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.quarkus.smallrye.openapi.test;

import org.hamcrest.Matchers;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;

public class OpenApiWithConfigTestCase {
private static final String OPEN_API_PATH = "/openapi";

@RegisterExtension
static QuarkusUnitTest runner = new QuarkusUnitTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addClasses(OpenApiResource.class)
.addAsManifestResource("test-openapi.yaml", "openapi.yaml")
.addAsResource(new StringAsset("mp.openapi.scan.disable=true\nmp.openapi.servers=https://api.acme.org/"),
"application.properties"));

@Test
public void testOpenAPI() {
RestAssured.given().header("Accept", "application/json")
.when().get(OPEN_API_PATH)
.then()
.header("Content-Type", "application/json;charset=UTF-8")
.body("openapi", Matchers.startsWith("3.0"))
.body("info.title", Matchers.equalTo("Test OpenAPI"))
.body("info.description", Matchers.equalTo("Some description"))
.body("info.version", Matchers.equalTo("4.2"))
.body("servers[0].url", Matchers.equalTo("https://api.acme.org/"))
.body("paths", Matchers.hasKey("/openapi"))
.body("paths", Matchers.not(Matchers.hasKey("/resource")));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
openapi: 3.0.0
info:
title: Test OpenAPI
description: Some description
version: 4.2
paths:
/openapi:
get:
operationId: someOperation
responses:
200:
description: Ok

0 comments on commit 36501c8

Please sign in to comment.