Search in sources :

Example 1 with PathsImpl

use of org.apache.geronimo.microprofile.openapi.impl.model.PathsImpl in project tomee by apache.

the class TomEEOpenAPIExtension method createOpenApi.

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);
}
Also used : Array(java.lang.reflect.Array) OASModelReader(org.eclipse.microprofile.openapi.OASModelReader) Path(javax.ws.rs.Path) ProcessBean(javax.enterprise.inject.spi.ProcessBean) HashMap(java.util.HashMap) Application(javax.ws.rs.core.Application) AnnotatedTypeElement(org.apache.geronimo.microprofile.openapi.impl.processor.AnnotatedTypeElement) ArrayList(java.util.ArrayList) MediaType(javax.ws.rs.core.MediaType) AnnotationProcessor(org.apache.geronimo.microprofile.openapi.impl.processor.AnnotationProcessor) BeforeBeanDiscovery(javax.enterprise.inject.spi.BeforeBeanDiscovery) Observes(javax.enterprise.event.Observes) Map(java.util.Map) Yaml(org.apache.geronimo.microprofile.openapi.impl.loader.yaml.Yaml) Instance(javax.enterprise.inject.Instance) Collectors.toSet(java.util.stream.Collectors.toSet) GeronimoOpenAPIConfig(org.apache.geronimo.microprofile.openapi.config.GeronimoOpenAPIConfig) AnnotatedMethodElement(org.apache.geronimo.microprofile.openapi.impl.processor.AnnotatedMethodElement) NamingStrategy(org.apache.geronimo.microprofile.openapi.impl.processor.spi.NamingStrategy) Annotated(javax.enterprise.inject.spi.Annotated) Extension(javax.enterprise.inject.spi.Extension) Optional.ofNullable(java.util.Optional.ofNullable) FilterImpl(org.apache.geronimo.microprofile.openapi.impl.filter.FilterImpl) Collection(java.util.Collection) ProcessAnnotatedType(javax.enterprise.inject.spi.ProcessAnnotatedType) CDI(javax.enterprise.inject.spi.CDI) JacksonOpenAPIYamlBodyWriter(org.apache.geronimo.microprofile.openapi.jaxrs.JacksonOpenAPIYamlBodyWriter) InvocationTargetException(java.lang.reflect.InvocationTargetException) OpenAPI(org.eclipse.microprofile.openapi.models.OpenAPI) Stream(java.util.stream.Stream) Type(java.lang.reflect.Type) PathsImpl(org.apache.geronimo.microprofile.openapi.impl.model.PathsImpl) DefaultLoader(org.apache.geronimo.microprofile.openapi.impl.loader.DefaultLoader) Annotation(java.lang.annotation.Annotation) APPLICATION_JSON_TYPE(javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE) ServletContext(javax.servlet.ServletContext) OASConfig(org.eclipse.microprofile.openapi.OASConfig) OASFilter(org.eclipse.microprofile.openapi.OASFilter) Bean(javax.enterprise.inject.spi.Bean) GeronimoOpenAPIExtension(org.apache.geronimo.microprofile.openapi.cdi.GeronimoOpenAPIExtension) RegisterRestClient(org.eclipse.microprofile.rest.client.inject.RegisterRestClient) AnnotatedMethod(javax.enterprise.inject.spi.AnnotatedMethod) BeanManager(javax.enterprise.inject.spi.BeanManager) AnnotatedElement(java.lang.reflect.AnnotatedElement) FilterImpl(org.apache.geronimo.microprofile.openapi.impl.filter.FilterImpl) OASModelReader(org.eclipse.microprofile.openapi.OASModelReader) PathsImpl(org.apache.geronimo.microprofile.openapi.impl.model.PathsImpl) ServletContext(javax.servlet.ServletContext) OpenAPI(org.eclipse.microprofile.openapi.models.OpenAPI) DefaultLoader(org.apache.geronimo.microprofile.openapi.impl.loader.DefaultLoader) BeanManager(javax.enterprise.inject.spi.BeanManager)

Aggregations

Annotation (java.lang.annotation.Annotation)1 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 Array (java.lang.reflect.Array)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional.ofNullable (java.util.Optional.ofNullable)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 Stream (java.util.stream.Stream)1 Observes (javax.enterprise.event.Observes)1 Instance (javax.enterprise.inject.Instance)1 Annotated (javax.enterprise.inject.spi.Annotated)1 AnnotatedMethod (javax.enterprise.inject.spi.AnnotatedMethod)1 Bean (javax.enterprise.inject.spi.Bean)1 BeanManager (javax.enterprise.inject.spi.BeanManager)1 BeforeBeanDiscovery (javax.enterprise.inject.spi.BeforeBeanDiscovery)1 CDI (javax.enterprise.inject.spi.CDI)1