2121import static software .amazon .awssdk .codegen .internal .Utils .isMapShape ;
2222import static software .amazon .awssdk .codegen .internal .Utils .isScalar ;
2323
24- import java .util .Collections ;
2524import java .util .List ;
2625import java .util .Map ;
2726import java .util .Optional ;
3837import software .amazon .awssdk .codegen .model .intermediate .VariableModel ;
3938import software .amazon .awssdk .codegen .model .service .Location ;
4039import software .amazon .awssdk .codegen .model .service .Member ;
41- import software .amazon .awssdk .codegen .model .service .Operation ;
4240import software .amazon .awssdk .codegen .model .service .ServiceModel ;
4341import software .amazon .awssdk .codegen .model .service .Shape ;
4442import software .amazon .awssdk .codegen .naming .NamingStrategy ;
4543import 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 ;
5044import software .amazon .awssdk .utils .StringUtils ;
5145import software .amazon .awssdk .utils .Validate ;
5246
@@ -342,9 +336,9 @@ private boolean isRequiredMember(String memberName, Shape memberShape) {
342336 */
343337 private boolean isGreedy (Shape parentShape , Map <String , Shape > allC2jShapes , ParameterHttpMapping mapping ) {
344338 if (mapping .getLocation () == Location .URI ) {
345- // If the location is URI we can assume the parent shape is an input shape.
346- String requestUri = findRequestUri ( parentShape , allC2jShapes );
347- if ( requestUri .contains (String .format ("{%s+}" , mapping .getMarshallLocationName ()))) {
339+ Optional < String > requestUri = findRequestUri ( parentShape , allC2jShapes );
340+ if ( requestUri . isPresent ()
341+ && requestUri . get () .contains (String .format ("{%s+}" , mapping .getMarshallLocationName ()))) {
348342 return true ;
349343 }
350344 }
@@ -353,33 +347,19 @@ private boolean isGreedy(Shape parentShape, Map<String, Shape> allC2jShapes, Par
353347
354348 /**
355349 * Given an input shape, finds the Request URI for the operation that input is referenced from.
350+ * Per the Smithy spec, httpLabel on non-input shapes has no meaning and is ignored,
351+ * so this returns Optional.empty() if the shape is not a direct operation input.
356352 *
357- * @param parentShape Input shape to find operation's request URI for.
353+ * @param parentShape Shape to find operation's request URI for.
358354 * @param allC2jShapes All shapes in the service model.
359- * @return Request URI for operation.
360- * @throws RuntimeException If operation can't be found.
355+ * @return Request URI for operation, or empty if the shape is not a direct operation input.
361356 */
362- private String findRequestUri (Shape parentShape , Map <String , Shape > allC2jShapes ) {
363- Optional <Operation > operation = builder .getService ().getOperations ().values ().stream ()
364- .filter (o -> o .getInput () != null )
365- .filter (o -> allC2jShapes .get (o .getInput ().getShape ()).equals (parentShape ))
366- .findFirst ();
367-
368- return operation .map (o -> o .getHttp ().getRequestUri ())
369- .orElseThrow (() -> {
370- String shapeName = allC2jShapes .entrySet ().stream ()
371- .filter (e -> e .getValue ().equals (parentShape ))
372- .map (Map .Entry ::getKey )
373- .findFirst ()
374- .orElse ("unknown" );
375- String detailMsg = "Could not find request URI for input shape '" + shapeName
376- + "'. No operation was found that references this shape as its input." ;
377- ValidationEntry entry =
378- new ValidationEntry ().withErrorId (ValidationErrorId .REQUEST_URI_NOT_FOUND )
379- .withDetailMessage (detailMsg )
380- .withSeverity (ValidationErrorSeverity .DANGER );
381- return ModelInvalidException .builder ().validationEntries (Collections .singletonList (entry )).build ();
382- });
357+ 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 ());
383363 }
384364
385365 private String deriveUnmarshallerLocationName (Shape memberShape , String memberName , Member member ) {
0 commit comments