Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.

Commit ec1e843

Browse files
authored
private/mode/api: Update SDK to require URI path members not be empty (#2323)
Updates the SDK's validation to require that members serialized to URI path must not have empty (zero length) values. Generally these fields are modeled as required, but not always. Fixing this will prevent bugs with REST URI paths requests made for unexpected resources.
1 parent 1cc07f1 commit ec1e843

File tree

52 files changed

+2987
-38
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2987
-38
lines changed

models/protocol_tests/input/rest-xml.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,6 +1754,9 @@
17541754
"shapes": {
17551755
"InputShape": {
17561756
"type": "structure",
1757+
"required": [
1758+
"URIFooEnum"
1759+
],
17571760
"members": {
17581761
"HeaderEnum": {
17591762
"shape": "EnumType",
@@ -1824,14 +1827,15 @@
18241827
},
18251828
"http": {
18261829
"method": "POST",
1827-
"requestUri": "/path"
1830+
"requestUri": "/Enum/{URIEnum}"
18281831
},
18291832
"name": "OperationName"
18301833
},
18311834
"params": {
1835+
"URIFooEnum": "bar"
18321836
},
18331837
"serialized": {
1834-
"uri": "/path",
1838+
"uri": "/Enum/bar",
18351839
"headers": {}
18361840
}
18371841
}

private/model/api/shape.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,13 @@ type Shape struct {
117117

118118
// CanBeEmpty returns if the shape value can sent request as an empty value.
119119
// String, blob, list, and map are types must not be empty when the member is
120-
// decorated with HostLabel.
120+
// serialized to the uri path, or decorated with HostLabel.
121121
func (ref *ShapeRef) CanBeEmpty() bool {
122122
switch ref.Shape.Type {
123123
case "string":
124-
return !ref.HostLabel
124+
return !(ref.Location == "uri" || ref.HostLabel)
125+
case "blob", "map", "list":
126+
return !(ref.Location == "uri")
125127
default:
126128
return true
127129
}
@@ -796,7 +798,7 @@ func (s *Shape) IsEnum() bool {
796798
}
797799

798800
// IsRequired returns if member is a required field. Required fields are fields
799-
// marked as required, or hostLabels.
801+
// marked as required, hostLabels, or location of uri path.
800802
func (s *Shape) IsRequired(member string) bool {
801803
ref, ok := s.MemberRefs[member]
802804
if !ok {
@@ -805,7 +807,7 @@ func (s *Shape) IsRequired(member string) bool {
805807
s.ShapeName, member,
806808
))
807809
}
808-
if ref.HostLabel {
810+
if ref.Location == "uri" || ref.HostLabel {
809811
return true
810812
}
811813
for _, n := range s.Required {

private/protocol/restjson/build_test.go

Lines changed: 132 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,24 @@ func (c *InputService2ProtocolTest) InputService2TestCaseOperation1WithContext(c
317317
type InputService2TestShapeInputService2TestCaseOperation1Input struct {
318318
_ struct{} `type:"structure"`
319319

320-
PipelineId *string `location:"uri" type:"string"`
320+
// PipelineId is a required field
321+
PipelineId *string `location:"uri" type:"string" required:"true"`
322+
}
323+
324+
// Validate inspects the fields of the type to determine if they are valid.
325+
func (s *InputService2TestShapeInputService2TestCaseOperation1Input) Validate() error {
326+
invalidParams := request.ErrInvalidParams{Context: "InputService2TestShapeInputService2TestCaseOperation1Input"}
327+
if s.PipelineId == nil {
328+
invalidParams.Add(request.NewErrParamRequired("PipelineId"))
329+
}
330+
if s.PipelineId != nil && len(*s.PipelineId) < 1 {
331+
invalidParams.Add(request.NewErrParamMinLen("PipelineId", 1))
332+
}
333+
334+
if invalidParams.Len() > 0 {
335+
return invalidParams
336+
}
337+
return nil
321338
}
322339

323340
// SetPipelineId sets the PipelineId field's value.
@@ -464,7 +481,24 @@ func (c *InputService3ProtocolTest) InputService3TestCaseOperation1WithContext(c
464481
type InputService3TestShapeInputService3TestCaseOperation1Input struct {
465482
_ struct{} `type:"structure"`
466483

467-
Foo *string `location:"uri" locationName:"PipelineId" type:"string"`
484+
// Foo is a required field
485+
Foo *string `location:"uri" locationName:"PipelineId" type:"string" required:"true"`
486+
}
487+
488+
// Validate inspects the fields of the type to determine if they are valid.
489+
func (s *InputService3TestShapeInputService3TestCaseOperation1Input) Validate() error {
490+
invalidParams := request.ErrInvalidParams{Context: "InputService3TestShapeInputService3TestCaseOperation1Input"}
491+
if s.Foo == nil {
492+
invalidParams.Add(request.NewErrParamRequired("Foo"))
493+
}
494+
if s.Foo != nil && len(*s.Foo) < 1 {
495+
invalidParams.Add(request.NewErrParamMinLen("Foo", 1))
496+
}
497+
498+
if invalidParams.Len() > 0 {
499+
return invalidParams
500+
}
501+
return nil
468502
}
469503

470504
// SetFoo sets the Foo field's value.
@@ -758,11 +792,28 @@ func (c *InputService5ProtocolTest) InputService5TestCaseOperation1WithContext(c
758792
type InputService5TestShapeInputService5TestCaseOperation1Input struct {
759793
_ struct{} `type:"structure"`
760794

761-
PipelineId *string `location:"uri" type:"string"`
795+
// PipelineId is a required field
796+
PipelineId *string `location:"uri" type:"string" required:"true"`
762797

763798
QueryDoc map[string]*string `location:"querystring" type:"map"`
764799
}
765800

801+
// Validate inspects the fields of the type to determine if they are valid.
802+
func (s *InputService5TestShapeInputService5TestCaseOperation1Input) Validate() error {
803+
invalidParams := request.ErrInvalidParams{Context: "InputService5TestShapeInputService5TestCaseOperation1Input"}
804+
if s.PipelineId == nil {
805+
invalidParams.Add(request.NewErrParamRequired("PipelineId"))
806+
}
807+
if s.PipelineId != nil && len(*s.PipelineId) < 1 {
808+
invalidParams.Add(request.NewErrParamMinLen("PipelineId", 1))
809+
}
810+
811+
if invalidParams.Len() > 0 {
812+
return invalidParams
813+
}
814+
return nil
815+
}
816+
766817
// SetPipelineId sets the PipelineId field's value.
767818
func (s *InputService5TestShapeInputService5TestCaseOperation1Input) SetPipelineId(v string) *InputService5TestShapeInputService5TestCaseOperation1Input {
768819
s.PipelineId = &v
@@ -913,11 +964,28 @@ func (c *InputService6ProtocolTest) InputService6TestCaseOperation1WithContext(c
913964
type InputService6TestShapeInputService6TestCaseOperation1Input struct {
914965
_ struct{} `type:"structure"`
915966

916-
PipelineId *string `location:"uri" type:"string"`
967+
// PipelineId is a required field
968+
PipelineId *string `location:"uri" type:"string" required:"true"`
917969

918970
QueryDoc map[string][]*string `location:"querystring" type:"map"`
919971
}
920972

973+
// Validate inspects the fields of the type to determine if they are valid.
974+
func (s *InputService6TestShapeInputService6TestCaseOperation1Input) Validate() error {
975+
invalidParams := request.ErrInvalidParams{Context: "InputService6TestShapeInputService6TestCaseOperation1Input"}
976+
if s.PipelineId == nil {
977+
invalidParams.Add(request.NewErrParamRequired("PipelineId"))
978+
}
979+
if s.PipelineId != nil && len(*s.PipelineId) < 1 {
980+
invalidParams.Add(request.NewErrParamMinLen("PipelineId", 1))
981+
}
982+
983+
if invalidParams.Len() > 0 {
984+
return invalidParams
985+
}
986+
return nil
987+
}
988+
921989
// SetPipelineId sets the PipelineId field's value.
922990
func (s *InputService6TestShapeInputService6TestCaseOperation1Input) SetPipelineId(v string) *InputService6TestShapeInputService6TestCaseOperation1Input {
923991
s.PipelineId = &v
@@ -1306,7 +1374,24 @@ type InputService8TestShapeInputService8TestCaseOperation1Input struct {
13061374

13071375
PageToken *string `location:"querystring" locationName:"PageToken" type:"string"`
13081376

1309-
PipelineId *string `location:"uri" locationName:"PipelineId" type:"string"`
1377+
// PipelineId is a required field
1378+
PipelineId *string `location:"uri" locationName:"PipelineId" type:"string" required:"true"`
1379+
}
1380+
1381+
// Validate inspects the fields of the type to determine if they are valid.
1382+
func (s *InputService8TestShapeInputService8TestCaseOperation1Input) Validate() error {
1383+
invalidParams := request.ErrInvalidParams{Context: "InputService8TestShapeInputService8TestCaseOperation1Input"}
1384+
if s.PipelineId == nil {
1385+
invalidParams.Add(request.NewErrParamRequired("PipelineId"))
1386+
}
1387+
if s.PipelineId != nil && len(*s.PipelineId) < 1 {
1388+
invalidParams.Add(request.NewErrParamMinLen("PipelineId", 1))
1389+
}
1390+
1391+
if invalidParams.Len() > 0 {
1392+
return invalidParams
1393+
}
1394+
return nil
13101395
}
13111396

13121397
// SetAscending sets the Ascending field's value.
@@ -1471,7 +1556,24 @@ type InputService9TestShapeInputService9TestCaseOperation1Input struct {
14711556

14721557
PageToken *string `location:"querystring" locationName:"PageToken" type:"string"`
14731558

1474-
PipelineId *string `location:"uri" locationName:"PipelineId" type:"string"`
1559+
// PipelineId is a required field
1560+
PipelineId *string `location:"uri" locationName:"PipelineId" type:"string" required:"true"`
1561+
}
1562+
1563+
// Validate inspects the fields of the type to determine if they are valid.
1564+
func (s *InputService9TestShapeInputService9TestCaseOperation1Input) Validate() error {
1565+
invalidParams := request.ErrInvalidParams{Context: "InputService9TestShapeInputService9TestCaseOperation1Input"}
1566+
if s.PipelineId == nil {
1567+
invalidParams.Add(request.NewErrParamRequired("PipelineId"))
1568+
}
1569+
if s.PipelineId != nil && len(*s.PipelineId) < 1 {
1570+
invalidParams.Add(request.NewErrParamMinLen("PipelineId", 1))
1571+
}
1572+
1573+
if invalidParams.Len() > 0 {
1574+
return invalidParams
1575+
}
1576+
return nil
14751577
}
14761578

14771579
// SetAscending sets the Ascending field's value.
@@ -1664,7 +1766,24 @@ type InputService10TestShapeInputService10TestCaseOperation1Input struct {
16641766

16651767
PageToken *string `location:"querystring" locationName:"PageToken" type:"string"`
16661768

1667-
PipelineId *string `location:"uri" locationName:"PipelineId" type:"string"`
1769+
// PipelineId is a required field
1770+
PipelineId *string `location:"uri" locationName:"PipelineId" type:"string" required:"true"`
1771+
}
1772+
1773+
// Validate inspects the fields of the type to determine if they are valid.
1774+
func (s *InputService10TestShapeInputService10TestCaseOperation1Input) Validate() error {
1775+
invalidParams := request.ErrInvalidParams{Context: "InputService10TestShapeInputService10TestCaseOperation1Input"}
1776+
if s.PipelineId == nil {
1777+
invalidParams.Add(request.NewErrParamRequired("PipelineId"))
1778+
}
1779+
if s.PipelineId != nil && len(*s.PipelineId) < 1 {
1780+
invalidParams.Add(request.NewErrParamMinLen("PipelineId", 1))
1781+
}
1782+
1783+
if invalidParams.Len() > 0 {
1784+
return invalidParams
1785+
}
1786+
return nil
16681787
}
16691788

16701789
// SetAscending sets the Ascending field's value.
@@ -1869,6 +1988,9 @@ func (s *InputService11TestShapeInputService11TestCaseOperation1Input) Validate(
18691988
if s.VaultName == nil {
18701989
invalidParams.Add(request.NewErrParamRequired("VaultName"))
18711990
}
1991+
if s.VaultName != nil && len(*s.VaultName) < 1 {
1992+
invalidParams.Add(request.NewErrParamMinLen("VaultName", 1))
1993+
}
18721994

18731995
if invalidParams.Len() > 0 {
18741996
return invalidParams
@@ -2045,6 +2167,9 @@ func (s *InputService12TestShapeInputService12TestCaseOperation1Input) Validate(
20452167
if s.Foo == nil {
20462168
invalidParams.Add(request.NewErrParamRequired("Foo"))
20472169
}
2170+
if s.Foo != nil && len(*s.Foo) < 1 {
2171+
invalidParams.Add(request.NewErrParamMinLen("Foo", 1))
2172+
}
20482173

20492174
if invalidParams.Len() > 0 {
20502175
return invalidParams

0 commit comments

Comments
 (0)