mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(apigateway): return embedded resource methods (#5109)
* fix(apigateway): return embedded resource methods * fix(apigateway): guard method maps during concurrent reads --------- Co-authored-by: Vamsi Akavarapu <16164447+vamsiak@users.noreply.github.com>
This commit is contained in:
1 parent
840d1bb6c1
commit
d508a4e197
7 files changed
+396
-9
No files matched your search
+21
-4
@@ -419,12 +419,14 @@ public class ApiGatewayController {
|
||||
|
||||
@GET
|
||||
@Path("/restapis/{apiId}/resources")
|
||||
public Response getResources(@Context HttpHeaders headers, @PathParam("apiId") String apiId) {
|
||||
public Response getResources(@Context HttpHeaders headers, @PathParam("apiId") String apiId,
|
||||
@QueryParam("embed") List<String> embed) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
List<ApiGatewayResource> resources = service.getResources(region, apiId);
|
||||
ObjectNode root = objectMapper.createObjectNode();
|
||||
ArrayNode items = root.putArray("item");
|
||||
resources.forEach(r -> items.add(toResourceNode(r)));
|
||||
boolean embedMethods = embed != null && embed.contains("methods");
|
||||
resources.forEach(r -> items.add(toResourceNode(r, embedMethods)));
|
||||
return Response.ok(root.toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
|
||||
@@ -432,9 +434,11 @@ public class ApiGatewayController {
|
||||
@Path("/restapis/{apiId}/resources/{resourceId}")
|
||||
public Response getResource(@Context HttpHeaders headers,
|
||||
@PathParam("apiId") String apiId,
|
||||
@PathParam("resourceId") String resourceId) {
|
||||
@PathParam("resourceId") String resourceId,
|
||||
@QueryParam("embed") List<String> embed) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
return Response.ok(toResourceNode(service.getResource(region, apiId, resourceId))).build();
|
||||
boolean embedMethods = embed != null && embed.contains("methods");
|
||||
return Response.ok(toResourceNode(service.getResource(region, apiId, resourceId), embedMethods)).build();
|
||||
}
|
||||
|
||||
@PATCH
|
||||
@@ -2215,11 +2219,20 @@ public class ApiGatewayController {
|
||||
}
|
||||
|
||||
private ObjectNode toResourceNode(ApiGatewayResource r) {
|
||||
return toResourceNode(r, false);
|
||||
}
|
||||
|
||||
private ObjectNode toResourceNode(ApiGatewayResource r, boolean embedMethods) {
|
||||
ObjectNode node = objectMapper.createObjectNode();
|
||||
node.put("id", r.getId());
|
||||
if (r.getParentId() != null) node.put("parentId", r.getParentId());
|
||||
if (r.getPathPart() != null) node.put("pathPart", r.getPathPart());
|
||||
node.put("path", r.getPath());
|
||||
if (!r.getResourceMethods().isEmpty()) {
|
||||
ObjectNode methods = node.putObject("resourceMethods");
|
||||
r.getResourceMethods().forEach((httpMethod, method) -> methods.set(httpMethod,
|
||||
embedMethods ? toMethodNode(method, r.getId()) : objectMapper.createObjectNode()));
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
@@ -2245,6 +2258,10 @@ public class ApiGatewayController {
|
||||
if (m.getMethodIntegration() != null) {
|
||||
node.set("methodIntegration", toIntegrationNode(m.getMethodIntegration(), resourceId));
|
||||
}
|
||||
if (!m.getMethodResponses().isEmpty()) {
|
||||
ObjectNode responses = node.putObject("methodResponses");
|
||||
m.getMethodResponses().forEach((status, response) -> responses.set(status, toMethodResponseNode(response)));
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -4,8 +4,8 @@ import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@RegisterForReflection
|
||||
@@ -16,7 +16,7 @@ public class ApiGatewayResource {
|
||||
private String parentId;
|
||||
private String pathPart;
|
||||
private String path;
|
||||
private Map<String, MethodConfig> resourceMethods = new HashMap<>();
|
||||
private Map<String, MethodConfig> resourceMethods = new ConcurrentHashMap<>();
|
||||
|
||||
public String getId() { return id; }
|
||||
public void setId(String id) { this.id = id; }
|
||||
@@ -35,6 +35,6 @@ public class ApiGatewayResource {
|
||||
|
||||
public Map<String, MethodConfig> getResourceMethods() { return resourceMethods; }
|
||||
public void setResourceMethods(Map<String, MethodConfig> resourceMethods) {
|
||||
this.resourceMethods = resourceMethods != null ? resourceMethods : new HashMap<>();
|
||||
this.resourceMethods = resourceMethods != null ? new ConcurrentHashMap<>(resourceMethods) : new ConcurrentHashMap<>();
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -8,6 +8,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@RegisterForReflection
|
||||
@@ -21,7 +22,7 @@ public class MethodConfig {
|
||||
private boolean apiKeyRequired;
|
||||
private Map<String, Boolean> requestParameters = new HashMap<>();
|
||||
private Map<String, String> requestModels = new HashMap<>();
|
||||
private Map<String, MethodResponse> methodResponses = new HashMap<>();
|
||||
private Map<String, MethodResponse> methodResponses = new ConcurrentHashMap<>();
|
||||
private Integration methodIntegration;
|
||||
|
||||
public String getHttpMethod() { return httpMethod; }
|
||||
@@ -56,7 +57,7 @@ public class MethodConfig {
|
||||
|
||||
public Map<String, MethodResponse> getMethodResponses() { return methodResponses; }
|
||||
public void setMethodResponses(Map<String, MethodResponse> methodResponses) {
|
||||
this.methodResponses = methodResponses != null ? methodResponses : new HashMap<>();
|
||||
this.methodResponses = methodResponses != null ? new ConcurrentHashMap<>(methodResponses) : new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
public Integration getMethodIntegration() { return methodIntegration; }
|
||||
|
||||
Reference in new issue
Block a user