Skip to content

Commit 46481b0

Browse files
committed
Generate GetBucketEncryption PutBucketEncryption and GetBucketAccelerate
1 parent 5c93993 commit 46481b0

File tree

38 files changed

+1852
-1383
lines changed

38 files changed

+1852
-1383
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"core": {
3+
"changeLogMessages": [
4+
"refactor generator to reduce duplication by splitting logic into methods."
5+
],
6+
"type": "patch",
7+
"updateMinimum": true
8+
},
9+
"services": [
10+
{
11+
"serviceName": "S3",
12+
"type": "patch",
13+
"changeLogMessages": [
14+
"Generate GetBucketAccelerate, PutBucketEncryption, GetBucketEncryption."
15+
]
16+
}
17+
]
18+
}

generator/ServiceClientGeneratorLib/Generators/Marshallers/BaseResponseUnmarshaller.tt

Lines changed: 113 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ using Amazon.Runtime.Internal.Util;
387387
protected string DetermineXmlMarshallName(Member member, bool withPrefix = true)
388388
{
389389
var locationName = member.data[ServiceModel.LocationNameKey];
390-
if (locationName == null)
390+
// operation can be null if we're determining the xml marshall name for a structure
391+
if (locationName == null && this.Operation != null)
391392
{
392393
var payload = this.Operation.ResponsePayloadMember;
393394
var shouldMarshallPayload = (payload != null && payload.IsStructure);
@@ -402,12 +403,119 @@ using Amazon.Runtime.Internal.Util;
402403
return colonIndex != -1 ? locationNameString.Substring(colonIndex + 1) : locationNameString;
403404
}
404405
// the locationName and modeled name must only be different for those members which are marshalled on the body.
405-
if (!string.Equals(locationName.ToString(), member.ModeledName, StringComparison.Ordinal) || member.MarshallLocation != MarshallLocation.Body)
406-
{
407-
return locationName.ToString();
408-
}
406+
// S3 / S3 Control don't seem to follow this rule where the location name is used only if it doesn't match the member's name.
407+
if (locationName != null)
408+
{
409+
if (this.Config.ServiceId == "S3" || this.Config.ServiceId == "S3 Control" || !string.Equals(locationName.ToString(), member.ModeledName, StringComparison.Ordinal) || member.MarshallLocation != MarshallLocation.Body)
410+
{
411+
return locationName.ToString();
412+
}
413+
}
414+
415+
// some structure members do not have a locationName.
416+
// so if we get to this point, it is gauranteed that the marshall name we are determining is for a
417+
// member of a structure. For a member of a structure the marshall name is straightforward.
418+
if (locationName == null)
419+
{
420+
return member.MarshallName;
421+
}
409422
var memberTarget = member.Shape.data[ServiceModel.LocationNameKey];
410423

411424
return memberTarget != null ? memberTarget.ToString() : member.Shape.Name;
412425
}
413426
#>
427+
428+
<#+
429+
/// Only to be used by rest-xml response unmarshallers
430+
protected void ProcessResponseBodyOrStructureMembers(Member member, bool isStructure)
431+
{
432+
string unmarshalledVariable = isStructure ? "unmarshalledObject" : "response";
433+
if (member.Shape.IsList)
434+
{
435+
var listMarshallName = member.Shape.ListMarshallName ?? "member";
436+
437+
if (member.IsFlattened || member.Shape.IsFlattened)
438+
{
439+
#>
440+
if (context.TestExpression("<#=DetermineXmlMarshallName(member)#>", targetDepth))
441+
{
442+
if (<#=unmarshalledVariable#>.<#=member.PropertyName#> == null)
443+
{
444+
<#=unmarshalledVariable#>.<#=member.PropertyName#> = new <#=member.DetermineType()#>();
445+
}
446+
var unmarshaller = <#= member.DetermineTypeUnmarshallerInstantiate() #>;
447+
<#=unmarshalledVariable#>.<#=member.PropertyName#>.Add(unmarshaller.Unmarshall(context));
448+
continue;
449+
}
450+
<#+
451+
}
452+
else
453+
{
454+
#>
455+
if (context.TestExpression("<#=DetermineXmlMarshallName(member)#>/<#=listMarshallName#>", targetDepth))
456+
{
457+
if (<#=unmarshalledVariable#>.<#=member.PropertyName#> == null)
458+
{
459+
<#=unmarshalledVariable#>.<#=member.PropertyName#> = new <#=member.DetermineType()#>();
460+
}
461+
var unmarshaller = <#= member.DetermineTypeUnmarshallerInstantiate() #>;
462+
<#=unmarshalledVariable#>.<#=member.PropertyName#>.Add(unmarshaller.Unmarshall(context));
463+
continue;
464+
}
465+
<#+
466+
}
467+
}
468+
else if(member.Shape.IsMap)
469+
{
470+
if(member.IsFlattened)
471+
{
472+
#>
473+
if (context.TestExpression("<#=DetermineXmlMarshallName(member)#>", targetDepth))
474+
{
475+
if (response.<#=member.PropertyName#> == null)
476+
{
477+
response.<#=member.PropertyName#> = new <#=member.DetermineType()#>();
478+
}
479+
var unmarshaller = <#= member.DetermineTypeUnmarshallerInstantiate() #>;
480+
<#=unmarshalledVariable#>.<#=member.PropertyName#>.Add(unmarshaller.Unmarshall(context));
481+
continue;
482+
}
483+
<#+
484+
}
485+
else
486+
{
487+
#>
488+
if (context.TestExpression("<#=DetermineXmlMarshallName(member)#>", targetDepth))
489+
{
490+
var unmarshaller = <#= member.DetermineTypeUnmarshallerInstantiate() #>;
491+
<#=unmarshalledVariable#>.<#=member.PropertyName#> = unmarshaller.Unmarshall(context);
492+
continue;
493+
}
494+
<#+
495+
}
496+
}
497+
else
498+
{
499+
if (!member.IsXmlAttribute)
500+
{
501+
#>
502+
if (context.TestExpression("<#=DetermineXmlMarshallName(member)#>", targetDepth))
503+
<#+
504+
}
505+
else
506+
{
507+
#>
508+
if (context.TestExpression("@<#=DetermineXmlMarshallName(member, false)#>", targetDepth - 1))
509+
510+
<#+
511+
}
512+
#>
513+
{
514+
var unmarshaller = <#= member.DetermineTypeUnmarshallerInstantiate() #>;
515+
<#=unmarshalledVariable#>.<#=member.PropertyName#> = unmarshaller.Unmarshall(context);
516+
continue;
517+
}
518+
<#+
519+
}
520+
}
521+
#>

generator/ServiceClientGeneratorLib/Generators/Marshallers/RestXmlRequestMarshaller.tt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ WriteXmlAttributeString(level + 1, member, variableName, isPayload: true, operat
416416

417417
// Use shape's ListMarshallName if the structure is a list.
418418
var marshallName = member.Shape.IsList ? member.Shape.ListMarshallName ?? "member" : member.MarshallName;
419-
if(member.IsFlattened)
419+
if(member.Shape.IsFlattened || member.IsFlattened)
420420
marshallName = member.LocationName ?? member.ModeledName;
421421
#>
422422
<#=new string(' ', level * 4)#> if (<#=variableName#> != null)
@@ -440,7 +440,7 @@ WriteXmlAttributeString(level + 1, member, variableName, isPayload: true, operat
440440
<#=new string(' ', level * 4)#> if (<#=listVariable#> != null && (<#=listVariable#>.Count > 0 || !AWSConfigs.InitializeCollections))
441441
<#=new string(' ', level * 4)#> {
442442
<#+
443-
if (!member.IsFlattened)
443+
if (!member.IsFlattened && !member.Shape.IsFlattened)
444444
{
445445
if (string.IsNullOrEmpty(member.XmlNamespace))
446446
{
@@ -543,7 +543,7 @@ WriteXmlAttributeString(level + 1, member, variableName, isPayload: true, operat
543543
#>
544544
<#=new string(' ', level * 4)#> }
545545
<#+
546-
if (!member.IsFlattened)
546+
if (!member.IsFlattened && !member.Shape.IsFlattened)
547547
{
548548
#>
549549
<#=new string(' ', level * 4)#> xmlWriter.WriteEndElement();

generator/ServiceClientGeneratorLib/Generators/Marshallers/RestXmlResponseUnmarshaller.tt

Lines changed: 2 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -135,106 +135,12 @@ namespace <#=this.Config.Namespace #>.Model.Internal.MarshallTransformations
135135
<#
136136
foreach (var member in this.Operation.ResponseBodyMembers)
137137
{
138-
if (member.Shape.IsList)
139-
{
140-
var listMarshallName = member.Shape.ListMarshallName ?? "member";
141-
142-
if (member.IsFlattened || member.Shape.IsFlattened)
143-
{
144-
#>
145-
if (context.TestExpression("<#=DetermineXmlMarshallName(member)#>", targetDepth))
146-
{
147-
if (response.<#=member.PropertyName#> == null)
148-
{
149-
response.<#=member.PropertyName#> = new <#=member.DetermineType()#>();
150-
}
151-
var unmarshaller = <#= member.DetermineTypeUnmarshallerInstantiate() #>;
152-
response.<#=member.PropertyName#>.Add(unmarshaller.Unmarshall(context));
153-
continue;
154-
}
155-
<#
156-
}
157-
158-
159-
else
160-
{
161-
#>
162-
if (context.TestExpression("<#=DetermineXmlMarshallName(member)#>/<#=listMarshallName#>", targetDepth))
163-
{
164-
if (response.<#=member.PropertyName#> == null)
165-
{
166-
response.<#=member.PropertyName#> = new <#=member.DetermineType()#>();
167-
}
168-
var unmarshaller = <#= member.DetermineTypeUnmarshallerInstantiate() #>;
169-
response.<#=member.PropertyName#>.Add(unmarshaller.Unmarshall(context));
170-
continue;
171-
}
172-
<#
173-
}
174-
}
175-
else if(member.Shape.IsMap)
176-
{
177-
if(member.IsFlattened)
178-
{
179-
#>
180-
if (context.TestExpression("<#=DetermineXmlMarshallName(member)#>", targetDepth))
181-
{
182-
if (response.<#=member.PropertyName#> == null)
183-
{
184-
response.<#=member.PropertyName#> = new <#=member.DetermineType()#>();
185-
}
186-
var unmarshaller = <#= member.DetermineTypeUnmarshallerInstantiate() #>;
187-
response.<#=member.PropertyName#>.Add(unmarshaller.Unmarshall(context));
188-
continue;
189-
}
190-
<#
191-
}
192-
else
193-
{
194-
#>
195-
if (context.TestExpression("<#=DetermineXmlMarshallName(member)#>", targetDepth))
196-
{
197-
var unmarshaller = <#= member.DetermineTypeUnmarshallerInstantiate() #>;
198-
response.<#=member.PropertyName#> = unmarshaller.Unmarshall(context);
199-
continue;
200-
}
201-
<#
202-
}
203-
}
204-
else
205-
{
206-
if (!member.IsXmlAttribute)
207-
{
208-
#>
209-
if (context.TestExpression("<#=DetermineXmlMarshallName(member)#>", targetDepth))
210-
<#
211-
}
212-
else
213-
{
214-
#>
215-
if (context.TestExpression("@<#=DetermineXmlMarshallName(member, false)#>", targetDepth - 1))
216-
<#
217-
}
218-
#>
219-
{
220-
var unmarshaller = <#= member.DetermineTypeUnmarshallerInstantiate() #>;
221-
response.<#=member.PropertyName#> = unmarshaller.Unmarshall(context);
222-
continue;
223-
}
224-
<#
225-
}
138+
ProcessResponseBodyOrStructureMembers(member, false);
226139
}
227140

228141
if (shouldMarshallPayload)
229142
{
230-
#>
231-
if (context.TestExpression("<#=DetermineXmlMarshallName(payload)#>", targetDepth))
232-
{
233-
var unmarshaller = <#=payload.DetermineTypeUnmarshallerInstantiate()#>;
234-
response.<#=payload.PropertyName#> = unmarshaller.Unmarshall(context);
235-
continue;
236-
}
237-
<#
143+
ProcessResponseBodyOrStructureMembers(payload, false);
238144
}
239145
#>
240146
}

generator/ServiceClientGeneratorLib/Generators/Marshallers/RestXmlStructureUnmarshaller.tt

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -70,44 +70,9 @@ namespace <#=this.Config.Namespace #>.Model.Internal.MarshallTransformations
7070
// For every member, generate code to add the unmarshalled member to the response object
7171
foreach (var member in this.Structure.Members)
7272
{
73-
if(member.Shape.IsList)
74-
{
75-
var listMarshallName = member.Shape.ListMarshallName ?? "member";
73+
ProcessResponseBodyOrStructureMembers(member, true);
7674
#>
77-
if (context.TestExpression("<#=member.MarshallName#>/<#=listMarshallName#>", targetDepth))
78-
{
79-
if (unmarshalledObject.<#=member.PropertyName#> == null)
80-
{
81-
unmarshalledObject.<#=member.PropertyName#> = new <#=member.DetermineType()#>();
82-
}
83-
var unmarshaller = <#= member.DetermineTypeUnmarshallerInstantiate() #>;
84-
unmarshalledObject.<#=member.PropertyName#>.Add(unmarshaller.Unmarshall(context));
85-
continue;
86-
}
8775
<#
88-
}
89-
else
90-
{
91-
if(!member.IsXmlAttribute)
92-
{
93-
#>
94-
if (context.TestExpression("<#=member.MarshallName#>", targetDepth))
95-
<#
96-
}
97-
else
98-
{
99-
#>
100-
if (context.TestExpression("@<#=DetermineXmlMarshallName(member, false)#>", targetDepth - 1))
101-
<#
102-
}
103-
#>
104-
{
105-
var unmarshaller = <#= member.DetermineTypeUnmarshallerInstantiate() #>;
106-
unmarshalledObject.<#=member.PropertyName#> = unmarshaller.Unmarshall(context);
107-
continue;
108-
}
109-
<#
110-
}
11176
}
11277
}
11378
#>

generator/ServiceClientGeneratorLib/ServiceModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,9 @@ public List<Operation> S3AllowListOperations
480480
new Operation(this, "DeleteBucketReplication", DocumentRoot[OperationsKey]["DeleteBucketReplication"]),
481481
new Operation(this, "DeleteBucketTagging", DocumentRoot[OperationsKey]["DeleteBucketTagging"]),
482482
new Operation(this, "DeletePublicAccessBlock", DocumentRoot[OperationsKey]["DeletePublicAccessBlock"]),
483-
//new Operation(this, "GetBucketAccelerateConfiguration", DocumentRoot[OperationsKey]["GetBucketAccelerateConfiguration"]),
483+
new Operation(this, "GetBucketAccelerateConfiguration", DocumentRoot[OperationsKey]["GetBucketAccelerateConfiguration"]),
484484
//new Operation(this, "GetBucketAnalyticsConfiguration", DocumentRoot[OperationsKey]["GetBucketAnalyticsConfiguration"]),
485-
//new Operation(this, "GetBucketEncryption", DocumentRoot[OperationsKey]["GetBucketEncryption"]),
485+
new Operation(this, "GetBucketEncryption", DocumentRoot[OperationsKey]["GetBucketEncryption"]),
486486
//new Operation(this, "GetBucketIntelligentTieringConfiguration", DocumentRoot[OperationsKey]["GetBucketIntelligentTieringConfiguration"]),
487487
//new Operation(this, "GetBucketInventoryConfiguration", DocumentRoot[OperationsKey]["GetBucketInventoryConfiguration"]),
488488
//new Operation(this, "GetBucketLocation", DocumentRoot[OperationsKey]["GetBucketLocation"]),
@@ -512,7 +512,7 @@ public List<Operation> S3AllowListOperations
512512
new Operation(this, "ListDirectoryBuckets", DocumentRoot[OperationsKey]["ListDirectoryBuckets"]),
513513
//new Operation(this, "ListParts", DocumentRoot[OperationsKey]["ListParts"]),
514514
//new Operation(this, "PutBucketAccelerateConfiguration", DocumentRoot[OperationsKey]["PutBucketAccelerateConfiguration"]),
515-
//new Operation(this, "PutBucketEncryption", DocumentRoot[OperationsKey]["PutBucketEncryption"]),
515+
new Operation(this, "PutBucketEncryption", DocumentRoot[OperationsKey]["PutBucketEncryption"]),
516516
//new Operation(this, "PutBucketPolicy", DocumentRoot[OperationsKey]["PutBucketPolicy"]),
517517
//new Operation(this, "PutObjectLegalHold", DocumentRoot[OperationsKey]["PutObjectLegalHold"]),
518518
//new Operation(this, "PutObjectLockConfiguration", DocumentRoot[OperationsKey]["PutObjectLockConfiguration"]),

0 commit comments

Comments
 (0)