Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ private List<ValidationEvent> validateResponseChecksumConfiguration(
});

// Check for header binding conflicts with each error shape.
if (!operation.getErrors().isEmpty()) {
for (ShapeId id : operation.getErrors()) {
if (!operation.getErrorsSet().isEmpty()) {
for (ShapeId id : operation.getErrorsSet()) {
StructureShape shape = model.expectShape(id, StructureShape.class);
events.addAll(validateHeaderConflicts(operation, shape));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private List<ValidationEvent> validateOperation(OperationShape operation, List<C

return infos.stream()
.filter(discoveryInfo -> discoveryInfo.getOptionalError().isPresent())
.filter(discoveryInfo -> !operation.getErrors()
.filter(discoveryInfo -> !operation.getErrorsSet()
.contains(
discoveryInfo.getOptionalError().get().getId()))
.map(discoveryInfo -> error(operation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private List<ValidationEvent> validateService(
List<HttpBinding> responseBindings = bindingIndex.getResponseBindings(operation, Location.PAYLOAD);
validateBindings(model, responseBindings).ifPresent(events::add);

for (ShapeId error : operation.getErrors()) {
for (ShapeId error : operation.getErrorsSet()) {
List<HttpBinding> errorBindings = bindingIndex.getResponseBindings(error, Location.PAYLOAD);
validateBindings(model, errorBindings).ifPresent(events::add);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public List<ValidationEvent> validate(Model model) {

private List<ValidationEvent> validateService(Model model, ServiceShape service) {
TopDownIndex index = TopDownIndex.of(model);
Set<ShapeId> errors = new HashSet<>(service.getErrors());
Set<ShapeId> errors = new HashSet<>(service.getErrorsSet());
for (OperationShape operation : index.getContainedOperations(service)) {
errors.addAll(operation.getErrors());
errors.addAll(operation.getErrorsSet());
}

Map<String, Set<String>> errorCodeBindings = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public List<ValidationEvent> evaluate(Differences differences) {
}

private List<ValidationEvent> createErrorViolations(ChangedShape<OperationShape> change, Model newModel) {
if (change.getOldShape().getErrors().equals(change.getNewShape().getErrors())) {
if (change.getOldShape().getErrorsSet().equals(change.getNewShape().getErrorsSet())) {
return Collections.emptyList();
}

List<ValidationEvent> events = new ArrayList<>();
for (ShapeId error : change.getNewShape().getErrors()) {
for (ShapeId error : change.getNewShape().getErrorsSet()) {
SourceLocation errorSource = newModel.expectShape(error).getSourceLocation();
if (!change.getOldShape().getErrors().contains(error)) {
if (!change.getOldShape().getErrorsSet().contains(error)) {
events.add(
ValidationEvent.builder()
.id(getEventId() + "." + error.getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public List<ValidationEvent> evaluate(Differences differences) {
}

private List<ValidationEvent> createErrorViolations(ChangedShape<ServiceShape> change) {
if (change.getOldShape().getErrors().equals(change.getNewShape().getErrors())) {
if (change.getOldShape().getErrorsSet().equals(change.getNewShape().getErrorsSet())) {
return Collections.emptyList();
}

List<ValidationEvent> events = new ArrayList<>();
for (ShapeId id : change.getNewShape().getErrors()) {
if (!change.getOldShape().getErrors().contains(id)) {
for (ShapeId id : change.getNewShape().getErrorsSet()) {
if (!change.getOldShape().getErrorsSet().contains(id)) {
events.add(warning(change.getNewShape(),
String.format(
"The `%s` error was added to the `%s` service, making this error common "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public List<ValidationEvent> evaluate(Differences differences) {
}

private List<ValidationEvent> createErrorViolations(ChangedShape<OperationShape> change) {
if (change.getOldShape().getErrors().equals(change.getNewShape().getErrors())) {
if (change.getOldShape().getErrorsSet().equals(change.getNewShape().getErrorsSet())) {
return Collections.emptyList();
}

List<ValidationEvent> events = new ArrayList<>();
for (ShapeId error : change.getOldShape().getErrors()) {
if (!change.getNewShape().getErrors().contains(error)) {
for (ShapeId error : change.getOldShape().getErrorsSet()) {
if (!change.getNewShape().getErrorsSet().contains(error)) {
events.add(
ValidationEvent.builder()
.id(getEventId() + "." + error.getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public List<ValidationEvent> evaluate(Differences differences) {
}

private List<ValidationEvent> createErrorViolations(ChangedShape<ServiceShape> change) {
if (change.getOldShape().getErrors().equals(change.getNewShape().getErrors())) {
if (change.getOldShape().getErrorsSet().equals(change.getNewShape().getErrorsSet())) {
return Collections.emptyList();
}

List<ValidationEvent> events = new ArrayList<>();
for (ShapeId id : change.getOldShape().getErrors()) {
if (!change.getNewShape().getErrors().contains(id)) {
for (ShapeId id : change.getOldShape().getErrorsSet()) {
if (!change.getNewShape().getErrorsSet().contains(id)) {
events.add(warning(change.getNewShape(),
String.format(
"The `%s` error was removed from the `%s` service. This means that it "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package software.amazon.smithy.model.knowledge;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -55,15 +56,15 @@ public OperationIndex(Model model) {
outputs.put(operation.getId(), shape);
boundOutputOperations.computeIfAbsent(shape.getId(), id -> new HashSet<>()).add(operation);
});
addErrorsFromShape(model, operation.getId(), operation.getErrors());
addErrorsFromShape(model, operation.getId(), operation.getErrorsSet());
}

for (ServiceShape service : model.getServiceShapes()) {
addErrorsFromShape(model, service.getId(), service.getErrors());
addErrorsFromShape(model, service.getId(), service.getErrorsSet());
}
}

private void addErrorsFromShape(Model model, ShapeId source, List<ShapeId> errorShapeIds) {
private void addErrorsFromShape(Model model, ShapeId source, Collection<ShapeId> errorShapeIds) {
List<StructureShape> errorShapes = new ArrayList<>(errorShapeIds.size());
Shape sourceShape = model.expectShape(source);
for (ShapeId target : errorShapeIds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private List<Relationship> initializeRelationships(Shape shape, int knownMemberC

@Override
public List<Relationship> serviceShape(ServiceShape shape) {
int neededSize = shape.getOperations().size() + shape.getResources().size() + shape.getErrors().size();
int neededSize = shape.getOperations().size() + shape.getResources().size() + shape.getErrorsSet().size();
List<Relationship> result = initializeRelationships(shape, neededSize);

for (ShapeId operation : shape.getOperations()) {
Expand All @@ -79,7 +79,7 @@ public List<Relationship> serviceShape(ServiceShape shape) {
push(result, shape, RelationshipType.RESOURCE, resource);
}

for (ShapeId errorId : shape.getErrors()) {
for (ShapeId errorId : shape.getErrorsSet()) {
push(result, shape, RelationshipType.ERROR, errorId);
}

Expand Down Expand Up @@ -120,7 +120,7 @@ public List<Relationship> operationShape(OperationShape shape) {
ShapeId output = shape.getOutput().orElse(null);

// Calculate the number of relationships up front.
int assumedRelationshipCount = shape.getErrors().size()
int assumedRelationshipCount = shape.getErrorsSet().size()
+ (input == null ? 0 : 1)
+ (output == null ? 0 : 1);
List<Relationship> result = initializeRelationships(shape, assumedRelationshipCount);
Expand All @@ -133,7 +133,7 @@ public List<Relationship> operationShape(OperationShape shape) {
push(result, shape, RelationshipType.OUTPUT, output);
}

for (ShapeId errorId : shape.getErrors()) {
for (ShapeId errorId : shape.getErrorsSet()) {
push(result, shape, RelationshipType.ERROR, errorId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public Node operationShape(OperationShape shape) {
createTypedBuilder(shape)
.withMember("input", serializeReference(shape.getInputShape()))
.withMember("output", serializeReference(shape.getOutputShape()))
.withOptionalMember("errors", createOptionalIdList(shape.getIntroducedErrors())))
.withOptionalMember("errors", createOptionalIdList(shape.getIntroducedErrorsSet())))
.build();
}

Expand Down Expand Up @@ -394,7 +394,7 @@ public Node serviceShape(ServiceShape shape) {

serviceBuilder.withOptionalMember("operations", createOptionalIdList(shape.getIntroducedOperations()));
serviceBuilder.withOptionalMember("resources", createOptionalIdList(shape.getIntroducedResources()));
serviceBuilder.withOptionalMember("errors", createOptionalIdList(shape.getIntroducedErrors()));
serviceBuilder.withOptionalMember("errors", createOptionalIdList(shape.getIntroducedErrorsSet()));

if (!shape.getIntroducedRename().isEmpty()) {
ObjectNode.Builder renameBuilder = Node.objectNodeBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import software.amazon.smithy.model.traits.MixinTrait;
import software.amazon.smithy.model.traits.UnitTypeTrait;
import software.amazon.smithy.utils.BuilderRef;
import software.amazon.smithy.utils.ListUtils;
import software.amazon.smithy.utils.ToSmithyBuilder;

/**
Expand All @@ -25,8 +26,8 @@
public final class OperationShape extends Shape implements ToSmithyBuilder<OperationShape> {
private final ShapeId input;
private final ShapeId output;
private final List<ShapeId> errors;
private final List<ShapeId> introducedErrors;
private final Set<ShapeId> errors;
private final Set<ShapeId> introducedErrors;

private OperationShape(Builder builder) {
super(builder, false);
Expand All @@ -43,11 +44,11 @@ private OperationShape(Builder builder) {
// here.
Set<ShapeId> computedErrors = new LinkedHashSet<>();
for (Shape shape : builder.getMixins().values()) {
shape.asOperationShape().ifPresent(mixin -> computedErrors.addAll(mixin.getErrors()));
shape.asOperationShape().ifPresent(mixin -> computedErrors.addAll(mixin.getErrorsSet()));
}
introducedErrors = builder.errors.copy();
computedErrors.addAll(introducedErrors);
errors = Collections.unmodifiableList(new ArrayList<>(computedErrors));
errors = Collections.unmodifiableSet(new LinkedHashSet<>(computedErrors));
}

if (hasTrait(MixinTrait.ID) && (!input.equals(UnitTypeTrait.UNIT) || !output.equals(UnitTypeTrait.UNIT))) {
Expand All @@ -68,7 +69,7 @@ public Builder toBuilder() {
return updateBuilder(builder())
.input(input)
.output(output)
.errors(getIntroducedErrors());
.errors(getIntroducedErrorsSet());
}

@Override
Expand Down Expand Up @@ -134,8 +135,13 @@ public ShapeId getOutputShape() {
return output;
}

@Deprecated
public List<ShapeId> getErrors() {
return ListUtils.copyOf(errors);
}

/**
* <p>Gets a list of the error shape IDs bound directly to the operation
* <p>Gets a set of the error shape IDs bound directly to the operation
* that can be encountered.
*
* <p>This DOES NOT include errors that are common to a service. Operations
Expand All @@ -152,17 +158,22 @@ public ShapeId getOutputShape() {
* @see #getErrors(ServiceShape)
* @see OperationIndex#getErrors(ToShapeId, ToShapeId)
*/
public List<ShapeId> getErrors() {
public Set<ShapeId> getErrorsSet() {
return errors;
}

@Deprecated
public List<ShapeId> getIntroducedErrors() {
return ListUtils.copyOf(introducedErrors);
}

/**
* Gets the errors introduced by the shape and not inherited
* from mixins.
*
* @return Returns the introduced errors.
*/
public List<ShapeId> getIntroducedErrors() {
public Set<ShapeId> getIntroducedErrorsSet() {
return introducedErrors;
}

Expand All @@ -177,8 +188,8 @@ public List<ShapeId> getIntroducedErrors() {
* @see OperationIndex#getErrors(ToShapeId, ToShapeId)
*/
public List<ShapeId> getErrors(ServiceShape service) {
Set<ShapeId> result = new LinkedHashSet<>(service.getErrors());
result.addAll(getErrors());
Set<ShapeId> result = new LinkedHashSet<>(service.getErrorsSet());
result.addAll(getErrorsSet());
return new ArrayList<>(result);
}

Expand All @@ -200,7 +211,7 @@ public boolean equals(Object other) {
public static final class Builder extends AbstractShapeBuilder<Builder, OperationShape> {
private ShapeId input = UnitTypeTrait.UNIT;
private ShapeId output = UnitTypeTrait.UNIT;
private final BuilderRef<List<ShapeId>> errors = BuilderRef.forList();
private final BuilderRef<Set<ShapeId>> errors = BuilderRef.forOrderedSet();

@Override
public ShapeType getShapeType() {
Expand Down Expand Up @@ -307,7 +318,7 @@ public Builder flattenMixins() {

Set<ShapeId> computedErrors = new LinkedHashSet<>();
for (Shape shape : getMixins().values()) {
shape.asOperationShape().ifPresent(mixin -> computedErrors.addAll(mixin.getErrors()));
shape.asOperationShape().ifPresent(mixin -> computedErrors.addAll(mixin.getErrorsSet()));
}

computedErrors.addAll(errors.peek());
Expand Down
Loading
Loading