Skip to content

Commit 667dab8

Browse files
tsp, bug fix multiple content-type + json-patch+json (#2870)
1 parent 8e20ba4 commit 667dab8

File tree

10 files changed

+28
-20
lines changed

10 files changed

+28
-20
lines changed

javagen/src/main/java/com/azure/autorest/mapper/ClientMethodMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ private List<ClientMethod> createClientMethods(Operation operation, boolean isPr
233233
.map(parameter, isProtocolMethod);
234234

235235
if (isJsonPatch) {
236-
clientMethodParameter = CustomClientParameterMapper.getInstance().map(parameter);
236+
clientMethodParameter = CustomClientParameterMapper.getInstance().map(parameter, isProtocolMethod);
237237
}
238238

239239
// If the codemodel parameter and proxy method parameter types don't match, update the client

javagen/src/main/java/com/azure/autorest/mapper/ClientParameterMapper.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public ClientMethodParameter map(Parameter parameter, boolean isProtocolMethod)
5151
: parameter.getLanguage().getJava().getName();
5252
name = CodeNamer.getEscapedReservedClientMethodParameterName(name);
5353

54-
JavaSettings settings = JavaSettings.getInstance();
5554
ClientMethodParameter.Builder builder = new ClientMethodParameter.Builder()
5655
.name(name)
5756
.required(parameter.isRequired())

javagen/src/main/java/com/azure/autorest/mapper/CustomClientParameterMapper.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
import com.azure.autorest.extension.base.model.codemodel.ArraySchema;
88
import com.azure.autorest.extension.base.model.codemodel.ConstantSchema;
99
import com.azure.autorest.extension.base.model.codemodel.Parameter;
10-
import com.azure.autorest.extension.base.plugin.JavaSettings;
1110
import com.azure.autorest.model.clientmodel.ClassType;
1211
import com.azure.autorest.model.clientmodel.ClientMethodParameter;
1312
import com.azure.autorest.model.clientmodel.IType;
1413
import com.azure.autorest.util.CodeNamer;
14+
import com.azure.autorest.util.MethodUtil;
15+
import com.azure.autorest.util.SchemaUtil;
1516

1617
import java.util.ArrayList;
1718

@@ -28,11 +29,14 @@ public static CustomClientParameterMapper getInstance() {
2829

2930
@Override
3031
public ClientMethodParameter map(Parameter parameter) {
32+
return map(parameter, false);
33+
}
34+
35+
public ClientMethodParameter map(Parameter parameter, boolean isProtocolMethod) {
3136
String name = parameter.getOriginalParameter() != null && parameter.getLanguage().getJava().getName().equals(parameter.getOriginalParameter().getLanguage().getJava().getName())
3237
? CodeNamer.toCamelCase(parameter.getOriginalParameter().getSchema().getLanguage().getJava().getName()) + CodeNamer.toPascalCase(parameter.getLanguage().getJava().getName())
3338
: parameter.getLanguage().getJava().getName();
3439

35-
JavaSettings settings = JavaSettings.getInstance();
3640
ClientMethodParameter.Builder builder = new ClientMethodParameter.Builder()
3741
.name(name)
3842
.required(parameter.isRequired())
@@ -46,6 +50,10 @@ public ClientMethodParameter map(Parameter parameter) {
4650
}
4751
}
4852

53+
if (isProtocolMethod) {
54+
wireType = SchemaUtil.removeModelFromParameter(parameter.getProtocol().getHttp().getIn(), wireType);
55+
}
56+
4957
if (parameter.isNullable() || !parameter.isRequired()) {
5058
wireType = wireType.asNullable();
5159
}
@@ -62,15 +70,8 @@ public ClientMethodParameter map(Parameter parameter) {
6270
}
6371
builder.constant(isConstant).defaultValue(defaultValue);
6472

65-
if (parameter.getSchema() != null && parameter.getSchema().getLanguage() != null) {
66-
String description = parameter.getSchema().getLanguage().getDefault().getDescription();
67-
if (description == null || description.isEmpty()) {
68-
if (parameter.getLanguage() != null) {
69-
description = parameter.getLanguage().getDefault().getDescription();
70-
}
71-
}
72-
builder.description(description);
73-
}
73+
builder.description(MethodUtil.getMethodParameterDescription(parameter, name, isProtocolMethod));
74+
7475
return builder.build();
7576
}
7677
}

typespec-extension/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release History
22

3+
## 0.18.2 (2024-07-22)
4+
5+
Compatible with compiler 0.58.
6+
37
## 0.18.1 (2024-07-17)
48

59
Compatible with compiler 0.58.

typespec-extension/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@azure-tools/typespec-java",
3-
"version": "0.18.1",
3+
"version": "0.18.2",
44
"description": "TypeSpec library for emitting Java client from the TypeSpec REST protocol binding",
55
"keywords": [
66
"TypeSpec"

typespec-tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
"dependencies": {
1212
"@azure-tools/cadl-ranch-specs": "0.34.7",
13-
"@azure-tools/typespec-java": "file:/../typespec-extension/azure-tools-typespec-java-0.18.1.tgz"
13+
"@azure-tools/typespec-java": "file:/../typespec-extension/azure-tools-typespec-java-0.18.2.tgz"
1414
},
1515
"devDependencies": {
1616
"@typespec/prettier-plugin-typespec": "~0.58.0",

typespec-tests/src/main/java/com/cadl/multicontenttypes/MultipleContentTypesOnRequestAsyncClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public final class MultipleContentTypesOnRequestAsyncClient {
4747
* }</pre>
4848
*
4949
* @param contentType The contentType parameter. Allowed values: "application/octet-stream", "image/jpeg",
50-
* "image/png".
50+
* "image/png", "application/json-patch+json".
5151
* @param data The data parameter.
5252
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
5353
* @throws HttpResponseException thrown if the request is rejected by server.

typespec-tests/src/main/java/com/cadl/multicontenttypes/MultipleContentTypesOnRequestClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public final class MultipleContentTypesOnRequestClient {
4545
* }</pre>
4646
*
4747
* @param contentType The contentType parameter. Allowed values: "application/octet-stream", "image/jpeg",
48-
* "image/png".
48+
* "image/png", "application/json-patch+json".
4949
* @param data The data parameter.
5050
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
5151
* @throws HttpResponseException thrown if the request is rejected by server.

typespec-tests/src/main/java/com/cadl/multicontenttypes/implementation/MultipleContentTypesOnRequestsImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ Response<Void> uploadJsonOrBytesWithMultiBodyTypesForMultiContentTypesSync(
150150
* }</pre>
151151
*
152152
* @param contentType The contentType parameter. Allowed values: "application/octet-stream", "image/jpeg",
153-
* "image/png".
153+
* "image/png", "application/json-patch+json".
154154
* @param data The data parameter.
155155
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
156156
* @throws HttpResponseException thrown if the request is rejected by server.
@@ -177,7 +177,7 @@ public Mono<Response<Void>> uploadBytesWithSingleBodyTypeForMultiContentTypesWit
177177
* }</pre>
178178
*
179179
* @param contentType The contentType parameter. Allowed values: "application/octet-stream", "image/jpeg",
180-
* "image/png".
180+
* "image/png", "application/json-patch+json".
181181
* @param data The data parameter.
182182
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
183183
* @throws HttpResponseException thrown if the request is rejected by server.

typespec-tests/tsp/multiple-content-types.tsp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ interface MultipleContentTypesOnRequest {
4242
@post
4343
uploadBytesWithSingleBodyTypeForMultiContentTypes(
4444
@body data: bytes,
45-
@header contentType: "application/octet-stream" | "image/jpeg" | "image/png",
45+
@header contentType:
46+
| "application/octet-stream"
47+
| "image/jpeg"
48+
| "image/png"
49+
| "application/json-patch+json",
4650
): void;
4751

4852
@doc("multiple data types map to multiple content types using shared route")

0 commit comments

Comments
 (0)