refactor(cors): adds doc links and addressed review comments

pr https://github.com/smithy-lang/smithy/pull/2290
This commit is contained in:
🥷⚔️💀👻 2024-05-22 03:19:12 -07:00 committed by Kevin Stich
parent 58bd9bdfbb
commit 878517a88d
3 changed files with 7 additions and 4 deletions

View File

@ -710,8 +710,8 @@ syncCorsPreflightIntegration (``boolean``)
} }
} }
With this enabled, the ``passthroughBehavior`` for the CORS preflight integration With this enabled, the `integration's passthroughBehavior`_ for CORS preflight integration
will be set to "never". will be set to ``never``.
---------------------------------- ----------------------------------
@ -2060,4 +2060,5 @@ The conversion process is highly extensible through
.. _Lambda authorizers: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-authorizer.html .. _Lambda authorizers: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-authorizer.html
.. _API Gateway's API key usage plans: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-api-usage-plans.html .. _API Gateway's API key usage plans: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-api-usage-plans.html
.. _OpenAPI specification extension: https://spec.openapis.org/oas/v3.1.0#specification-extensions .. _OpenAPI specification extension: https://spec.openapis.org/oas/v3.1.0#specification-extensions
.. _integration's passthroughBehavior: https://docs.aws.amazon.com/apigateway/latest/developerguide/integration-passthrough-behaviors.html
.. _gradle installed: https://gradle.org/install/ .. _gradle installed: https://gradle.org/install/

View File

@ -230,6 +230,8 @@ final class AddCorsPreflightIntegration implements ApiGatewayMapper {
MockIntegrationTrait.Builder integration = MockIntegrationTrait.builder() MockIntegrationTrait.Builder integration = MockIntegrationTrait.builder()
// See https://forums.aws.amazon.com/thread.jspa?threadID=256140 // See https://forums.aws.amazon.com/thread.jspa?threadID=256140
.contentHandling("CONVERT_TO_TEXT") .contentHandling("CONVERT_TO_TEXT")
// Passthrough behavior "never" will fail the request with unsupported content type more appropriately.
// https://docs.aws.amazon.com/apigateway/latest/developerguide/integration-passthrough-behaviors.html
.passThroughBehavior(isPreflightSynced ? "never" : "when_no_match") .passThroughBehavior(isPreflightSynced ? "never" : "when_no_match")
.putResponse("default", responseBuilder.build()) .putResponse("default", responseBuilder.build())
.putRequestTemplate(API_GATEWAY_DEFAULT_ACCEPT_VALUE, PREFLIGHT_SUCCESS); .putRequestTemplate(API_GATEWAY_DEFAULT_ACCEPT_VALUE, PREFLIGHT_SUCCESS);
@ -243,7 +245,7 @@ final class AddCorsPreflightIntegration implements ApiGatewayMapper {
for (OperationObject operation : pathItem.getOperations().values()) { for (OperationObject operation : pathItem.getOperations().values()) {
ObjectNode extensionNode = operation.getExtension(INTEGRATION_EXTENSION) ObjectNode extensionNode = operation.getExtension(INTEGRATION_EXTENSION)
.flatMap(Node::asObjectNode) .flatMap(Node::asObjectNode)
.orElse(ObjectNode.EMPTY); .orElse(Node.objectNode());
Set<String> mimeTypes = extensionNode.getObjectMember(REQUEST_TEMPLATES_KEY) Set<String> mimeTypes = extensionNode.getObjectMember(REQUEST_TEMPLATES_KEY)
.map(ObjectNode::getStringMap) .map(ObjectNode::getStringMap)
.map(Map::keySet) .map(Map::keySet)

View File

@ -43,7 +43,7 @@ import software.amazon.smithy.utils.ToSmithyBuilder;
* Represents an object node. * Represents an object node.
*/ */
public final class ObjectNode extends Node implements ToSmithyBuilder<ObjectNode> { public final class ObjectNode extends Node implements ToSmithyBuilder<ObjectNode> {
public static final ObjectNode EMPTY = new ObjectNode(MapUtils.of(), SourceLocation.none(), false); static final ObjectNode EMPTY = new ObjectNode(MapUtils.of(), SourceLocation.none(), false);
private static final Logger LOGGER = Logger.getLogger(ObjectNode.class.getName()); private static final Logger LOGGER = Logger.getLogger(ObjectNode.class.getName());
private final Map<StringNode, Node> nodeMap; private final Map<StringNode, Node> nodeMap;