org.eclipse.microprofile.openapi.OASConfig Java Examples
The following examples show how to use
org.eclipse.microprofile.openapi.OASConfig.
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: OpenApiDeploymentProcessorTest.java From thorntail with Apache License 2.0 | 6 votes |
/** * 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 #2
Source File: FilteredIndexViewTest.java From smallrye-open-api with Apache License 2.0 | 5 votes |
@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 #3
Source File: TomEEOpenAPIExtension.java From tomee with Apache License 2.0 | 5 votes |
private OpenAPI createOpenApi(final Class<?> application, final Stream<Class<?>> beans) { final CDI<Object> current = CDI.current(); final OpenAPI api = ofNullable(config.read(OASConfig.MODEL_READER, null)) .map(value -> newInstance(current, value)) .map(it -> OASModelReader.class.cast(it).buildModel()) .orElseGet(() -> current.select(DefaultLoader.class).get().loadDefaultApi()); final BeanManager beanManager = current.getBeanManager(); processor.processApplication(api, new ElementImpl(beanManager.createAnnotatedType(application))); if (skipScan) { return api.paths(new PathsImpl()); } // adds the context path to the base final Instance<ServletContext> servletContextInstance = current.select(ServletContext.class); final boolean appendContextPath = Boolean.valueOf(config.read("application.append-context-path", "true")); String contextPath = ""; if (appendContextPath && !servletContextInstance.isAmbiguous() && !servletContextInstance.isUnsatisfied()) { contextPath = servletContextInstance.get().getContextPath(); } final String base = contextPath + processor.getApplicationBinding(application); processor.beforeProcessing(); beans.filter(c -> (excludeClasses == null || !excludeClasses.contains(c.getName()))) .filter(c -> (excludePackages == null || excludePackages.stream().noneMatch(it -> c.getName().startsWith(it)))) .map(beanManager::createAnnotatedType) .forEach(at -> processor.processClass( base, api, new ElementImpl(at), at.getMethods().stream().map(MethodElementImpl::new))); return ofNullable(config.read(OASConfig.FILTER, null)) .map(it -> newInstance(current, it)) .map(i -> new FilterImpl(OASFilter.class.cast(i)).filter(api)) .orElse(api); }
Example #4
Source File: TomEEOpenAPIExtension.java From tomee with Apache License 2.0 | 5 votes |
void init(@Observes final BeforeBeanDiscovery beforeBeanDiscovery) { config = GeronimoOpenAPIConfig.create(); processor = new AnnotationProcessor(config, loadNamingStrategy(config), null); skipScan = Boolean.parseBoolean(config.read(OASConfig.SCAN_DISABLE, "false")); classes = getConfigCollection(OASConfig.SCAN_CLASSES); packages = getConfigCollection(OASConfig.SCAN_PACKAGES); excludePackages = getConfigCollection(OASConfig.SCAN_EXCLUDE_PACKAGES); excludeClasses = getConfigCollection(OASConfig.SCAN_EXCLUDE_CLASSES); try { Yaml.getObjectMapper(); jacksonIsPresent = true; } catch (final Error | RuntimeException e) { // no-op } }
Example #5
Source File: SmallRyeOpenApiProcessor.java From quarkus with Apache License 2.0 | 5 votes |
private boolean shouldScanAnnotations(Capabilities capabilities) { // Disabled via config Config config = ConfigProvider.getConfig(); boolean scanDisable = config.getOptionalValue(OASConfig.SCAN_DISABLE, Boolean.class).orElse(false); if (scanDisable) { return false; } // Only scan if either JaxRS or Spring is used boolean isJaxrs = capabilities.isCapabilityPresent(Capabilities.RESTEASY); boolean isSpring = capabilities.isCapabilityPresent(Capabilities.SPRING_WEB); return isJaxrs || isSpring; }
Example #6
Source File: FilteredIndexViewTest.java From smallrye-open-api with Apache License 2.0 | 5 votes |
@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"))); }
Example #7
Source File: FilteredIndexViewTest.java From smallrye-open-api with Apache License 2.0 | 5 votes |
@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 #8
Source File: FilteredIndexViewTest.java From smallrye-open-api with Apache License 2.0 | 5 votes |
@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 #9
Source File: FilteredIndexViewTest.java From smallrye-open-api with Apache License 2.0 | 5 votes |
@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 #10
Source File: FilteredIndexViewTest.java From smallrye-open-api with Apache License 2.0 | 5 votes |
@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 #11
Source File: FilteredIndexViewTest.java From smallrye-open-api with Apache License 2.0 | 5 votes |
@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 #12
Source File: FilteredIndexViewTest.java From smallrye-open-api with Apache License 2.0 | 5 votes |
@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 #13
Source File: FilteredIndexViewTest.java From smallrye-open-api with Apache License 2.0 | 5 votes |
@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 #14
Source File: FilteredIndexViewTest.java From smallrye-open-api with Apache License 2.0 | 5 votes |
@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 #15
Source File: OpenApiConfigImpl.java From smallrye-open-api with Apache License 2.0 | 5 votes |
/** * @see io.smallrye.openapi.api.OpenApiConfig#modelReader() */ @Override public String modelReader() { if (modelReader == null) { modelReader = getStringConfigValue(OASConfig.MODEL_READER); } return modelReader; }
Example #16
Source File: FilteredIndexViewTest.java From smallrye-open-api with Apache License 2.0 | 5 votes |
@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 #17
Source File: FilteredIndexViewTest.java From smallrye-open-api with Apache License 2.0 | 5 votes |
@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 #18
Source File: FilteredIndexViewTest.java From smallrye-open-api with Apache License 2.0 | 5 votes |
@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 |
@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 #20
Source File: OpenApiConfigImpl.java From smallrye-open-api with Apache License 2.0 | 5 votes |
/** * @see io.smallrye.openapi.api.OpenApiConfig#servers() */ @Override public Set<String> servers() { if (servers == null) { String theServers = getStringConfigValue(OASConfig.SERVERS); servers = asCsvSet(theServers); } return servers; }
Example #21
Source File: OpenApiConfigImpl.java From smallrye-open-api with Apache License 2.0 | 5 votes |
/** * @see io.smallrye.openapi.api.OpenApiConfig#scanExcludeClasses() */ @Override public Pattern scanExcludeClasses() { if (scanExcludeClasses == null) { scanExcludeClasses = patternOf(OASConfig.SCAN_EXCLUDE_CLASSES, OpenApiConstants.NEVER_SCAN_CLASSES); } return scanExcludeClasses; }
Example #22
Source File: OpenApiConfigImpl.java From smallrye-open-api with Apache License 2.0 | 5 votes |
/** * @see io.smallrye.openapi.api.OpenApiConfig#scanExcludePackages() */ @Override public Pattern scanExcludePackages() { if (scanExcludePackages == null) { scanExcludePackages = patternOf(OASConfig.SCAN_EXCLUDE_PACKAGES, OpenApiConstants.NEVER_SCAN_PACKAGES); } return scanExcludePackages; }
Example #23
Source File: OpenApiConfigImpl.java From smallrye-open-api with Apache License 2.0 | 5 votes |
/** * @see io.smallrye.openapi.api.OpenApiConfig#scanClasses() */ @Override public Pattern scanClasses() { if (scanClasses == null) { scanClasses = patternOf(OASConfig.SCAN_CLASSES); } return scanClasses; }
Example #24
Source File: OpenApiConfigImpl.java From smallrye-open-api with Apache License 2.0 | 5 votes |
/** * @see io.smallrye.openapi.api.OpenApiConfig#scanPackages() */ @Override public Pattern scanPackages() { if (scanPackages == null) { scanPackages = patternOf(OASConfig.SCAN_PACKAGES); } return scanPackages; }
Example #25
Source File: OpenApiConfigImpl.java From smallrye-open-api with Apache License 2.0 | 5 votes |
/** * @see io.smallrye.openapi.api.OpenApiConfig#scanDisable() */ @Override public boolean scanDisable() { if (scanDisable == null) { scanDisable = getConfig().getOptionalValue(OASConfig.SCAN_DISABLE, Boolean.class).orElse(false); } return scanDisable; }
Example #26
Source File: OpenApiConfigImpl.java From smallrye-open-api with Apache License 2.0 | 5 votes |
/** * @see io.smallrye.openapi.api.OpenApiConfig#filter() */ @Override public String filter() { if (filter == null) { filter = getStringConfigValue(OASConfig.FILTER); } return filter; }
Example #27
Source File: OpenApiConfigImpl.java From smallrye-open-api with Apache License 2.0 | 4 votes |
/** * @see io.smallrye.openapi.api.OpenApiConfig#operationServers(java.lang.String) */ @Override public Set<String> operationServers(String operationId) { String opServers = getStringConfigValue(OASConfig.SERVERS_OPERATION_PREFIX + operationId); return asCsvSet(opServers); }