Skip to content

Commit

Permalink
Split builder API build method to enable downstream optimizations (#…
Browse files Browse the repository at this point in the history
…2003)

* Split builder API's build method to allow overrides

Signed-off-by: Michael Edgar <michael@xlate.io>

* Reduce number of initializer lambdas throughout model classes

Signed-off-by: Michael Edgar <michael@xlate.io>

---------

Signed-off-by: Michael Edgar <michael@xlate.io>
  • Loading branch information
MikeEdgar authored Sep 30, 2024
1 parent ceaf605 commit 5edcb21
Show file tree
Hide file tree
Showing 23 changed files with 285 additions and 161 deletions.
243 changes: 184 additions & 59 deletions core/src/main/java/io/smallrye/openapi/api/SmallRyeOpenAPI.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.smallrye.openapi.api.models;

import java.util.LinkedHashMap;
import java.util.Map;

import org.eclipse.microprofile.openapi.models.Components;
Expand Down Expand Up @@ -46,7 +45,7 @@ public Map<String, Schema> getSchemas() {
*/
@Override
public void setSchemas(Map<String, Schema> schemas) {
this.schemas = ModelUtil.replace(schemas, LinkedHashMap<String, Schema>::new);
this.schemas = ModelUtil.replace(schemas);
}

/**
Expand All @@ -55,7 +54,7 @@ public void setSchemas(Map<String, Schema> schemas) {
*/
@Override
public Components addSchema(String key, Schema schema) {
this.schemas = ModelUtil.add(key, schema, this.schemas, LinkedHashMap<String, Schema>::new);
this.schemas = ModelUtil.add(key, schema, this.schemas);
return this;
}

Expand All @@ -80,7 +79,7 @@ public Map<String, APIResponse> getResponses() {
*/
@Override
public void setResponses(Map<String, APIResponse> responses) {
this.responses = ModelUtil.replace(responses, LinkedHashMap<String, APIResponse>::new);
this.responses = ModelUtil.replace(responses);
}

/**
Expand All @@ -89,7 +88,7 @@ public void setResponses(Map<String, APIResponse> responses) {
*/
@Override
public Components addResponse(String key, APIResponse response) {
this.responses = ModelUtil.add(key, response, this.responses, LinkedHashMap<String, APIResponse>::new);
this.responses = ModelUtil.add(key, response, this.responses);
return this;
}

Expand All @@ -114,7 +113,7 @@ public Map<String, Parameter> getParameters() {
*/
@Override
public void setParameters(Map<String, Parameter> parameters) {
this.parameters = ModelUtil.replace(parameters, LinkedHashMap<String, Parameter>::new);
this.parameters = ModelUtil.replace(parameters);
}

/**
Expand All @@ -123,7 +122,7 @@ public void setParameters(Map<String, Parameter> parameters) {
*/
@Override
public Components addParameter(String key, Parameter parameter) {
this.parameters = ModelUtil.add(key, parameter, this.parameters, LinkedHashMap<String, Parameter>::new);
this.parameters = ModelUtil.add(key, parameter, this.parameters);
return this;
}

Expand All @@ -148,7 +147,7 @@ public Map<String, Example> getExamples() {
*/
@Override
public void setExamples(Map<String, Example> examples) {
this.examples = ModelUtil.replace(examples, LinkedHashMap<String, Example>::new);
this.examples = ModelUtil.replace(examples);
}

/**
Expand All @@ -157,7 +156,7 @@ public void setExamples(Map<String, Example> examples) {
*/
@Override
public Components addExample(String key, Example example) {
this.examples = ModelUtil.add(key, example, this.examples, LinkedHashMap<String, Example>::new);
this.examples = ModelUtil.add(key, example, this.examples);
return this;
}

Expand All @@ -182,7 +181,7 @@ public Map<String, RequestBody> getRequestBodies() {
*/
@Override
public void setRequestBodies(Map<String, RequestBody> requestBodies) {
this.requestBodies = ModelUtil.replace(requestBodies, LinkedHashMap<String, RequestBody>::new);
this.requestBodies = ModelUtil.replace(requestBodies);
}

/**
Expand All @@ -191,7 +190,7 @@ public void setRequestBodies(Map<String, RequestBody> requestBodies) {
*/
@Override
public Components addRequestBody(String key, RequestBody requestBody) {
this.requestBodies = ModelUtil.add(key, requestBody, this.requestBodies, LinkedHashMap<String, RequestBody>::new);
this.requestBodies = ModelUtil.add(key, requestBody, this.requestBodies);
return this;
}

Expand All @@ -216,7 +215,7 @@ public Map<String, Header> getHeaders() {
*/
@Override
public void setHeaders(Map<String, Header> headers) {
this.headers = ModelUtil.replace(headers, LinkedHashMap<String, Header>::new);
this.headers = ModelUtil.replace(headers);
}

/**
Expand All @@ -225,7 +224,7 @@ public void setHeaders(Map<String, Header> headers) {
*/
@Override
public Components addHeader(String key, Header header) {
this.headers = ModelUtil.add(key, header, this.headers, LinkedHashMap<String, Header>::new);
this.headers = ModelUtil.add(key, header, this.headers);
return this;
}

Expand All @@ -250,7 +249,7 @@ public Map<String, SecurityScheme> getSecuritySchemes() {
*/
@Override
public void setSecuritySchemes(Map<String, SecurityScheme> securitySchemes) {
this.securitySchemes = ModelUtil.replace(securitySchemes, LinkedHashMap<String, SecurityScheme>::new);
this.securitySchemes = ModelUtil.replace(securitySchemes);
}

/**
Expand All @@ -259,8 +258,7 @@ public void setSecuritySchemes(Map<String, SecurityScheme> securitySchemes) {
*/
@Override
public Components addSecurityScheme(String key, SecurityScheme securityScheme) {
this.securitySchemes = ModelUtil.add(key, securityScheme, this.securitySchemes,
LinkedHashMap<String, SecurityScheme>::new);
this.securitySchemes = ModelUtil.add(key, securityScheme, this.securitySchemes);
return this;
}

Expand All @@ -285,7 +283,7 @@ public Map<String, Link> getLinks() {
*/
@Override
public void setLinks(Map<String, Link> links) {
this.links = ModelUtil.replace(links, LinkedHashMap<String, Link>::new);
this.links = ModelUtil.replace(links);
}

/**
Expand All @@ -294,7 +292,7 @@ public void setLinks(Map<String, Link> links) {
*/
@Override
public Components addLink(String key, Link link) {
this.links = ModelUtil.add(key, link, this.links, LinkedHashMap<String, Link>::new);
this.links = ModelUtil.add(key, link, this.links);
return this;
}

Expand All @@ -319,7 +317,7 @@ public Map<String, Callback> getCallbacks() {
*/
@Override
public void setCallbacks(Map<String, Callback> callbacks) {
this.callbacks = ModelUtil.replace(callbacks, LinkedHashMap<String, Callback>::new);
this.callbacks = ModelUtil.replace(callbacks);
}

/**
Expand All @@ -328,7 +326,7 @@ public void setCallbacks(Map<String, Callback> callbacks) {
*/
@Override
public Components addCallback(String key, Callback callback) {
this.callbacks = ModelUtil.add(key, callback, this.callbacks, LinkedHashMap<String, Callback>::new);
this.callbacks = ModelUtil.add(key, callback, this.callbacks);
return this;
}

Expand All @@ -347,12 +345,12 @@ public Map<String, PathItem> getPathItems() {

@Override
public void setPathItems(Map<String, PathItem> pathItems) {
this.pathItems = ModelUtil.replace(pathItems, LinkedHashMap<String, PathItem>::new);
this.pathItems = ModelUtil.replace(pathItems);
}

@Override
public Components addPathItem(String name, PathItem pathItem) {
this.pathItems = ModelUtil.add(name, pathItem, this.pathItems, LinkedHashMap<String, PathItem>::new);
this.pathItems = ModelUtil.add(name, pathItem, this.pathItems);
return this;
}

Expand All @@ -361,4 +359,4 @@ public void removePathItem(String name) {
ModelUtil.remove(this.pathItems, name);
}

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.smallrye.openapi.api.models;

import java.util.LinkedHashMap;
import java.util.Map;

import org.eclipse.microprofile.openapi.models.Extensible;
Expand Down Expand Up @@ -31,7 +30,7 @@ public Map<String, Object> getExtensions() {
@SuppressWarnings("unchecked")
@Override
public T addExtension(String name, Object value) {
this.extensions = ModelUtil.add(name, value, this.extensions, LinkedHashMap<String, Object>::new);
this.extensions = ModelUtil.add(name, value, this.extensions);
return (T) this;
}

Expand All @@ -48,7 +47,7 @@ public void removeExtension(String name) {
*/
@Override
public void setExtensions(Map<String, Object> extensions) {
this.extensions = ModelUtil.replace(extensions, LinkedHashMap<String, Object>::new);
this.extensions = ModelUtil.replace(extensions);
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.smallrye.openapi.api.models;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -93,15 +92,15 @@ public List<Server> getServers() {
*/
@Override
public void setServers(List<Server> servers) {
this.servers = ModelUtil.replace(servers, ArrayList<Server>::new);
this.servers = ModelUtil.replace(servers);
}

/**
* @see org.eclipse.microprofile.openapi.models.OpenAPI#addServer(org.eclipse.microprofile.openapi.models.servers.Server)
*/
@Override
public OpenAPI addServer(Server server) {
this.servers = ModelUtil.add(server, this.servers, ArrayList<Server>::new);
this.servers = ModelUtil.add(server, this.servers);
return this;
}

Expand All @@ -126,15 +125,15 @@ public List<SecurityRequirement> getSecurity() {
*/
@Override
public void setSecurity(List<SecurityRequirement> security) {
this.security = ModelUtil.replace(security, ArrayList<SecurityRequirement>::new);
this.security = ModelUtil.replace(security);
}

/**
* @see org.eclipse.microprofile.openapi.models.OpenAPI#addSecurityRequirement(org.eclipse.microprofile.openapi.models.security.SecurityRequirement)
*/
@Override
public OpenAPI addSecurityRequirement(SecurityRequirement securityRequirement) {
this.security = ModelUtil.add(securityRequirement, this.security, ArrayList<SecurityRequirement>::new);
this.security = ModelUtil.add(securityRequirement, this.security);
return this;
}

Expand All @@ -159,7 +158,7 @@ public List<Tag> getTags() {
*/
@Override
public void setTags(List<Tag> tags) {
this.tags = ModelUtil.replace(tags, ArrayList<Tag>::new);
this.tags = ModelUtil.replace(tags);
}

/**
Expand Down Expand Up @@ -238,12 +237,12 @@ public Map<String, PathItem> getWebhooks() {

@Override
public void setWebhooks(Map<String, PathItem> webhooks) {
this.webhooks = ModelUtil.replace(webhooks, LinkedHashMap<String, PathItem>::new);
this.webhooks = ModelUtil.replace(webhooks);
}

@Override
public OpenAPI addWebhook(String name, PathItem webhook) {
this.webhooks = ModelUtil.add(name, webhook, this.webhooks, LinkedHashMap<String, PathItem>::new);
this.webhooks = ModelUtil.add(name, webhook, this.webhooks);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.smallrye.openapi.api.models;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -57,15 +55,15 @@ public List<String> getTags() {
*/
@Override
public void setTags(List<String> tags) {
this.tags = ModelUtil.replace(tags, ArrayList<String>::new);
this.tags = ModelUtil.replace(tags);
}

/**
* @see org.eclipse.microprofile.openapi.models.Operation#addTag(java.lang.String)
*/
@Override
public Operation addTag(String tag) {
this.tags = ModelUtil.add(tag, this.tags, ArrayList<String>::new);
this.tags = ModelUtil.add(tag, this.tags);
return this;
}

Expand Down Expand Up @@ -154,15 +152,15 @@ public List<Parameter> getParameters() {
*/
@Override
public void setParameters(List<Parameter> parameters) {
this.parameters = ModelUtil.replace(parameters, ArrayList<Parameter>::new);
this.parameters = ModelUtil.replace(parameters);
}

/**
* @see org.eclipse.microprofile.openapi.models.Operation#addParameter(org.eclipse.microprofile.openapi.models.parameters.Parameter)
*/
@Override
public Operation addParameter(Parameter parameter) {
this.parameters = ModelUtil.add(parameter, this.parameters, ArrayList<Parameter>::new);
this.parameters = ModelUtil.add(parameter, this.parameters);
return this;
}

Expand Down Expand Up @@ -219,7 +217,7 @@ public Map<String, Callback> getCallbacks() {
*/
@Override
public void setCallbacks(Map<String, Callback> callbacks) {
this.callbacks = ModelUtil.replace(callbacks, LinkedHashMap<String, Callback>::new);
this.callbacks = ModelUtil.replace(callbacks);
}

/**
Expand All @@ -228,7 +226,7 @@ public void setCallbacks(Map<String, Callback> callbacks) {
*/
@Override
public Operation addCallback(String key, Callback callback) {
this.callbacks = ModelUtil.add(key, callback, this.callbacks, LinkedHashMap<String, Callback>::new);
this.callbacks = ModelUtil.add(key, callback, this.callbacks);
return this;
}

Expand Down Expand Up @@ -269,15 +267,15 @@ public List<SecurityRequirement> getSecurity() {
*/
@Override
public void setSecurity(List<SecurityRequirement> security) {
this.security = ModelUtil.replace(security, ArrayList<SecurityRequirement>::new);
this.security = ModelUtil.replace(security);
}

/**
* @see org.eclipse.microprofile.openapi.models.Operation#addSecurityRequirement(org.eclipse.microprofile.openapi.models.security.SecurityRequirement)
*/
@Override
public Operation addSecurityRequirement(SecurityRequirement securityRequirement) {
this.security = ModelUtil.add(securityRequirement, this.security, ArrayList<SecurityRequirement>::new);
this.security = ModelUtil.add(securityRequirement, this.security);
return this;
}

Expand All @@ -302,15 +300,15 @@ public List<Server> getServers() {
*/
@Override
public void setServers(List<Server> servers) {
this.servers = ModelUtil.replace(servers, ArrayList<Server>::new);
this.servers = ModelUtil.replace(servers);
}

/**
* @see org.eclipse.microprofile.openapi.models.Operation#addServer(org.eclipse.microprofile.openapi.models.servers.Server)
*/
@Override
public Operation addServer(Server server) {
this.servers = ModelUtil.add(server, this.servers, ArrayList<Server>::new);
this.servers = ModelUtil.add(server, this.servers);
return this;
}

Expand All @@ -335,7 +333,7 @@ public void setMethodRef(String methodRef) {
this.methodRef = methodRef;
}

static public String getMethodRef(Operation operation) {
public static String getMethodRef(Operation operation) {
return (operation instanceof OperationImpl) ? ((OperationImpl) operation).getMethodRef() : null;
}
}
Loading

0 comments on commit 5edcb21

Please sign in to comment.