io.smallrye.openapi.api.OpenApiConfig Java Examples

The following examples show how to use io.smallrye.openapi.api.OpenApiConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RolesAllowedScopeScanTests.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testClassRolesAllowedGeneratedScheme() throws IOException {
    Index index = indexOf(RolesAllowedApp.class, RolesAllowedResource1.class);
    OpenApiConfig config = emptyConfig();
    IndexView filtered = new FilteredIndexView(index, config);
    OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(config, filtered);
    OpenAPI result = scanner.scan();
    printToConsole(result);
    SecurityRequirement requirement = result.getPaths().getPathItem("/v1/secured").getGET().getSecurity().get(0);
    assertNotNull(requirement);
    assertEquals(1, requirement.getScheme("rolesScheme").size());
    assertEquals("admin", requirement.getScheme("rolesScheme").get(0));
    assertEquals("admin",
            result.getComponents()
                    .getSecuritySchemes()
                    .get("rolesScheme")
                    .getFlows()
                    .getClientCredentials()
                    .getScopes()
                    .keySet()
                    .iterator().next());
}
 
Example #2
Source File: OpenApiAnnotationScanner.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
private CustomSchemaRegistry getCustomSchemaRegistry(final OpenApiConfig config) {
    if (config == null || config.customSchemaRegistryClass() == null) {
        // Provide default implementation that does nothing
        return type -> {
        };
    } else {
        try {
            return (CustomSchemaRegistry) Class.forName(config.customSchemaRegistryClass(), true, getContextClassLoader())
                    .getDeclaredConstructor().newInstance();
        } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException
                | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
            throw ScannerMessages.msg.failedCreateInstance(config.customSchemaRegistryClass(), ex);
        }

    }
}
 
Example #3
Source File: ServersUtil.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
/**
 * Configures the servers for an Operation.
 * 
 * @param config OpenApiConfig
 * @param operation Operation
 */
protected static void configureServers(OpenApiConfig config, Operation operation) {
    if (operation == null) {
        return;
    }
    if (operation.getOperationId() == null) {
        return;
    }

    Set<String> operationServers = config.operationServers(operation.getOperationId());
    if (operationServers != null && !operationServers.isEmpty()) {
        operation.servers(new ArrayList<>());
        for (String operationServer : operationServers) {
            Server server = new ServerImpl();
            server.setUrl(operationServer);
            operation.addServer(server);
        }
    }
}
 
Example #4
Source File: ServersUtil.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
/**
 * Configures the servers for a PathItem.
 * 
 * @param config OpenApiConfig
 * @param pathName String representing the pathName
 * @param pathItem String representing the pathItem
 */
protected static void configureServers(OpenApiConfig config, String pathName, PathItem pathItem) {
    if (pathItem == null) {
        return;
    }

    Set<String> pathServers = config.pathServers(pathName);
    if (pathServers != null && !pathServers.isEmpty()) {
        pathItem.servers(new ArrayList<>());
        for (String pathServer : pathServers) {
            Server server = new ServerImpl();
            server.setUrl(pathServer);
            pathItem.addServer(server);
        }
    }

    configureServers(config, pathItem.getGET());
    configureServers(config, pathItem.getPUT());
    configureServers(config, pathItem.getPOST());
    configureServers(config, pathItem.getDELETE());
    configureServers(config, pathItem.getHEAD());
    configureServers(config, pathItem.getOPTIONS());
    configureServers(config, pathItem.getPATCH());
    configureServers(config, pathItem.getTRACE());
}
 
Example #5
Source File: ServersUtil.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
public static final void configureServers(OpenApiConfig config, OpenAPI oai) {
    // Start with the global servers.
    Set<String> servers = config.servers();
    if (servers != null && !servers.isEmpty()) {
        oai.servers(new ArrayList<>());
        for (String server : servers) {
            Server s = new ServerImpl();
            s.setUrl(server);
            oai.addServer(s);
        }
    }

    // Now the PathItem and Operation servers
    Map<String, PathItem> pathItems = oai.getPaths().getPathItems();
    if (pathItems != null) {
        pathItems.entrySet().forEach(entry -> configureServers(config, entry.getKey(), entry.getValue()));
    }
}
 
