Skip to content

Commit

Permalink
double continuation
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenbaker committed Dec 17, 2024
1 parent aeb6b4d commit b56136f
Show file tree
Hide file tree
Showing 1,136 changed files with 33,832 additions and 33,677 deletions.
2 changes: 1 addition & 1 deletion config/spotless/formatting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@
<setting id="org.eclipse.jdt.core.formatter.keep_record_constructor_on_one_line" value="one_line_preserve"/>
<setting id="org.eclipse.jdt.core.formatter.keep_annotation_declaration_on_one_line" value="one_line_preserve"/>
<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="120"/>
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="2"/>
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="1"/>
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="false"/>
<setting id="org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested" value="false"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ public List<ApiGatewayConfig.ApiType> getApiTypes() {
@Override
public OpenApi after(Context<? extends Trait> context, OpenApi openApi) {
return context.getService()
.getTrait(ApiKeySourceTrait.class)
.map(trait -> {
LOGGER.fine(
() -> String.format(
"Adding %s trait to %s",
EXTENSION_NAME,
context.getService().getId()
)
);
return openApi.toBuilder()
.putExtension(EXTENSION_NAME, trait.getValue())
.build();
})
.orElse(openApi);
.getTrait(ApiKeySourceTrait.class)
.map(trait -> {
LOGGER.fine(
() -> String.format(
"Adding %s trait to %s",
EXTENSION_NAME,
context.getService().getId()
)
);
return openApi.toBuilder()
.putExtension(EXTENSION_NAME, trait.getValue())
.build();
})
.orElse(openApi);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,35 +61,35 @@ public List<ApiGatewayConfig.ApiType> getApiTypes() {

@Override
public Map<String, List<String>> updateSecurity(
Context<? extends Trait> context,
Shape shape,
SecuritySchemeConverter<? extends Trait> converter,
Map<String, List<String>> requirement
Context<? extends Trait> context,
Shape shape,
SecuritySchemeConverter<? extends Trait> converter,
Map<String, List<String>> requirement
) {
// Only modify requirements that exactly match the updated scheme.
if (requirement.size() != 1
|| !requirement.keySet().iterator().next().equals(converter.getOpenApiAuthSchemeName())) {
|| !requirement.keySet().iterator().next().equals(converter.getOpenApiAuthSchemeName())) {
return requirement;
}

ServiceShape service = context.getService();
AuthorizerIndex authorizerIndex = AuthorizerIndex.of(context.getModel());

return authorizerIndex
.getAuthorizer(service, shape)
// Remove the original scheme authentication scheme from the operation if found.
// Add a new scheme for this operation using the authorizer name.
.map(authorizer -> MapUtils.of(authorizer, requirement.values().iterator().next()))
.orElse(requirement);
.getAuthorizer(service, shape)
// Remove the original scheme authentication scheme from the operation if found.
// Add a new scheme for this operation using the authorizer name.
.map(authorizer -> MapUtils.of(authorizer, requirement.values().iterator().next()))
.orElse(requirement);
}

@Override
public OperationObject updateOperation(
Context<? extends Trait> context,
OperationShape shape,
OperationObject operation,
String httpMethodName,
String path
Context<? extends Trait> context,
OperationShape shape,
OperationObject operation,
String httpMethodName,
String path
) {
ServiceShape service = context.getService();
AuthorizerIndex authorizerIndex = AuthorizerIndex.of(context.getModel());
Expand All @@ -113,22 +113,22 @@ public OperationObject updateOperation(
}

return operation.toBuilder()
.addSecurity(MapUtils.of(operationAuth, ListUtils.of()))
.build();
.addSecurity(MapUtils.of(operationAuth, ListUtils.of()))
.build();
}

private boolean usesApiGatewayApiKeys(ServiceShape service, String operationAuth) {
// Get the authorizer for this operation if it has no "type" or
// "customAuthType" set, as is required for API Gateway's API keys.
Optional<AuthorizerDefinition> definitionOptional = service.getTrait(AuthorizersTrait.class)
.flatMap(
authorizers -> authorizers
.getAuthorizer(operationAuth)
.filter(
authorizer -> !authorizer.getType().isPresent()
&& !authorizer.getCustomAuthType().isPresent()
)
);
.flatMap(
authorizers -> authorizers
.getAuthorizer(operationAuth)
.filter(
authorizer -> !authorizer.getType().isPresent()
&& !authorizer.getCustomAuthType().isPresent()
)
);

if (!definitionOptional.isPresent()) {
return false;
Expand All @@ -143,9 +143,9 @@ private boolean usesApiGatewayApiKeys(ServiceShape service, String operationAuth
@Override
public OpenApi after(Context<? extends Trait> context, OpenApi openapi) {
return context.getService()
.getTrait(AuthorizersTrait.class)
.map(authorizers -> addComputedAuthorizers(context, openapi, authorizers))
.orElse(openapi);
.getTrait(AuthorizersTrait.class)
.map(authorizers -> addComputedAuthorizers(context, openapi, authorizers))
.orElse(openapi);
}

private OpenApi addComputedAuthorizers(Context<? extends Trait> context, OpenApi openApi, AuthorizersTrait trait) {
Expand All @@ -171,19 +171,19 @@ private OpenApi addComputedAuthorizers(Context<? extends Trait> context, OpenApi
}

private boolean isAuthConverterMatched(
Context<? extends Trait> context,
SecuritySchemeConverter<? extends Trait> converter,
ShapeId scheme
Context<? extends Trait> context,
SecuritySchemeConverter<? extends Trait> converter,
ShapeId scheme
) {
return converter.getAuthSchemeId().equals(scheme)
&& context.getService().hasTrait(converter.getAuthSchemeType());
&& context.getService().hasTrait(converter.getAuthSchemeType());
}

private <T extends Trait> SecurityScheme convertAuthScheme(
Context<? extends Trait> context,
SecuritySchemeConverter<T> converter,
AuthorizerDefinition authorizer,
String authorizerName
Context<? extends Trait> context,
SecuritySchemeConverter<T> converter,
AuthorizerDefinition authorizer,
String authorizerName
) {
T authTrait = context.getService().expectTrait(converter.getAuthSchemeType());
SecurityScheme createdScheme = converter.createSecurityScheme(context, authTrait);
Expand All @@ -202,33 +202,33 @@ private <T extends Trait> SecurityScheme convertAuthScheme(
}

ObjectNode authorizerNode = Node.objectNodeBuilder()
.withOptionalMember("type", authorizer.getType().map(Node::from))
.withOptionalMember("authorizerUri", authorizer.getUri().map(Node::from))
.withOptionalMember(
"authorizerCredentials",
authorizer.getCredentials().map(Node::from)
)
.withOptionalMember(
"identityValidationExpression",
authorizer.getIdentityValidationExpression().map(Node::from)
)
.withOptionalMember(
"identitySource",
authorizer.getIdentitySource().map(Node::from)
)
.withOptionalMember(
"authorizerResultTtlInSeconds",
authorizer.getResultTtlInSeconds().map(Node::from)
)
.withOptionalMember(
"authorizerPayloadFormatVersion",
authorizer.getAuthorizerPayloadFormatVersion().map(Node::from)
)
.withOptionalMember(
"enableSimpleResponses",
authorizer.getEnableSimpleResponses().map(Node::from)
)
.build();
.withOptionalMember("type", authorizer.getType().map(Node::from))
.withOptionalMember("authorizerUri", authorizer.getUri().map(Node::from))
.withOptionalMember(
"authorizerCredentials",
authorizer.getCredentials().map(Node::from)
)
.withOptionalMember(
"identityValidationExpression",
authorizer.getIdentityValidationExpression().map(Node::from)
)
.withOptionalMember(
"identitySource",
authorizer.getIdentitySource().map(Node::from)
)
.withOptionalMember(
"authorizerResultTtlInSeconds",
authorizer.getResultTtlInSeconds().map(Node::from)
)
.withOptionalMember(
"authorizerPayloadFormatVersion",
authorizer.getAuthorizerPayloadFormatVersion().map(Node::from)
)
.withOptionalMember(
"enableSimpleResponses",
authorizer.getEnableSimpleResponses().map(Node::from)
)
.build();
if (authorizerNode.size() != 0) {
schemeBuilder.putExtension(EXTENSION_NAME, authorizerNode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ public OpenApi after(Context<? extends Trait> context, OpenApi openApi) {
if (!binaryTypes.isEmpty()) {
LOGGER.fine(() -> "Adding recognized binary types to model: " + binaryTypes);
return openApi.toBuilder()
.putExtension(
EXTENSION_NAME,
Stream.concat(binaryTypes.stream(), Stream.of(DEFAULT_BINARY_TYPE))
.distinct()
.map(Node::from)
.collect(ArrayNode.collect())
)
.build();
.putExtension(
EXTENSION_NAME,
Stream.concat(binaryTypes.stream(), Stream.of(DEFAULT_BINARY_TYPE))
.distinct()
.map(Node::from)
.collect(ArrayNode.collect())
)
.build();
}

return openApi;
Expand All @@ -68,22 +68,26 @@ private Stream<String> supportedMediaTypes(Context<? extends Trait> context) {

// Find the media types defined on all request and response bindings.
return topDownIndex.getContainedOperations(context.getService())
.stream()
.flatMap(
operation -> Stream.concat(
OptionalUtils.stream(binaryMediaType(model, httpBindingIndex.getRequestBindings(operation))),
OptionalUtils.stream(binaryMediaType(model, httpBindingIndex.getResponseBindings(operation)))
)
);
.stream()
.flatMap(
operation -> Stream.concat(
OptionalUtils.stream(
binaryMediaType(model, httpBindingIndex.getRequestBindings(operation))
),
OptionalUtils.stream(
binaryMediaType(model, httpBindingIndex.getResponseBindings(operation))
)
)
);
}

private Optional<String> binaryMediaType(Model model, Map<String, HttpBinding> httpBindings) {
return httpBindings.values()
.stream()
.filter(binding -> binding.getLocation().equals(HttpBinding.Location.PAYLOAD))
.map(HttpBinding::getMember)
.flatMap(member -> OptionalUtils.stream(member.getMemberTrait(model, MediaTypeTrait.class)))
.map(MediaTypeTrait::getValue)
.findFirst();
.stream()
.filter(binding -> binding.getLocation().equals(HttpBinding.Location.PAYLOAD))
.map(HttpBinding::getMember)
.flatMap(member -> OptionalUtils.stream(member.getMemberTrait(model, MediaTypeTrait.class)))
.map(MediaTypeTrait::getValue)
.findFirst();
}
}
Loading

0 comments on commit b56136f

Please sign in to comment.