Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAYARA-3466 Open API 1.1 #3827

Merged
merged 10 commits into from
Mar 19, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

import javax.ws.rs.Consumes;
Expand All @@ -65,8 +64,10 @@
import org.eclipse.microprofile.openapi.annotations.callbacks.Callback;
import org.eclipse.microprofile.openapi.annotations.callbacks.Callbacks;
import org.eclipse.microprofile.openapi.annotations.extensions.Extension;
import org.eclipse.microprofile.openapi.annotations.extensions.Extensions;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.eclipse.microprofile.openapi.annotations.parameters.Parameter;
import org.eclipse.microprofile.openapi.annotations.parameters.Parameters;
import org.eclipse.microprofile.openapi.annotations.parameters.RequestBody;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponses;
Expand Down Expand Up @@ -127,6 +128,8 @@ interface VisitorFunction<A extends Annotation, E extends AnnotatedElement> {

void visitExtension(Extension extension, AnnotatedElement element, ApiContext context);

void visitExtensions(Extensions extensions, AnnotatedElement element, ApiContext context);

void visitOperation(Operation operation, AnnotatedElement element, ApiContext context);

void visitCallback(Callback callback, AnnotatedElement element, ApiContext context);
Expand All @@ -141,6 +144,8 @@ interface VisitorFunction<A extends Annotation, E extends AnnotatedElement> {

void visitParameter(Parameter parameter, AnnotatedElement element, ApiContext context);

void visitParameters(Parameters parameters, AnnotatedElement element, ApiContext context);

void visitExternalDocumentation(ExternalDocumentation externalDocs, AnnotatedElement element, ApiContext context);

void visitServer(Server server, AnnotatedElement element, ApiContext context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import fish.payara.microprofile.openapi.impl.processor.FileProcessor;
import fish.payara.microprofile.openapi.impl.processor.FilterProcessor;
import fish.payara.microprofile.openapi.impl.processor.ModelReaderProcessor;
import fish.payara.nucleus.executorservice.PayaraExecutorService;
import java.beans.PropertyChangeEvent;
import java.net.InetAddress;
import java.net.MalformedURLException;
Expand All @@ -58,7 +57,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Deque;
import java.util.Enumeration;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedDeque;
Expand Down Expand Up @@ -105,9 +103,6 @@ public class OpenApiService implements PostConstruct, PreDestroy, EventListener,
@Inject
private OpenApiServiceConfiguration config;

@Inject
private PayaraExecutorService executor;

@Inject
private ServerEnvironment environment;

Expand Down Expand Up @@ -189,7 +184,7 @@ public OpenAPI getDocument() throws OpenAPIBuildException {
if (mappings.isEmpty() || !isEnabled()) {
return null;
}
return (OpenAPI) mappings.peekLast().getDocument();
return mappings.peekLast().getDocument();
}

/**
Expand Down Expand Up @@ -224,7 +219,7 @@ private static String getContextRoot(ApplicationInfo appInfo) {
* @return a list of all loadable classes in the archive.
*/
private static Set<Class<?>> getClassesFromArchive(ReadableArchive archive, ClassLoader appClassLoader) {
return Collections.list((Enumeration<String>) archive.entries()).stream()
return Collections.list(archive.entries()).stream()
// Only use the classes
.filter(x -> x.endsWith(".class"))
// Remove the WEB-INF/classes and return the proper class name format
Expand Down Expand Up @@ -262,12 +257,12 @@ private class OpenApiMapping {
private final OpenApiConfiguration appConfig;
private volatile OpenAPI document;

private OpenApiMapping(ApplicationInfo appInfo) {
OpenApiMapping(ApplicationInfo appInfo) {
Pandrex247 marked this conversation as resolved.
Show resolved Hide resolved
this.appInfo = appInfo;
this.appConfig = new OpenApiConfiguration(appInfo.getAppClassLoader());
}

private ApplicationInfo getAppInfo() {
Pandrex247 marked this conversation as resolved.
Show resolved Hide resolved
ApplicationInfo getAppInfo() {
return appInfo;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@
import java.beans.PropertyVetoException;
import org.glassfish.api.admin.config.ConfigExtension;
import org.jvnet.hk2.config.Attribute;
import org.jvnet.hk2.config.ConfigBeanProxy;
import org.jvnet.hk2.config.Configured;

/**
* Configuration for the OpenAPI Service.
*/
@Configured(name = "microprofile-openapi-configuration")
public interface OpenApiServiceConfiguration extends ConfigBeanProxy, ConfigExtension {
public interface OpenApiServiceConfiguration extends ConfigExtension {

/**
* @return whether the service is enabled or not.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ private Class<? extends OASFilter> findFilterFromConfig(Config config, ClassLoad
return null;
}

private boolean findScanDisableFromConfig(Config config) {
private static boolean findScanDisableFromConfig(Config config) {
try {
return config.getValue(SCAN_DISABLE_KEY, Boolean.class);
} catch (NoSuchElementException ex) {
Expand All @@ -233,7 +233,7 @@ private boolean findScanDisableFromConfig(Config config) {
return false;
}

private List<String> findScanPackagesFromConfig(Config config) {
private static List<String> findScanPackagesFromConfig(Config config) {
List<String> packages = new ArrayList<>();
try {
packages.addAll(Arrays.asList(config.getValue(SCAN_PACKAGES_KEY, String[].class)));
Expand All @@ -259,7 +259,7 @@ private List<Class<?>> findScanClassesFromConfig(Config config, ClassLoader clas
return classes;
}

private List<String> findExcludePackages(Config config) {
private static List<String> findExcludePackages(Config config) {
List<String> packages = new ArrayList<>();
try {
packages.addAll(Arrays.asList(config.getValue(SCAN_EXCLUDE_PACKAGES_KEY, String[].class)));
Expand All @@ -285,7 +285,7 @@ private List<Class<?>> findExcludeClasses(Config config, ClassLoader classLoader
return classes;
}

private List<String> findServers(Config config) {
private static List<String> findServers(Config config) {
List<String> serverList = new ArrayList<>();
try {
serverList.addAll(Arrays.asList(config.getValue(SERVERS_KEY, String[].class)));
Expand All @@ -295,7 +295,7 @@ private List<String> findServers(Config config) {
return serverList;
}

private Map<String, Set<String>> findPathServerMap(Config config) {
private static Map<String, Set<String>> findPathServerMap(Config config) {
Map<String, Set<String>> map = new HashMap<>();
try {
for (String propertyName : config.getPropertyNames()) {
Expand All @@ -310,7 +310,7 @@ private Map<String, Set<String>> findPathServerMap(Config config) {
return map;
}

private Map<String, Set<String>> findOperationServerMap(Config config) {
private static Map<String, Set<String>> findOperationServerMap(Config config) {
Map<String, Set<String>> map = new HashMap<>();
try {
for (String propertyName : config.getPropertyNames()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
import fish.payara.microprofile.openapi.impl.model.responses.APIResponseImpl;
import fish.payara.microprofile.openapi.impl.model.security.SecuritySchemeImpl;

public class ComponentsImpl extends ExtensibleImpl implements Components {
public class ComponentsImpl extends ExtensibleImpl<Components> implements Components {

protected Map<String, Schema> schemas = new TreeMap<>();
protected Map<String, APIResponse> responses = new TreeMap<>();
Expand All @@ -87,15 +87,16 @@ public void setSchemas(Map<String, Schema> schemas) {
}

@Override
public Components schemas(Map<String, Schema> schemas) {
setSchemas(schemas);
public Components addSchema(String key, Schema schema) {
if (schema != null) {
schemas.put(key, schema);
}
return this;
}

@Override
public Components addSchema(String key, Schema schema) {
schemas.put(key, schema);
return this;
public void removeSchema(String key) {
schemas.remove(key);
}

@Override
Expand All @@ -109,15 +110,16 @@ public void setResponses(Map<String, APIResponse> responses) {
}

@Override
public Components responses(Map<String, APIResponse> responses) {
setResponses(responses);
public Components addResponse(String key, APIResponse response) {
if (response != null) {
responses.put(key, response);
}
return this;
}

@Override
public Components addResponse(String key, APIResponse response) {
responses.put(key, response);
return this;
public void removeResponse(String key) {
responses.remove(key);
}

@Override
Expand All @@ -131,15 +133,16 @@ public void setParameters(Map<String, Parameter> parameters) {
}

@Override
public Components parameters(Map<String, Parameter> parameters) {
setParameters(parameters);
public Components addParameter(String key, Parameter parameter) {
if (parameter != null) {
parameters.put(key, parameter);
}
return this;
}

@Override
public Components addParameter(String key, Parameter parameter) {
parameters.put(key, parameter);
return this;
public void removeParameter(String key) {
parameters.remove(key);
}

@Override
Expand All @@ -153,15 +156,16 @@ public void setExamples(Map<String, Example> examples) {
}

@Override
public Components examples(Map<String, Example> examples) {
setExamples(examples);
public Components addExample(String key, Example example) {
if (example != null) {
examples.put(key, example);
}
return this;
}

@Override
public Components addExample(String key, Example example) {
examples.put(key, example);
return this;
public void removeExample(String key) {
examples.remove(key);
}

@Override
Expand All @@ -175,15 +179,16 @@ public void setRequestBodies(Map<String, RequestBody> requestBodies) {
}

@Override
public Components requestBodies(Map<String, RequestBody> requestBodies) {
setRequestBodies(requestBodies);
public Components addRequestBody(String key, RequestBody requestBody) {
if (requestBody != null) {
requestBodies.put(key, requestBody);
}
return this;
}

@Override
public Components addRequestBody(String key, RequestBody requestBody) {
requestBodies.put(key, requestBody);
return this;
public void removeRequestBody(String key) {
requestBodies.remove(key);
}

@Override
Expand All @@ -197,15 +202,16 @@ public void setHeaders(Map<String, Header> headers) {
}

@Override
public Components headers(Map<String, Header> headers) {
setHeaders(headers);
public Components addHeader(String key, Header header) {
if (header != null) {
headers.put(key, header);
}
return this;
}

@Override
public Components addHeader(String key, Header header) {
headers.put(key, header);
return this;
public void removeHeader(String key) {
headers.remove(key);
}

@Override
Expand All @@ -219,15 +225,16 @@ public void setSecuritySchemes(Map<String, SecurityScheme> securitySchemes) {
}

@Override
public Components securitySchemes(Map<String, SecurityScheme> securitySchemes) {
setSecuritySchemes(securitySchemes);
public Components addSecurityScheme(String key, SecurityScheme securityScheme) {
if (securityScheme != null) {
securitySchemes.put(key, securityScheme);
}
return this;
}

@Override
public Components addSecurityScheme(String key, SecurityScheme securityScheme) {
securitySchemes.put(key, securityScheme);
return this;
public void removeSecurityScheme(String key) {
securitySchemes.remove(key);
}

@Override
Expand All @@ -241,15 +248,16 @@ public void setLinks(Map<String, Link> links) {
}

@Override
public Components links(Map<String, Link> links) {
setLinks(links);
public Components addLink(String key, Link link) {
if (link != null) {
links.put(key, link);
}
return this;
}

@Override
public Components addLink(String key, Link link) {
links.put(key, link);
return this;
public void removeLink(String key) {
links.remove(key);
}

@Override
Expand All @@ -263,15 +271,16 @@ public void setCallbacks(Map<String, Callback> callbacks) {
}

@Override
public Components callbacks(Map<String, Callback> callbacks) {
setCallbacks(callbacks);
public Components addCallback(String key, Callback callback) {
if (callback != null) {
callbacks.put(key, callback);
}
return this;
}

@Override
public Components addCallback(String key, Callback callback) {
callbacks.put(key, callback);
return this;
public void removeCallback(String key) {
callbacks.remove(key);
}

public static void merge(org.eclipse.microprofile.openapi.annotations.Components from, Components to,
Expand Down
Loading