Example #6
Source File: ResourceParameterTests.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
/*************************************************************************/

    /*
     * Test case derived from original example in SmallRye OpenAPI issue #237.
     *
     * https://github.com/smallrye/smallrye-open-api/issues/237
     *
     */
    @Test
    public void testTypeVariableResponse() throws IOException, JSONException {
        Index i = indexOf(TypeVariableResponseTestResource.class,
                TypeVariableResponseTestResource.Dto.class);
        OpenApiConfig config = emptyConfig();
        IndexView filtered = new FilteredIndexView(i, config);
        OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(config, filtered);
        OpenAPI result = scanner.scan();
        printToConsole(result);
        assertJsonEquals("resource.parameters.type-variable.json", result);
    }
 
Example #7
Source File: ResourceParameterTests.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
/*************************************************************************/

    /*
     * Test case derived from original example in Smallrye OpenAPI issue #201.
     *
     * https://github.com/smallrye/smallrye-open-api/issues/201
     *
     */
    @Test
    public void testSchemaImplementationType() throws IOException, JSONException {
        Index i = indexOf(SchemaImplementationTypeResource.class,
                SchemaImplementationTypeResource.GreetingMessage.class,
                SchemaImplementationTypeResource.SimpleString.class);

        OpenApiConfig config = emptyConfig();
        IndexView filtered = new FilteredIndexView(i, config);
        OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(config, filtered);
        OpenAPI result = scanner.scan();
        printToConsole(result);
        assertJsonEquals("resource.parameters.string-implementation-wrapped.json", result);
    }
 
Example #8
Source File: SmallRyeOpenApiProcessor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
private OpenAPI generateAnnotationModel(IndexView indexView, Capabilities capabilities) {
    Config config = ConfigProvider.getConfig();
    OpenApiConfig openApiConfig = new OpenApiConfigImpl(config);

    String defaultPath = config.getValue("quarkus.http.root-path", String.class);

    List<AnnotationScannerExtension> extensions = new ArrayList<>();
    // Add RestEasy if jaxrs
    if (capabilities.isCapabilityPresent(Capabilities.RESTEASY)) {
        extensions.add(new RESTEasyExtension(indexView));
    }
    // Add path if not null
    if (defaultPath != null) {
        extensions.add(new CustomPathExtension(defaultPath));
    }
    return new OpenApiAnnotationScanner(openApiConfig, indexView, extensions).scan();
}
 
Example #9
Source File: SmallRyeOpenApiProcessor.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public OpenApiDocument loadDocument(OpenAPI staticModel, OpenAPI annotationModel) {
    Config config = ConfigProvider.getConfig();
    OpenApiConfig openApiConfig = new OpenApiConfigImpl(config);

    OpenAPI readerModel = OpenApiProcessor.modelFromReader(openApiConfig,
            Thread.currentThread().getContextClassLoader());

    OpenApiDocument document = createDocument(openApiConfig);
    if (annotationModel != null) {
        document.modelFromAnnotations(annotationModel);
    }
    document.modelFromReader(readerModel);
    document.modelFromStaticFile(staticModel);
    document.filter(filter(openApiConfig));
    document.initialize();
    return document;
}
 
Example #10
Source File: RolesAllowedScopeScanTests.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testSchemesWithoutRoles() throws IOException {
    Index index = indexOf(UndeclaredFlowsNoRolesAllowedApp.class, NoRolesResource.class);
    OpenApiConfig config = emptyConfig();
    IndexView filtered = new FilteredIndexView(index, config);
    OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(config, filtered);
    OpenAPI result = scanner.scan();
    printToConsole(result);
    SecurityRequirement requirement = result.getPaths().getPathItem("/v1/secured").getGET().getSecurity().get(0);
    assertNotNull(requirement);
    assertEquals(1, requirement.getScheme("oidc").size());
    assertEquals("admin", requirement.getScheme("oidc").get(0));
    assertNull(result.getComponents()
            .getSecuritySchemes()
            .get("oidc")
            .getFlows());
}
 
