Skip to content

Commit 8ad1ea7

Browse files
committed
use consistent naming for poll intermediate-response/result and final response/result
1 parent 2ed4abc commit 8ad1ea7

File tree

6 files changed

+77
-71
lines changed

6 files changed

+77
-71
lines changed

packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/extension/plugin/PollingSettings.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,25 @@
1515
public final class PollingSettings implements JsonSerializable<PollingSettings> {
1616
private String strategy;
1717
private String syncStrategy;
18-
private String intermediateType;
19-
private String finalType;
18+
private String pollResultType;
19+
private String finalResultType;
2020
private String pollInterval;
2121

2222
public PollingSettings() {
2323
}
2424

2525
/**
2626
* The format of the java source code to instantiate a polling strategy class with PollingStrategyOptions argument.
27+
* For example, in case of the strategy 'OperationLocationPollingStrategy' class, the code after applying the format
28+
* looks like -
29+
* new OperationLocationPollingStrategy(new PollingStrategyOptions(...));
2730
*/
2831
public static final String INSTANTIATE_POLLING_STRATEGY_FORMAT;
2932
/**
3033
* The format of the java source code to instantiate a polling strategy class with PollingStrategyOptions and LRO
31-
* final result arguments.
34+
* final result arguments. For example, in case of the strategy 'OperationLocationPollingStrategy' class, the code
35+
* after applying the format looks like -
36+
* new OperationLocationPollingStrategy(new PollingStrategyOptions(...), finalResultType);
3237
*/
3338
public static final String INSTANTIATE_POLLING_STRATEGY_WITH_RESULT_FORMAT;
3439
private static final String INSTANTIATE_DEFAULT_POLLING_STRATEGY;
@@ -91,17 +96,17 @@ public String getSyncStrategy() {
9196
*
9297
* @return The intermediate type for polling.
9398
*/
94-
public String getIntermediateType() {
95-
return intermediateType;
99+
public String getPollResultType() {
100+
return pollResultType;
96101
}
97102

98103
/**
99104
* Gets the type of the poll response once the long-running operation is completed.
100105
*
101106
* @return The final type for polling.
102107
*/
103-
public String getFinalType() {
104-
return finalType;
108+
public String getFinalResultType() {
109+
return finalResultType;
105110
}
106111

107112
/**
@@ -118,8 +123,8 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
118123
return jsonWriter.writeStartObject()
119124
.writeStringField("strategy", strategy)
120125
.writeStringField("sync-strategy", syncStrategy)
121-
.writeStringField("intermediate-type", intermediateType)
122-
.writeStringField("final-type", finalType)
126+
.writeStringField("intermediate-type", pollResultType)
127+
.writeStringField("final-type", finalResultType)
123128
.writeStringField("poll-interval", pollInterval)
124129
.writeEndObject();
125130
}
@@ -144,9 +149,9 @@ public static PollingSettings fromJson(JsonReader jsonReader) throws IOException
144149
} else if ("sync-strategy".equals(fieldName)) {
145150
pollingSettings.syncStrategy = reader.getString();
146151
} else if ("intermediate-type".equals(fieldName)) {
147-
pollingSettings.intermediateType = reader.getString();
152+
pollingSettings.pollResultType = reader.getString();
148153
} else if ("final-type".equals(fieldName)) {
149-
pollingSettings.finalType = reader.getString();
154+
pollingSettings.finalResultType = reader.getString();
150155
} else if ("poll-interval".equals(fieldName)) {
151156
pollingSettings.pollInterval = reader.getString();
152157
} else {

packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/ClientMethodMapper.java

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,7 @@ private List<ClientMethod> createClientMethods(Operation operation, boolean isPr
379379
}
380380
}
381381

382-
PollingSettings pollingSettings = settings.getPollingSettings(proxyMethod.getOperationId());
383-
382+
final PollingSettings pollingSettings = settings.getPollingSettings(proxyMethod.getOperationId());
384383
MethodPollingDetails methodPollingDetails = null;
385384
MethodPollingDetails dpgMethodPollingDetailsWithModel = null; // for additional LRO methods
386385

@@ -395,34 +394,34 @@ private List<ClientMethod> createClientMethods(Operation operation, boolean isPr
395394
methodPollingDetails
396395
= new MethodPollingDetails(pollingSettings.getStrategy(),
397396
pollingSettings.getSyncStrategy(),
398-
getPollingIntermediateType(pollingSettings, syncReturnType),
399-
getPollingFinalType(pollingSettings, syncReturnType,
397+
getPollResultType(pollingSettings, syncReturnType),
398+
getPollingFinalResultType(pollingSettings, syncReturnType,
400399
MethodUtil.getHttpMethod(operation)),
401400
pollingSettings.getPollIntervalInSeconds());
402401
}
403402
}
404403

405404
if (methodPollingDetails != null && isProtocolMethod
406405
// models of LRO configured
407-
&& !(ClassType.BINARY_DATA.equals(methodPollingDetails.getIntermediateType())
408-
&& (ClassType.BINARY_DATA.equals(methodPollingDetails.getFinalType())
409-
|| ClassType.VOID.equals(methodPollingDetails.getFinalType().asNullable())))) {
406+
&& !(ClassType.BINARY_DATA.equals(methodPollingDetails.getPollResultType())
407+
&& (ClassType.BINARY_DATA.equals(methodPollingDetails.getFinalResultType())
408+
|| ClassType.VOID.equals(methodPollingDetails.getFinalResultType().asNullable())))) {
410409

411410
// a new method to be added as implementation only (not exposed to client) for developer
412411
dpgMethodPollingDetailsWithModel = methodPollingDetails;
413412

414413
// keep consistency with DPG from Swagger, see getPollingFinalType
415-
IType resultType = ClassType.BINARY_DATA;
414+
IType finalResultType = ClassType.BINARY_DATA;
416415
// DELETE would not have final response as resource is deleted
417416
if (MethodUtil.getHttpMethod(operation) == HttpMethod.DELETE) {
418-
resultType = PrimitiveType.VOID;
417+
finalResultType = PrimitiveType.VOID;
419418
}
420419

421420
// DPG keep the method with BinaryData
422421
methodPollingDetails
423422
= new MethodPollingDetails(dpgMethodPollingDetailsWithModel.getPollingStrategy(),
424423
dpgMethodPollingDetailsWithModel.getSyncPollingStrategy(), ClassType.BINARY_DATA,
425-
resultType, dpgMethodPollingDetailsWithModel.getPollIntervalInSeconds());
424+
finalResultType, dpgMethodPollingDetailsWithModel.getPollIntervalInSeconds());
426425
}
427426

428427
final ClientMethod lroBaseMethod
@@ -1047,28 +1046,29 @@ protected void addClientMethodWithContext(List<ClientMethod> methods, ClientMeth
10471046
methods.add(withContextMethod);
10481047
}
10491048

1050-
private IType getPollingIntermediateType(PollingSettings pollingSettings, IType syncReturnType) {
1049+
private IType getPollResultType(PollingSettings pollingSettings, IType syncReturnType) {
10511050
assert pollingSettings != null;
10521051

10531052
if (JavaSettings.getInstance().isFluent()) {
10541053
return syncReturnType.asNullable();
10551054
}
10561055

1057-
final IType intermediateResponseType;
1058-
if (pollingSettings.getIntermediateType() != null) {
1059-
intermediateResponseType = createTypeFromModelName(pollingSettings.getIntermediateType());
1056+
final IType pollResultType;
1057+
if (pollingSettings.getPollResultType() != null) {
1058+
pollResultType = createTypeFromModelName(pollingSettings.getPollResultType());
10601059
} else {
1061-
intermediateResponseType = syncReturnType.asNullable();
1060+
pollResultType = syncReturnType.asNullable();
10621061
}
1063-
if (intermediateResponseType.asNullable() == ClassType.VOID) {
1062+
if (pollResultType.asNullable() == ClassType.VOID) {
10641063
// azure-core wants poll response to be non-null
10651064
return ClassType.BINARY_DATA;
10661065
} else {
1067-
return intermediateResponseType;
1066+
return pollResultType;
10681067
}
10691068
}
10701069

1071-
private IType getPollingFinalType(PollingSettings pollingSettings, IType syncReturnType, HttpMethod httpMethod) {
1070+
private IType getPollingFinalResultType(PollingSettings pollingSettings, IType syncReturnType,
1071+
HttpMethod httpMethod) {
10721072
assert pollingSettings != null;
10731073

10741074
if (JavaSettings.getInstance().isFluent()) {
@@ -1080,17 +1080,17 @@ private IType getPollingFinalType(PollingSettings pollingSettings, IType syncRet
10801080
return PrimitiveType.VOID;
10811081
}
10821082

1083-
final IType finalResponseType;
1084-
if (pollingSettings.getFinalType() != null) {
1085-
finalResponseType = createTypeFromModelName(pollingSettings.getFinalType());
1083+
final IType finalResultType;
1084+
if (pollingSettings.getFinalResultType() != null) {
1085+
finalResultType = createTypeFromModelName(pollingSettings.getFinalResultType());
10861086
} else {
1087-
finalResponseType = syncReturnType.asNullable();
1087+
finalResultType = syncReturnType.asNullable();
10881088
}
1089-
if (finalResponseType.asNullable() == ClassType.VOID) {
1089+
if (finalResultType.asNullable() == ClassType.VOID) {
10901090
// azure-core wants poll response to be non-null
10911091
return ClassType.BINARY_DATA;
10921092
} else {
1093-
return finalResponseType;
1093+
return finalResultType;
10941094
}
10951095
}
10961096

@@ -1111,22 +1111,22 @@ private static MethodPollingDetails methodPollingDetailsFromMetadata(Operation o
11111111
// Step_1: Resolve LRO intermediate and final response types.
11121112
//
11131113
ObjectMapper objectMapper = Mappers.getObjectMapper();
1114-
final IType intermediateType;
1115-
if (pollingSettings.getIntermediateType() != null) {
1114+
final IType pollResultType;
1115+
if (pollingSettings.getPollResultType() != null) {
11161116
// pollingSettings would take precedence over 'LongRunningMetadata'
1117-
intermediateType = createTypeFromModelName(pollingSettings.getIntermediateType());
1117+
pollResultType = createTypeFromModelName(pollingSettings.getPollResultType());
11181118
} else {
1119-
intermediateType = objectMapper.map(metadata.getPollResultType());
1119+
pollResultType = objectMapper.map(metadata.getPollResultType());
11201120
}
11211121

1122-
final IType finalType;
1123-
if (pollingSettings.getFinalType() != null) {
1124-
finalType = createTypeFromModelName(pollingSettings.getFinalType());
1122+
final IType finalResultType;
1123+
if (pollingSettings.getFinalResultType() != null) {
1124+
finalResultType = createTypeFromModelName(pollingSettings.getFinalResultType());
11251125
} else {
11261126
if (metadata.getFinalResultType() == null) {
1127-
finalType = PrimitiveType.VOID;
1127+
finalResultType = PrimitiveType.VOID;
11281128
} else {
1129-
finalType = objectMapper.map(metadata.getFinalResultType());
1129+
finalResultType = objectMapper.map(metadata.getFinalResultType());
11301130
}
11311131
}
11321132

@@ -1158,7 +1158,7 @@ private static MethodPollingDetails methodPollingDetailsFromMetadata(Operation o
11581158
syncPollingStrategy = pollingSettings.getSyncStrategy();
11591159
}
11601160

1161-
return new MethodPollingDetails(pollingStrategy, syncPollingStrategy, intermediateType, finalType,
1161+
return new MethodPollingDetails(pollingStrategy, syncPollingStrategy, pollResultType, finalResultType,
11621162
pollingSettings.getPollIntervalInSeconds());
11631163
}
11641164

packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/mapper/ClientMethodsReturnDescription.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,19 +231,19 @@ public ReturnValue getReturnValue(ClientMethodType methodType, MethodPollingDeta
231231
syncReturnType.asNullable());
232232
return createReturnValue(returnType, syncReturnType);
233233
} else {
234-
IType returnType
235-
= GenericType.SyncPoller(pollingDetails.getIntermediateType(), pollingDetails.getFinalType());
236-
return createReturnValue(returnType, pollingDetails.getFinalType());
234+
IType returnType = GenericType.SyncPoller(pollingDetails.getPollResultType(),
235+
pollingDetails.getFinalResultType());
236+
return createReturnValue(returnType, pollingDetails.getFinalResultType());
237237
}
238238
case LongRunningBeginAsync:
239239
if (settings.isFluent()) {
240240
IType returnType = GenericType.PollerFlux(GenericType.PollResult(syncReturnType.asNullable()),
241241
syncReturnType.asNullable());
242242
return createReturnValue(returnType, syncReturnType);
243243
} else {
244-
IType returnType
245-
= GenericType.PollerFlux(pollingDetails.getIntermediateType(), pollingDetails.getFinalType());
246-
return createReturnValue(returnType, pollingDetails.getFinalType());
244+
IType returnType = GenericType.PollerFlux(pollingDetails.getPollResultType(),
245+
pollingDetails.getFinalResultType());
246+
return createReturnValue(returnType, pollingDetails.getFinalResultType());
247247
}
248248
default:
249249
throw new IllegalArgumentException("Unsupported method type: " + methodType

packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/model/clientmodel/MethodPollingDetails.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
public class MethodPollingDetails {
77
private final String pollingStrategy;
88
private final String syncPollingStrategy;
9-
private final IType intermediateType;
10-
private final IType finalType;
9+
private final IType pollResultType;
10+
private final IType finalResultType;
1111
private final int pollIntervalInSeconds;
1212

13-
public MethodPollingDetails(String pollingStrategy, String syncPollingStrategy, IType intermediateType,
14-
IType finalType, int pollIntervalInSeconds) {
13+
public MethodPollingDetails(String pollingStrategy, String syncPollingStrategy, IType pollResultType,
14+
IType finalResultType, int pollIntervalInSeconds) {
1515
this.pollingStrategy = pollingStrategy;
1616
this.syncPollingStrategy = syncPollingStrategy;
17-
this.intermediateType = intermediateType;
18-
this.finalType = finalType;
17+
this.pollResultType = pollResultType;
18+
this.finalResultType = finalResultType;
1919
this.pollIntervalInSeconds = pollIntervalInSeconds;
2020
}
2121

@@ -27,12 +27,12 @@ public String getSyncPollingStrategy() {
2727
return syncPollingStrategy;
2828
}
2929

30-
public IType getIntermediateType() {
31-
return intermediateType;
30+
public IType getPollResultType() {
31+
return pollResultType;
3232
}
3333

34-
public IType getFinalType() {
35-
return finalType;
34+
public IType getFinalResultType() {
35+
return finalResultType;
3636
}
3737

3838
public int getPollIntervalInSeconds() {

packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/template/ClientMethodTemplate.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,8 +1769,8 @@ private String getPollingStrategy(ClientMethod clientMethod, String contextParam
17691769
.replace("{context}", contextParam)
17701770
.replace("{serviceVersion}", getServiceVersionValue(clientMethod))
17711771
.replace("{serializerAdapter}", clientMethod.getClientReference() + ".getSerializerAdapter()")
1772-
.replace("{intermediate-type}", clientMethod.getMethodPollingDetails().getIntermediateType().toString())
1773-
.replace("{final-type}", clientMethod.getMethodPollingDetails().getFinalType().toString())
1772+
.replace("{intermediate-type}", clientMethod.getMethodPollingDetails().getPollResultType().toString())
1773+
.replace("{final-type}", clientMethod.getMethodPollingDetails().getFinalResultType().toString())
17741774
.replace(".setServiceVersion(null)", "")
17751775
.replace(".setEndpoint(null)", "");
17761776
}
@@ -1808,8 +1808,8 @@ private String getSyncPollingStrategy(ClientMethod clientMethod, String contextP
18081808
.replace("{context}", contextParam)
18091809
.replace("{serviceVersion}", getServiceVersionValue(clientMethod))
18101810
.replace("{serializerAdapter}", clientMethod.getClientReference() + ".getSerializerAdapter()")
1811-
.replace("{intermediate-type}", clientMethod.getMethodPollingDetails().getIntermediateType().toString())
1812-
.replace("{final-type}", clientMethod.getMethodPollingDetails().getFinalType().toString())
1811+
.replace("{intermediate-type}", clientMethod.getMethodPollingDetails().getPollResultType().toString())
1812+
.replace("{final-type}", clientMethod.getMethodPollingDetails().getFinalResultType().toString())
18131813
.replace(".setServiceVersion(null)", "")
18141814
.replace(".setEndpoint(null)", "");
18151815
}

packages/http-client-java/generator/http-client-generator-core/src/main/java/com/microsoft/typespec/http/client/generator/core/util/TemplateUtil.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,14 @@ public static void writeClientMethodsAndHelpers(JavaClass classBlock, List<Clien
144144
// getLongRunningOperationTypeReferenceExpression
145145
if (clientMethod.getType() == ClientMethodType.LongRunningBeginAsync
146146
&& clientMethod.getMethodPollingDetails() != null) {
147-
if (clientMethod.getMethodPollingDetails().getIntermediateType() instanceof GenericType) {
147+
if (clientMethod.getMethodPollingDetails().getPollResultType() instanceof GenericType) {
148148
typeReferenceStaticClasses
149-
.add((GenericType) clientMethod.getMethodPollingDetails().getIntermediateType());
149+
.add((GenericType) clientMethod.getMethodPollingDetails().getPollResultType());
150150
}
151151

152-
if (clientMethod.getMethodPollingDetails().getFinalType() instanceof GenericType) {
153-
typeReferenceStaticClasses.add((GenericType) clientMethod.getMethodPollingDetails().getFinalType());
152+
if (clientMethod.getMethodPollingDetails().getFinalResultType() instanceof GenericType) {
153+
typeReferenceStaticClasses
154+
.add((GenericType) clientMethod.getMethodPollingDetails().getFinalResultType());
154155
}
155156
}
156157
}
@@ -176,8 +177,8 @@ public static void writeClientMethodsAndHelpers(JavaClass classBlock, List<Clien
176177
*/
177178
public static String getLongRunningOperationTypeReferenceExpression(MethodPollingDetails details) {
178179
// see writeTypeReferenceStaticClass
179-
return getTypeReferenceCreation(details.getIntermediateType()) + ", "
180-
+ getTypeReferenceCreation(details.getFinalType());
180+
return getTypeReferenceCreation(details.getPollResultType()) + ", "
181+
+ getTypeReferenceCreation(details.getFinalResultType());
181182
}
182183

183184
/**

0 commit comments

Comments
 (0)