Skip to content

Commit 48e1b37

Browse files
committed
Fix logic to ignore instead of throw
1 parent 1b094c0 commit 48e1b37

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

codegen/src/main/java/software/amazon/awssdk/codegen/AddShapes.java

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static software.amazon.awssdk.codegen.internal.Utils.isMapShape;
2222
import static software.amazon.awssdk.codegen.internal.Utils.isScalar;
2323

24+
import java.util.Collections;
2425
import java.util.List;
2526
import java.util.Map;
2627
import java.util.Optional;
@@ -37,10 +38,15 @@
3738
import software.amazon.awssdk.codegen.model.intermediate.VariableModel;
3839
import software.amazon.awssdk.codegen.model.service.Location;
3940
import software.amazon.awssdk.codegen.model.service.Member;
41+
import software.amazon.awssdk.codegen.model.service.Operation;
4042
import software.amazon.awssdk.codegen.model.service.ServiceModel;
4143
import software.amazon.awssdk.codegen.model.service.Shape;
4244
import software.amazon.awssdk.codegen.naming.NamingStrategy;
4345
import software.amazon.awssdk.codegen.utils.ProtocolUtils;
46+
import software.amazon.awssdk.codegen.validation.ModelInvalidException;
47+
import software.amazon.awssdk.codegen.validation.ValidationEntry;
48+
import software.amazon.awssdk.codegen.validation.ValidationErrorId;
49+
import software.amazon.awssdk.codegen.validation.ValidationErrorSeverity;
4450
import software.amazon.awssdk.utils.StringUtils;
4551
import software.amazon.awssdk.utils.Validate;
4652

@@ -349,17 +355,38 @@ private boolean isGreedy(Shape parentShape, Map<String, Shape> allC2jShapes, Par
349355
* Given an input shape, finds the Request URI for the operation that input is referenced from.
350356
* Per the Smithy spec, httpLabel on non-input shapes has no meaning and is ignored,
351357
* so this returns Optional.empty() if the shape is not a direct operation input.
352-
*
353-
* @param parentShape Shape to find operation's request URI for.
354-
* @param allC2jShapes All shapes in the service model.
355-
* @return Request URI for operation, or empty if the shape is not a direct operation input.
358+
* If the shape IS a direct operation input but the operation is missing a requestUri,
359+
* a validation error is thrown.
356360
*/
357361
private Optional<String> findRequestUri(Shape parentShape, Map<String, Shape> allC2jShapes) {
358-
return builder.getService().getOperations().values().stream()
359-
.filter(o -> o.getInput() != null)
360-
.filter(o -> allC2jShapes.get(o.getInput().getShape()).equals(parentShape))
361-
.findFirst()
362-
.map(o -> o.getHttp().getRequestUri());
362+
Optional<Operation> operation = builder.getService().getOperations().values().stream()
363+
.filter(o -> o.getInput() != null)
364+
.filter(o -> allC2jShapes.get(o.getInput().getShape()).equals(parentShape))
365+
.findFirst();
366+
367+
if (!operation.isPresent()) {
368+
// Not a direct operation input shape, should be ignored.
369+
// https://smithy.io/2.0/spec/http-bindings.html#httplabel-is-only-used-on-top-level-input
370+
return Optional.empty();
371+
}
372+
373+
String requestUri = operation.get().getHttp().getRequestUri();
374+
if (requestUri == null) {
375+
String shapeName = allC2jShapes.entrySet().stream()
376+
.filter(e -> e.getValue().equals(parentShape))
377+
.map(Map.Entry::getKey)
378+
.findFirst()
379+
.get();
380+
String detailMsg = "Could not find request URI for input shape '" + shapeName
381+
+ "'. No operation was found that references this shape as its input.";
382+
ValidationEntry entry =
383+
new ValidationEntry().withErrorId(ValidationErrorId.REQUEST_URI_NOT_FOUND)
384+
.withDetailMessage(detailMsg)
385+
.withSeverity(ValidationErrorSeverity.DANGER);
386+
throw ModelInvalidException.builder().validationEntries(Collections.singletonList(entry)).build();
387+
}
388+
389+
return Optional.of(requestUri);
363390
}
364391

365392
private String deriveUnmarshallerLocationName(Shape memberShape, String memberName, Member member) {

0 commit comments

Comments
 (0)