Example #11
Source File: RolesAllowedScopeScanTests.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeclaredRolesMethodRolesAllowedGeneratedScheme() throws IOException {
    Index index = indexOf(RolesAllowedApp.class, RolesDeclaredResource.class);
    OpenApiConfig config = emptyConfig();
    IndexView filtered = new FilteredIndexView(index, config);
    OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(config, filtered);
    OpenAPI result = scanner.scan();
    printToConsole(result);
    SecurityRequirement requirement = result.getPaths().getPathItem("/v1/secured").getGET().getSecurity().get(0);
    assertNotNull(requirement);
    assertEquals(1, requirement.getScheme("rolesScheme").size());
    assertEquals("admin", requirement.getScheme("rolesScheme").get(0));
    assertArrayEquals(new String[] { "admin", "users" },
            result.getComponents()
                    .getSecuritySchemes()
                    .get("rolesScheme")
                    .getFlows()
                    .getClientCredentials()
                    .getScopes()
                    .keySet()
                    .toArray());
}
 
Example #12
Source File: OpenApiDocumentProducer.java    From quarkus with Apache License 2.0 6 votes vote down vote up
/**
 * We load the document from the generated JSON file, which should have all the annotations
 *
 * Most apps will likely just want to serve the OpenAPI doc, rather than inject it, which is why we generated the
 * static file and parse it if required. The more Quarkus-like approach of serializing the doc to bytecode
 * can result in a lot of bytecode, which will likely just be turned straight into a static file anyway.
 */
@PostConstruct
void create() throws IOException {
    try (InputStream is = getClass().getClassLoader()
            .getResourceAsStream(OpenApiHandler.BASE_NAME + Format.JSON)) {
        if (is != null) {
            try (OpenApiStaticFile staticFile = new OpenApiStaticFile(is, Format.JSON)) {
                Config config = ConfigProvider.getConfig();
                OpenApiConfig openApiConfig = new OpenApiConfigImpl(config);

                OpenAPI readerModel = OpenApiProcessor.modelFromReader(openApiConfig,
                        Thread.currentThread().getContextClassLoader());
                document = OpenApiDocument.INSTANCE;
                document.reset();
                document.config(openApiConfig);

                document.modelFromReader(readerModel);
                document.modelFromStaticFile(io.smallrye.openapi.runtime.OpenApiProcessor.modelFromStaticFile(staticFile));
                document.filter(OpenApiProcessor.getFilter(openApiConfig, Thread.currentThread().getContextClassLoader()));
                document.initialize();
            }
        }
    }

}
 
Example #13
Source File: RolesAllowedScopeScanTests.java    From smallrye-open-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testMethodRolesAllowedGeneratedScheme() throws IOException {
    Index index = indexOf(RolesAllowedApp.class, RolesAllowedResource2.class);
    OpenApiConfig config = emptyConfig();
    IndexView filtered = new FilteredIndexView(index, config);
    OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(config, filtered);
    OpenAPI result = scanner.scan();
    printToConsole(result);
    SecurityRequirement requirement = result.getPaths().getPathItem("/v2/secured").getGET().getSecurity().get(0);
    assertNotNull(requirement);
    assertEquals(2, requirement.getScheme("rolesScheme").size());
    assertEquals("admin", requirement.getScheme("rolesScheme").get(0));
    assertEquals("users", requirement.getScheme("rolesScheme").get(1));
    assertArrayEquals(new String[] { "admin", "users" },
            result.getComponents()
                    .getSecuritySchemes()
                    .get("rolesScheme")
                    .getFlows()
                    .getClientCredentials()
                    .getScopes()
                    .keySet()
                    .toArray());
}
 
