Skip to content

Commit

Permalink
Fix several issues with IAM trait classes
Browse files Browse the repository at this point in the history
This commit foremost fixes an issue where the toNode method on ActionResources
does not function properly, omitting all values instead.

It also updates several type signatures for SmithyBuilder generic type responses
to use the specific implementation of the interface.

It also includes an simplification of the createNode method for the
defineConditionKeys trait.
  • Loading branch information
kstich committed Oct 19, 2024
1 parent dcfdc3a commit beaff95
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Node toNode() {
}

@Override
public SmithyBuilder<ActionResource> toBuilder() {
public Builder toBuilder() {
return builder().conditionKeys(conditionKeys);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,20 @@ public Node toNode() {
for (Map.Entry<String, ActionResource> requiredEntry : required.entrySet()) {
requiredBuilder.withMember(requiredEntry.getKey(), requiredEntry.getValue().toNode());
}
builder.withMember(REQUIRED, requiredBuilder.build());
}
if (!optional.isEmpty()) {
ObjectNode.Builder optionalBuilder = Node.objectNodeBuilder();
for (Map.Entry<String, ActionResource> optionalEntry : optional.entrySet()) {
optionalBuilder.withMember(optionalEntry.getKey(), optionalEntry.getValue().toNode());
}
builder.withMember(OPTIONAL, optionalBuilder.build());
}
return builder.build();
}

@Override
public SmithyBuilder<ActionResources> toBuilder() {
public Builder toBuilder() {
return builder().required(required).optional(optional);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public boolean isRequired() {
}

@Override
public SmithyBuilder<ConditionKeyDefinition> toBuilder() {
public Builder toBuilder() {
return builder()
.documentation(documentation)
.externalDocumentation(externalDocumentation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

package software.amazon.smithy.aws.iam.traits;

import java.util.AbstractMap;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -78,19 +77,19 @@ public Map<String, ConditionKeyDefinition> getConditionKeys() {
* Get a specific condition key by name.
*
* @param name Name of the condition key to get.
* @return Returns the optionall found condition key.
* @return Returns the optionally found condition key.
*/
public Optional<ConditionKeyDefinition> getConditionKey(String name) {
return Optional.ofNullable(conditionKeys.get(name));
}

@Override
protected Node createNode() {
return conditionKeys.entrySet().stream()
.map(entry -> new AbstractMap.SimpleImmutableEntry<>(
Node.from(entry.getKey()), entry.getValue().toNode()))
.collect(ObjectNode.collect(Map.Entry::getKey, Map.Entry::getValue))
.toBuilder().sourceLocation(getSourceLocation()).build();
ObjectNode.Builder builder = ObjectNode.builder().sourceLocation(getSourceLocation());
for (Map.Entry<String, ConditionKeyDefinition> entry : conditionKeys.entrySet()) {
builder.withMember(entry.getKey(), entry.getValue().toNode());
}
return builder.build();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import software.amazon.smithy.utils.BuilderRef;
import software.amazon.smithy.utils.FunctionalUtils;
import software.amazon.smithy.utils.ListUtils;
import software.amazon.smithy.utils.SmithyBuilder;
import software.amazon.smithy.utils.ToSmithyBuilder;

/**
Expand Down Expand Up @@ -191,7 +190,7 @@ protected Node createNode() {
}

@Override
public SmithyBuilder<IamActionTrait> toBuilder() {
public Builder toBuilder() {
return builder().sourceLocation(getSourceLocation()).name(name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import software.amazon.smithy.model.traits.AbstractTrait;
import software.amazon.smithy.model.traits.AbstractTraitBuilder;
import software.amazon.smithy.model.traits.Trait;
import software.amazon.smithy.utils.SmithyBuilder;
import software.amazon.smithy.utils.ToSmithyBuilder;

/**
Expand Down Expand Up @@ -106,7 +105,7 @@ protected Node createNode() {
}

@Override
public SmithyBuilder<IamResourceTrait> toBuilder() {
public Builder toBuilder() {
return builder().sourceLocation(getSourceLocation()).name(name);
}

Expand Down

0 comments on commit beaff95

Please sign in to comment.