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
@@ -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;
@@ -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;
@@ -127,6 +128,8 @@

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);
@@ -141,6 +144,8 @@

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);
@@ -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;
@@ -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;
@@ -105,9 +103,6 @@
@Inject
private OpenApiServiceConfiguration config;

@Inject
private PayaraExecutorService executor;

@Inject
private ServerEnvironment environment;

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

/**
@@ -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
@@ -262,12 +257,12 @@ private static String getContextRoot(ApplicationInfo appInfo) {
private final OpenApiConfiguration appConfig;
private volatile OpenAPI document;

private OpenApiMapping(ApplicationInfo appInfo) {
OpenApiMapping(ApplicationInfo appInfo) {
This conversation was marked as resolved by Pandrex247

This comment has been minimized.

Copy link
@MattGill98

MattGill98 Mar 13, 2019

Member

Is there any reason for this?

This comment has been minimized.

Copy link
@jbee

jbee Mar 13, 2019

Author Contributor

Short: Synthetic methods. Long explanation given in another comment.

this.appInfo = appInfo;
this.appConfig = new OpenApiConfiguration(appInfo.getAppClassLoader());
}

private ApplicationInfo getAppInfo() {
This conversation was marked as resolved by Pandrex247

This comment has been minimized.

Copy link
@Pandrex247

Pandrex247 Mar 13, 2019

Member

Is there a reason for this change? I'm not spotting anything for it in this PR.

This comment has been minimized.

Copy link
@jbee

jbee Mar 13, 2019

Author Contributor

Its not 1.1. related. If the method is private it is not accessible for the caller what java mitigates with synthetic methods added that forward to the private method. I saw no reason why we have to force this being private when default visibility can avoid synthetic methods.

ApplicationInfo getAppInfo() {
return appInfo;
}

@@ -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.
@@ -224,7 +224,7 @@ public boolean getScanDisable() {
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) {
@@ -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)));
@@ -259,7 +259,7 @@ private boolean findScanDisableFromConfig(Config config) {
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)));
@@ -285,7 +285,7 @@ private boolean findScanDisableFromConfig(Config config) {
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)));
@@ -295,7 +295,7 @@ private boolean findScanDisableFromConfig(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()) {
@@ -310,7 +310,7 @@ private boolean findScanDisableFromConfig(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()) {
@@ -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<>();
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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,
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.