Example #14
Source File: OpenApiDeploymentProcessorTest.java    From thorntail with Apache License 2.0 6 votes vote down vote up
/**
 * Common test method.
 * @throws Exception
 */
protected void doTest(
        Class modelReaderClass,
        String staticResource,
        boolean disableAnnotationScanning,
        Class filterClass,
        String expectedResource) throws Exception {

    System.setProperty(OASConfig.SCAN_DISABLE, "" + disableAnnotationScanning);
    System.setProperty(OASConfig.MODEL_READER, modelReaderClass != null ? modelReaderClass.getName() : "");
    System.setProperty(OASConfig.FILTER, filterClass != null ? filterClass.getName() : "");

    TestConfig cfg = new TestConfig();
    OpenApiConfig oaiConfig = new OpenApiConfigImpl(cfg);
    Archive archive = archive(staticResource);
    OpenApiDocument.INSTANCE.reset();
    OpenApiDeploymentProcessor processor = new OpenApiDeploymentProcessor(oaiConfig, archive);
    processor.process();
    new OpenApiServletContextListener(cfg).contextInitialized(null);

    String actual = OpenApiSerializer.serialize(OpenApiDocument.INSTANCE.get(), Format.JSON);
    String expected = loadResource(getClass().getResource(expectedResource));

    assertJsonEquals(expected, actual);
}
 
Example #15
Source File: RolesAllowedScopeScanTests.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testPermitAllWithoutGeneratedScheme() throws IOException {
    Index index = indexOf(RolesAllowedApp.class, RolesAllowedResource1.class);
    OpenApiConfig config = emptyConfig();
    IndexView filtered = new FilteredIndexView(index, config);
    OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(config, filtered);
    OpenAPI result = scanner.scan();
    printToConsole(result);
    assertNull(result.getPaths().getPathItem("/v1/open").getGET().getSecurity());
}
 
Example #16
Source File: FilteredIndexViewTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testAcceptsEmptyConfig() {
    Map<String, Object> properties = new HashMap<>();
    OpenApiConfig config = IndexScannerTestBase.dynamicConfig(properties);
    FilteredIndexView view = new FilteredIndexView(null, config);
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyBean")));
}
 
Example #17
Source File: FilteredIndexViewTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testAccepts_IncludedClass_ExcludedPackage() {
    Map<String, Object> properties = new HashMap<>();
    properties.put(OASConfig.SCAN_CLASSES, "com.example.pkgA.MyBean,com.example.pkgA.MyClass");
    properties.put(OASConfig.SCAN_EXCLUDE_PACKAGES, "com.example.pkgA");
    OpenApiConfig config = IndexScannerTestBase.dynamicConfig(properties);
    FilteredIndexView view = new FilteredIndexView(null, config);
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyBean")));
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyClass")));
}
 
Example #18
Source File: FilteredIndexViewTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testAccepts_ExcludedClass_IncludedClassPattern() {
    Map<String, Object> properties = new HashMap<>();
    properties.put(OASConfig.SCAN_CLASSES, "^(?:com.example.pkgA.My.*)$");
    properties.put(OASConfig.SCAN_EXCLUDE_CLASSES, "com.example.pkgA.MyImpl");
    OpenApiConfig config = IndexScannerTestBase.dynamicConfig(properties);
    FilteredIndexView view = new FilteredIndexView(null, config);
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyBean")));
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyClass")));
    assertFalse(view.accepts(DotName.createSimple("com.example.pkgA.MyImpl")));
}
 
Example #19
Source File: FilteredIndexViewTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testAccepts_IncludedClassPattern_ExcludedPackage() {
    Map<String, Object> properties = new HashMap<>();
    properties.put(OASConfig.SCAN_CLASSES, "^(?:com.example.pkgA.My.*)$");
    properties.put(OASConfig.SCAN_EXCLUDE_PACKAGES, "com.example.pkgA");
    OpenApiConfig config = IndexScannerTestBase.dynamicConfig(properties);
    FilteredIndexView view = new FilteredIndexView(null, config);
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyBean")));
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyClass")));
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyImpl")));
}
 
