Skip to content

Commit

Permalink
Update continuation indentation to level to 2
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenbaker committed Dec 13, 2024
1 parent 2559334 commit 5e7a64a
Show file tree
Hide file tree
Showing 1,074 changed files with 32,035 additions and 31,886 deletions.
4 changes: 2 additions & 2 deletions config/spotless/formatting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@
<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_for_array_initializer" 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="2"/>
<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"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration" value="16"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ 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,34 +61,34 @@ 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);
// 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 @@ -111,21 +111,21 @@ 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 @@ -140,15 +140,15 @@ 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
Context<? extends Trait> context,
OpenApi openApi,
AuthorizersTrait trait
) {
OpenApi.Builder builder = openApi.toBuilder();
ComponentsObject.Builder components = openApi.getComponents().toBuilder();
Expand All @@ -172,19 +172,19 @@ private OpenApi addComputedAuthorizers(
}

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 @@ -203,27 +203,27 @@ 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,26 +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 5e7a64a

Please sign in to comment.