From f576f2f4cf2fbb442bec8b73589ce36557a17b81 Mon Sep 17 00:00:00 2001 From: Jan Bernitt Date: Fri, 8 Mar 2019 17:58:10 +0100 Subject: [PATCH 01/10] PAYARA-3466 Open API 1.1 implemented new methods, removed builder with defaults, removed warnings, extracted common base classes for extensible maps, switched to non-deprecated methods --- .../openapi/api/visitor/ApiVisitor.java | 1 - .../openapi/impl/OpenApiService.java | 13 +- .../admin/OpenApiServiceConfiguration.java | 3 +- .../impl/config/OpenApiConfiguration.java | 12 +- .../openapi/impl/model/ComponentsImpl.java | 83 +++--- .../openapi/impl/model/ExtensibleImpl.java | 13 +- .../impl/model/ExtensibleLinkedHashMap.java | 43 +++ .../impl/model/ExternalDocumentationImpl.java | 14 +- .../openapi/impl/model/OpenAPIImpl.java | 61 +---- .../openapi/impl/model/OperationImpl.java | 83 ++---- .../openapi/impl/model/PathItemImpl.java | 94 ++----- .../openapi/impl/model/PathsImpl.java | 31 ++- .../impl/model/callbacks/CallbackImpl.java | 49 ++-- .../impl/model/examples/ExampleImpl.java | 32 +-- .../impl/model/headers/HeaderImpl.java | 71 +---- .../openapi/impl/model/info/ContactImpl.java | 20 +- .../openapi/impl/model/info/InfoImpl.java | 38 +-- .../openapi/impl/model/info/LicenseImpl.java | 14 +- .../openapi/impl/model/links/LinkImpl.java | 47 +--- .../openapi/impl/model/media/ContentImpl.java | 30 ++- .../impl/model/media/DiscriminatorImpl.java | 16 +- .../impl/model/media/EncodingImpl.java | 35 +-- .../impl/model/media/MediaTypeImpl.java | 32 +-- .../openapi/impl/model/media/SchemaImpl.java | 254 +++--------------- .../openapi/impl/model/media/XMLImpl.java | 32 +-- .../impl/model/parameters/ParameterImpl.java | 89 +----- .../model/parameters/RequestBodyImpl.java | 26 +- .../impl/model/responses/APIResponseImpl.java | 38 +-- .../model/responses/APIResponsesImpl.java | 49 +++- .../impl/model/security/OAuthFlowImpl.java | 26 +- .../impl/model/security/OAuthFlowsImpl.java | 26 +- .../impl/model/security/ScopesImpl.java | 27 +- .../security/SecurityRequirementImpl.java | 25 ++ .../model/security/SecuritySchemeImpl.java | 56 +--- .../impl/model/servers/ServerImpl.java | 29 +- .../model/servers/ServerVariableImpl.java | 25 +- .../model/servers/ServerVariablesImpl.java | 29 +- .../openapi/impl/model/tags/TagImpl.java | 20 +- .../openapi/impl/model/util/ModelUtils.java | 24 +- .../impl/processor/ApplicationProcessor.java | 65 +++-- .../openapi/impl/processor/BaseProcessor.java | 24 +- .../impl/processor/FilterProcessor.java | 5 +- .../impl/processor/ModelReaderProcessor.java | 3 +- .../classloader/ApplicationClassLoader.java | 8 +- .../test/app/application/ResponseTest.java | 14 +- .../test/app/application/RootPathTest.java | 4 +- appserver/pom.xml | 2 +- 47 files changed, 515 insertions(+), 1220 deletions(-) create mode 100644 appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleLinkedHashMap.java diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/api/visitor/ApiVisitor.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/api/visitor/ApiVisitor.java index eb0bccf2ddf..9b68002576e 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/api/visitor/ApiVisitor.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/api/visitor/ApiVisitor.java @@ -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; diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/OpenApiService.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/OpenApiService.java index f8dbce05780..28064b5e173 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/OpenApiService.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/OpenApiService.java @@ -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 @@ public class OpenApiService implements PostConstruct, PreDestroy, EventListener, @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> getClassesFromArchive(ReadableArchive archive, ClassLoader appClassLoader) { - return Collections.list((Enumeration) 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 class OpenApiMapping { private final OpenApiConfiguration appConfig; private volatile OpenAPI document; - private OpenApiMapping(ApplicationInfo appInfo) { + OpenApiMapping(ApplicationInfo appInfo) { this.appInfo = appInfo; this.appConfig = new OpenApiConfiguration(appInfo.getAppClassLoader()); } - private ApplicationInfo getAppInfo() { + ApplicationInfo getAppInfo() { return appInfo; } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/admin/OpenApiServiceConfiguration.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/admin/OpenApiServiceConfiguration.java index ba7eb07e9b7..9858b0561fc 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/admin/OpenApiServiceConfiguration.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/admin/OpenApiServiceConfiguration.java @@ -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. diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/config/OpenApiConfiguration.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/config/OpenApiConfiguration.java index fb104683f8b..7ada410d15a 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/config/OpenApiConfiguration.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/config/OpenApiConfiguration.java @@ -224,7 +224,7 @@ private Class 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) { @@ -233,7 +233,7 @@ private boolean findScanDisableFromConfig(Config config) { return false; } - private List findScanPackagesFromConfig(Config config) { + private static List findScanPackagesFromConfig(Config config) { List packages = new ArrayList<>(); try { packages.addAll(Arrays.asList(config.getValue(SCAN_PACKAGES_KEY, String[].class))); @@ -259,7 +259,7 @@ private List> findScanClassesFromConfig(Config config, ClassLoader clas return classes; } - private List findExcludePackages(Config config) { + private static List findExcludePackages(Config config) { List packages = new ArrayList<>(); try { packages.addAll(Arrays.asList(config.getValue(SCAN_EXCLUDE_PACKAGES_KEY, String[].class))); @@ -285,7 +285,7 @@ private List> findExcludeClasses(Config config, ClassLoader classLoader return classes; } - private List findServers(Config config) { + private static List findServers(Config config) { List serverList = new ArrayList<>(); try { serverList.addAll(Arrays.asList(config.getValue(SERVERS_KEY, String[].class))); @@ -295,7 +295,7 @@ private List findServers(Config config) { return serverList; } - private Map> findPathServerMap(Config config) { + private static Map> findPathServerMap(Config config) { Map> map = new HashMap<>(); try { for (String propertyName : config.getPropertyNames()) { @@ -310,7 +310,7 @@ private Map> findPathServerMap(Config config) { return map; } - private Map> findOperationServerMap(Config config) { + private static Map> findOperationServerMap(Config config) { Map> map = new HashMap<>(); try { for (String propertyName : config.getPropertyNames()) { diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ComponentsImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ComponentsImpl.java index 95f05cf6068..51613fdd642 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ComponentsImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ComponentsImpl.java @@ -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 implements Components { protected Map schemas = new TreeMap<>(); protected Map responses = new TreeMap<>(); @@ -87,15 +87,14 @@ public void setSchemas(Map schemas) { } @Override - public Components schemas(Map schemas) { - setSchemas(schemas); + public Components addSchema(String key, Schema schema) { + 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 +108,14 @@ public void setResponses(Map responses) { } @Override - public Components responses(Map responses) { - setResponses(responses); + public Components addResponse(String key, APIResponse response) { + 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 +129,14 @@ public void setParameters(Map parameters) { } @Override - public Components parameters(Map parameters) { - setParameters(parameters); + public Components addParameter(String key, Parameter parameter) { + 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 +150,14 @@ public void setExamples(Map examples) { } @Override - public Components examples(Map examples) { - setExamples(examples); + public Components addExample(String key, Example example) { + 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 +171,14 @@ public void setRequestBodies(Map requestBodies) { } @Override - public Components requestBodies(Map requestBodies) { - setRequestBodies(requestBodies); + public Components addRequestBody(String key, RequestBody requestBody) { + 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 +192,14 @@ public void setHeaders(Map headers) { } @Override - public Components headers(Map headers) { - setHeaders(headers); + public Components addHeader(String key, Header header) { + 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 +213,14 @@ public void setSecuritySchemes(Map securitySchemes) { } @Override - public Components securitySchemes(Map securitySchemes) { - setSecuritySchemes(securitySchemes); + public Components addSecurityScheme(String key, SecurityScheme securityScheme) { + 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 +234,14 @@ public void setLinks(Map links) { } @Override - public Components links(Map links) { - setLinks(links); + public Components addLink(String key, Link link) { + 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 +255,14 @@ public void setCallbacks(Map callbacks) { } @Override - public Components callbacks(Map callbacks) { - setCallbacks(callbacks); + public Components addCallback(String key, Callback callback) { + 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, diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java index 96555b12abd..6c6db641ffa 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java @@ -49,7 +49,7 @@ import org.eclipse.microprofile.openapi.annotations.extensions.Extension; import org.eclipse.microprofile.openapi.models.Extensible; -public abstract class ExtensibleImpl implements Extensible { +public abstract class ExtensibleImpl> implements Extensible { protected Map extensions = new HashMap<>(); @@ -58,9 +58,16 @@ public Map getExtensions() { return extensions; } + @SuppressWarnings("unchecked") @Override - public void addExtension(String name, Object value) { + public T addExtension(String name, Object value) { extensions.put(name, value); + return (T) this; + } + + @Override + public void removeExtension(String name) { + extensions.remove(name); } @Override @@ -68,7 +75,7 @@ public void setExtensions(Map extensions) { this.extensions = extensions; } - public static void merge(Extension from, Extensible to, boolean override) { + public static void merge(Extension from, Extensible to, boolean override) { if (isAnnotationNull(from)) { return; } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleLinkedHashMap.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleLinkedHashMap.java new file mode 100644 index 00000000000..477307e6d5d --- /dev/null +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleLinkedHashMap.java @@ -0,0 +1,43 @@ +package fish.payara.microprofile.openapi.impl.model; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +import org.eclipse.microprofile.openapi.models.Extensible; + +public abstract class ExtensibleLinkedHashMap> extends LinkedHashMap +implements Extensible { + + protected Map extensions = new HashMap<>(); + + protected ExtensibleLinkedHashMap() { + super(); + } + + protected ExtensibleLinkedHashMap(Map items) { + super(items); + } + + @Override + public final Map getExtensions() { + return extensions; + } + + @Override + public final void setExtensions(Map extensions) { + this.extensions = extensions; + } + + @SuppressWarnings("unchecked") + @Override + public final T addExtension(String name, Object value) { + this.extensions.put(name, value); + return (T) this; + } + + @Override + public final void removeExtension(String name) { + this.extensions.remove(name); + } +} diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExternalDocumentationImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExternalDocumentationImpl.java index ae7b6aa08bf..4812fd6591e 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExternalDocumentationImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExternalDocumentationImpl.java @@ -44,7 +44,7 @@ import org.eclipse.microprofile.openapi.models.ExternalDocumentation; -public class ExternalDocumentationImpl extends ExtensibleImpl implements ExternalDocumentation { +public class ExternalDocumentationImpl extends ExtensibleImpl implements ExternalDocumentation { protected String description; protected String url; @@ -59,12 +59,6 @@ public void setDescription(String description) { this.description = description; } - @Override - public ExternalDocumentation description(String description) { - setDescription(description); - return this; - } - @Override public String getUrl() { return url; @@ -75,12 +69,6 @@ public void setUrl(String url) { this.url = url; } - @Override - public ExternalDocumentation url(String url) { - setUrl(url); - return this; - } - public static void merge(org.eclipse.microprofile.openapi.annotations.ExternalDocumentation from, ExternalDocumentation to, boolean override) { if (isAnnotationNull(from)) { diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/OpenAPIImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/OpenAPIImpl.java index 371eba7b123..4697a22f492 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/OpenAPIImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/OpenAPIImpl.java @@ -61,7 +61,7 @@ import fish.payara.microprofile.openapi.impl.model.tags.TagImpl; import fish.payara.microprofile.openapi.impl.model.util.ModelUtils; -public class OpenAPIImpl extends ExtensibleImpl implements OpenAPI { +public class OpenAPIImpl extends ExtensibleImpl implements OpenAPI { protected String openapi; protected Info info; @@ -82,12 +82,6 @@ public void setOpenapi(String openapi) { this.openapi = openapi; } - @Override - public OpenAPI openapi(String openapi) { - setOpenapi(openapi); - return this; - } - @Override public Info getInfo() { return info; @@ -98,12 +92,6 @@ public void setInfo(Info info) { this.info = info; } - @Override - public OpenAPI info(Info info) { - setInfo(info); - return this; - } - @Override public ExternalDocumentation getExternalDocs() { return externalDocs; @@ -114,12 +102,6 @@ public void setExternalDocs(ExternalDocumentation externalDocs) { this.externalDocs = externalDocs; } - @Override - public OpenAPI externalDocs(ExternalDocumentation externalDocs) { - setExternalDocs(externalDocs); - return this; - } - @Override public List getServers() { return servers; @@ -130,12 +112,6 @@ public void setServers(List servers) { this.servers = servers; } - @Override - public OpenAPI servers(List servers) { - setServers(servers); - return this; - } - @Override public OpenAPI addServer(Server server) { if (server.getUrl() != null) { @@ -153,6 +129,11 @@ public OpenAPI addServer(Server server) { return this; } + @Override + public void removeServer(Server server) { + servers.remove(server); + } + @Override public List getSecurity() { return security; @@ -164,15 +145,14 @@ public void setSecurity(List security) { } @Override - public OpenAPI security(List security) { - setSecurity(security); + public OpenAPI addSecurityRequirement(SecurityRequirement securityRequirement) { + security.add(securityRequirement); return this; } @Override - public OpenAPI addSecurityRequirement(SecurityRequirement securityRequirement) { - security.add(securityRequirement); - return this; + public void removeSecurityRequirement(SecurityRequirement securityRequirement) { + security.remove(securityRequirement); } @Override @@ -186,15 +166,14 @@ public void setTags(List tags) { } @Override - public OpenAPI tags(List tags) { - setTags(tags); + public OpenAPI addTag(Tag tag) { + tags.add(tag); return this; } @Override - public OpenAPI addTag(Tag tag) { - tags.add(tag); - return this; + public void removeTag(Tag tag) { + tags.remove(tag); } @Override @@ -207,12 +186,6 @@ public void setPaths(Paths paths) { this.paths = paths; } - @Override - public OpenAPI paths(Paths paths) { - setPaths(paths); - return this; - } - @Override public OpenAPI path(String name, PathItem path) { paths.addPathItem(name, path); @@ -229,12 +202,6 @@ public void setComponents(Components components) { this.components = components; } - @Override - public OpenAPI components(Components components) { - setComponents(components); - return this; - } - public static void merge(OpenAPIDefinition from, OpenAPI to, boolean override) { if (isAnnotationNull(from)) { return; diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/OperationImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/OperationImpl.java index 72e1abd0067..10d1940ac2c 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/OperationImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/OperationImpl.java @@ -64,7 +64,7 @@ import fish.payara.microprofile.openapi.impl.model.parameters.RequestBodyImpl; import fish.payara.microprofile.openapi.impl.model.responses.APIResponsesImpl; -public class OperationImpl extends ExtensibleImpl implements Operation { +public class OperationImpl extends ExtensibleImpl implements Operation { protected List tags = new ArrayList<>(); protected String summary; @@ -90,15 +90,14 @@ public void setTags(List tags) { } @Override - public Operation tags(List tags) { - setTags(tags); + public Operation addTag(String tag) { + tags.add(tag); return this; } @Override - public Operation addTag(String tag) { - tags.add(tag); - return this; + public void removeTag(String tag) { + tags.remove(tag); } @Override @@ -111,12 +110,6 @@ public void setSummary(String summary) { this.summary = summary; } - @Override - public Operation summary(String summary) { - setSummary(summary); - return this; - } - @Override public String getDescription() { return description; @@ -127,12 +120,6 @@ public void setDescription(String description) { this.description = description; } - @Override - public Operation description(String description) { - setDescription(description); - return this; - } - @Override public ExternalDocumentation getExternalDocs() { return externalDocs; @@ -143,12 +130,6 @@ public void setExternalDocs(ExternalDocumentation externalDocs) { this.externalDocs = externalDocs; } - @Override - public Operation externalDocs(ExternalDocumentation externalDocs) { - setExternalDocs(externalDocs); - return this; - } - @Override public String getOperationId() { return operationId; @@ -159,12 +140,6 @@ public void setOperationId(String operationId) { this.operationId = operationId; } - @Override - public Operation operationId(String operationId) { - setOperationId(operationId); - return this; - } - @Override public List getParameters() { return parameters; @@ -176,15 +151,14 @@ public void setParameters(List parameters) { } @Override - public Operation parameters(List parameters) { - setParameters(parameters); + public Operation addParameter(Parameter parameter) { + parameters.add(parameter); return this; } @Override - public Operation addParameter(Parameter parameter) { - parameters.add(parameter); - return this; + public void removeParameter(Parameter parameter) { + parameters.remove(parameter); } @Override @@ -197,12 +171,6 @@ public void setRequestBody(RequestBody requestBody) { this.requestBody = requestBody; } - @Override - public Operation requestBody(RequestBody requestBody) { - setRequestBody(requestBody); - return this; - } - @Override public APIResponses getResponses() { return responses; @@ -213,12 +181,6 @@ public void setResponses(APIResponses responses) { this.responses = responses; } - @Override - public Operation responses(APIResponses responses) { - setResponses(responses); - return this; - } - @Override public Map getCallbacks() { return callbacks; @@ -230,11 +192,16 @@ public void setCallbacks(Map callbacks) { } @Override - public Operation callbacks(Map callbacks) { - setCallbacks(callbacks); + public Operation addCallback(String key, Callback callback) { + this.callbacks.put(key, callback); return this; } + @Override + public void removeCallback(String key) { + this.callbacks.remove(key); + } + @Override public Boolean getDeprecated() { return deprecated; @@ -262,15 +229,14 @@ public void setSecurity(List security) { } @Override - public Operation security(List security) { - setSecurity(security); + public Operation addSecurityRequirement(SecurityRequirement securityReq) { + security.add(securityReq); return this; } @Override - public Operation addSecurityRequirement(SecurityRequirement securityReq) { - security.add(securityReq); - return this; + public void removeSecurityRequirement(SecurityRequirement securityRequirement) { + security.remove(securityRequirement); } @Override @@ -284,15 +250,14 @@ public void setServers(List servers) { } @Override - public Operation servers(List servers) { - setServers(servers); + public Operation addServer(Server server) { + servers.add(server); return this; } @Override - public Operation addServer(Server server) { - servers.add(server); - return this; + public void removeServer(Server server) { + servers.remove(server); } public static void merge(org.eclipse.microprofile.openapi.annotations.Operation from, Operation to, diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathItemImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathItemImpl.java index e37eeaf54f6..e06c2e7fb3a 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathItemImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathItemImpl.java @@ -50,7 +50,7 @@ import org.eclipse.microprofile.openapi.models.parameters.Parameter; import org.eclipse.microprofile.openapi.models.servers.Server; -public class PathItemImpl extends ExtensibleImpl implements PathItem { +public class PathItemImpl extends ExtensibleImpl implements PathItem { protected String ref; protected String summary; @@ -76,12 +76,6 @@ public void setRef(String ref) { this.ref = ref; } - @Override - public PathItem ref(String ref) { - setRef(ref); - return this; - } - @Override public String getSummary() { return summary; @@ -92,12 +86,6 @@ public void setSummary(String summary) { this.summary = summary; } - @Override - public PathItem summary(String summary) { - setSummary(summary); - return this; - } - @Override public String getDescription() { return description; @@ -108,12 +96,6 @@ public void setDescription(String description) { this.description = description; } - @Override - public PathItem description(String description) { - setDescription(description); - return this; - } - @Override public Operation getGET() { return get; @@ -124,12 +106,6 @@ public void setGET(Operation get) { this.get = get; } - @Override - public PathItem GET(Operation get) { - setGET(get); - return this; - } - @Override public Operation getPUT() { return put; @@ -140,12 +116,6 @@ public void setPUT(Operation put) { this.put = put; } - @Override - public PathItem PUT(Operation put) { - setPUT(put); - return this; - } - @Override public Operation getPOST() { return post; @@ -156,12 +126,6 @@ public void setPOST(Operation post) { this.post = post; } - @Override - public PathItem POST(Operation post) { - setPOST(post); - return this; - } - @Override public Operation getDELETE() { return delete; @@ -172,12 +136,6 @@ public void setDELETE(Operation delete) { this.delete = delete; } - @Override - public PathItem DELETE(Operation delete) { - setDELETE(delete); - return this; - } - @Override public Operation getOPTIONS() { return options; @@ -188,12 +146,6 @@ public void setOPTIONS(Operation options) { this.options = options; } - @Override - public PathItem OPTIONS(Operation options) { - setOPTIONS(options); - return this; - } - @Override public Operation getHEAD() { return head; @@ -204,12 +156,6 @@ public void setHEAD(Operation head) { this.head = head; } - @Override - public PathItem HEAD(Operation head) { - setHEAD(head); - return this; - } - @Override public Operation getPATCH() { return patch; @@ -220,12 +166,6 @@ public void setPATCH(Operation patch) { this.patch = patch; } - @Override - public PathItem PATCH(Operation patch) { - setPATCH(patch); - return this; - } - @Override public Operation getTRACE() { return trace; @@ -237,9 +177,17 @@ public void setTRACE(Operation trace) { } @Override - public PathItem TRACE(Operation trace) { - setTRACE(trace); - return this; + public Map getOperations() { + EnumMap operations = new EnumMap<>(HttpMethod.class); + operations.put(HttpMethod.DELETE, delete); + operations.put(HttpMethod.GET, get); + operations.put(HttpMethod.HEAD, head); + operations.put(HttpMethod.OPTIONS, options); + operations.put(HttpMethod.PATCH, patch); + operations.put(HttpMethod.POST, post); + operations.put(HttpMethod.PUT, put); + operations.put(HttpMethod.TRACE, trace); + return operations; } @Override @@ -316,15 +264,14 @@ public void setServers(List servers) { } @Override - public PathItem servers(List servers) { - setServers(servers); + public PathItem addServer(Server server) { + servers.add(server); return this; } @Override - public PathItem addServer(Server server) { - servers.add(server); - return this; + public void removeServer(Server server) { + servers.remove(server); } @Override @@ -338,15 +285,14 @@ public void setParameters(List parameters) { } @Override - public PathItem parameters(List parameters) { - setParameters(parameters); + public PathItem addParameter(Parameter parameter) { + parameters.add(parameter); return this; } @Override - public PathItem addParameter(Parameter parameter) { - parameters.add(parameter); - return this; + public void removeParameter(Parameter parameter) { + parameters.remove(parameter); } @Override diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathsImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathsImpl.java index fb6b666a2aa..e49c65435b7 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathsImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathsImpl.java @@ -39,40 +39,45 @@ */ package fish.payara.microprofile.openapi.impl.model; -import java.util.HashMap; import java.util.Map; -import java.util.TreeMap; import org.eclipse.microprofile.openapi.models.PathItem; import org.eclipse.microprofile.openapi.models.Paths; import fish.payara.microprofile.openapi.impl.model.util.ModelUtils; -public class PathsImpl extends TreeMap implements Paths { +public class PathsImpl extends ExtensibleLinkedHashMap implements Paths { private static final long serialVersionUID = -3876996963579977405L; - protected Map extensions = new HashMap<>(); + public PathsImpl() { + super(); + } + + public PathsImpl(Map items) { + super(items); + } @Override public Paths addPathItem(String name, PathItem item) { - super.put(name, item); + put(name, item); return this; } @Override - public Map getExtensions() { - return extensions; + public void removePathItem(String name) { + remove(name); } @Override - public void addExtension(String name, Object value) { - extensions.put(name, value); + public Map getPathItems() { + return new PathsImpl(this); } @Override - public void setExtensions(Map extensions) { - this.extensions = extensions; + public void setPathItems(Map items) { + clear(); + putAll(items); } public static void merge(Paths from, Paths to, boolean override) { @@ -80,10 +85,10 @@ public static void merge(Paths from, Paths to, boolean override) { return; } from.entrySet().forEach(entry -> { - if (!to.containsKey(entry.getKey())) { + if (!to.hasPathItem(entry.getKey())) { to.addPathItem(entry.getKey(), entry.getValue()); } else { - ModelUtils.merge(entry.getValue(), to.get(entry.getKey()), override); + ModelUtils.merge(entry.getValue(), to.getPathItem(entry.getKey()), override); } }); } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/callbacks/CallbackImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/callbacks/CallbackImpl.java index a38e6313b7f..93bc3e8f437 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/callbacks/CallbackImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/callbacks/CallbackImpl.java @@ -44,8 +44,6 @@ import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.getOrCreateOperation; import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.isAnnotationNull; -import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.Map; import org.eclipse.microprofile.openapi.annotations.callbacks.CallbackOperation; @@ -55,15 +53,23 @@ import org.eclipse.microprofile.openapi.models.callbacks.Callback; import org.eclipse.microprofile.openapi.models.media.Schema; +import fish.payara.microprofile.openapi.impl.model.ExtensibleLinkedHashMap; import fish.payara.microprofile.openapi.impl.model.OperationImpl; import fish.payara.microprofile.openapi.impl.model.PathItemImpl; -public class CallbackImpl extends LinkedHashMap implements Callback { +public class CallbackImpl extends ExtensibleLinkedHashMap implements Callback { private static final long serialVersionUID = 5549098533131353142L; protected String ref; - protected Map extensions = new HashMap<>(); + + public CallbackImpl() { + super(); + } + + public CallbackImpl(Map items) { + super(items); + } @Override public Callback addPathItem(String name, PathItem item) { @@ -72,37 +78,32 @@ public Callback addPathItem(String name, PathItem item) { } @Override - public String getRef() { - return this.ref; - } - - @Override - public void setRef(String ref) { - if (ref != null && !ref.contains(".") && !ref.contains("/")) { - ref = "#/components/callbacks/" + ref; - } - this.ref = ref; + public void removePathItem(String name) { + remove(name); } @Override - public Callback ref(String ref) { - setRef(ref); - return this; + public Map getPathItems() { + return new CallbackImpl(this); } @Override - public Map getExtensions() { - return extensions; + public void setPathItems(Map items) { + clear(); + putAll(items); } @Override - public void setExtensions(Map extensions) { - this.extensions = extensions; + public String getRef() { + return this.ref; } @Override - public void addExtension(String name, Object value) { - this.extensions.put(name, value); + public void setRef(String ref) { + if (ref != null && !ref.contains(".") && !ref.contains("/")) { + ref = "#/components/callbacks/" + ref; + } + this.ref = ref; } public static void merge(org.eclipse.microprofile.openapi.annotations.callbacks.Callback from, Callback to, @@ -116,7 +117,7 @@ public static void merge(org.eclipse.microprofile.openapi.annotations.callbacks. } if (!from.callbackUrlExpression().isEmpty()) { PathItem pathItem = to.getOrDefault(from.callbackUrlExpression(), new PathItemImpl()); - to.put(from.callbackUrlExpression(), pathItem); + to.addPathItem(from.callbackUrlExpression(), pathItem); if (from.operations() != null) { for (CallbackOperation callbackOperation : from.operations()) { applyCallbackOperationAnnotation(pathItem, callbackOperation, override, currentSchemas); diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/examples/ExampleImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/examples/ExampleImpl.java index b042d9577de..9c9174ed90c 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/examples/ExampleImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/examples/ExampleImpl.java @@ -50,7 +50,7 @@ import fish.payara.microprofile.openapi.impl.model.ExtensibleImpl; -public class ExampleImpl extends ExtensibleImpl implements Example { +public class ExampleImpl extends ExtensibleImpl implements Example { protected String summary; protected String description; @@ -68,12 +68,6 @@ public void setSummary(String summary) { this.summary = summary; } - @Override - public Example summary(String summary) { - setSummary(summary); - return this; - } - @Override public String getDescription() { return description; @@ -84,12 +78,6 @@ public void setDescription(String description) { this.description = description; } - @Override - public Example description(String description) { - setDescription(description); - return this; - } - @Override public Object getValue() { return value; @@ -100,12 +88,6 @@ public void setValue(Object value) { this.value = value; } - @Override - public Example value(Object value) { - setValue(value); - return this; - } - @Override public String getExternalValue() { return externalValue; @@ -116,12 +98,6 @@ public void setExternalValue(String externalValue) { this.externalValue = externalValue; } - @Override - public Example externalValue(String externalValue) { - setExternalValue(externalValue); - return this; - } - @Override public String getRef() { return ref; @@ -135,12 +111,6 @@ public void setRef(String ref) { this.ref = ref; } - @Override - public Example ref(String ref) { - setRef(ref); - return this; - } - public static void merge(ExampleObject from, Example to, boolean override) { if (isAnnotationNull(from)) { return; diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/headers/HeaderImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/headers/HeaderImpl.java index 469f19aade1..61aff64a342 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/headers/HeaderImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/headers/HeaderImpl.java @@ -55,7 +55,7 @@ import fish.payara.microprofile.openapi.impl.model.ExtensibleImpl; import fish.payara.microprofile.openapi.impl.model.media.SchemaImpl; -public class HeaderImpl extends ExtensibleImpl implements Header { +public class HeaderImpl extends ExtensibleImpl
implements Header { protected String ref; protected String description; @@ -82,12 +82,6 @@ public void setRef(String ref) { this.ref = ref; } - @Override - public Header ref(String ref) { - setRef(ref); - return this; - } - @Override public String getDescription() { return description; @@ -98,12 +92,6 @@ public void setDescription(String description) { this.description = description; } - @Override - public Header description(String description) { - setDescription(description); - return this; - } - @Override public Boolean getRequired() { return required; @@ -114,12 +102,6 @@ public void setRequired(Boolean required) { this.required = required; } - @Override - public Header required(Boolean required) { - setRequired(required); - return this; - } - @Override public Boolean getDeprecated() { return deprecated; @@ -130,12 +112,6 @@ public void setDeprecated(Boolean deprecated) { this.deprecated = deprecated; } - @Override - public Header deprecated(Boolean deprecated) { - setDeprecated(deprecated); - return this; - } - @Override public Boolean getAllowEmptyValue() { return allowEmptyValue; @@ -146,12 +122,6 @@ public void setAllowEmptyValue(Boolean allowEmptyValue) { this.allowEmptyValue = allowEmptyValue; } - @Override - public Header allowEmptyValue(Boolean allowEmptyValue) { - setAllowEmptyValue(allowEmptyValue); - return this; - } - @Override public Style getStyle() { return style; @@ -162,12 +132,6 @@ public void setStyle(Style style) { this.style = style; } - @Override - public Header style(Style style) { - setStyle(style); - return this; - } - @Override public Boolean getExplode() { return explode; @@ -178,12 +142,6 @@ public void setExplode(Boolean explode) { this.explode = explode; } - @Override - public Header explode(Boolean explode) { - setExplode(explode); - return this; - } - @Override public Schema getSchema() { return schema; @@ -194,12 +152,6 @@ public void setSchema(Schema schema) { this.schema = schema; } - @Override - public Header schema(Schema schema) { - setSchema(schema); - return this; - } - @Override public Map getExamples() { return examples; @@ -211,15 +163,14 @@ public void setExamples(Map examples) { } @Override - public Header examples(Map examples) { - setExamples(examples); + public Header addExample(String key, Example examplesItem) { + this.examples.put(key, examplesItem); return this; } @Override - public Header addExample(String key, Example examplesItem) { - this.examples.put(key, examplesItem); - return this; + public void removeExample(String key) { + this.examples.remove(key); } @Override @@ -232,12 +183,6 @@ public void setExample(Object example) { this.example = example; } - @Override - public Header example(Object example) { - setExample(example); - return this; - } - @Override public Content getContent() { return content; @@ -248,12 +193,6 @@ public void setContent(Content content) { this.content = content; } - @Override - public Header content(Content content) { - setContent(content); - return this; - } - public static void merge(org.eclipse.microprofile.openapi.annotations.headers.Header from, Header to, boolean override, Map currentSchemas) { if (isAnnotationNull(from)) { diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/info/ContactImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/info/ContactImpl.java index 169d07090c6..34e004474b3 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/info/ContactImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/info/ContactImpl.java @@ -46,7 +46,7 @@ import fish.payara.microprofile.openapi.impl.model.ExtensibleImpl; -public class ContactImpl extends ExtensibleImpl implements Contact { +public class ContactImpl extends ExtensibleImpl implements Contact { protected String name; protected String url; @@ -62,12 +62,6 @@ public void setName(String name) { this.name = name; } - @Override - public Contact name(String name) { - setName(name); - return this; - } - @Override public String getUrl() { return url; @@ -78,12 +72,6 @@ public void setUrl(String url) { this.url = url; } - @Override - public Contact url(String url) { - setUrl(url); - return this; - } - @Override public String getEmail() { return email; @@ -94,12 +82,6 @@ public void setEmail(String email) { this.email = email; } - @Override - public Contact email(String email) { - setEmail(email); - return this; - } - public static void merge(org.eclipse.microprofile.openapi.annotations.info.Contact from, Contact to, boolean override) { if (isAnnotationNull(from)) { diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/info/InfoImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/info/InfoImpl.java index 5405b4c12b5..fbc518115d5 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/info/InfoImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/info/InfoImpl.java @@ -48,7 +48,7 @@ import fish.payara.microprofile.openapi.impl.model.ExtensibleImpl; -public class InfoImpl extends ExtensibleImpl implements Info { +public class InfoImpl extends ExtensibleImpl implements Info { protected String title; protected String description; @@ -67,12 +67,6 @@ public void setTitle(String title) { this.title = title; } - @Override - public Info title(String title) { - setTitle(title); - return this; - } - @Override public String getDescription() { return description; @@ -83,12 +77,6 @@ public void setDescription(String description) { this.description = description; } - @Override - public Info description(String description) { - setDescription(description); - return this; - } - @Override public String getTermsOfService() { return termsOfService; @@ -99,12 +87,6 @@ public void setTermsOfService(String termsOfService) { this.termsOfService = termsOfService; } - @Override - public Info termsOfService(String termsOfService) { - setTermsOfService(termsOfService); - return this; - } - @Override public Contact getContact() { return contact; @@ -115,12 +97,6 @@ public void setContact(Contact contact) { this.contact = contact; } - @Override - public Info contact(Contact contact) { - setContact(contact); - return this; - } - @Override public License getLicense() { return license; @@ -131,12 +107,6 @@ public void setLicense(License license) { this.license = license; } - @Override - public Info license(License license) { - setLicense(license); - return this; - } - @Override public String getVersion() { return version; @@ -147,12 +117,6 @@ public void setVersion(String version) { this.version = version; } - @Override - public Info version(String version) { - setVersion(version); - return this; - } - public static void merge(org.eclipse.microprofile.openapi.annotations.info.Info from, Info to, boolean override) { if (isAnnotationNull(from)) { return; diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/info/LicenseImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/info/LicenseImpl.java index 773cf073d9c..f0e12dea008 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/info/LicenseImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/info/LicenseImpl.java @@ -46,7 +46,7 @@ import fish.payara.microprofile.openapi.impl.model.ExtensibleImpl; -public class LicenseImpl extends ExtensibleImpl implements License { +public class LicenseImpl extends ExtensibleImpl implements License { protected String name; protected String url; @@ -61,12 +61,6 @@ public void setName(String name) { this.name = name; } - @Override - public License name(String name) { - setName(name); - return this; - } - @Override public String getUrl() { return url; @@ -77,12 +71,6 @@ public void setUrl(String url) { this.url = url; } - @Override - public License url(String url) { - setUrl(url); - return this; - } - public static void merge(org.eclipse.microprofile.openapi.annotations.info.License from, License to, boolean override) { if (isAnnotationNull(from)) { diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/links/LinkImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/links/LinkImpl.java index d4929ab43b0..027d385304d 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/links/LinkImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/links/LinkImpl.java @@ -53,7 +53,7 @@ import fish.payara.microprofile.openapi.impl.model.ExtensibleImpl; -public class LinkImpl extends ExtensibleImpl implements Link { +public class LinkImpl extends ExtensibleImpl implements Link { protected String operationRef; protected String operationId; @@ -73,12 +73,6 @@ public void setServer(Server server) { this.server = server; } - @Override - public Link server(Server server) { - setServer(server); - return this; - } - @Override public String getOperationRef() { return operationRef; @@ -89,12 +83,6 @@ public void setOperationRef(String operationRef) { this.operationRef = operationRef; } - @Override - public Link operationRef(String operationRef) { - setOperationRef(operationRef); - return this; - } - @Override public Object getRequestBody() { return requestBody; @@ -105,12 +93,6 @@ public void setRequestBody(Object requestBody) { this.requestBody = requestBody; } - @Override - public Link requestBody(Object requestBody) { - setRequestBody(requestBody); - return this; - } - @Override public String getOperationId() { return operationId; @@ -121,12 +103,6 @@ public void setOperationId(String operationId) { this.operationId = operationId; } - @Override - public Link operationId(String operationId) { - setOperationId(operationId); - return this; - } - @Override public Map getParameters() { return parameters; @@ -138,15 +114,14 @@ public void setParameters(Map parameters) { } @Override - public Link parameters(Map parameters) { - setParameters(parameters); + public Link addParameter(String name, Object parameter) { + this.parameters.put(name, parameter); return this; } @Override - public Link addParameter(String name, Object parameter) { - this.parameters.put(name, parameter); - return this; + public void removeParameter(String name) { + this.parameters.remove(name); } @Override @@ -159,12 +134,6 @@ public void setDescription(String description) { this.description = description; } - @Override - public Link description(String description) { - setDescription(description); - return this; - } - @Override public String getRef() { return ref; @@ -178,12 +147,6 @@ public void setRef(String ref) { this.ref = ref; } - @Override - public Link ref(String ref) { - setRef(ref); - return this; - } - public static void merge(org.eclipse.microprofile.openapi.annotations.links.Link from, Link to, boolean override) { if (isAnnotationNull(from)) { return; diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/ContentImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/ContentImpl.java index cbe163eb295..0ee319ee614 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/ContentImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/ContentImpl.java @@ -56,12 +56,36 @@ public class ContentImpl extends LinkedHashMap implements Con private static final long serialVersionUID = 1575356277308242221L; + public ContentImpl() { + super(); + } + + public ContentImpl(Map items) { + super(items); + } + @Override public Content addMediaType(String name, MediaType item) { this.put(name, item); return this; } + @Override + public void removeMediaType(String name) { + remove(name); + } + + @Override + public Map getMediaTypes() { + return new ContentImpl(this); + } + + @Override + public void setMediaTypes(Map mediaTypes) { + clear(); + putAll(mediaTypes); + } + public static void merge(org.eclipse.microprofile.openapi.annotations.media.Content from, Content to, boolean override, Map currentSchemas) { if (from == null) { @@ -76,16 +100,16 @@ public static void merge(org.eclipse.microprofile.openapi.annotations.media.Cont // Get or create the corresponding media type MediaType mediaType = to.getOrDefault(typeName, new MediaTypeImpl()); - to.put(typeName, mediaType); + to.addMediaType(typeName, mediaType); // Merge encoding for (Encoding encoding : from.encoding()) { - EncodingImpl.merge(encoding, to.get(typeName).getEncoding(), override, currentSchemas); + EncodingImpl.merge(encoding, to.getMediaType(typeName).getEncoding(), override, currentSchemas); } // Merge examples for (ExampleObject example : from.examples()) { - ExampleImpl.merge(example, to.get(typeName).getExamples(), override); + ExampleImpl.merge(example, to.getMediaType(typeName).getExamples(), override); } // Merge schema diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/DiscriminatorImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/DiscriminatorImpl.java index c71cba9bf15..7d7754bf973 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/DiscriminatorImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/DiscriminatorImpl.java @@ -59,12 +59,6 @@ public void setPropertyName(String propertyName) { this.propertyName = propertyName; } - @Override - public Discriminator propertyName(String propertyName) { - setPropertyName(propertyName); - return this; - } - @Override public Map getMapping() { return mapping; @@ -75,16 +69,14 @@ public void setMapping(Map mapping) { this.mapping = mapping; } - @Override - public Discriminator mapping(Map mapping) { - setMapping(mapping); - return this; - } - @Override public Discriminator addMapping(String name, String value) { mapping.put(name, value); return this; } + @Override + public void removeMapping(String name) { + mapping.remove(name); + } } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/EncodingImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/EncodingImpl.java index 4436050fdaa..94d1b82abf6 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/EncodingImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/EncodingImpl.java @@ -52,7 +52,7 @@ import fish.payara.microprofile.openapi.impl.model.ExtensibleImpl; import fish.payara.microprofile.openapi.impl.model.headers.HeaderImpl; -public class EncodingImpl extends ExtensibleImpl implements Encoding { +public class EncodingImpl extends ExtensibleImpl implements Encoding { protected String contentType; protected Map headers = new HashMap<>(); @@ -70,12 +70,6 @@ public void setContentType(String contentType) { this.contentType = contentType; } - @Override - public Encoding contentType(String contentType) { - setContentType(contentType); - return this; - } - @Override public Map getHeaders() { return headers; @@ -87,11 +81,16 @@ public void setHeaders(Map headers) { } @Override - public Encoding headers(Map headers) { - setHeaders(headers); + public Encoding addHeader(String key, Header header) { + headers.put(key, header); return this; } + @Override + public void removeHeader(String key) { + headers.remove(key); + } + @Override public Style getStyle() { return style; @@ -102,12 +101,6 @@ public void setStyle(Style style) { this.style = style; } - @Override - public Encoding style(Style style) { - setStyle(style); - return this; - } - @Override public Boolean getExplode() { return explode; @@ -118,12 +111,6 @@ public void setExplode(Boolean explode) { this.explode = explode; } - @Override - public Encoding explode(Boolean explode) { - setExplode(explode); - return this; - } - @Override public Boolean getAllowReserved() { return allowReserved; @@ -134,12 +121,6 @@ public void setAllowReserved(Boolean allowReserved) { this.allowReserved = allowReserved; } - @Override - public Encoding allowReserved(Boolean allowReserved) { - setAllowReserved(allowReserved); - return this; - } - public static void merge(org.eclipse.microprofile.openapi.annotations.media.Encoding from, Encoding to, boolean override, Map currentSchemas) { if (isAnnotationNull(from)) { diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/MediaTypeImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/MediaTypeImpl.java index f24e84c62d9..febfa6ed3d5 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/MediaTypeImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/MediaTypeImpl.java @@ -49,7 +49,7 @@ import fish.payara.microprofile.openapi.impl.model.ExtensibleImpl; -public class MediaTypeImpl extends ExtensibleImpl implements MediaType { +public class MediaTypeImpl extends ExtensibleImpl implements MediaType { protected Schema schema; protected Map examples = new HashMap<>(); @@ -66,12 +66,6 @@ public void setSchema(Schema schema) { this.schema = schema; } - @Override - public MediaType schema(Schema schema) { - setSchema(schema); - return this; - } - @Override public Map getExamples() { return examples; @@ -83,15 +77,14 @@ public void setExamples(Map examples) { } @Override - public MediaType examples(Map examples) { - setExamples(examples); + public MediaType addExample(String key, Example example) { + this.examples.put(key, example); return this; } @Override - public MediaType addExample(String key, Example example) { - this.examples.put(key, example); - return this; + public void removeExample(String key) { + this.examples.remove(key); } @Override @@ -104,12 +97,6 @@ public void setExample(Object example) { this.example = example; } - @Override - public MediaType example(Object example) { - setExample(example); - return this; - } - @Override public Map getEncoding() { return encoding; @@ -121,15 +108,14 @@ public void setEncoding(Map encoding) { } @Override - public MediaType encoding(Map encoding) { - setEncoding(encoding); + public MediaType addEncoding(String key, Encoding encodingItem) { + this.encoding.put(key, encodingItem); return this; } @Override - public MediaType addEncoding(String key, Encoding encodingItem) { - this.encoding.put(key, encodingItem); - return this; + public void removeEncoding(String key) { + this.encoding.remove(key); } } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/SchemaImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/SchemaImpl.java index 3fd065d0480..c13a71a8267 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/SchemaImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/SchemaImpl.java @@ -62,7 +62,7 @@ import fish.payara.microprofile.openapi.impl.model.ExternalDocumentationImpl; import fish.payara.microprofile.openapi.impl.model.util.ModelUtils; -public class SchemaImpl extends ExtensibleImpl implements Schema { +public class SchemaImpl extends ExtensibleImpl implements Schema { private static final Logger LOGGER = Logger.getLogger(SchemaImpl.class.getName()); @@ -116,12 +116,6 @@ public void setDiscriminator(Discriminator discriminator) { this.discriminator = discriminator; } - @Override - public Schema discriminator(Discriminator discriminator) { - setDiscriminator(discriminator); - return this; - } - @Override public String getTitle() { return title; @@ -132,12 +126,6 @@ public void setTitle(String title) { this.title = title; } - @Override - public Schema title(String title) { - setTitle(title); - return this; - } - @Override public Object getDefaultValue() { return defaultValue; @@ -148,12 +136,6 @@ public void setDefaultValue(Object defaultValue) { this.defaultValue = defaultValue; } - @Override - public Schema defaultValue(Object defaultValue) { - setDefaultValue(defaultValue); - return this; - } - @Override public List getEnumeration() { return enumeration; @@ -170,6 +152,11 @@ public Schema addEnumeration(Object enumerationItem) { return this; } + @Override + public void removeEnumeration(Object enumeration) { + this.enumeration.remove(enumeration); + } + @Override public BigDecimal getMultipleOf() { return multipleOf; @@ -180,12 +167,6 @@ public void setMultipleOf(BigDecimal multipleOf) { this.multipleOf = multipleOf; } - @Override - public Schema multipleOf(BigDecimal multipleOf) { - setMultipleOf(multipleOf); - return this; - } - @Override public BigDecimal getMaximum() { return maximum; @@ -196,12 +177,6 @@ public void setMaximum(BigDecimal maximum) { this.maximum = maximum; } - @Override - public Schema maximum(BigDecimal maximum) { - setMaximum(maximum); - return this; - } - @Override public Boolean getExclusiveMaximum() { return exclusiveMaximum; @@ -212,12 +187,6 @@ public void setExclusiveMaximum(Boolean exclusiveMaximum) { this.exclusiveMaximum = exclusiveMaximum; } - @Override - public Schema exclusiveMaximum(Boolean exclusiveMaximum) { - setExclusiveMaximum(exclusiveMaximum); - return this; - } - @Override public BigDecimal getMinimum() { return minimum; @@ -228,12 +197,6 @@ public void setMinimum(BigDecimal minimum) { this.minimum = minimum; } - @Override - public Schema minimum(BigDecimal minimum) { - setMinimum(minimum); - return this; - } - @Override public Boolean getExclusiveMinimum() { return exclusiveMinimum; @@ -244,12 +207,6 @@ public void setExclusiveMinimum(Boolean exclusiveMinimum) { this.exclusiveMinimum = exclusiveMinimum; } - @Override - public Schema exclusiveMinimum(Boolean exclusiveMinimum) { - setExclusiveMinimum(exclusiveMinimum); - return this; - } - @Override public Integer getMaxLength() { return maxLength; @@ -260,12 +217,6 @@ public void setMaxLength(Integer maxLength) { this.maxLength = maxLength; } - @Override - public Schema maxLength(Integer maxLength) { - setMaxLength(maxLength); - return this; - } - @Override public Integer getMinLength() { return minLength; @@ -276,12 +227,6 @@ public void setMinLength(Integer minLength) { this.minLength = minLength; } - @Override - public Schema minLength(Integer minLength) { - setMinLength(minLength); - return this; - } - @Override public String getPattern() { return pattern; @@ -292,12 +237,6 @@ public void setPattern(String pattern) { this.pattern = pattern; } - @Override - public Schema pattern(String pattern) { - setPattern(pattern); - return this; - } - @Override public Integer getMaxItems() { return maxItems; @@ -308,12 +247,6 @@ public void setMaxItems(Integer maxItems) { this.maxItems = maxItems; } - @Override - public Schema maxItems(Integer maxItems) { - setMaxItems(maxItems); - return this; - } - @Override public Integer getMinItems() { return minItems; @@ -324,12 +257,6 @@ public void setMinItems(Integer minItems) { this.minItems = minItems; } - @Override - public Schema minItems(Integer minItems) { - setMinItems(minItems); - return this; - } - @Override public Boolean getUniqueItems() { return uniqueItems; @@ -340,12 +267,6 @@ public void setUniqueItems(Boolean uniqueItems) { this.uniqueItems = uniqueItems; } - @Override - public Schema uniqueItems(Boolean uniqueItems) { - setUniqueItems(uniqueItems); - return this; - } - @Override public Integer getMaxProperties() { return maxProperties; @@ -356,12 +277,6 @@ public void setMaxProperties(Integer maxProperties) { this.maxProperties = maxProperties; } - @Override - public Schema maxProperties(Integer maxProperties) { - setMaxProperties(maxProperties); - return this; - } - @Override public Integer getMinProperties() { return minProperties; @@ -372,12 +287,6 @@ public void setMinProperties(Integer minProperties) { this.minProperties = minProperties; } - @Override - public Schema minProperties(Integer minProperties) { - setMinProperties(minProperties); - return this; - } - @Override public List getRequired() { return required; @@ -388,12 +297,6 @@ public void setRequired(List required) { this.required = required; } - @Override - public Schema required(List required) { - setRequired(required); - return this; - } - @Override public Schema addRequired(String requiredItem) { this.required.add(requiredItem); @@ -401,6 +304,11 @@ public Schema addRequired(String requiredItem) { return this; } + @Override + public void removeRequired(String required) { + this.required.remove(required); + } + @Override public SchemaType getType() { return type; @@ -411,12 +319,6 @@ public void setType(SchemaType type) { this.type = type; } - @Override - public Schema type(SchemaType type) { - setType(type); - return this; - } - @Override public Schema getNot() { return not; @@ -427,12 +329,6 @@ public void setNot(Schema not) { this.not = not; } - @Override - public Schema not(Schema not) { - setNot(not); - return this; - } - @Override public Map getProperties() { return properties; @@ -444,15 +340,14 @@ public void setProperties(Map properties) { } @Override - public Schema properties(Map properties) { - setProperties(properties); + public Schema addProperty(String key, Schema propertiesItem) { + this.properties.put(key, propertiesItem); return this; } @Override - public Schema addProperty(String key, Schema propertiesItem) { - this.properties.put(key, propertiesItem); - return this; + public void removeProperty(String key) { + this.properties.remove(key); } @Override @@ -466,9 +361,23 @@ public void setAdditionalProperties(Schema additionalProperties) { } @Override - public Schema additionalProperties(Schema additionalProperties) { - setAdditionalProperties(additionalProperties); - return this; + public Schema getAdditionalPropertiesSchema() { + return (Schema) additionalProperties; + } + + @Override + public Boolean getAdditionalPropertiesBoolean() { + return (Boolean) additionalProperties; + } + + @Override + public void setAdditionalPropertiesSchema(Schema additionalProperties) { + this.additionalProperties = additionalProperties; + } + + @Override + public void setAdditionalPropertiesBoolean(Boolean additionalProperties) { + this.additionalProperties = additionalProperties; } @Override @@ -481,12 +390,6 @@ public void setDescription(String description) { this.description = description; } - @Override - public Schema description(String description) { - setDescription(description); - return this; - } - @Override public String getFormat() { return format; @@ -497,12 +400,6 @@ public void setFormat(String format) { this.format = format; } - @Override - public Schema format(String format) { - setFormat(format); - return this; - } - @Override public String getRef() { return ref; @@ -516,12 +413,6 @@ public void setRef(String ref) { this.ref = ref; } - @Override - public Schema ref(String ref) { - setRef(ref); - return this; - } - @Override public Boolean getNullable() { return nullable; @@ -532,12 +423,6 @@ public void setNullable(Boolean nullable) { this.nullable = nullable; } - @Override - public Schema nullable(Boolean nullable) { - setNullable(nullable); - return this; - } - @Override public Boolean getReadOnly() { return readOnly; @@ -548,12 +433,6 @@ public void setReadOnly(Boolean readOnly) { this.readOnly = readOnly; } - @Override - public Schema readOnly(Boolean readOnly) { - setReadOnly(readOnly); - return this; - } - @Override public Boolean getWriteOnly() { return writeOnly; @@ -564,12 +443,6 @@ public void setWriteOnly(Boolean writeOnly) { this.writeOnly = writeOnly; } - @Override - public Schema writeOnly(Boolean writeOnly) { - setWriteOnly(writeOnly); - return this; - } - @Override public Object getExample() { return example; @@ -580,12 +453,6 @@ public void setExample(Object example) { this.example = example; } - @Override - public Schema example(Object example) { - setExample(example); - return this; - } - @Override public ExternalDocumentation getExternalDocs() { return externalDocs; @@ -596,12 +463,6 @@ public void setExternalDocs(ExternalDocumentation externalDocs) { this.externalDocs = externalDocs; } - @Override - public Schema externalDocs(ExternalDocumentation externalDocs) { - setExternalDocs(externalDocs); - return this; - } - @Override public Boolean getDeprecated() { return deprecated; @@ -612,12 +473,6 @@ public void setDeprecated(Boolean deprecated) { this.deprecated = deprecated; } - @Override - public Schema deprecated(Boolean deprecated) { - setDeprecated(deprecated); - return this; - } - @Override public XML getXml() { return xml; @@ -628,12 +483,6 @@ public void setXml(XML xml) { this.xml = xml; } - @Override - public Schema xml(XML xml) { - setXml(xml); - return this; - } - @Override public Schema enumeration(List enumeration) { setEnumeration(enumeration); @@ -650,12 +499,6 @@ public void setItems(Schema items) { this.items = items; } - @Override - public Schema items(Schema items) { - setItems(items); - return this; - } - @Override public List getAllOf() { return allOf; @@ -667,15 +510,14 @@ public void setAllOf(List allOf) { } @Override - public Schema allOf(List allOf) { - setAllOf(allOf); + public Schema addAllOf(Schema allOf) { + this.allOf.add(allOf); return this; } @Override - public Schema addAllOf(Schema allOf) { - this.allOf.add(allOf); - return this; + public void removeAllOf(Schema allOf) { + this.allOf.remove(allOf); } @Override @@ -689,15 +531,14 @@ public void setAnyOf(List anyOf) { } @Override - public Schema anyOf(List anyOf) { - setAnyOf(anyOf); + public Schema addAnyOf(Schema anyOf) { + this.anyOf.add(anyOf); return this; } @Override - public Schema addAnyOf(Schema anyOf) { - this.anyOf.add(anyOf); - return this; + public void removeAnyOf(Schema anyOf) { + this.anyOf.remove(anyOf); } @Override @@ -710,12 +551,6 @@ public void setOneOf(List oneOf) { this.oneOf = oneOf; } - @Override - public Schema oneOf(List oneOf) { - setOneOf(oneOf); - return this; - } - @Override public Schema addOneOf(Schema oneOf) { this.oneOf.add(oneOf); @@ -723,14 +558,13 @@ public Schema addOneOf(Schema oneOf) { } @Override - public void setAdditionalProperties(Boolean additionalProperties) { - this.additionalProperties = additionalProperties; + public void removeOneOf(Schema oneOf) { + this.oneOf.remove(oneOf); } @Override - public Schema additionalProperties(Boolean additionalProperties) { - setAdditionalProperties(additionalProperties); - return this; + public void setAdditionalProperties(Boolean additionalProperties) { + this.additionalProperties = additionalProperties; } public static void merge(org.eclipse.microprofile.openapi.annotations.media.Schema from, Schema to, diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/XMLImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/XMLImpl.java index 479d480bd26..f27a34ffbe3 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/XMLImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/XMLImpl.java @@ -43,7 +43,7 @@ import fish.payara.microprofile.openapi.impl.model.ExtensibleImpl; -public class XMLImpl extends ExtensibleImpl implements XML { +public class XMLImpl extends ExtensibleImpl implements XML { protected String name; protected String namespace; @@ -61,12 +61,6 @@ public void setName(String name) { this.name = name; } - @Override - public XML name(String name) { - setName(name); - return this; - } - @Override public String getNamespace() { return namespace; @@ -77,12 +71,6 @@ public void setNamespace(String namespace) { this.namespace = namespace; } - @Override - public XML namespace(String namespace) { - setNamespace(namespace); - return this; - } - @Override public String getPrefix() { return prefix; @@ -93,12 +81,6 @@ public void setPrefix(String prefix) { this.prefix = prefix; } - @Override - public XML prefix(String prefix) { - setPrefix(prefix); - return this; - } - @Override public Boolean getAttribute() { return attribute; @@ -109,12 +91,6 @@ public void setAttribute(Boolean attribute) { this.attribute = attribute; } - @Override - public XML attribute(Boolean attribute) { - setAttribute(attribute); - return this; - } - @Override public Boolean getWrapped() { return wrapped; @@ -125,10 +101,4 @@ public void setWrapped(Boolean wrapped) { this.wrapped = wrapped; } - @Override - public XML wrapped(Boolean wrapped) { - setWrapped(wrapped); - return this; - } - } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/parameters/ParameterImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/parameters/ParameterImpl.java index 786381a65bd..070d44b218a 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/parameters/ParameterImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/parameters/ParameterImpl.java @@ -60,7 +60,7 @@ import fish.payara.microprofile.openapi.impl.model.media.ContentImpl; import fish.payara.microprofile.openapi.impl.model.media.SchemaImpl; -public class ParameterImpl extends ExtensibleImpl implements Parameter { +public class ParameterImpl extends ExtensibleImpl implements Parameter { protected String name; protected In in; @@ -88,12 +88,6 @@ public void setName(String name) { this.name = name; } - @Override - public Parameter name(String name) { - setName(name); - return this; - } - @Override public In getIn() { return in; @@ -104,12 +98,6 @@ public void setIn(In in) { this.in = in; } - @Override - public Parameter in(In in) { - setIn(in); - return this; - } - @Override public String getDescription() { return description; @@ -120,12 +108,6 @@ public void setDescription(String description) { this.description = description; } - @Override - public Parameter description(String description) { - setDescription(description); - return this; - } - @Override public Boolean getRequired() { return required; @@ -136,12 +118,6 @@ public void setRequired(Boolean required) { this.required = required; } - @Override - public Parameter required(Boolean required) { - setRequired(required); - return this; - } - @Override public Boolean getDeprecated() { return deprecated; @@ -152,12 +128,6 @@ public void setDeprecated(Boolean deprecated) { this.deprecated = deprecated; } - @Override - public Parameter deprecated(Boolean deprecated) { - setDeprecated(deprecated); - return this; - } - @Override public Boolean getAllowEmptyValue() { return allowEmptyValue; @@ -168,12 +138,6 @@ public void setAllowEmptyValue(Boolean allowEmptyValue) { this.allowEmptyValue = allowEmptyValue; } - @Override - public Parameter allowEmptyValue(Boolean allowEmptyValue) { - setAllowEmptyValue(allowEmptyValue); - return this; - } - @Override public Style getStyle() { return style; @@ -184,12 +148,6 @@ public void setStyle(Style style) { this.style = style; } - @Override - public Parameter style(Style style) { - setStyle(style); - return this; - } - @Override public Boolean getExplode() { return explode; @@ -200,12 +158,6 @@ public void setExplode(Boolean explode) { this.explode = explode; } - @Override - public Parameter explode(Boolean explode) { - setExplode(explode); - return this; - } - @Override public Boolean getAllowReserved() { return allowReserved; @@ -216,12 +168,6 @@ public void setAllowReserved(Boolean allowReserved) { this.allowReserved = allowReserved; } - @Override - public Parameter allowReserved(Boolean allowReserved) { - setAllowReserved(allowReserved); - return this; - } - @Override public Schema getSchema() { return schema; @@ -232,12 +178,6 @@ public void setSchema(Schema schema) { this.schema = schema; } - @Override - public Parameter schema(Schema schema) { - setSchema(schema); - return this; - } - @Override public Map getExamples() { return examples; @@ -249,15 +189,14 @@ public void setExamples(Map examples) { } @Override - public Parameter examples(Map examples) { - setExamples(examples); + public Parameter addExample(String key, Example example) { + this.examples.put(key, example); return this; } @Override - public Parameter addExample(String key, Example example) { - this.examples.put(key, example); - return this; + public void removeExample(String key) { + this.examples.remove(key); } @Override @@ -270,12 +209,6 @@ public void setExample(Object example) { this.example = example; } - @Override - public Parameter example(Object example) { - setExample(example); - return this; - } - @Override public Content getContent() { return content; @@ -286,12 +219,6 @@ public void setContent(Content content) { this.content = content; } - @Override - public Parameter content(Content content) { - setContent(content); - return this; - } - @Override public String getRef() { return ref; @@ -305,12 +232,6 @@ public void setRef(String ref) { this.ref = ref; } - @Override - public Parameter ref(String ref) { - setRef(ref); - return this; - } - public static void merge(org.eclipse.microprofile.openapi.annotations.parameters.Parameter from, Parameter to, boolean override, Map currentSchemas) { if (isAnnotationNull(from)) { diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/parameters/RequestBodyImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/parameters/RequestBodyImpl.java index 6843fea8aaa..73f0d7329a3 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/parameters/RequestBodyImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/parameters/RequestBodyImpl.java @@ -52,7 +52,7 @@ import fish.payara.microprofile.openapi.impl.model.ExtensibleImpl; import fish.payara.microprofile.openapi.impl.model.media.ContentImpl; -public class RequestBodyImpl extends ExtensibleImpl implements RequestBody { +public class RequestBodyImpl extends ExtensibleImpl implements RequestBody { protected String description; protected Content content = new ContentImpl(); @@ -69,12 +69,6 @@ public void setDescription(String description) { this.description = description; } - @Override - public RequestBody description(String description) { - setDescription(description); - return this; - } - @Override public Content getContent() { return content; @@ -85,12 +79,6 @@ public void setContent(Content content) { this.content = content; } - @Override - public RequestBody content(Content content) { - setContent(content); - return this; - } - @Override public Boolean getRequired() { return required; @@ -101,12 +89,6 @@ public void setRequired(Boolean required) { this.required = required; } - @Override - public RequestBody required(Boolean required) { - setRequired(required); - return this; - } - @Override public String getRef() { return ref; @@ -120,12 +102,6 @@ public void setRef(String ref) { this.ref = ref; } - @Override - public RequestBody ref(String ref) { - setRef(ref); - return this; - } - public static void merge(org.eclipse.microprofile.openapi.annotations.parameters.RequestBody from, RequestBody to, boolean override, Map currentSchemas) { if (isAnnotationNull(from)) { diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/responses/APIResponseImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/responses/APIResponseImpl.java index feb2f7ea4e2..498247f378e 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/responses/APIResponseImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/responses/APIResponseImpl.java @@ -57,7 +57,7 @@ import fish.payara.microprofile.openapi.impl.model.links.LinkImpl; import fish.payara.microprofile.openapi.impl.model.media.ContentImpl; -public class APIResponseImpl extends ExtensibleImpl implements APIResponse { +public class APIResponseImpl extends ExtensibleImpl implements APIResponse { protected String description; protected Map headers = new HashMap<>(); @@ -75,12 +75,6 @@ public void setDescription(String description) { this.description = description; } - @Override - public APIResponse description(String description) { - setDescription(description); - return this; - } - @Override public Map getHeaders() { return headers; @@ -92,15 +86,14 @@ public void setHeaders(Map headers) { } @Override - public APIResponse headers(Map headers) { - setHeaders(headers); + public APIResponse addHeader(String name, Header header) { + headers.put(name, header); return this; } @Override - public APIResponse addHeader(String name, Header header) { - headers.put(name, header); - return this; + public void removeHeader(String name) { + headers.remove(name); } @Override @@ -113,12 +106,6 @@ public void setContent(Content content) { this.content = content; } - @Override - public APIResponse content(Content content) { - setContent(content); - return this; - } - @Override public Map getLinks() { return links; @@ -130,15 +117,14 @@ public void setLinks(Map links) { } @Override - public APIResponse links(Map links) { - setLinks(links); + public APIResponse addLink(String name, Link link) { + links.put(name, link); return this; } @Override - public APIResponse addLink(String name, Link link) { - links.put(name, link); - return this; + public void removeLink(String name) { + links.remove(name); } @Override @@ -154,12 +140,6 @@ public void setRef(String ref) { this.ref = ref; } - @Override - public APIResponse ref(String ref) { - setRef(ref); - return this; - } - public static void merge(org.eclipse.microprofile.openapi.annotations.responses.APIResponse from, APIResponse to, boolean override, Map currentSchemas) { if (isAnnotationNull(from)) { diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/responses/APIResponsesImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/responses/APIResponsesImpl.java index 19ae86f59a4..b2f800b3878 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/responses/APIResponsesImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/responses/APIResponsesImpl.java @@ -41,37 +41,60 @@ import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.isAnnotationNull; -import java.util.LinkedHashMap; +import java.util.HashMap; import java.util.Map; import org.eclipse.microprofile.openapi.models.media.Schema; import org.eclipse.microprofile.openapi.models.responses.APIResponse; import org.eclipse.microprofile.openapi.models.responses.APIResponses; -public class APIResponsesImpl extends LinkedHashMap implements APIResponses { +import fish.payara.microprofile.openapi.impl.model.ExtensibleLinkedHashMap; + +public class APIResponsesImpl extends ExtensibleLinkedHashMap + implements APIResponses { private static final long serialVersionUID = 2811935761440110541L; - @Override - public APIResponses addApiResponse(String name, APIResponse item) { - put(name, item); + protected Map extensions = new HashMap<>(); + + public APIResponsesImpl() { + super(); + } + + public APIResponsesImpl(Map responses) { + super(responses); + } + + @Override + public APIResponses addAPIResponse(String name, APIResponse apiResponse) { + put(name, apiResponse); return this; } @Override - public APIResponse getDefault() { - return this.get(DEFAULT); + public void removeAPIResponse(String name) { + remove(name); } @Override - public void setDefaultValue(APIResponse defaultValue) { - addApiResponse(DEFAULT, defaultValue); + public Map getAPIResponses() { + return new APIResponsesImpl(this); } @Override - public APIResponses defaultValue(APIResponse defaultValue) { - setDefaultValue(defaultValue); - return this; + public void setAPIResponses(Map items) { + clear(); + putAll(items); + } + + @Override + public APIResponse getDefaultValue() { + return this.get(DEFAULT); + } + + @Override + public void setDefaultValue(APIResponse defaultValue) { + addAPIResponse(DEFAULT, defaultValue); } public static void merge(org.eclipse.microprofile.openapi.annotations.responses.APIResponse from, APIResponses to, @@ -87,7 +110,7 @@ public static void merge(org.eclipse.microprofile.openapi.annotations.responses. org.eclipse.microprofile.openapi.models.responses.APIResponse response = to .getOrDefault(responseName, new APIResponseImpl()); - to.addApiResponse(responseName, response); + to.addAPIResponse(responseName, response); APIResponseImpl.merge(from, response, override, currentSchemas); } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/OAuthFlowImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/OAuthFlowImpl.java index 74f3d2ebaf9..e6ad4daa23c 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/OAuthFlowImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/OAuthFlowImpl.java @@ -48,7 +48,7 @@ import fish.payara.microprofile.openapi.impl.model.ExtensibleImpl; -public class OAuthFlowImpl extends ExtensibleImpl implements OAuthFlow { +public class OAuthFlowImpl extends ExtensibleImpl implements OAuthFlow { protected String authorizationUrl; protected String tokenUrl; @@ -65,12 +65,6 @@ public void setAuthorizationUrl(String authorizationUrl) { this.authorizationUrl = authorizationUrl; } - @Override - public OAuthFlow authorizationUrl(String authorizationUrl) { - setAuthorizationUrl(authorizationUrl); - return this; - } - @Override public String getTokenUrl() { return tokenUrl; @@ -81,12 +75,6 @@ public void setTokenUrl(String tokenUrl) { this.tokenUrl = tokenUrl; } - @Override - public OAuthFlow tokenUrl(String tokenUrl) { - setTokenUrl(tokenUrl); - return this; - } - @Override public String getRefreshUrl() { return refreshUrl; @@ -97,12 +85,6 @@ public void setRefreshUrl(String refreshUrl) { this.refreshUrl = refreshUrl; } - @Override - public OAuthFlow refreshUrl(String refreshUrl) { - setRefreshUrl(refreshUrl); - return this; - } - @Override public Scopes getScopes() { return scopes; @@ -113,12 +95,6 @@ public void setScopes(Scopes scopes) { this.scopes = scopes; } - @Override - public OAuthFlow scopes(Scopes scopes) { - setScopes(scopes); - return this; - } - public static void merge(org.eclipse.microprofile.openapi.annotations.security.OAuthFlow from, OAuthFlow to, boolean override) { if (isAnnotationNull(from)) { diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/OAuthFlowsImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/OAuthFlowsImpl.java index bd46c9afa3e..330324c787b 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/OAuthFlowsImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/OAuthFlowsImpl.java @@ -47,7 +47,7 @@ import fish.payara.microprofile.openapi.impl.model.ExtensibleImpl; -public class OAuthFlowsImpl extends ExtensibleImpl implements OAuthFlows { +public class OAuthFlowsImpl extends ExtensibleImpl implements OAuthFlows { protected OAuthFlow implicit; protected OAuthFlow password; @@ -64,12 +64,6 @@ public void setImplicit(OAuthFlow implicit) { this.implicit = implicit; } - @Override - public OAuthFlows implicit(OAuthFlow implicit) { - setImplicit(implicit); - return this; - } - @Override public OAuthFlow getPassword() { return password; @@ -80,12 +74,6 @@ public void setPassword(OAuthFlow password) { this.password = password; } - @Override - public OAuthFlows password(OAuthFlow password) { - setPassword(password); - return this; - } - @Override public OAuthFlow getClientCredentials() { return clientCredentials; @@ -96,12 +84,6 @@ public void setClientCredentials(OAuthFlow clientCredentials) { this.clientCredentials = clientCredentials; } - @Override - public OAuthFlows clientCredentials(OAuthFlow clientCredentials) { - setClientCredentials(clientCredentials); - return this; - } - @Override public OAuthFlow getAuthorizationCode() { return authorizationCode; @@ -112,12 +94,6 @@ public void setAuthorizationCode(OAuthFlow authorizationCode) { this.authorizationCode = authorizationCode; } - @Override - public OAuthFlows authorizationCode(OAuthFlow authorizationCode) { - setAuthorizationCode(authorizationCode); - return this; - } - public static void merge(org.eclipse.microprofile.openapi.annotations.security.OAuthFlows from, OAuthFlows to, boolean override) { if (from == null) { diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/ScopesImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/ScopesImpl.java index 20f58d4b0bb..1ed1852075f 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/ScopesImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/ScopesImpl.java @@ -39,17 +39,23 @@ */ package fish.payara.microprofile.openapi.impl.model.security; -import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.Map; import org.eclipse.microprofile.openapi.models.security.Scopes; -public class ScopesImpl extends LinkedHashMap implements Scopes { +import fish.payara.microprofile.openapi.impl.model.ExtensibleLinkedHashMap; + +public class ScopesImpl extends ExtensibleLinkedHashMap implements Scopes { private static final long serialVersionUID = -615440059031779085L; - protected Map extensions = new HashMap<>(); + public ScopesImpl() { + super(); + } + + public ScopesImpl(Map scopes) { + super(scopes); + } @Override public Scopes addScope(String name, String item) { @@ -58,18 +64,19 @@ public Scopes addScope(String name, String item) { } @Override - public Map getExtensions() { - return extensions; + public void removeScope(String scope) { + this.remove(scope); } @Override - public void setExtensions(Map extensions) { - this.extensions = extensions; + public Map getScopes() { + return new ScopesImpl(this); } @Override - public void addExtension(String name, Object value) { - this.extensions.put(name, value); + public void setScopes(Map items) { + clear(); + putAll(items); } } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/SecurityRequirementImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/SecurityRequirementImpl.java index 0706cb66f5b..381e2b1789a 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/SecurityRequirementImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/SecurityRequirementImpl.java @@ -45,6 +45,7 @@ import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import org.eclipse.microprofile.openapi.models.security.SecurityRequirement; @@ -52,6 +53,14 @@ public class SecurityRequirementImpl extends LinkedHashMap> private static final long serialVersionUID = -677783376083861245L; + public SecurityRequirementImpl() { + super(); + } + + public SecurityRequirementImpl(Map> items) { + super(items); + } + @Override public SecurityRequirement addScheme(String name, String item) { this.put(name, Arrays.asList(item)); @@ -70,6 +79,22 @@ public SecurityRequirement addScheme(String name) { return this; } + @Override + public void removeScheme(String securitySchemeName) { + this.remove(securitySchemeName); + } + + @Override + public Map> getSchemes() { + return new SecurityRequirementImpl(this); + } + + @Override + public void setSchemes(Map> items) { + clear(); + putAll(items); + } + public static void merge(org.eclipse.microprofile.openapi.annotations.security.SecurityRequirement from, SecurityRequirement to) { if (isAnnotationNull(from)) { diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/SecuritySchemeImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/SecuritySchemeImpl.java index 1f710ee2dc6..c8a39503dc2 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/SecuritySchemeImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/SecuritySchemeImpl.java @@ -50,7 +50,7 @@ import fish.payara.microprofile.openapi.impl.model.ExtensibleImpl; -public class SecuritySchemeImpl extends ExtensibleImpl implements SecurityScheme { +public class SecuritySchemeImpl extends ExtensibleImpl implements SecurityScheme { protected SecurityScheme.Type type; protected String description; @@ -73,12 +73,6 @@ public void setType(SecurityScheme.Type type) { this.type = type; } - @Override - public SecurityScheme type(SecurityScheme.Type type) { - setType(type); - return this; - } - @Override public String getDescription() { return description; @@ -89,12 +83,6 @@ public void setDescription(String description) { this.description = description; } - @Override - public SecurityScheme description(String description) { - setDescription(description); - return this; - } - @Override public String getName() { return name; @@ -105,12 +93,6 @@ public void setName(String name) { this.name = name; } - @Override - public SecurityScheme name(String name) { - setName(name); - return this; - } - @Override public SecurityScheme.In getIn() { return in; @@ -121,12 +103,6 @@ public void setIn(SecurityScheme.In in) { this.in = in; } - @Override - public SecurityScheme in(SecurityScheme.In in) { - setIn(in); - return this; - } - @Override public String getScheme() { return scheme; @@ -137,12 +113,6 @@ public void setScheme(String scheme) { this.scheme = scheme; } - @Override - public SecurityScheme scheme(String scheme) { - setScheme(scheme); - return this; - } - @Override public String getBearerFormat() { return bearerFormat; @@ -153,12 +123,6 @@ public void setBearerFormat(String bearerFormat) { this.bearerFormat = bearerFormat; } - @Override - public SecurityScheme bearerFormat(String bearerFormat) { - setBearerFormat(bearerFormat); - return this; - } - @Override public OAuthFlows getFlows() { return flows; @@ -169,12 +133,6 @@ public void setFlows(OAuthFlows flows) { this.flows = flows; } - @Override - public SecurityScheme flows(OAuthFlows flows) { - setFlows(flows); - return this; - } - @Override public String getOpenIdConnectUrl() { return openIdConnectUrl; @@ -185,12 +143,6 @@ public void setOpenIdConnectUrl(String openIdConnectUrl) { this.openIdConnectUrl = openIdConnectUrl; } - @Override - public SecurityScheme openIdConnectUrl(String openIdConnectUrl) { - setOpenIdConnectUrl(openIdConnectUrl); - return this; - } - @Override public String getRef() { return ref; @@ -204,12 +156,6 @@ public void setRef(String ref) { this.ref = ref; } - @Override - public SecurityScheme ref(String ref) { - setRef(ref); - return this; - } - public static void merge(org.eclipse.microprofile.openapi.annotations.security.SecurityScheme from, SecurityScheme to, boolean override) { if (isAnnotationNull(from)) { diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerImpl.java index 7147050d097..c32d9d2c264 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerImpl.java @@ -42,17 +42,19 @@ import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.isAnnotationNull; import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.mergeProperty; -import org.eclipse.microprofile.openapi.annotations.servers.ServerVariable; +import java.util.Map; + import org.eclipse.microprofile.openapi.models.servers.Server; +import org.eclipse.microprofile.openapi.models.servers.ServerVariable; import org.eclipse.microprofile.openapi.models.servers.ServerVariables; import fish.payara.microprofile.openapi.impl.model.ExtensibleImpl; -public class ServerImpl extends ExtensibleImpl implements Server { +public class ServerImpl extends ExtensibleImpl implements Server { protected String url; protected String description; - protected ServerVariables variables; + protected Map variables; @Override public String getUrl() { @@ -64,12 +66,6 @@ public void setUrl(String url) { this.url = url; } - @Override - public Server url(String url) { - setUrl(url); - return this; - } - @Override public String getDescription() { return description; @@ -80,15 +76,9 @@ public void setDescription(String description) { this.description = description; } - @Override - public Server description(String description) { - setDescription(description); - return this; - } - @Override public ServerVariables getVariables() { - return variables; + return variables instanceof ServerVariables ? (ServerVariables) variables : new ServerVariablesImpl(variables); } @Override @@ -97,9 +87,8 @@ public void setVariables(ServerVariables variables) { } @Override - public Server variables(ServerVariables variables) { - setVariables(variables); - return this; + public void setVariables(Map variables) { + this.variables = variables; } public static void merge(org.eclipse.microprofile.openapi.annotations.servers.Server from, Server to, @@ -113,7 +102,7 @@ public static void merge(org.eclipse.microprofile.openapi.annotations.servers.Se if (to.getVariables() == null) { to.setVariables(new ServerVariablesImpl()); } - for (ServerVariable variable : from.variables()) { + for (org.eclipse.microprofile.openapi.annotations.servers.ServerVariable variable : from.variables()) { ServerVariablesImpl.merge(variable, to.getVariables(), override); } } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerVariableImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerVariableImpl.java index 188a649505e..b180b25f34f 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerVariableImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerVariableImpl.java @@ -46,7 +46,7 @@ import fish.payara.microprofile.openapi.impl.model.ExtensibleImpl; -public class ServerVariableImpl extends ExtensibleImpl implements ServerVariable { +public class ServerVariableImpl extends ExtensibleImpl implements ServerVariable { protected String description; protected String defaultValue; @@ -63,12 +63,6 @@ public void setDescription(String description) { this.description = description; } - @Override - public ServerVariable description(String description) { - setDescription(description); - return this; - } - @Override public String getDefaultValue() { return defaultValue; @@ -79,12 +73,6 @@ public void setDefaultValue(String defaultValue) { this.defaultValue = defaultValue; } - @Override - public ServerVariable defaultValue(String defaultValue) { - setDefaultValue(defaultValue); - return this; - } - @Override public List getEnumeration() { return enumeration; @@ -95,12 +83,6 @@ public void setEnumeration(List enumeration) { this.enumeration = enumeration; } - @Override - public ServerVariable enumeration(List enumeration) { - setEnumeration(enumeration); - return this; - } - @Override public ServerVariable addEnumeration(String enumeration) { if (!this.enumeration.contains(enumeration)) { @@ -109,4 +91,9 @@ public ServerVariable addEnumeration(String enumeration) { return this; } + @Override + public void removeEnumeration(String enumeration) { + this.enumeration.remove(enumeration); + } + } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerVariablesImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerVariablesImpl.java index c0fec9e06bc..ee22abd091c 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerVariablesImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerVariablesImpl.java @@ -43,18 +43,24 @@ import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.mergeProperty; import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.Map; import org.eclipse.microprofile.openapi.models.servers.ServerVariable; import org.eclipse.microprofile.openapi.models.servers.ServerVariables; -public class ServerVariablesImpl extends LinkedHashMap implements ServerVariables { +import fish.payara.microprofile.openapi.impl.model.ExtensibleLinkedHashMap; + +public class ServerVariablesImpl extends ExtensibleLinkedHashMap implements ServerVariables { private static final long serialVersionUID = 8869393484826870024L; - protected Map extensions = new HashMap<>(); + public ServerVariablesImpl() { + super(); + } + + public ServerVariablesImpl(Map variables) { + super(variables); + } @Override public ServerVariables addServerVariable(String name, ServerVariable item) { @@ -63,18 +69,19 @@ public ServerVariables addServerVariable(String name, ServerVariable item) { } @Override - public Map getExtensions() { - return extensions; + public void removeServerVariable(String name) { + remove(name); } @Override - public void setExtensions(Map extensions) { - this.extensions = extensions; + public Map getServerVariables() { + return new ServerVariablesImpl(this); } @Override - public void addExtension(String name, Object value) { - this.extensions.put(name, value); + public void setServerVariables(Map items) { + clear(); + putAll(items); } public static void merge(org.eclipse.microprofile.openapi.annotations.servers.ServerVariable from, @@ -93,7 +100,7 @@ public static void merge(org.eclipse.microprofile.openapi.annotations.servers.Se variable.addEnumeration(value); } } - if ((to.containsKey(from.name()) && override) || !to.containsKey(from.name())) { + if ((to.hasServerVariable(from.name()) && override) || !to.hasServerVariable(from.name())) { to.addServerVariable(from.name(), variable); } } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/tags/TagImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/tags/TagImpl.java index 8b9c56e7c11..8610c01f985 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/tags/TagImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/tags/TagImpl.java @@ -51,7 +51,7 @@ import fish.payara.microprofile.openapi.impl.model.ExtensibleImpl; import fish.payara.microprofile.openapi.impl.model.ExternalDocumentationImpl; -public class TagImpl extends ExtensibleImpl implements Tag { +public class TagImpl extends ExtensibleImpl implements Tag { protected String name; protected String description; @@ -67,12 +67,6 @@ public void setName(String name) { this.name = name; } - @Override - public Tag name(String name) { - setName(name); - return this; - } - @Override public String getDescription() { return description; @@ -83,12 +77,6 @@ public void setDescription(String description) { this.description = description; } - @Override - public Tag description(String description) { - setDescription(description); - return this; - } - @Override public ExternalDocumentation getExternalDocs() { return externalDocs; @@ -99,12 +87,6 @@ public void setExternalDocs(ExternalDocumentation externalDocs) { this.externalDocs = externalDocs; } - @Override - public Tag externalDocs(ExternalDocumentation externalDocs) { - setExternalDocs(externalDocs); - return this; - } - public static void merge(org.eclipse.microprofile.openapi.annotations.tags.Tag from, Tag to, boolean override) { if (isAnnotationNull(from)) { return; diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/util/ModelUtils.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/util/ModelUtils.java index 88e01c1c7cb..a0202bc73df 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/util/ModelUtils.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/util/ModelUtils.java @@ -194,8 +194,8 @@ public static HttpMethod getHttpMethod(String method) { */ public static Operation getOrCreateOperation(PathItem pathItem, HttpMethod httpMethod) { Operation operation = new OperationImpl(); - if (pathItem.readOperationsMap().get(httpMethod) != null) { - return pathItem.readOperationsMap().get(httpMethod); + if (pathItem.getOperations().get(httpMethod) != null) { + return pathItem.getOperations().get(httpMethod); } switch (httpMethod) { case GET: @@ -231,7 +231,7 @@ public static Operation getOrCreateOperation(PathItem pathItem, HttpMethod httpM public static Operation findOperation(OpenAPI api, Method method, String path) { Operation foundOperation = null; try { - return api.getPaths().get(path).readOperationsMap().get(getHttpMethod(method)); + return api.getPaths().getPathItem(path).getOperations().get(getHttpMethod(method)); } catch (NullPointerException ex) { // Operation not found } @@ -405,7 +405,7 @@ public static boolean isAnnotationNull(Annotation annotation) { return false; } else if (value instanceof Collection && !Collection.class.cast(value).isEmpty()) { return false; - } else if (value instanceof Boolean && Boolean.class.cast(value)) { + } else if (value instanceof Boolean && ((Boolean)value).booleanValue()) { return false; } else if (value.getClass().equals(Class.class) && !Class.class.cast(value).getTypeName().equals("java.lang.Void")) { @@ -427,6 +427,18 @@ public static boolean isAnnotationNull(Annotation annotation) { return allNull; } + public static Boolean mergeProperty(Boolean current, boolean offer, boolean override) { + return mergeProperty(current, Boolean.valueOf(offer), override); + } + + public static Boolean mergeProperty(boolean current, Boolean offer, boolean override) { + return mergeProperty(Boolean.valueOf(current), offer, override); + } + + public static Boolean mergeProperty(boolean current, boolean offer, boolean override) { + return mergeProperty(Boolean.valueOf(current), Boolean.valueOf(offer), override); + } + public static E mergeProperty(E current, E offer, boolean override) { // Treat empty strings as null if (offer instanceof String && offer.toString().isEmpty()) { @@ -547,10 +559,10 @@ public static org.eclipse.microprofile.openapi.models.Operation getOperation(Met OpenAPI api, Map>> resourceMapping) { String path = getResourcePath(method, resourceMapping); if (path != null) { - PathItem pathItem = api.getPaths().get(path); + PathItem pathItem = api.getPaths().getPathItem(path); if (pathItem != null) { PathItem.HttpMethod httpMethod = getHttpMethod(method); - return pathItem.readOperationsMap().get(httpMethod); + return pathItem.getOperations().get(httpMethod); } } return null; diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/ApplicationProcessor.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/ApplicationProcessor.java index eca027ee2a3..35d69500780 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/ApplicationProcessor.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/ApplicationProcessor.java @@ -321,15 +321,15 @@ public void visitProduces(Produces produces, AnnotatedElement element, ApiContex if (response != null) { // Find the wildcard return type if (response.getContent() != null - && response.getContent().get(javax.ws.rs.core.MediaType.WILDCARD) != null) { - MediaType wildcardMedia = response.getContent().get(javax.ws.rs.core.MediaType.WILDCARD); + && response.getContent().getMediaType(javax.ws.rs.core.MediaType.WILDCARD) != null) { + MediaType wildcardMedia = response.getContent().getMediaType(javax.ws.rs.core.MediaType.WILDCARD); // Copy the wildcard return type to the valid response types for (String mediaType : produces.value()) { - response.getContent().put(getContentType(mediaType), wildcardMedia); + response.getContent().addMediaType(getContentType(mediaType), wildcardMedia); } // If there is an @Produces, remove the wildcard - response.getContent().remove(javax.ws.rs.core.MediaType.WILDCARD); + response.getContent().removeMediaType(javax.ws.rs.core.MediaType.WILDCARD); } } } @@ -340,20 +340,20 @@ public void visitProduces(Produces produces, AnnotatedElement element, ApiContex public void visitConsumes(Consumes consumes, AnnotatedElement element, ApiContext context) { if (element instanceof Method && context.getWorkingOperation() != null) { org.eclipse.microprofile.openapi.models.parameters.RequestBody requestBody = context.getWorkingOperation() - .getRequestBody(); + .getRequestBody(); if (requestBody != null) { // Find the wildcard return type if (requestBody.getContent() != null - && requestBody.getContent().get(javax.ws.rs.core.MediaType.WILDCARD) != null) { - MediaType wildcardMedia = requestBody.getContent().get(javax.ws.rs.core.MediaType.WILDCARD); + && requestBody.getContent().getMediaType(javax.ws.rs.core.MediaType.WILDCARD) != null) { + MediaType wildcardMedia = requestBody.getContent().getMediaType(javax.ws.rs.core.MediaType.WILDCARD); // Copy the wildcard return type to the valid request body types for (String mediaType : consumes.value()) { - requestBody.getContent().put(getContentType(mediaType), wildcardMedia); + requestBody.getContent().addMediaType(getContentType(mediaType), wildcardMedia); } // If there is an @Consumes, remove the wildcard - requestBody.getContent().remove(javax.ws.rs.core.MediaType.WILDCARD); + requestBody.getContent().removeMediaType(javax.ws.rs.core.MediaType.WILDCARD); } } } @@ -367,7 +367,7 @@ public void visitQueryParam(QueryParam param, AnnotatedElement element, ApiConte newParameter.setStyle(Style.SIMPLE); addParameter(element, context, newParameter); } - + @Override public void visitPathParam(PathParam param, AnnotatedElement element, ApiContext context) { org.eclipse.microprofile.openapi.models.parameters.Parameter newParameter = new ParameterImpl(); @@ -377,7 +377,7 @@ public void visitPathParam(PathParam param, AnnotatedElement element, ApiContext newParameter.setStyle(Style.SIMPLE); addParameter(element, context, newParameter); } - + @Override public void visitFormParam(FormParam param, AnnotatedElement element, ApiContext context) { // Find the aggregate schema type of all the parameters @@ -404,8 +404,8 @@ public void visitFormParam(FormParam param, AnnotatedElement element, ApiContext // Set the request body type accordingly. context.getWorkingOperation().getRequestBody().getContent() - .get(javax.ws.rs.core.MediaType.WILDCARD).getSchema() - .setType(formSchemaType); + .getMediaType(javax.ws.rs.core.MediaType.WILDCARD).getSchema() + .setType(formSchemaType); } } @@ -426,7 +426,7 @@ public void visitCookieParam(CookieParam param, AnnotatedElement element, ApiCon newParameter.setStyle(Style.SIMPLE); addParameter(element, context, newParameter); } - + private void addParameter(AnnotatedElement element, ApiContext context, org.eclipse.microprofile.openapi.models.parameters.Parameter newParameter) { SchemaImpl schema = new SchemaImpl(); @@ -469,13 +469,13 @@ private void addParameter(AnnotatedElement element, ApiContext context, } } else { LOGGER.log(SEVERE, "Couldn't add " + newParameter.getIn() + " parameter, \"" + newParameter.getName() - + "\" to the OpenAPI Document. This is usually caused by declaring parameter under a method with " - + "an unsupported annotation."); + + "\" to the OpenAPI Document. This is usually caused by declaring parameter under a method with " + + "an unsupported annotation."); } } } - - private SchemaImpl getArraySchema(AnnotatedElement element) { + + private static SchemaImpl getArraySchema(AnnotatedElement element) { SchemaImpl arraySchema = new SchemaImpl(); ParameterizedType parameterizedType; @@ -490,8 +490,8 @@ private SchemaImpl getArraySchema(AnnotatedElement element) { arraySchema.setType(ModelUtils.getSchemaType((Class) parameterizedType.getActualTypeArguments()[0])); return arraySchema; } - - private String getDefaultValueIfPresent(AnnotatedElement element) { + + private static String getDefaultValueIfPresent(AnnotatedElement element) { Annotation[] annotations = element.getDeclaredAnnotations(); for (Annotation annotation : annotations) { if ("javax.ws.rs.DefaultValue".equals(annotation.annotationType().getName())) { @@ -504,7 +504,7 @@ private String getDefaultValueIfPresent(AnnotatedElement element) { } return null; } - + @Override public void visitOpenAPI(OpenAPIDefinition definition, AnnotatedElement element, ApiContext context) { OpenAPIImpl.merge(definition, context.getApi(), true); @@ -604,7 +604,7 @@ public void visitSchema(Schema schema, AnnotatedElement element, ApiContext cont } // Insert the schema to the request body media type MediaType mediaType = context.getWorkingOperation().getRequestBody().getContent() - .get(javax.ws.rs.core.MediaType.WILDCARD); + .getMediaType(javax.ws.rs.core.MediaType.WILDCARD); SchemaImpl.merge(schema, mediaType.getSchema(), true, context.getApi().getComponents().getSchemas()); if (schema.ref() != null && !schema.ref().isEmpty()) { mediaType.setSchema(new SchemaImpl().ref(schema.ref())); @@ -641,7 +641,7 @@ public void visitOperation(Operation operation, AnnotatedElement element, ApiCon OperationImpl.merge(operation, context.getWorkingOperation(), true); // If the operation should be hidden, remove it if (operation.hidden()) { - ModelUtils.removeOperation(context.getApi().getPaths().get(context.getPath()), + ModelUtils.removeOperation(context.getApi().getPaths().getPathItem(context.getPath()), context.getWorkingOperation()); } } @@ -690,10 +690,10 @@ public void visitAPIResponse(APIResponse apiResponse, AnnotatedElement element, // If the element doesn't also contain a response mapping to the default if (Arrays.asList(element.getDeclaredAnnotationsByType(APIResponse.class)).stream() .noneMatch(a -> a.responseCode() == null || a.responseCode().isEmpty() || a.responseCode() - .equals(org.eclipse.microprofile.openapi.models.responses.APIResponses.DEFAULT))) { + .equals(org.eclipse.microprofile.openapi.models.responses.APIResponses.DEFAULT))) { // Then remove the default response context.getWorkingOperation().getResponses() - .remove(org.eclipse.microprofile.openapi.models.responses.APIResponses.DEFAULT); + .removeAPIResponse(org.eclipse.microprofile.openapi.models.responses.APIResponses.DEFAULT); } } } @@ -732,7 +732,7 @@ public void visitParameter(Parameter parameter, AnnotatedElement element, ApiCon && parameter.in() != ParameterIn.DEFAULT) { // Remove all parameters of the wrong input type matchingMethodParameters - .removeIf(x -> ModelUtils.getParameterType(x) != In.valueOf(parameter.in().name())); + .removeIf(x -> ModelUtils.getParameterType(x) != In.valueOf(parameter.in().name())); } // If there's only one matching parameter, handle it immediately String matchingMethodParamName = ModelUtils.getParameterName(matchingMethodParameters.get(0)); @@ -760,7 +760,7 @@ public void visitParameter(Parameter parameter, AnnotatedElement element, ApiCon mediaType.setSchema(new SchemaImpl()); } mediaType.getSchema() - .setType(ModelUtils.mergeProperty(mediaType.getSchema().getType(), type, false)); + .setType(ModelUtils.mergeProperty(mediaType.getSchema().getType(), type, false)); } } } @@ -863,7 +863,7 @@ public void visitSecurityRequirements(SecurityRequirements securityRequirements, /** * Generates a map listing the location each resource class is mapped to. */ - private Map>> generateResourceMapping(Set> classList) { + private static Map>> generateResourceMapping(Set> classList) { Map>> resourceMapping = new HashMap<>(); for (Class clazz : classList) { if (clazz.isAnnotationPresent(ApplicationPath.class) && Application.class.isAssignableFrom(clazz)) { @@ -952,7 +952,7 @@ private org.eclipse.microprofile.openapi.models.responses.APIResponse insertDefa * @return the {@link javax.ws.rs.core.MediaType} with the given name. Defaults * to WILDCARD. */ - private String getContentType(String name) { + private static String getContentType(String name) { String contentType = javax.ws.rs.core.MediaType.WILDCARD; try { javax.ws.rs.core.MediaType mediaType = javax.ws.rs.core.MediaType.valueOf(name); @@ -1002,11 +1002,10 @@ private org.eclipse.microprofile.openapi.models.media.Schema createSchema(ApiCon schema.setType(null); schema.setItems(null); return schema; - } else { - return createSchema(context, type); - } + } + return createSchema(context, type); } - + /** * Replace the object in the referee with a reference, and create the reference * in the API. diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/BaseProcessor.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/BaseProcessor.java index d55ce514174..8c3ca5622f6 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/BaseProcessor.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/BaseProcessor.java @@ -46,9 +46,7 @@ import fish.payara.microprofile.openapi.impl.model.servers.ServerImpl; import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.normaliseUrl; import java.net.URL; -import java.util.Iterator; import java.util.List; -import java.util.Map; import java.util.Map.Entry; import java.util.Set; import org.eclipse.microprofile.openapi.models.OpenAPI; @@ -105,16 +103,16 @@ public OpenAPI process(OpenAPI api, OpenApiConfiguration config) { String path = normaliseUrl(entry.getKey()); // If the path doesn't exist, create it - if (!api.getPaths().containsKey(path)) { + if (!api.getPaths().hasPathItem(path)) { api.getPaths().addPathItem(path, new PathItemImpl()); } // Clear the current list of servers - api.getPaths().get(path).getServers().clear(); + api.getPaths().getPathItem(path).getServers().clear(); // Add each url for (String serverUrl : entry.getValue()) { - api.getPaths().get(path).addServer(new ServerImpl().url(serverUrl)); + api.getPaths().getPathItem(path).addServer(new ServerImpl().url(serverUrl)); } } } @@ -125,7 +123,7 @@ public OpenAPI process(OpenAPI api, OpenApiConfiguration config) { // Find the matching operation for (PathItem pathItem : api.getPaths().values()) { - for (Operation operation : pathItem.readOperations()) { + for (Operation operation : pathItem.getOperations().values()) { if (operation.getOperationId().equals(entry.getKey())) { // Clear the current list of servers @@ -141,19 +139,13 @@ public OpenAPI process(OpenAPI api, OpenApiConfiguration config) { } } - removeEmptyPaths(api, config); + removeEmptyPaths(api); return api; } - private OpenAPI removeEmptyPaths(OpenAPI api, OpenApiConfiguration config) { - Iterator> it = api.getPaths().entrySet().iterator(); - while (it.hasNext()) { - Map.Entry entry = it.next(); - if (new PathItemImpl().equals(entry.getValue())) { - it.remove(); - } - } - return api; + private static void removeEmptyPaths(OpenAPI api) { + PathItem emptyItem = new PathItemImpl(); + api.getPaths().entrySet().removeIf(entry -> emptyItem.equals(entry.getValue())); } } \ No newline at end of file diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/FilterProcessor.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/FilterProcessor.java index ec1b3360ba1..50cc7a506eb 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/FilterProcessor.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/FilterProcessor.java @@ -91,9 +91,8 @@ public OpenAPI process(OpenAPI api, OpenApiConfiguration config) { } if (filter != null) { return (OpenAPI) filterObject(api); - } else { - LOGGER.fine("No OASFilter provided."); } + LOGGER.fine("No OASFilter provided."); return api; } @@ -134,7 +133,7 @@ private Object filterObject(Object object) { } for (Object removeTarget : resultsToRemove) { - Iterator iterator = (Iterator) Iterable.class.cast(object).iterator(); + Iterator iterator = Iterable.class.cast(object).iterator(); while (iterator.hasNext()) { if (iterator.next().equals(removeTarget)) { iterator.remove(); diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/ModelReaderProcessor.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/ModelReaderProcessor.java index 722d13e7687..72e74cc89dd 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/ModelReaderProcessor.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/ModelReaderProcessor.java @@ -75,9 +75,8 @@ public OpenAPI process(OpenAPI api, OpenApiConfiguration config) { OpenAPI model = reader.buildModel(); if (model != null) { return model; - } else { - LOGGER.log(WARNING, "The OpenAPI model returned by " + reader.getClass().getName() + " was null!"); } + LOGGER.log(WARNING, "The OpenAPI model returned by " + reader.getClass().getName() + " was null!"); } else { LOGGER.fine("No OASModelReader provided."); } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/test/java/fish/payara/microprofile/openapi/resource/classloader/ApplicationClassLoader.java b/appserver/payara-appserver-modules/microprofile/openapi/src/test/java/fish/payara/microprofile/openapi/resource/classloader/ApplicationClassLoader.java index e21a5827064..81c7bc88fa5 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/test/java/fish/payara/microprofile/openapi/resource/classloader/ApplicationClassLoader.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/test/java/fish/payara/microprofile/openapi/resource/classloader/ApplicationClassLoader.java @@ -106,10 +106,10 @@ private byte[] loadClassData(String name) throws IOException { InputStream stream = getClass().getClassLoader().getResourceAsStream(name); int size = stream.available(); byte buff[] = new byte[size]; - DataInputStream in = new DataInputStream(stream); - // Reading the binary data - in.readFully(buff); - in.close(); + try (DataInputStream in = new DataInputStream(stream)) { + // Reading the binary data + in.readFully(buff); + } return buff; } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/test/java/fish/payara/microprofile/openapi/test/app/application/ResponseTest.java b/appserver/payara-appserver-modules/microprofile/openapi/src/test/java/fish/payara/microprofile/openapi/test/app/application/ResponseTest.java index f957b941d7c..550efd49ce0 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/test/java/fish/payara/microprofile/openapi/test/app/application/ResponseTest.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/test/java/fish/payara/microprofile/openapi/test/app/application/ResponseTest.java @@ -88,20 +88,20 @@ public String getInheritedMediaType() { @Test public void inheritedMediaTypeTest() { - APIResponses responses = document.getPaths().get("/test/response").getGET().getResponses(); + APIResponses responses = document.getPaths().getPathItem("/test/response").getGET().getResponses(); // Test the default response doesn't exist - assertNull("The default response should be removed when not used.", responses.getDefault()); + assertNull("The default response should be removed when not used.", responses.getDefaultValue()); // Test the 200 response - assertNotNull("The 200 response should have been created.", responses.get("200")); + assertNotNull("The 200 response should have been created.", responses.getAPIResponse("200")); assertNotNull("The 200 response should return application/json.", - responses.get("200").getContent().get(APPLICATION_JSON)); + responses.getAPIResponse("200").getContent().getMediaType(APPLICATION_JSON)); assertEquals("The 200 response application/json should match the specified schema.", "hello!", - responses.get("200").getContent().get(APPLICATION_JSON).getSchema().getDescription()); + responses.getAPIResponse("200").getContent().getMediaType(APPLICATION_JSON).getSchema().getDescription()); assertNotNull("The 200 response should return application/xml.", - responses.get("200").getContent().get(APPLICATION_XML)); + responses.getAPIResponse("200").getContent().getMediaType(APPLICATION_XML)); assertEquals("The 200 response application/xml should match the specified schema.", "hello!", - responses.get("200").getContent().get(APPLICATION_XML).getSchema().getDescription()); + responses.getAPIResponse("200").getContent().getMediaType(APPLICATION_XML).getSchema().getDescription()); } } \ No newline at end of file diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/test/java/fish/payara/microprofile/openapi/test/app/application/RootPathTest.java b/appserver/payara-appserver-modules/microprofile/openapi/src/test/java/fish/payara/microprofile/openapi/test/app/application/RootPathTest.java index 8e5676a1c29..0e4b48f0b68 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/test/java/fish/payara/microprofile/openapi/test/app/application/RootPathTest.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/test/java/fish/payara/microprofile/openapi/test/app/application/RootPathTest.java @@ -77,8 +77,8 @@ public String getRoot() { @Test public void testRoot() { - assertNotNull("The root resource wasn't found.", document.getPaths().get("/test")); + assertNotNull("The root resource wasn't found.", document.getPaths().getPathItem("/test")); assertEquals("The root resource had the wrong origin.", "getRoot", - document.getPaths().get("/test").getGET().getOperationId()); + document.getPaths().getPathItem("/test").getGET().getOperationId()); } } \ No newline at end of file diff --git a/appserver/pom.xml b/appserver/pom.xml index bed2fad11ed..8c4fbb2093e 100644 --- a/appserver/pom.xml +++ b/appserver/pom.xml @@ -206,7 +206,7 @@ 1.0.payara-p1 1.1.payara-p1 1.1-payara-p1 - 1.0 + 1.1.1 5.4 1.2.payara-p2 From 3229892506f4b7336219078c7741e40adc4d5282 Mon Sep 17 00:00:00 2001 From: Jan Bernitt Date: Mon, 11 Mar 2019 16:07:06 +0100 Subject: [PATCH 02/10] PAYARA-3466 new properties and fixes --- .../openapi/impl/model/ExtensibleImpl.java | 30 ++- ...kedHashMap.java => ExtensibleTreeMap.java} | 10 +- .../openapi/impl/model/PathItemImpl.java | 11 +- .../openapi/impl/model/PathsImpl.java | 4 +- .../impl/model/callbacks/CallbackImpl.java | 6 +- .../openapi/impl/model/media/ContentImpl.java | 3 + .../model/responses/APIResponsesImpl.java | 4 +- .../impl/model/security/ScopesImpl.java | 6 +- .../impl/model/servers/ServerImpl.java | 12 +- .../model/servers/ServerVariablesImpl.java | 4 +- .../impl/processor/ApplicationProcessor.java | 179 +++++++++--------- appserver/pom.xml | 2 +- 12 files changed, 153 insertions(+), 118 deletions(-) rename appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/{ExtensibleLinkedHashMap.java => ExtensibleTreeMap.java} (74%) diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java index 6c6db641ffa..9925f306cf9 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java @@ -42,13 +42,20 @@ import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.isAnnotationNull; import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.mergeProperty; +import java.io.IOException; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; +import javax.json.Json; + import org.eclipse.microprofile.openapi.annotations.extensions.Extension; import org.eclipse.microprofile.openapi.models.Extensible; +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.ObjectMapper; + public abstract class ExtensibleImpl> implements Extensible { protected Map extensions = new HashMap<>(); @@ -83,16 +90,33 @@ public static void merge(Extension from, Extensible to, boolean override) { to.setExtensions(new LinkedHashMap<>()); } if (from.name() != null && !from.name().isEmpty()) { - Object value = mergeProperty(to.getExtensions().get(from.name()), convertExtensionValue(from.value()), - override); + Object value = mergeProperty(to.getExtensions().get(from.name()), + convertExtensionValue(from.value(), from.parseValue()), override); to.getExtensions().put(from.name(), value); } } - public static Object convertExtensionValue(String value) { + public static Object convertExtensionValue(String value, boolean parseValue) { if (value == null) { return null; } + if (parseValue) { + if (value.startsWith("{") || value.startsWith("[")) { // JSON object + array + try { + return new ObjectMapper().readTree(value); + } catch (Exception e) { + return value; + } + } + if ("true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value)) { + return Boolean.valueOf(value); + } + // must be number + if (value.indexOf('.') >= 0) { + return Double.valueOf(value); + } + return Long.valueOf(value); + } // Could be an array if (value.contains(",")) { // Remove leading and trailing brackets, then parse to an array diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleLinkedHashMap.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleTreeMap.java similarity index 74% rename from appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleLinkedHashMap.java rename to appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleTreeMap.java index 477307e6d5d..fecd5fd6445 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleLinkedHashMap.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleTreeMap.java @@ -1,21 +1,21 @@ package fish.payara.microprofile.openapi.impl.model; import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.Map; +import java.util.TreeMap; import org.eclipse.microprofile.openapi.models.Extensible; -public abstract class ExtensibleLinkedHashMap> extends LinkedHashMap -implements Extensible { +public abstract class ExtensibleTreeMap> extends TreeMap + implements Extensible { protected Map extensions = new HashMap<>(); - protected ExtensibleLinkedHashMap() { + protected ExtensibleTreeMap() { super(); } - protected ExtensibleLinkedHashMap(Map items) { + protected ExtensibleTreeMap(Map items) { super(items); } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathItemImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathItemImpl.java index e06c2e7fb3a..41cf49d074e 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathItemImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathItemImpl.java @@ -178,16 +178,7 @@ public void setTRACE(Operation trace) { @Override public Map getOperations() { - EnumMap operations = new EnumMap<>(HttpMethod.class); - operations.put(HttpMethod.DELETE, delete); - operations.put(HttpMethod.GET, get); - operations.put(HttpMethod.HEAD, head); - operations.put(HttpMethod.OPTIONS, options); - operations.put(HttpMethod.PATCH, patch); - operations.put(HttpMethod.POST, post); - operations.put(HttpMethod.PUT, put); - operations.put(HttpMethod.TRACE, trace); - return operations; + return readOperationsMap(); } @Override diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathsImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathsImpl.java index e49c65435b7..0fb24e1bb78 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathsImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathsImpl.java @@ -46,7 +46,7 @@ import fish.payara.microprofile.openapi.impl.model.util.ModelUtils; -public class PathsImpl extends ExtensibleLinkedHashMap implements Paths { +public class PathsImpl extends ExtensibleTreeMap implements Paths { private static final long serialVersionUID = -3876996963579977405L; @@ -54,7 +54,7 @@ public PathsImpl() { super(); } - public PathsImpl(Map items) { + public PathsImpl(Map items) { super(items); } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/callbacks/CallbackImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/callbacks/CallbackImpl.java index 93bc3e8f437..d115314e180 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/callbacks/CallbackImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/callbacks/CallbackImpl.java @@ -53,11 +53,11 @@ import org.eclipse.microprofile.openapi.models.callbacks.Callback; import org.eclipse.microprofile.openapi.models.media.Schema; -import fish.payara.microprofile.openapi.impl.model.ExtensibleLinkedHashMap; +import fish.payara.microprofile.openapi.impl.model.ExtensibleTreeMap; import fish.payara.microprofile.openapi.impl.model.OperationImpl; import fish.payara.microprofile.openapi.impl.model.PathItemImpl; -public class CallbackImpl extends ExtensibleLinkedHashMap implements Callback { +public class CallbackImpl extends ExtensibleTreeMap implements Callback { private static final long serialVersionUID = 5549098533131353142L; @@ -67,7 +67,7 @@ public CallbackImpl() { super(); } - public CallbackImpl(Map items) { + public CallbackImpl(Map items) { super(items); } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/ContentImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/ContentImpl.java index 0ee319ee614..7e2540e1aae 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/ContentImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/ContentImpl.java @@ -111,6 +111,9 @@ public static void merge(org.eclipse.microprofile.openapi.annotations.media.Cont for (ExampleObject example : from.examples()) { ExampleImpl.merge(example, to.getMediaType(typeName).getExamples(), override); } + if (!from.example().isEmpty()) { + to.getMediaType(typeName).setExample(from.example()); + } // Merge schema if (!isAnnotationNull(from.schema())) { diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/responses/APIResponsesImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/responses/APIResponsesImpl.java index b2f800b3878..0a30fb4082f 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/responses/APIResponsesImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/responses/APIResponsesImpl.java @@ -48,9 +48,9 @@ import org.eclipse.microprofile.openapi.models.responses.APIResponse; import org.eclipse.microprofile.openapi.models.responses.APIResponses; -import fish.payara.microprofile.openapi.impl.model.ExtensibleLinkedHashMap; +import fish.payara.microprofile.openapi.impl.model.ExtensibleTreeMap; -public class APIResponsesImpl extends ExtensibleLinkedHashMap +public class APIResponsesImpl extends ExtensibleTreeMap implements APIResponses { private static final long serialVersionUID = 2811935761440110541L; diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/ScopesImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/ScopesImpl.java index 1ed1852075f..d0ff158c036 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/ScopesImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/ScopesImpl.java @@ -43,9 +43,9 @@ import org.eclipse.microprofile.openapi.models.security.Scopes; -import fish.payara.microprofile.openapi.impl.model.ExtensibleLinkedHashMap; +import fish.payara.microprofile.openapi.impl.model.ExtensibleTreeMap; -public class ScopesImpl extends ExtensibleLinkedHashMap implements Scopes { +public class ScopesImpl extends ExtensibleTreeMap implements Scopes { private static final long serialVersionUID = -615440059031779085L; @@ -53,7 +53,7 @@ public ScopesImpl() { super(); } - public ScopesImpl(Map scopes) { + public ScopesImpl(Map scopes) { super(scopes); } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerImpl.java index c32d9d2c264..14bdf340c38 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerImpl.java @@ -44,10 +44,16 @@ import java.util.Map; +import javax.json.bind.annotation.JsonbProperty; +import javax.xml.bind.annotation.XmlTransient; + import org.eclipse.microprofile.openapi.models.servers.Server; import org.eclipse.microprofile.openapi.models.servers.ServerVariable; import org.eclipse.microprofile.openapi.models.servers.ServerVariables; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + import fish.payara.microprofile.openapi.impl.model.ExtensibleImpl; public class ServerImpl extends ExtensibleImpl implements Server { @@ -78,14 +84,18 @@ public void setDescription(String description) { @Override public ServerVariables getVariables() { - return variables instanceof ServerVariables ? (ServerVariables) variables : new ServerVariablesImpl(variables); + return variables instanceof ServerVariables || variables == null + ? (ServerVariables) variables + : new ServerVariablesImpl(variables); } + @JsonIgnore @Override public void setVariables(ServerVariables variables) { this.variables = variables; } + @JsonProperty("variables") @Override public void setVariables(Map variables) { this.variables = variables; diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerVariablesImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerVariablesImpl.java index ee22abd091c..6e2b9d31a34 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerVariablesImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerVariablesImpl.java @@ -48,9 +48,9 @@ import org.eclipse.microprofile.openapi.models.servers.ServerVariable; import org.eclipse.microprofile.openapi.models.servers.ServerVariables; -import fish.payara.microprofile.openapi.impl.model.ExtensibleLinkedHashMap; +import fish.payara.microprofile.openapi.impl.model.ExtensibleTreeMap; -public class ServerVariablesImpl extends ExtensibleLinkedHashMap implements ServerVariables { +public class ServerVariablesImpl extends ExtensibleTreeMap implements ServerVariables { private static final long serialVersionUID = 8869393484826870024L; diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/ApplicationProcessor.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/ApplicationProcessor.java index 35d69500780..71234583e9f 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/ApplicationProcessor.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/ApplicationProcessor.java @@ -513,111 +513,118 @@ public void visitOpenAPI(OpenAPIDefinition definition, AnnotatedElement element, @Override public void visitSchema(Schema schema, AnnotatedElement element, ApiContext context) { if (element instanceof Class) { + visitSchemaClass(schema, (Class) element, context); + } + if (element instanceof Field) { + visitSchemaField(schema, (Field) element, context); + } + if (element instanceof java.lang.reflect.Parameter) { + visitSchemaParameter(schema, (java.lang.reflect.Parameter) element, context); + } + } - // Get the schema object name - String schemaName = (schema == null) ? null : schema.name(); - if (schemaName == null || schemaName.isEmpty()) { - schemaName = Class.class.cast(element).getSimpleName(); - } + private void visitSchemaClass(Schema schema, Class clazz, ApiContext context) { + // Get the schema object name + String schemaName = (schema == null) ? null : schema.name(); + if (schemaName == null || schemaName.isEmpty()) { + schemaName = clazz.getSimpleName(); + } - // Add a new schema - org.eclipse.microprofile.openapi.models.media.Schema newSchema = new SchemaImpl(); - context.getApi().getComponents().addSchema(schemaName, newSchema); + // Add a new schema + org.eclipse.microprofile.openapi.models.media.Schema newSchema = new SchemaImpl(); + context.getApi().getComponents().addSchema(schemaName, newSchema); - // If there is an annotation - if (schema != null) { - SchemaImpl.merge(schema, newSchema, true, context.getApi().getComponents().getSchemas()); - } else { - newSchema.setType(SchemaType.OBJECT); - Map fields = new LinkedHashMap<>(); - for (Field field : Class.class.cast(element).getDeclaredFields()) { - if (!Modifier.isTransient(field.getModifiers())) { - fields.put(field.getName(), createSchema(context, element, field.getType())); - } + // If there is an annotation + if (schema != null) { + SchemaImpl.merge(schema, newSchema, true, context.getApi().getComponents().getSchemas()); + } else { + newSchema.setType(SchemaType.OBJECT); + Map fields = new LinkedHashMap<>(); + for (Field field : clazz.getDeclaredFields()) { + if (!Modifier.isTransient(field.getModifiers())) { + fields.put(field.getName(), createSchema(context, clazz, field.getType())); } - newSchema.setProperties(fields); } + newSchema.setProperties(fields); + } - // If there is an extending class, add the data - if (Class.class.cast(element).getSuperclass() != null) { - Class superClass = Class.class.cast(element).getSuperclass(); - - // If the super class is legitimate - if (!superClass.equals(Object.class)) { + // If there is an extending class, add the data + if (clazz.getSuperclass() != null) { + Class superClass = clazz.getSuperclass(); - // Get the parent schema annotation - Schema parentSchema = superClass.getDeclaredAnnotation(Schema.class); + // If the super class is legitimate + if (!superClass.equals(Object.class)) { - // Create a schema for the parent - visitSchema(parentSchema, superClass, context); + // Get the parent schema annotation + Schema parentSchema = superClass.getDeclaredAnnotation(Schema.class); - // Get the superclass schema name - String parentSchemaName = (parentSchema == null) ? null : parentSchema.name(); - if (parentSchemaName == null || parentSchemaName.isEmpty()) { - parentSchemaName = Class.class.cast(superClass).getSimpleName(); - } + // Create a schema for the parent + visitSchema(parentSchema, superClass, context); - // Link the schemas - newSchema.addAllOf(new SchemaImpl().ref(parentSchemaName)); + // Get the superclass schema name + String parentSchemaName = (parentSchema == null) ? null : parentSchema.name(); + if (parentSchemaName == null || parentSchemaName.isEmpty()) { + parentSchemaName = superClass.getSimpleName(); } + + // Link the schemas + newSchema.addAllOf(new SchemaImpl().ref(parentSchemaName)); } } - if (element instanceof Field) { + } - // Get the schema object name - String schemaName = schema.name(); - if (schemaName == null || schemaName.isEmpty()) { - schemaName = Field.class.cast(element).getName(); - } + private void visitSchemaField(Schema schema, Field field, ApiContext context) { + // Get the schema object name + String schemaName = schema.name(); + if (schemaName == null || schemaName.isEmpty()) { + schemaName = field.getName(); + } - // Get the parent schema object name - String parentName = null; - if (Field.class.cast(element).getDeclaringClass().isAnnotationPresent(Schema.class)) { - parentName = Field.class.cast(element).getDeclaringClass().getDeclaredAnnotation(Schema.class).name(); - } - if (parentName == null || parentName.isEmpty()) { - parentName = Field.class.cast(element).getDeclaringClass().getSimpleName(); - } + // Get the parent schema object name + String parentName = null; + if (field.getDeclaringClass().isAnnotationPresent(Schema.class)) { + parentName = field.getDeclaringClass().getDeclaredAnnotation(Schema.class).name(); + } + if (parentName == null || parentName.isEmpty()) { + parentName = field.getDeclaringClass().getSimpleName(); + } - // Get or create the parent schema object - org.eclipse.microprofile.openapi.models.media.Schema parent = context.getApi().getComponents().getSchemas() - .getOrDefault(parentName, new SchemaImpl()); - context.getApi().getComponents().getSchemas().put(parentName, parent); + // Get or create the parent schema object + org.eclipse.microprofile.openapi.models.media.Schema parent = context.getApi().getComponents().getSchemas() + .getOrDefault(parentName, new SchemaImpl()); + context.getApi().getComponents().getSchemas().put(parentName, parent); - org.eclipse.microprofile.openapi.models.media.Schema property = new SchemaImpl(); - parent.addProperty(schemaName, property); - property.setType(ModelUtils.getSchemaType(Field.class.cast(element).getType())); - SchemaImpl.merge(schema, property, true, context.getApi().getComponents().getSchemas()); - } - if (element instanceof java.lang.reflect.Parameter) { + org.eclipse.microprofile.openapi.models.media.Schema property = new SchemaImpl(); + parent.addProperty(schemaName, property); + property.setType(ModelUtils.getSchemaType(field.getType())); + SchemaImpl.merge(schema, property, true, context.getApi().getComponents().getSchemas()); + } - // If this is being parsed at the start, ignore it as the path doesn't exist - if (context.getWorkingOperation() == null) { - return; + private void visitSchemaParameter(Schema schema, java.lang.reflect.Parameter parameter, ApiContext context) { + // If this is being parsed at the start, ignore it as the path doesn't exist + if (context.getWorkingOperation() == null) { + return; + } + // Check if it's a request body + if (ModelUtils.isRequestBody(parameter)) { + if (context.getWorkingOperation().getRequestBody() == null) { + context.getWorkingOperation().setRequestBody(new RequestBodyImpl()); } - - java.lang.reflect.Parameter parameter = (java.lang.reflect.Parameter) element; - // Check if it's a request body - if (ModelUtils.isRequestBody(parameter)) { - if (context.getWorkingOperation().getRequestBody() == null) { - context.getWorkingOperation().setRequestBody(new RequestBodyImpl()); - } - // Insert the schema to the request body media type - MediaType mediaType = context.getWorkingOperation().getRequestBody().getContent() - .getMediaType(javax.ws.rs.core.MediaType.WILDCARD); - SchemaImpl.merge(schema, mediaType.getSchema(), true, context.getApi().getComponents().getSchemas()); - if (schema.ref() != null && !schema.ref().isEmpty()) { - mediaType.setSchema(new SchemaImpl().ref(schema.ref())); - } - } else if (ModelUtils.getParameterType(parameter) != null) { - for (org.eclipse.microprofile.openapi.models.parameters.Parameter param : context.getWorkingOperation() - .getParameters()) { - if (param.getName().equals(ModelUtils.getParameterName(parameter))) { - SchemaImpl.merge(schema, param.getSchema(), true, - context.getApi().getComponents().getSchemas()); - if (schema.ref() != null && !schema.ref().isEmpty()) { - param.setSchema(new SchemaImpl().ref(schema.ref())); - } + // Insert the schema to the request body media type + MediaType mediaType = context.getWorkingOperation().getRequestBody().getContent() + .getMediaType(javax.ws.rs.core.MediaType.WILDCARD); + SchemaImpl.merge(schema, mediaType.getSchema(), true, context.getApi().getComponents().getSchemas()); + if (schema.ref() != null && !schema.ref().isEmpty()) { + mediaType.setSchema(new SchemaImpl().ref(schema.ref())); + } + } else if (ModelUtils.getParameterType(parameter) != null) { + for (org.eclipse.microprofile.openapi.models.parameters.Parameter param : context.getWorkingOperation() + .getParameters()) { + if (param.getName().equals(ModelUtils.getParameterName(parameter))) { + SchemaImpl.merge(schema, param.getSchema(), true, + context.getApi().getComponents().getSchemas()); + if (schema.ref() != null && !schema.ref().isEmpty()) { + param.setSchema(new SchemaImpl().ref(schema.ref())); } } } diff --git a/appserver/pom.xml b/appserver/pom.xml index 8c4fbb2093e..a9154e1291f 100644 --- a/appserver/pom.xml +++ b/appserver/pom.xml @@ -206,7 +206,7 @@ 1.0.payara-p1 1.1.payara-p1 1.1-payara-p1 - 1.1.1 + 1.1.2 5.4 1.2.payara-p2 From 1ecd722845f46ad4f6d5ef4ed9dceaf1005eca96 Mon Sep 17 00:00:00 2001 From: Jan Bernitt Date: Tue, 12 Mar 2019 15:33:15 +0100 Subject: [PATCH 03/10] PAYARA-3466 Fixed: Parameters and Extensions annotation processing, extension to JSON --- .../openapi/api/visitor/ApiVisitor.java | 6 + .../openapi/impl/model/ComponentsImpl.java | 36 ++++-- .../openapi/impl/model/ExtensibleImpl.java | 14 +-- .../openapi/impl/model/ExtensibleTreeMap.java | 11 +- .../openapi/impl/model/OperationImpl.java | 8 +- .../openapi/impl/model/PathItemImpl.java | 8 +- .../openapi/impl/model/PathsImpl.java | 4 +- .../impl/model/callbacks/CallbackImpl.java | 4 +- .../impl/model/headers/HeaderImpl.java | 4 +- .../openapi/impl/model/links/LinkImpl.java | 4 +- .../openapi/impl/model/media/ContentImpl.java | 4 +- .../impl/model/media/DiscriminatorImpl.java | 4 +- .../impl/model/media/EncodingImpl.java | 4 +- .../impl/model/media/MediaTypeImpl.java | 8 +- .../openapi/impl/model/media/SchemaImpl.java | 12 +- .../impl/model/parameters/ParameterImpl.java | 4 +- .../impl/model/responses/APIResponseImpl.java | 8 +- .../model/responses/APIResponsesImpl.java | 6 +- .../impl/model/security/ScopesImpl.java | 2 +- .../security/SecurityRequirementImpl.java | 4 +- .../impl/model/servers/ServerImpl.java | 3 - .../model/servers/ServerVariableImpl.java | 2 +- .../model/servers/ServerVariablesImpl.java | 4 +- .../openapi/impl/model/util/ModelUtils.java | 6 - .../impl/processor/ApplicationProcessor.java | 114 ++++++++++++------ .../openapi/impl/visitor/OpenApiWalker.java | 4 + 26 files changed, 195 insertions(+), 93 deletions(-) diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/api/visitor/ApiVisitor.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/api/visitor/ApiVisitor.java index 9b68002576e..f98e749eaf7 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/api/visitor/ApiVisitor.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/api/visitor/ApiVisitor.java @@ -64,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; @@ -126,6 +128,8 @@ interface VisitorFunction { 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); @@ -140,6 +144,8 @@ interface VisitorFunction { 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); diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ComponentsImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ComponentsImpl.java index 51613fdd642..ec507ba02ce 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ComponentsImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ComponentsImpl.java @@ -88,7 +88,9 @@ public void setSchemas(Map schemas) { @Override public Components addSchema(String key, Schema schema) { - schemas.put(key, schema); + if (schema != null) { + schemas.put(key, schema); + } return this; } @@ -109,7 +111,9 @@ public void setResponses(Map responses) { @Override public Components addResponse(String key, APIResponse response) { - responses.put(key, response); + if (response != null) { + responses.put(key, response); + } return this; } @@ -130,7 +134,9 @@ public void setParameters(Map parameters) { @Override public Components addParameter(String key, Parameter parameter) { - parameters.put(key, parameter); + if (parameter != null) { + parameters.put(key, parameter); + } return this; } @@ -151,7 +157,9 @@ public void setExamples(Map examples) { @Override public Components addExample(String key, Example example) { - examples.put(key, example); + if (example != null) { + examples.put(key, example); + } return this; } @@ -172,7 +180,9 @@ public void setRequestBodies(Map requestBodies) { @Override public Components addRequestBody(String key, RequestBody requestBody) { - requestBodies.put(key, requestBody); + if (requestBody != null) { + requestBodies.put(key, requestBody); + } return this; } @@ -193,7 +203,9 @@ public void setHeaders(Map headers) { @Override public Components addHeader(String key, Header header) { - headers.put(key, header); + if (header != null) { + headers.put(key, header); + } return this; } @@ -214,7 +226,9 @@ public void setSecuritySchemes(Map securitySchemes) { @Override public Components addSecurityScheme(String key, SecurityScheme securityScheme) { - securitySchemes.put(key, securityScheme); + if (securityScheme != null) { + securitySchemes.put(key, securityScheme); + } return this; } @@ -235,7 +249,9 @@ public void setLinks(Map links) { @Override public Components addLink(String key, Link link) { - links.put(key, link); + if (link != null) { + links.put(key, link); + } return this; } @@ -256,7 +272,9 @@ public void setCallbacks(Map callbacks) { @Override public Components addCallback(String key, Callback callback) { - callbacks.put(key, callback); + if (callback != null) { + callbacks.put(key, callback); + } return this; } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java index 9925f306cf9..1a232aef78a 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java @@ -42,24 +42,20 @@ import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.isAnnotationNull; import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.mergeProperty; -import java.io.IOException; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; -import javax.json.Json; - import org.eclipse.microprofile.openapi.annotations.extensions.Extension; import org.eclipse.microprofile.openapi.models.Extensible; -import com.fasterxml.jackson.core.JsonFactory; -import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.databind.ObjectMapper; public abstract class ExtensibleImpl> implements Extensible { - protected Map extensions = new HashMap<>(); + protected Map extensions = new LinkedHashMap<>(); + @JsonAnyGetter @Override public Map getExtensions() { return extensions; @@ -68,7 +64,9 @@ public Map getExtensions() { @SuppressWarnings("unchecked") @Override public T addExtension(String name, Object value) { - extensions.put(name, value); + if (value != null) { + extensions.put(name, value); + } return (T) this; } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleTreeMap.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleTreeMap.java index fecd5fd6445..67c8f1318c4 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleTreeMap.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleTreeMap.java @@ -1,15 +1,17 @@ package fish.payara.microprofile.openapi.impl.model; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import java.util.TreeMap; import org.eclipse.microprofile.openapi.models.Extensible; +import com.fasterxml.jackson.annotation.JsonAnyGetter; + public abstract class ExtensibleTreeMap> extends TreeMap implements Extensible { - protected Map extensions = new HashMap<>(); + protected Map extensions = new LinkedHashMap<>(); protected ExtensibleTreeMap() { super(); @@ -19,6 +21,7 @@ protected ExtensibleTreeMap(Map items) { super(items); } + @JsonAnyGetter @Override public final Map getExtensions() { return extensions; @@ -32,7 +35,9 @@ public final void setExtensions(Map extensions) { @SuppressWarnings("unchecked") @Override public final T addExtension(String name, Object value) { - this.extensions.put(name, value); + if (value != null) { + this.extensions.put(name, value); + } return (T) this; } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/OperationImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/OperationImpl.java index 10d1940ac2c..82d44469dfa 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/OperationImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/OperationImpl.java @@ -152,7 +152,9 @@ public void setParameters(List parameters) { @Override public Operation addParameter(Parameter parameter) { - parameters.add(parameter); + if (parameter != null) { + parameters.add(parameter); + } return this; } @@ -193,7 +195,9 @@ public void setCallbacks(Map callbacks) { @Override public Operation addCallback(String key, Callback callback) { - this.callbacks.put(key, callback); + if (callback != null) { + this.callbacks.put(key, callback); + } return this; } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathItemImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathItemImpl.java index 41cf49d074e..48dcdc3e19d 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathItemImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathItemImpl.java @@ -256,7 +256,9 @@ public void setServers(List servers) { @Override public PathItem addServer(Server server) { - servers.add(server); + if (server != null) { + servers.add(server); + } return this; } @@ -277,7 +279,9 @@ public void setParameters(List parameters) { @Override public PathItem addParameter(Parameter parameter) { - parameters.add(parameter); + if (parameter != null) { + parameters.add(parameter); + } return this; } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathsImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathsImpl.java index 0fb24e1bb78..25b9610d0b3 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathsImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathsImpl.java @@ -60,7 +60,9 @@ public PathsImpl(Map items) { @Override public Paths addPathItem(String name, PathItem item) { - put(name, item); + if (item != null) { + put(name, item); + } return this; } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/callbacks/CallbackImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/callbacks/CallbackImpl.java index d115314e180..dad382c3898 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/callbacks/CallbackImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/callbacks/CallbackImpl.java @@ -73,7 +73,9 @@ public CallbackImpl(Map items) { @Override public Callback addPathItem(String name, PathItem item) { - this.put(name, item); + if (item != null) { + this.put(name, item); + } return this; } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/headers/HeaderImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/headers/HeaderImpl.java index 61aff64a342..994291f1e22 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/headers/HeaderImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/headers/HeaderImpl.java @@ -164,7 +164,9 @@ public void setExamples(Map examples) { @Override public Header addExample(String key, Example examplesItem) { - this.examples.put(key, examplesItem); + if (examplesItem != null) { + this.examples.put(key, examplesItem); + } return this; } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/links/LinkImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/links/LinkImpl.java index 027d385304d..45dde646c0a 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/links/LinkImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/links/LinkImpl.java @@ -115,7 +115,9 @@ public void setParameters(Map parameters) { @Override public Link addParameter(String name, Object parameter) { - this.parameters.put(name, parameter); + if (parameter != null) { + this.parameters.put(name, parameter); + } return this; } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/ContentImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/ContentImpl.java index 7e2540e1aae..5b3101afe0c 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/ContentImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/ContentImpl.java @@ -66,7 +66,9 @@ public ContentImpl(Map items) { @Override public Content addMediaType(String name, MediaType item) { - this.put(name, item); + if (item != null) { + this.put(name, item); + } return this; } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/DiscriminatorImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/DiscriminatorImpl.java index 7d7754bf973..614a0989d3b 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/DiscriminatorImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/DiscriminatorImpl.java @@ -71,7 +71,9 @@ public void setMapping(Map mapping) { @Override public Discriminator addMapping(String name, String value) { - mapping.put(name, value); + if (value != null) { + mapping.put(name, value); + } return this; } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/EncodingImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/EncodingImpl.java index 94d1b82abf6..4a146052f91 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/EncodingImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/EncodingImpl.java @@ -82,7 +82,9 @@ public void setHeaders(Map headers) { @Override public Encoding addHeader(String key, Header header) { - headers.put(key, header); + if (header != null) { + headers.put(key, header); + } return this; } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/MediaTypeImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/MediaTypeImpl.java index febfa6ed3d5..2a980c9b8d5 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/MediaTypeImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/MediaTypeImpl.java @@ -78,7 +78,9 @@ public void setExamples(Map examples) { @Override public MediaType addExample(String key, Example example) { - this.examples.put(key, example); + if (example != null) { + this.examples.put(key, example); + } return this; } @@ -109,7 +111,9 @@ public void setEncoding(Map encoding) { @Override public MediaType addEncoding(String key, Encoding encodingItem) { - this.encoding.put(key, encodingItem); + if (encodingItem != null) { + this.encoding.put(key, encodingItem); + } return this; } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/SchemaImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/SchemaImpl.java index c13a71a8267..9f2f20aba81 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/SchemaImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/media/SchemaImpl.java @@ -148,7 +148,9 @@ public void setEnumeration(List enumeration) { @Override public Schema addEnumeration(Object enumerationItem) { - this.enumeration.add(enumerationItem); + if (enumerationItem != null) { + this.enumeration.add(enumerationItem); + } return this; } @@ -341,7 +343,9 @@ public void setProperties(Map properties) { @Override public Schema addProperty(String key, Schema propertiesItem) { - this.properties.put(key, propertiesItem); + if (propertiesItem != null) { + this.properties.put(key, propertiesItem); + } return this; } @@ -362,12 +366,12 @@ public void setAdditionalProperties(Schema additionalProperties) { @Override public Schema getAdditionalPropertiesSchema() { - return (Schema) additionalProperties; + return additionalProperties instanceof Schema ? (Schema) additionalProperties : null; } @Override public Boolean getAdditionalPropertiesBoolean() { - return (Boolean) additionalProperties; + return additionalProperties instanceof Boolean ? (Boolean)additionalProperties : null; } @Override diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/parameters/ParameterImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/parameters/ParameterImpl.java index 070d44b218a..7b36cfadbdb 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/parameters/ParameterImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/parameters/ParameterImpl.java @@ -190,7 +190,9 @@ public void setExamples(Map examples) { @Override public Parameter addExample(String key, Example example) { - this.examples.put(key, example); + if (example != null) { + this.examples.put(key, example); + } return this; } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/responses/APIResponseImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/responses/APIResponseImpl.java index 498247f378e..0ede06cf529 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/responses/APIResponseImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/responses/APIResponseImpl.java @@ -87,7 +87,9 @@ public void setHeaders(Map headers) { @Override public APIResponse addHeader(String name, Header header) { - headers.put(name, header); + if (header != null) { + headers.put(name, header); + } return this; } @@ -118,7 +120,9 @@ public void setLinks(Map links) { @Override public APIResponse addLink(String name, Link link) { - links.put(name, link); + if (link != null) { + links.put(name, link); + } return this; } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/responses/APIResponsesImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/responses/APIResponsesImpl.java index 0a30fb4082f..99fd4de5066 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/responses/APIResponsesImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/responses/APIResponsesImpl.java @@ -67,7 +67,9 @@ public APIResponsesImpl(Map responses) { @Override public APIResponses addAPIResponse(String name, APIResponse apiResponse) { - put(name, apiResponse); + if (apiResponse != null) { + put(name, apiResponse); + } return this; } @@ -94,7 +96,7 @@ public APIResponse getDefaultValue() { @Override public void setDefaultValue(APIResponse defaultValue) { - addAPIResponse(DEFAULT, defaultValue); + put(DEFAULT, defaultValue); // this is not the same as addAPIResponse as null is set but not added } public static void merge(org.eclipse.microprofile.openapi.annotations.responses.APIResponse from, APIResponses to, diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/ScopesImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/ScopesImpl.java index d0ff158c036..5718f9903eb 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/ScopesImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/ScopesImpl.java @@ -59,7 +59,7 @@ public ScopesImpl(Map scopes) { @Override public Scopes addScope(String name, String item) { - this.put(name, item); + this.put(name, item); // this DOES accept null! return this; } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/SecurityRequirementImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/SecurityRequirementImpl.java index 381e2b1789a..6afff0c8785 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/SecurityRequirementImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/security/SecurityRequirementImpl.java @@ -63,13 +63,13 @@ public SecurityRequirementImpl(Map> ite @Override public SecurityRequirement addScheme(String name, String item) { - this.put(name, Arrays.asList(item)); + this.put(name, item == null ? new ArrayList<>() : Arrays.asList(item)); return this; } @Override public SecurityRequirement addScheme(String name, List item) { - this.put(name, item); + this.put(name, item == null ? new ArrayList<>() : item); return this; } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerImpl.java index 14bdf340c38..566764f8c8a 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerImpl.java @@ -44,9 +44,6 @@ import java.util.Map; -import javax.json.bind.annotation.JsonbProperty; -import javax.xml.bind.annotation.XmlTransient; - import org.eclipse.microprofile.openapi.models.servers.Server; import org.eclipse.microprofile.openapi.models.servers.ServerVariable; import org.eclipse.microprofile.openapi.models.servers.ServerVariables; diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerVariableImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerVariableImpl.java index b180b25f34f..20f4c61c702 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerVariableImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerVariableImpl.java @@ -85,7 +85,7 @@ public void setEnumeration(List enumeration) { @Override public ServerVariable addEnumeration(String enumeration) { - if (!this.enumeration.contains(enumeration)) { + if (enumeration != null && !this.enumeration.contains(enumeration)) { this.enumeration.add(enumeration); } return this; diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerVariablesImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerVariablesImpl.java index 6e2b9d31a34..fd03abb645a 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerVariablesImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerVariablesImpl.java @@ -64,7 +64,9 @@ public ServerVariablesImpl(Map variables) { @Override public ServerVariables addServerVariable(String name, ServerVariable item) { - this.put(name, item); + if (item != null) { + this.put(name, item); + } return this; } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/util/ModelUtils.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/util/ModelUtils.java index a0202bc73df..1f58455efc8 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/util/ModelUtils.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/util/ModelUtils.java @@ -313,12 +313,6 @@ public static SchemaType getParentSchemaType(SchemaType type1, SchemaType type2) if (type2 == null) { return type1; } - if (type1 == SchemaType.OBJECT || type2 == SchemaType.OBJECT) { - return SchemaType.OBJECT; - } - if (type1 == SchemaType.STRING || type2 == SchemaType.STRING) { - return SchemaType.STRING; - } if (type1 != type2) { return SchemaType.STRING; } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/ApplicationProcessor.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/ApplicationProcessor.java index 71234583e9f..9f908c1433e 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/ApplicationProcessor.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/ApplicationProcessor.java @@ -81,8 +81,10 @@ import org.eclipse.microprofile.openapi.annotations.callbacks.Callbacks; import org.eclipse.microprofile.openapi.annotations.enums.ParameterIn; 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; @@ -106,6 +108,7 @@ import fish.payara.microprofile.openapi.api.visitor.ApiVisitor; import fish.payara.microprofile.openapi.api.visitor.ApiWalker; import fish.payara.microprofile.openapi.impl.config.OpenApiConfiguration; +import fish.payara.microprofile.openapi.impl.model.ExtensibleImpl; import fish.payara.microprofile.openapi.impl.model.ExternalDocumentationImpl; import fish.payara.microprofile.openapi.impl.model.OpenAPIImpl; import fish.payara.microprofile.openapi.impl.model.OperationImpl; @@ -633,16 +636,26 @@ private void visitSchemaParameter(Schema schema, java.lang.reflect.Parameter par @Override public void visitExtension(Extension extension, AnnotatedElement element, ApiContext context) { - if (extension.name() != null && !extension.name().isEmpty() && extension.value() != null - && !extension.value().isEmpty()) { + String value = extension.value(); + String name = extension.name(); + if (name != null && !name.isEmpty() && value != null + && !value.isEmpty()) { + Object parsedValue = ExtensibleImpl.convertExtensionValue(value, extension.parseValue()); if (element instanceof Method) { - context.getWorkingOperation().addExtension(extension.name(), extension.value()); + context.getWorkingOperation().addExtension(name, parsedValue); } else { - context.getApi().addExtension(extension.name(), extension.value()); + context.getApi().addExtension(name, parsedValue); } } } + @Override + public void visitExtensions(Extensions extensions, AnnotatedElement element, ApiContext context) { + for (Extension extension : extensions.value()) { + visitExtension(extension, element, context); + } + } + @Override public void visitOperation(Operation operation, AnnotatedElement element, ApiContext context) { OperationImpl.merge(operation, context.getWorkingOperation(), true); @@ -712,47 +725,23 @@ public void visitAPIResponses(APIResponses apiResponses, AnnotatedElement elemen } } + @Override + public void visitParameters(Parameters parameters, AnnotatedElement element, ApiContext context) { + for (Parameter parameter : parameters.value()) { + visitParameter(parameter, element, context); + } + } + @Override public void visitParameter(Parameter parameter, AnnotatedElement element, ApiContext context) { org.eclipse.microprofile.openapi.models.parameters.Parameter matchedParam = null; if (element instanceof java.lang.reflect.Parameter) { - // Find the matching parameter, and match it - for (org.eclipse.microprofile.openapi.models.parameters.Parameter param : context.getWorkingOperation() - .getParameters()) { - if (param.getName() != null - && param.getName().equals(ModelUtils.getParameterName((java.lang.reflect.Parameter) element))) { - matchedParam = param; - } - } + matchedParam = findOperationParameterFor((java.lang.reflect.Parameter) element, context); } if (element instanceof Method) { - // If the parameter reference is valid - if (parameter.name() != null && !parameter.name().isEmpty()) { - // Get all parameters with the same name - List matchingMethodParameters = Arrays - .asList(Method.class.cast(element).getParameters()).stream() - .filter(x -> ModelUtils.getParameterName(x).equals(parameter.name())) - .collect(Collectors.toList()); - // If there is more than one match, filter it further - if (matchingMethodParameters.size() > 1 && parameter.in() != null - && parameter.in() != ParameterIn.DEFAULT) { - // Remove all parameters of the wrong input type - matchingMethodParameters - .removeIf(x -> ModelUtils.getParameterType(x) != In.valueOf(parameter.in().name())); - } - // If there's only one matching parameter, handle it immediately - String matchingMethodParamName = ModelUtils.getParameterName(matchingMethodParameters.get(0)); - // Find the matching operation parameter - for (org.eclipse.microprofile.openapi.models.parameters.Parameter operationParam : context - .getWorkingOperation().getParameters()) { - if (operationParam.getName().equals(matchingMethodParamName)) { - matchedParam = operationParam; - } - } - } + matchedParam = findOperationParameterFor(parameter, (Method) element, context); } - if (matchedParam != null) { ParameterImpl.merge(parameter, matchedParam, true, context.getApi().getComponents().getSchemas()); @@ -773,6 +762,57 @@ public void visitParameter(Parameter parameter, AnnotatedElement element, ApiCon } } + private static org.eclipse.microprofile.openapi.models.parameters.Parameter findOperationParameterFor(Parameter parameter, + Method annotated, ApiContext context) { + String name = parameter.name(); + // If the parameter reference is valid + if (name != null && !name.isEmpty()) { + // Get all parameters with the same name + List matchingMethodParameters = Arrays + .asList(annotated.getParameters()).stream() + .filter(x -> name.equals(ModelUtils.getParameterName(x))) + .collect(Collectors.toList()); + // If there is more than one match, filter it further + ParameterIn in = parameter.in(); + if (matchingMethodParameters.size() > 1 && in != null && in != ParameterIn.DEFAULT) { + // Remove all parameters of the wrong input type + matchingMethodParameters + .removeIf(x -> ModelUtils.getParameterType(x) != In.valueOf(in.name())); + } + if (matchingMethodParameters.isEmpty()) { + return null; + } + // If there's only one matching parameter, handle it immediately + String matchingMethodParamName = ModelUtils.getParameterName(matchingMethodParameters.get(0)); + // Find the matching operation parameter + for (org.eclipse.microprofile.openapi.models.parameters.Parameter operationParam : context + .getWorkingOperation().getParameters()) { + if (operationParam.getName().equals(matchingMethodParamName)) { + return operationParam; + } + } + } + return null; + } + + /** + * Find the matching parameter, and match it + */ + private static org.eclipse.microprofile.openapi.models.parameters.Parameter findOperationParameterFor( + java.lang.reflect.Parameter annotated, ApiContext context) { + String actualName = ModelUtils.getParameterName(annotated); + if (actualName == null) { + return null; + } + for (org.eclipse.microprofile.openapi.models.parameters.Parameter param : context.getWorkingOperation() + .getParameters()) { + if (actualName.equals(param.getName())) { + return param; + } + } + return null; + } + @Override public void visitExternalDocumentation(ExternalDocumentation externalDocs, AnnotatedElement element, ApiContext context) { diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/visitor/OpenApiWalker.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/visitor/OpenApiWalker.java index 79502e7a6e0..73be00453c1 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/visitor/OpenApiWalker.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/visitor/OpenApiWalker.java @@ -74,8 +74,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; @@ -153,11 +155,13 @@ public void accept(ApiVisitor visitor) { // All other OpenAPI annotations processAnnotations(Schema.class, visitor::visitSchema, true); processAnnotations(Server.class, visitor::visitServer, Servers.class, visitor::visitServers, true); + processAnnotations(Extensions.class, visitor::visitExtensions, true); processAnnotations(Extension.class, visitor::visitExtension, true); processAnnotations(Operation.class, visitor::visitOperation); processAnnotations(Callback.class, visitor::visitCallback, Callbacks.class, visitor::visitCallbacks); processAnnotations(APIResponse.class, visitor::visitAPIResponse, APIResponses.class, visitor::visitAPIResponses, true); + processAnnotations(Parameters.class, visitor::visitParameters, true); processAnnotations(Parameter.class, visitor::visitParameter, true); processAnnotations(ExternalDocumentation.class, visitor::visitExternalDocumentation, true); processAnnotations(Tag.class, visitor::visitTag, Tags.class, visitor::visitTags, true); From d85abf821297f5f74f8fbb9f6bd378215d314bfa Mon Sep 17 00:00:00 2001 From: Jan Bernitt Date: Tue, 12 Mar 2019 16:49:52 +0100 Subject: [PATCH 04/10] PAYARA-3466 fixed JSON serialisation issues --- .../openapi/impl/model/ExtensibleImpl.java | 32 +++++++++++++++++++ .../openapi/impl/model/PathItemImpl.java | 3 ++ 2 files changed, 35 insertions(+) diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java index 1a232aef78a..97556cb34ba 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java @@ -42,6 +42,8 @@ import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.isAnnotationNull; import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.mergeProperty; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; import java.util.LinkedHashMap; import java.util.Map; @@ -127,4 +129,34 @@ public static Object convertExtensionValue(String value, boolean parseValue) { return value; } + @Override + public String toString() { + StringBuilder str = new StringBuilder(); + toString(str, "\t"); + return str.toString(); + } + + void toString(StringBuilder str, String indent) { + str.append(getClass().getSimpleName()); + Class type = getClass(); + while (type != Object.class) { + for (Field field : type.getDeclaredFields()) { + if (!Modifier.isStatic(field.getModifiers()) && !field.isSynthetic()) { + str.append("\n").append(indent).append(field.getName()).append(": "); + try { + field.setAccessible(true); + Object value = field.get(this); + if (value instanceof ExtensibleImpl) { + ((ExtensibleImpl)value).toString(str, indent + "\t"); + } else { + str.append(value); + } + } catch (IllegalArgumentException | IllegalAccessException e) { + str.append(""); + } + } + } + type = type.getSuperclass(); + } + } } \ No newline at end of file diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathItemImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathItemImpl.java index 48dcdc3e19d..a3fa982fe03 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathItemImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathItemImpl.java @@ -50,6 +50,8 @@ import org.eclipse.microprofile.openapi.models.parameters.Parameter; import org.eclipse.microprofile.openapi.models.servers.Server; +import com.fasterxml.jackson.annotation.JsonIgnore; + public class PathItemImpl extends ExtensibleImpl implements PathItem { protected String ref; @@ -176,6 +178,7 @@ public void setTRACE(Operation trace) { this.trace = trace; } + @JsonIgnore @Override public Map getOperations() { return readOperationsMap(); From 5a44ff2526a767b48d68b340a547050b8bef81fe Mon Sep 17 00:00:00 2001 From: Jan Bernitt Date: Wed, 13 Mar 2019 11:31:31 +0100 Subject: [PATCH 05/10] PAYARA-3466 fixed extension JSON parsing --- .../openapi/impl/model/ExtensibleImpl.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java index 97556cb34ba..e655d759b7b 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java @@ -46,15 +46,19 @@ import java.lang.reflect.Modifier; import java.util.LinkedHashMap; import java.util.Map; +import java.util.logging.Logger; import org.eclipse.microprofile.openapi.annotations.extensions.Extension; import org.eclipse.microprofile.openapi.models.Extensible; import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; public abstract class ExtensibleImpl> implements Extensible { + private static final Logger LOGGER = Logger.getLogger(ExtensibleImpl.class.getName()); + protected Map extensions = new LinkedHashMap<>(); @JsonAnyGetter @@ -101,21 +105,19 @@ public static Object convertExtensionValue(String value, boolean parseValue) { return null; } if (parseValue) { - if (value.startsWith("{") || value.startsWith("[")) { // JSON object + array - try { - return new ObjectMapper().readTree(value); - } catch (Exception e) { - return value; + try { + JsonNode node = new ObjectMapper().readTree(value); + if (node.isBoolean()) { + return node.booleanValue(); } + if (node.isNumber()) { + return node.numberValue(); + } + return node; + } catch (Exception e) { + LOGGER.warning("Failed to parse extension value: " + value); + return value; } - if ("true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value)) { - return Boolean.valueOf(value); - } - // must be number - if (value.indexOf('.') >= 0) { - return Double.valueOf(value); - } - return Long.valueOf(value); } // Could be an array if (value.contains(",")) { From 15a5fe2fd1c338112c2d0a9cc1c6281056eca77f Mon Sep 17 00:00:00 2001 From: Jan Bernitt Date: Wed, 13 Mar 2019 15:11:10 +0100 Subject: [PATCH 06/10] PAYARA-3466 addressed formatting issue --- .../openapi/impl/processor/ApplicationProcessor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/ApplicationProcessor.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/ApplicationProcessor.java index 9f908c1433e..7d81b251f8c 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/ApplicationProcessor.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/processor/ApplicationProcessor.java @@ -407,8 +407,8 @@ public void visitFormParam(FormParam param, AnnotatedElement element, ApiContext // Set the request body type accordingly. context.getWorkingOperation().getRequestBody().getContent() - .getMediaType(javax.ws.rs.core.MediaType.WILDCARD).getSchema() - .setType(formSchemaType); + .getMediaType(javax.ws.rs.core.MediaType.WILDCARD).getSchema() + .setType(formSchemaType); } } From d0bbc63922d06d606d80eeef7872b886be463f2e Mon Sep 17 00:00:00 2001 From: Jan Bernitt Date: Wed, 13 Mar 2019 15:39:26 +0100 Subject: [PATCH 07/10] PAYARA-3466 reverted logic in getParentSchemaType --- .../microprofile/openapi/impl/model/util/ModelUtils.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/util/ModelUtils.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/util/ModelUtils.java index 1f58455efc8..a0202bc73df 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/util/ModelUtils.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/util/ModelUtils.java @@ -313,6 +313,12 @@ public static SchemaType getParentSchemaType(SchemaType type1, SchemaType type2) if (type2 == null) { return type1; } + if (type1 == SchemaType.OBJECT || type2 == SchemaType.OBJECT) { + return SchemaType.OBJECT; + } + if (type1 == SchemaType.STRING || type2 == SchemaType.STRING) { + return SchemaType.STRING; + } if (type1 != type2) { return SchemaType.STRING; } From 95fe53460293c3c1d63abd92cd569b1897efb9b8 Mon Sep 17 00:00:00 2001 From: Jan Bernitt Date: Fri, 15 Mar 2019 09:49:53 +0100 Subject: [PATCH 08/10] PAYARA-3466 moved all JSON output tweaks to mixin interface --- .../openapi/impl/model/ExtensibleImpl.java | 4 +-- .../openapi/impl/model/ExtensibleTreeMap.java | 3 -- .../openapi/impl/model/PathItemImpl.java | 3 -- .../impl/model/servers/ServerImpl.java | 5 ---- .../app/provider/mixin/ExtensionsMixin.java | 30 +++++++++++++++---- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java index e655d759b7b..c549ef80659 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java @@ -51,17 +51,15 @@ import org.eclipse.microprofile.openapi.annotations.extensions.Extension; import org.eclipse.microprofile.openapi.models.Extensible; -import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; public abstract class ExtensibleImpl> implements Extensible { private static final Logger LOGGER = Logger.getLogger(ExtensibleImpl.class.getName()); - + protected Map extensions = new LinkedHashMap<>(); - @JsonAnyGetter @Override public Map getExtensions() { return extensions; diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleTreeMap.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleTreeMap.java index 67c8f1318c4..8ed4c5ea37c 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleTreeMap.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleTreeMap.java @@ -6,8 +6,6 @@ import org.eclipse.microprofile.openapi.models.Extensible; -import com.fasterxml.jackson.annotation.JsonAnyGetter; - public abstract class ExtensibleTreeMap> extends TreeMap implements Extensible { @@ -21,7 +19,6 @@ protected ExtensibleTreeMap(Map items) { super(items); } - @JsonAnyGetter @Override public final Map getExtensions() { return extensions; diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathItemImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathItemImpl.java index a3fa982fe03..48dcdc3e19d 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathItemImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/PathItemImpl.java @@ -50,8 +50,6 @@ import org.eclipse.microprofile.openapi.models.parameters.Parameter; import org.eclipse.microprofile.openapi.models.servers.Server; -import com.fasterxml.jackson.annotation.JsonIgnore; - public class PathItemImpl extends ExtensibleImpl implements PathItem { protected String ref; @@ -178,7 +176,6 @@ public void setTRACE(Operation trace) { this.trace = trace; } - @JsonIgnore @Override public Map getOperations() { return readOperationsMap(); diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerImpl.java index 566764f8c8a..b3dc2e1b159 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/servers/ServerImpl.java @@ -48,9 +48,6 @@ import org.eclipse.microprofile.openapi.models.servers.ServerVariable; import org.eclipse.microprofile.openapi.models.servers.ServerVariables; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; - import fish.payara.microprofile.openapi.impl.model.ExtensibleImpl; public class ServerImpl extends ExtensibleImpl implements Server { @@ -86,13 +83,11 @@ public ServerVariables getVariables() { : new ServerVariablesImpl(variables); } - @JsonIgnore @Override public void setVariables(ServerVariables variables) { this.variables = variables; } - @JsonProperty("variables") @Override public void setVariables(Map variables) { this.variables = variables; diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/rest/app/provider/mixin/ExtensionsMixin.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/rest/app/provider/mixin/ExtensionsMixin.java index 1189a77de0e..b063c4a02cd 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/rest/app/provider/mixin/ExtensionsMixin.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/rest/app/provider/mixin/ExtensionsMixin.java @@ -40,33 +40,51 @@ package fish.payara.microprofile.openapi.impl.rest.app.provider.mixin; import java.util.List; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; +import org.eclipse.microprofile.openapi.models.Operation; import org.eclipse.microprofile.openapi.models.Paths; +import org.eclipse.microprofile.openapi.models.PathItem.HttpMethod; import org.eclipse.microprofile.openapi.models.security.SecurityRequirement; +import org.eclipse.microprofile.openapi.models.servers.ServerVariable; +import org.eclipse.microprofile.openapi.models.servers.ServerVariables; public interface ExtensionsMixin { @JsonProperty("enum") - public abstract void getEnumeration(); + void getEnumeration(); @JsonProperty("default") - public abstract void getDefaultValue(); + void getDefaultValue(); @JsonProperty("$ref") - public abstract void getRef(); + void getRef(); @JsonIgnore - public abstract void setAdditionalProperties(Boolean additionalProperties); + void setAdditionalProperties(Boolean additionalProperties); @JsonInclude(Include.NON_EMPTY) - public abstract List getSecurity(); + List getSecurity(); @JsonInclude(Include.ALWAYS) - public abstract Paths getPaths(); + Paths getPaths(); + + @JsonAnyGetter + Map getExtensions(); + + @JsonIgnore + Map getOperations(); + + @JsonIgnore + void setVariables(ServerVariables variables); + + @JsonProperty("variables") + void setVariables(Map variables); } \ No newline at end of file From 849ff1bb8d83861a49ef113a472f33c703b5d8c8 Mon Sep 17 00:00:00 2001 From: Jan Bernitt Date: Fri, 15 Mar 2019 18:03:57 +0100 Subject: [PATCH 09/10] PAYARA-3466 FIXED Extensible no longer adds node 'extensions' to JSON --- .../microprofile/openapi/impl/model/ExtensibleImpl.java | 2 ++ .../microprofile/openapi/impl/model/ExtensibleTreeMap.java | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java index c549ef80659..44989012b07 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java @@ -51,6 +51,7 @@ import org.eclipse.microprofile.openapi.annotations.extensions.Extension; import org.eclipse.microprofile.openapi.models.Extensible; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -58,6 +59,7 @@ public abstract class ExtensibleImpl> implements Extensi private static final Logger LOGGER = Logger.getLogger(ExtensibleImpl.class.getName()); + @JsonIgnore protected Map extensions = new LinkedHashMap<>(); @Override diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleTreeMap.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleTreeMap.java index 8ed4c5ea37c..77c65793f9b 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleTreeMap.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleTreeMap.java @@ -6,9 +6,12 @@ import org.eclipse.microprofile.openapi.models.Extensible; +import com.fasterxml.jackson.annotation.JsonIgnore; + public abstract class ExtensibleTreeMap> extends TreeMap implements Extensible { + @JsonIgnore protected Map extensions = new LinkedHashMap<>(); protected ExtensibleTreeMap() { @@ -32,7 +35,7 @@ public final void setExtensions(Map extensions) { @SuppressWarnings("unchecked") @Override public final T addExtension(String name, Object value) { - if (value != null) { + if (value != null && name.startsWith("x-")) { this.extensions.put(name, value); } return (T) this; From 2d2af207e2bd44723a897fc45d9ccfad053029a6 Mon Sep 17 00:00:00 2001 From: Jan Bernitt Date: Mon, 18 Mar 2019 17:39:15 +0100 Subject: [PATCH 10/10] PAYARA-3466 fixed serialisation of extentions and maps with properties --- .../openapi/impl/model/ExtensibleImpl.java | 14 ++++- .../openapi/impl/model/ExtensibleTreeMap.java | 60 +++++++++++++++++-- .../model/responses/APIResponsesImpl.java | 3 - 3 files changed, 67 insertions(+), 10 deletions(-) diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java index 44989012b07..dd7207ee4de 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleImpl.java @@ -46,6 +46,7 @@ import java.lang.reflect.Modifier; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Map.Entry; import java.util.logging.Logger; import org.eclipse.microprofile.openapi.annotations.extensions.Extension; @@ -71,19 +72,26 @@ public Map getExtensions() { @Override public T addExtension(String name, Object value) { if (value != null) { - extensions.put(name, value); + extensions.put(extensionName(name), value); } return (T) this; } @Override public void removeExtension(String name) { - extensions.remove(name); + extensions.remove(extensionName(name)); } @Override public void setExtensions(Map extensions) { - this.extensions = extensions; + this.extensions.clear(); + for (Entry entry : extensions.entrySet()) { + this.extensions.put(extensionName(entry.getKey()), entry.getValue()); + } + } + + public static String extensionName(String name) { + return name.startsWith("x-") ? name : "x-" + name; } public static void merge(Extension from, Extensible to, boolean override) { diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleTreeMap.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleTreeMap.java index 77c65793f9b..b0fabf39b7d 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleTreeMap.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/ExtensibleTreeMap.java @@ -1,13 +1,24 @@ package fish.payara.microprofile.openapi.impl.model; +import static fish.payara.microprofile.openapi.impl.model.ExtensibleImpl.extensionName; + +import java.io.IOException; +import java.lang.reflect.ParameterizedType; import java.util.LinkedHashMap; import java.util.Map; import java.util.TreeMap; +import java.util.Map.Entry; import org.eclipse.microprofile.openapi.models.Extensible; +import org.eclipse.microprofile.openapi.models.Reference; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +@JsonSerialize(using = ExtensibleTreeMap.ExtensibleTreeMapSerializer.class) public abstract class ExtensibleTreeMap> extends TreeMap implements Extensible { @@ -29,20 +40,61 @@ public final Map getExtensions() { @Override public final void setExtensions(Map extensions) { - this.extensions = extensions; + this.extensions.clear(); + for (Entry entry : extensions.entrySet()) { + this.extensions.put(extensionName(entry.getKey()), entry.getValue()); + } } @SuppressWarnings("unchecked") @Override public final T addExtension(String name, Object value) { - if (value != null && name.startsWith("x-")) { - this.extensions.put(name, value); + if (value != null) { + this.extensions.put(extensionName(name), value); } return (T) this; } @Override public final void removeExtension(String name) { - this.extensions.remove(name); + this.extensions.remove(extensionName(name)); + } + + /** + * Custom {@link JsonSerializer} that adds both the extended {@link TreeMap} entries as well as the + * {@link ExtensibleTreeMap#extensions} map to the output object unless the value represents a {@link Reference} in + * which case only the {@link Reference#getRef()} is added. + */ + static class ExtensibleTreeMapSerializer extends JsonSerializer> { + + @Override + public void serialize(ExtensibleTreeMap value, JsonGenerator gen, SerializerProvider serializers) + throws IOException { + if (value instanceof Reference) { + Reference reference = (Reference) value; + String ref = reference.getRef(); + if (ref != null) { + gen.writeStartObject(value); + gen.writeFieldName("$ref"); + gen.writeString(ref); + gen.writeEndObject(); + return; // if this is a ref no extensions or map entries are relevant + } + } + gen.writeStartObject(value); + ParameterizedType mapType = (ParameterizedType) value.getClass().getGenericSuperclass(); + Class valueType = (Class) mapType.getActualTypeArguments()[0]; + JsonSerializer valueSerializer = serializers.findValueSerializer(valueType); + for (Map.Entry entry : value.entrySet()) { + gen.writeFieldName(entry.getKey()); + valueSerializer.serialize(entry.getValue(), gen, serializers); + } + for (Map.Entry extension : value.getExtensions().entrySet()) { + gen.writeFieldName(extension.getKey()); + Object extensionValue = extension.getValue(); + serializers.findValueSerializer(extensionValue.getClass()).serialize(extensionValue, gen, serializers); + } + gen.writeEndObject(); + } } } diff --git a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/responses/APIResponsesImpl.java b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/responses/APIResponsesImpl.java index 99fd4de5066..e1ea4150c79 100644 --- a/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/responses/APIResponsesImpl.java +++ b/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/responses/APIResponsesImpl.java @@ -41,7 +41,6 @@ import static fish.payara.microprofile.openapi.impl.model.util.ModelUtils.isAnnotationNull; -import java.util.HashMap; import java.util.Map; import org.eclipse.microprofile.openapi.models.media.Schema; @@ -55,8 +54,6 @@ public class APIResponsesImpl extends ExtensibleTreeMap extensions = new HashMap<>(); - public APIResponsesImpl() { super(); }