Example #20
Source File: FilteredIndexViewTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testAccepts_ExcludedSimpleClassPattern_NotIncludedClassMatch() {
    Map<String, Object> properties = new HashMap<>();
    properties.put(OASConfig.SCAN_EXCLUDE_CLASSES, "example.pkgA.MyImpl$");
    OpenApiConfig config = IndexScannerTestBase.dynamicConfig(properties);
    FilteredIndexView view = new FilteredIndexView(null, config);
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyBean")));
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyClass")));
    assertFalse(view.accepts(DotName.createSimple("com.example.pkgA.MyImpl")));
}
 
Example #21
Source File: FilteredIndexViewTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testAccepts_ExcludedSimpleClassPattern_IncludedClassShorterMatch() {
    Map<String, Object> properties = new HashMap<>();
    properties.put(OASConfig.SCAN_CLASSES, "(?:pkgA.My.*)$");
    properties.put(OASConfig.SCAN_EXCLUDE_CLASSES, "example.pkgA.MyImpl$");
    OpenApiConfig config = IndexScannerTestBase.dynamicConfig(properties);
    FilteredIndexView view = new FilteredIndexView(null, config);
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyBean")));
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyClass")));
    assertFalse(view.accepts(DotName.createSimple("com.example.pkgA.MyImpl")));
}
 
Example #22
Source File: FilteredIndexViewTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testAccepts_ExcludedSimpleClassPattern_IncludedClassLongerMatch() {
    Map<String, Object> properties = new HashMap<>();
    properties.put(OASConfig.SCAN_CLASSES, "(?:example.pkgA.My.*)$");
    properties.put(OASConfig.SCAN_EXCLUDE_CLASSES, "pkgA.MyImpl$");
    OpenApiConfig config = IndexScannerTestBase.dynamicConfig(properties);
    FilteredIndexView view = new FilteredIndexView(null, config);
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyBean")));
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyClass")));
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyImpl")));
}
 
Example #23
Source File: FilteredIndexViewTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testAccepts_IncludedSimpleClassPattern_ExcludedPackage() {
    Map<String, Object> properties = new HashMap<>();
    properties.put(OASConfig.SCAN_CLASSES, "(?:pkgA.My(Bean|Class))$");
    properties.put(OASConfig.SCAN_EXCLUDE_PACKAGES, "com.example.pkgA");
    OpenApiConfig config = IndexScannerTestBase.dynamicConfig(properties);
    FilteredIndexView view = new FilteredIndexView(null, config);
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyBean")));
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyClass")));
    assertFalse(view.accepts(DotName.createSimple("com.example.pkgA.MyImpl")));
}
 
Example #24
Source File: FilteredIndexViewTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testAccepts_IncludedSimpleClassPattern_ExcludedPackagePrefix() {
    Map<String, Object> properties = new HashMap<>();
    properties.put(OASConfig.SCAN_CLASSES, "(?:pkgA.My(Bean|Class))$");
    properties.put(OASConfig.SCAN_EXCLUDE_PACKAGES, "com.example");
    OpenApiConfig config = IndexScannerTestBase.dynamicConfig(properties);
    FilteredIndexView view = new FilteredIndexView(null, config);
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyBean")));
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyClass")));
    assertFalse(view.accepts(DotName.createSimple("com.example.pkgA.MyImpl")));
}
 
