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
…3.x) (#2004)

* 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 4da1fb9 commit 37f14c5
Show file tree
Hide file tree
Showing 23 changed files with 281 additions and 156 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 @@ -44,7 +43,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 @@ -53,7 +52,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 @@ -78,7 +77,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 @@ -87,7 +86,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 @@ -112,7 +111,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 @@ -121,7 +120,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 @@ -146,7 +145,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 @@ -155,7 +154,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 @@ -180,7 +179,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 @@ -189,7 +188,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 @@ -214,7 +213,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 @@ -223,7 +222,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 @@ -248,7 +247,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 @@ -257,8 +256,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 @@ -283,7 +281,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 @@ -292,7 +290,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 @@ -317,7 +315,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 @@ -326,7 +324,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 @@ -338,4 +336,4 @@ public void removeCallback(String key) {
ModelUtil.remove(this.callbacks, key);
}

}
}
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
Expand Up @@ -89,15 +89,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 @@ -122,15 +122,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 @@ -155,7 +155,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
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 37f14c5

Please sign in to comment.