Skip to content

Commit e7f2ce7

Browse files
committed
Fix comments 2
1 parent d0daa36 commit e7f2ce7

3 files changed

Lines changed: 122 additions & 3 deletions

File tree

codegen/src/test/java/software/amazon/awssdk/codegen/CodeGeneratorTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ void execute_uriLocationOnNonInputShape_isIgnored() throws IOException {
202202
assertThat(nestedShape.findMemberModelByC2jName("pageSize").getHttp().isGreedy()).isFalse();
203203
assertThat(nestedShape.findMemberModelByC2jName("headerParam").getHttp().getLocation()).isNull();
204204
assertThat(nestedShape.findMemberModelByC2jName("queryParam").getHttp().getLocation()).isNull();
205+
assertThat(nestedShape.findMemberModelByC2jName("prefixHeaders").getHttp().getLocation()).isNull();
206+
207+
ShapeModel sharedShape = intermediateModel.getShapes().get("SharedShapeOperationRequest");
208+
assertThat(sharedShape.findMemberModelByC2jName("sharedId").getHttp().getLocation()).isEqualTo(Location.URI);
205209

206210
Path generatedNestedOptions = Files.walk(outputDir)
207211
.filter(p -> p.getFileName().toString().equals("NestedOptions.java"))

codegen/src/test/resources/software/amazon/awssdk/codegen/expected-nested-options.java

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
import software.amazon.awssdk.core.protocol.MarshallLocation;
3232
import software.amazon.awssdk.core.protocol.MarshallingType;
3333
import software.amazon.awssdk.core.traits.LocationTrait;
34+
import software.amazon.awssdk.core.traits.MapTrait;
35+
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructMap;
36+
import software.amazon.awssdk.core.util.SdkAutoConstructMap;
3437
import software.amazon.awssdk.utils.ToString;
3538
import software.amazon.awssdk.utils.builder.CopyableBuilder;
3639
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
@@ -52,8 +55,22 @@ public final class NestedOptions implements SdkPojo, Serializable, ToCopyableBui
5255
.memberName("queryParam").getter(getter(NestedOptions::queryParam)).setter(setter(Builder::queryParam))
5356
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("nestedQuery").build()).build();
5457

58+
private static final SdkField<Map<String, String>> PREFIX_HEADERS_FIELD = SdkField
59+
.<Map<String, String>> builder(MarshallingType.MAP)
60+
.memberName("prefixHeaders")
61+
.getter(getter(NestedOptions::prefixHeaders))
62+
.setter(setter(Builder::prefixHeaders))
63+
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("x-amz-prefix-").build(),
64+
MapTrait.builder()
65+
.keyLocationName("key")
66+
.valueLocationName("value")
67+
.valueFieldInfo(
68+
SdkField.<String> builder(MarshallingType.STRING)
69+
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
70+
.locationName("value").build()).build()).build()).build();
71+
5572
private static final List<SdkField<?>> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(PAGE_SIZE_FIELD,
56-
HEADER_PARAM_FIELD, QUERY_PARAM_FIELD));
73+
HEADER_PARAM_FIELD, QUERY_PARAM_FIELD, PREFIX_HEADERS_FIELD));
5774

5875
private static final Map<String, SdkField<?>> SDK_NAME_TO_FIELD = memberNameToFieldInitializer();
5976

@@ -65,10 +82,13 @@ public final class NestedOptions implements SdkPojo, Serializable, ToCopyableBui
6582

6683
private final String queryParam;
6784

85+
private final Map<String, String> prefixHeaders;
86+
6887
private NestedOptions(BuilderImpl builder) {
6988
this.pageSize = builder.pageSize;
7089
this.headerParam = builder.headerParam;
7190
this.queryParam = builder.queryParam;
91+
this.prefixHeaders = builder.prefixHeaders;
7292
}
7393

7494
/**
@@ -98,6 +118,34 @@ public final String queryParam() {
98118
return queryParam;
99119
}
100120

121+
/**
122+
* For responses, this returns true if the service returned a value for the PrefixHeaders property. This DOES NOT
123+
* check that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property).
124+
* This is useful because the SDK will never return a null collection or map, but you may need to differentiate
125+
* between the service returning nothing (or null) and the service returning an empty collection or map. For
126+
* requests, this returns true if a value for the property was specified in the request builder, and false if a
127+
* value was not specified.
128+
*/
129+
public final boolean hasPrefixHeaders() {
130+
return prefixHeaders != null && !(prefixHeaders instanceof SdkAutoConstructMap);
131+
}
132+
133+
/**
134+
* Returns the value of the PrefixHeaders property for this object.
135+
* <p>
136+
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
137+
* </p>
138+
* <p>
139+
* This method will never return null. If you would like to know whether the service returned this field (so that
140+
* you can differentiate between null and empty), you can use the {@link #hasPrefixHeaders} method.
141+
* </p>
142+
*
143+
* @return The value of the PrefixHeaders property for this object.
144+
*/
145+
public final Map<String, String> prefixHeaders() {
146+
return prefixHeaders;
147+
}
148+
101149
@Override
102150
public Builder toBuilder() {
103151
return new BuilderImpl(this);
@@ -117,6 +165,7 @@ public final int hashCode() {
117165
hashCode = 31 * hashCode + Objects.hashCode(pageSize());
118166
hashCode = 31 * hashCode + Objects.hashCode(headerParam());
119167
hashCode = 31 * hashCode + Objects.hashCode(queryParam());
168+
hashCode = 31 * hashCode + Objects.hashCode(hasPrefixHeaders() ? prefixHeaders() : null);
120169
return hashCode;
121170
}
122171

@@ -138,7 +187,8 @@ public final boolean equalsBySdkFields(Object obj) {
138187
}
139188
NestedOptions other = (NestedOptions) obj;
140189
return Objects.equals(pageSize(), other.pageSize()) && Objects.equals(headerParam(), other.headerParam())
141-
&& Objects.equals(queryParam(), other.queryParam());
190+
&& Objects.equals(queryParam(), other.queryParam()) && hasPrefixHeaders() == other.hasPrefixHeaders()
191+
&& Objects.equals(prefixHeaders(), other.prefixHeaders());
142192
}
143193