Example #25
Source File: FilteredIndexViewTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testAccepts_IncludedSimpleClassPattern_ExcludedPackagePatternDoesNotMatch() {
    Map<String, Object> properties = new HashMap<>();
    properties.put(OASConfig.SCAN_CLASSES, "(?:pkgA.MyBean)$");
    properties.put(OASConfig.SCAN_EXCLUDE_PACKAGES, "example.pkg[AB]$");
    properties.put(OASConfig.SCAN_PACKAGES, "^(com|org).example");
    OpenApiConfig config = IndexScannerTestBase.dynamicConfig(properties);
    FilteredIndexView view = new FilteredIndexView(null, config);
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyBean")));
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyClass")));
    assertTrue(view.accepts(DotName.createSimple("org.example.pkgB.MyImpl")));
}
 
Example #26
Source File: FilteredIndexViewTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testAccepts_ExcludedPackageOverridesIncludedPackage() {
    Map<String, Object> properties = new HashMap<>();
    properties.put(OASConfig.SCAN_PACKAGES, "com.example");
    properties.put(OASConfig.SCAN_EXCLUDE_PACKAGES, "com.example");
    OpenApiConfig config = IndexScannerTestBase.dynamicConfig(properties);
    FilteredIndexView view = new FilteredIndexView(null, config);
    assertFalse(view.accepts(DotName.createSimple("com.example.TopLevelClass")));
    assertFalse(view.accepts(DotName.createSimple("com.example.pkgA.MyBean")));
    assertFalse(view.accepts(DotName.createSimple("com.example.pkgA.MyClass")));
    assertFalse(view.accepts(DotName.createSimple("com.example.pkgA.MyImpl")));
}
 
Example #27
Source File: FilteredIndexViewTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testAccepts_IncludedPackageDoesNotMatch() {
    Map<String, Object> properties = new HashMap<>();
    properties.put(OASConfig.SCAN_PACKAGES, "example.pkgA$");
    OpenApiConfig config = IndexScannerTestBase.dynamicConfig(properties);
    FilteredIndexView view = new FilteredIndexView(null, config);
    assertFalse(view.accepts(DotName.createSimple("com.example.pkgA.MyBean")));
    assertFalse(view.accepts(DotName.createSimple("com.example.pkgA.MyClass")));
    assertFalse(view.accepts(DotName.createSimple("com.example.pkgA.MyImpl")));
}
 
Example #28
Source File: FilteredIndexViewTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testAccepts_IncludedPackageOverridesExcludedPackage() {
    Map<String, Object> properties = new HashMap<>();
    properties.put(OASConfig.SCAN_PACKAGES, "com.example.pkgA");
    properties.put(OASConfig.SCAN_EXCLUDE_PACKAGES, "com.example");
    OpenApiConfig config = IndexScannerTestBase.dynamicConfig(properties);
    FilteredIndexView view = new FilteredIndexView(null, config);
    assertFalse(view.accepts(DotName.createSimple("com.example.TopLevelClass")));
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyBean")));
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyClass")));
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyImpl")));
}
 
Example #29
Source File: FilteredIndexViewTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testAccepts_IncludedPackageExcludesOtherPackage() {
    Map<String, Object> properties = new HashMap<>();
    properties.put(OASConfig.SCAN_PACKAGES, "com.example.pkgA");
    OpenApiConfig config = IndexScannerTestBase.dynamicConfig(properties);
    FilteredIndexView view = new FilteredIndexView(null, config);
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyBean")));
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyClass")));
    assertFalse(view.accepts(DotName.createSimple("com.example.pkgB.MyImpl")));
}
 
Example #30
Source File: FilteredIndexViewTest.java    From smallrye-open-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testAccepts_IncludedClassesImpliesOtherClassesExcluded() {
    Map<String, Object> properties = new HashMap<>();
    properties.put(OASConfig.SCAN_CLASSES, "^com.example.pkgA.My(Bean|Class)$");
    OpenApiConfig config = IndexScannerTestBase.dynamicConfig(properties);
    FilteredIndexView view = new FilteredIndexView(null, config);
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyBean")));
    assertTrue(view.accepts(DotName.createSimple("com.example.pkgA.MyClass")));
    assertFalse(view.accepts(DotName.createSimple("com.example.pkgB.MyImpl")));
}