144194
/**
@@ -148,7 +198,7 @@ public final boolean equalsBySdkFields(Object obj) {
148198
@Override
149199
public final String toString() {
150200
return ToString.builder("NestedOptions").add("PageSize", pageSize()).add("HeaderParam", headerParam())
151-
.add("QueryParam", queryParam()).build();
201+
.add("QueryParam", queryParam()).add("PrefixHeaders", hasPrefixHeaders() ? prefixHeaders() : null).build();
152202
}
153203

154204
public final <T> Optional<T> getValueForField(String fieldName, Class<T> clazz) {
@@ -159,6 +209,8 @@ public final <T> Optional<T> getValueForField(String fieldName, Class<T> clazz)
159209
return Optional.ofNullable(clazz.cast(headerParam()));
160210
case "queryParam":
161211
return Optional.ofNullable(clazz.cast(queryParam()));
212+
case "prefixHeaders":
213+
return Optional.ofNullable(clazz.cast(prefixHeaders()));
162214
default:
163215
return Optional.empty();
164216
}
@@ -179,6 +231,7 @@ private static Map<String, SdkField<?>> memberNameToFieldInitializer() {
179231
map.put("pageSize", PAGE_SIZE_FIELD);
180232
map.put("x-amz-nested-header", HEADER_PARAM_FIELD);
181233
map.put("nestedQuery", QUERY_PARAM_FIELD);
234+
map.put("x-amz-prefix-", PREFIX_HEADERS_FIELD);
182235
return Collections.unmodifiableMap(map);
183236
}
184237

@@ -219,6 +272,15 @@ public interface Builder extends SdkPojo, CopyableBuilder<Builder, NestedOptions
219272
* @return Returns a reference to this object so that method calls can be chained together.
220273
*/
221274
Builder queryParam(String queryParam);
275+
276+
/**
277+
* Sets the value of the PrefixHeaders property for this object.
278+
*
279+
* @param prefixHeaders
280+
* The new value for the PrefixHeaders property for this object.
281+
* @return Returns a reference to this object so that method calls can be chained together.
282+
*/
283+
Builder prefixHeaders(Map<String, String> prefixHeaders);
222284
}
223285

224286
static final class BuilderImpl implements Builder {
@@ -228,13 +290,16 @@ static final class BuilderImpl implements Builder {
228290

229291
private String queryParam;
230292

293+
private Map<String, String> prefixHeaders = DefaultSdkAutoConstructMap.getInstance();
294+
231295
private BuilderImpl() {
232296
}
233297

234298
private BuilderImpl(NestedOptions model) {
235299
pageSize(model.pageSize);
236300
headerParam(model.headerParam);
237301
queryParam(model.queryParam);
302+
prefixHeaders(model.prefixHeaders);
238303
}
239304

240305
public final String getPageSize() {
@@ -279,6 +344,23 @@ public final Builder queryParam(String queryParam) {
279344
return this;
280345
}
281346

347+
public final Map<String, String> getPrefixHeaders() {
348+
if (prefixHeaders instanceof SdkAutoConstructMap) {
349+
return null;
350+
}
351+
return prefixHeaders;
352+
}
353+
354+
public final void setPrefixHeaders(Map<String, String> prefixHeaders) {
355+
this.prefixHeaders = MapOfStringsCopier.copy(prefixHeaders);
356+
}
357+
358+
@Override
359+
public final Builder prefixHeaders(Map<String, String> prefixHeaders) {
360+
this.prefixHeaders = MapOfStringsCopier.copy(prefixHeaders);
361+
return this;
362+
}
363+
282364
@Override
283365
public NestedOptions build() {
284366
return new NestedOptions(this);

codegen/src/test/resources/software/amazon/awssdk/codegen/uri-on-non-input-shape-service.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@
2323
"input": {
2424
"shape": "SomeOperationRequest"
2525
}
26+
},
27+
"SharedShapeOperation": {
28+
"name": "SharedShapeOperation",
29+
"http": {
30+
"method": "GET",
31+
"requestUri": "/shared/{sharedId}"
32+
},
33+
"input": {
34+
"shape": "SharedShape"
35+
}
2636
}
2737
},
2838
"shapes": {
@@ -36,6 +46,9 @@
3646
},
3747
"options": {
3848
"shape": "NestedOptions"
49+
},
50+
"shared": {
51+
"shape": "SharedShape"
3952
}
4053
}
4154
},
@@ -56,11 +69,31 @@
5669
"shape": "String",
5770
"location": "querystring",
5871
"locationName": "nestedQuery"
72+
},
73+
"prefixHeaders": {
74+
"shape": "MapOfStrings",
75+
"location": "headers",
76+
"locationName": "x-amz-prefix-"
77+
}
78+
}
79+
},
80+
"SharedShape": {
81+
"type": "structure",
82+
"members": {
83+
"sharedId": {
84+
"shape": "String",
85+
"location": "uri",
86+
"locationName": "sharedId"
5987
}
6088
}
6189
},
6290
"String": {
6391
"type": "string"
92+
},
93+
"MapOfStrings": {
94+
"type": "map",
95+
"key": {"shape": "String"},
96+
"value": {"shape": "String"}
6497
}
6598
},
6699
"documentation": "A service with HTTP binding locations on non-input shapes"

0 commit comments

Comments
 (0)