Skip to content

Commit 6342400

Browse files
tsp, fix wire name on header/query/path (#2848)
1 parent d14a9d2 commit 6342400

File tree

22 files changed

+1343
-91
lines changed

22 files changed

+1343
-91
lines changed

typespec-extension/changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Release History
22

3-
## 0.17.1 (Unreleased)
3+
## 0.17.1 (2024-07-03)
44

55
Compatible with compiler 0.57.
66

typespec-extension/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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.17.0",
3+
"version": "0.17.1",
44
"description": "TypeSpec library for emitting Java client from the TypeSpec REST protocol binding",
55
"keywords": [
66
"TypeSpec"

typespec-extension/src/code-model-builder.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,17 @@ import {
111111
HttpStatusCodesEntry,
112112
Visibility,
113113
getAuthentication,
114+
getHeaderFieldName,
114115
getHeaderFieldOptions,
115116
getHttpOperation,
117+
getPathParamName,
118+
getQueryParamName,
116119
getQueryParamOptions,
117120
getServers,
118121
getStatusCodeDescription,
122+
isHeader,
119123
isPathParam,
124+
isQueryParam,
120125
} from "@typespec/http";
121126
import { getResourceOperation, getSegment } from "@typespec/rest";
122127
import { Version, getAddedOnVersions, getVersion } from "@typespec/versioning";
@@ -2256,8 +2261,16 @@ export class CodeModelBuilder {
22562261
}
22572262

22582263
private getSerializedName(target: ModelProperty): string {
2259-
// TODO: currently this is only for JSON
2260-
return getWireName(this.sdkContext, target);
2264+
if (isHeader(this.program, target)) {
2265+
return getHeaderFieldName(this.program, target);
2266+
} else if (isQueryParam(this.program, target)) {
2267+
return getQueryParamName(this.program, target);
2268+
} else if (isPathParam(this.program, target)) {
2269+
return getPathParamName(this.program, target);
2270+
} else {
2271+
// TODO: currently this is only for JSON
2272+
return getWireName(this.sdkContext, target);
2273+
}
22612274
}
22622275

22632276
private isReadOnly(target: SdkModelPropertyType): boolean {

typespec-tests/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"testserver-run": "npx cadl-ranch serve ./node_modules/@azure-tools/cadl-ranch-specs/http --coverageFile ./cadl-ranch-coverage-java.json"
1010
},
1111
"dependencies": {
12-
"@azure-tools/cadl-ranch-specs": "0.34.1",
13-
"@azure-tools/typespec-java": "file:/../typespec-extension/azure-tools-typespec-java-0.17.0.tgz"
12+
"@azure-tools/cadl-ranch-specs": "0.34.3",
13+
"@azure-tools/typespec-java": "file:/../typespec-extension/azure-tools-typespec-java-0.17.1.tgz"
1414
},
1515
"devDependencies": {
1616
"@typespec/prettier-plugin-typespec": "~0.57.0",
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
// Code generated by Microsoft (R) TypeSpec Code Generator.
4+
5+
package com._specs_.azure.core.model;
6+
7+
import com._specs_.azure.core.model.implementation.AzureCoreEmbeddingVectorsImpl;
8+
import com._specs_.azure.core.model.models.AzureEmbeddingModel;
9+
import com.azure.core.annotation.Generated;
10+
import com.azure.core.annotation.ReturnType;
11+
import com.azure.core.annotation.ServiceClient;
12+
import com.azure.core.annotation.ServiceMethod;
13+
import com.azure.core.exception.ClientAuthenticationException;
14+
import com.azure.core.exception.HttpResponseException;
15+
import com.azure.core.exception.ResourceModifiedException;
16+
import com.azure.core.exception.ResourceNotFoundException;
17+
import com.azure.core.http.rest.RequestOptions;
18+
import com.azure.core.http.rest.Response;
19+
import com.azure.core.util.BinaryData;
20+
import com.azure.core.util.FluxUtil;
21+
import com.azure.core.util.serializer.TypeReference;
22+
import java.util.List;
23+
import reactor.core.publisher.Mono;
24+
25+
/**
26+
* Initializes a new instance of the asynchronous ModelClient type.
27+
*/
28+
@ServiceClient(builder = ModelClientBuilder.class, isAsync = true)
29+
public final class ModelAsyncClient {
30+
@Generated
31+
private final AzureCoreEmbeddingVectorsImpl serviceClient;
32+
33+
/**
34+
* Initializes an instance of ModelAsyncClient class.
35+
*
36+
* @param serviceClient the service client implementation.
37+
*/
38+
@Generated
39+
ModelAsyncClient(AzureCoreEmbeddingVectorsImpl serviceClient) {
40+
this.serviceClient = serviceClient;
41+
}
42+
43+
/**
44+
* get an embedding vector.
45+
* <p><strong>Response Body Schema</strong></p>
46+
*
47+
* <pre>{@code
48+
* [
49+
* int (Required)
50+
* ]
51+
* }</pre>
52+
*
53+
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
54+
* @throws HttpResponseException thrown if the request is rejected by server.
55+
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
56+
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
57+
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
58+
* @return an embedding vector along with {@link Response} on successful completion of {@link Mono}.
59+
*/
60+
@Generated
61+
@ServiceMethod(returns = ReturnType.SINGLE)
62+
public Mono<Response<BinaryData>> getWithResponse(RequestOptions requestOptions) {
63+
return this.serviceClient.getWithResponseAsync(requestOptions);
64+
}
65+
66+
/**
67+
* put an embedding vector.
68+
* <p><strong>Request Body Schema</strong></p>
69+
*
70+
* <pre>{@code
71+
* [
72+
* int (Required)
73+
* ]
74+
* }</pre>
75+
*
76+
* @param body _.
77+
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
78+
* @throws HttpResponseException thrown if the request is rejected by server.
79+
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
80+
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
81+
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
82+
* @return the {@link Response} on successful completion of {@link Mono}.
83+
*/
84+
@Generated
85+
@ServiceMethod(returns = ReturnType.SINGLE)
86+
public Mono<Response<Void>> putWithResponse(BinaryData body, RequestOptions requestOptions) {
87+
return this.serviceClient.putWithResponseAsync(body, requestOptions);
88+
}
89+
90+
/**
91+
* post a model which has an embeddingVector property.
92+
* <p><strong>Request Body Schema</strong></p>
93+
*
94+
* <pre>{@code
95+
* {
96+
* embedding (Required): [
97+
* int (Required)
98+
* ]
99+
* }
100+
* }</pre>
101+
*
102+
* <p><strong>Response Body Schema</strong></p>
103+
*
104+
* <pre>{@code
105+
* {
106+
* embedding (Required): [
107+
* int (Required)
108+
* ]
109+
* }
110+
* }</pre>
111+
*
112+
* @param body _.
113+
* @param requestOptions The options to configure the HTTP request before HTTP client sends it.
114+
* @throws HttpResponseException thrown if the request is rejected by server.
115+
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
116+
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
117+
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
118+
* @return the response body along with {@link Response} on successful completion of {@link Mono}.
119+
*/
120+
@Generated
121+
@ServiceMethod(returns = ReturnType.SINGLE)
122+
public Mono<Response<BinaryData>> postWithResponse(BinaryData body, RequestOptions requestOptions) {
123+
return this.serviceClient.postWithResponseAsync(body, requestOptions);
124+
}
125+
126+
/**
127+
* get an embedding vector.
128+
*
129+
* @throws HttpResponseException thrown if the request is rejected by server.
130+
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
131+
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
132+
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
133+
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
134+
* @return an embedding vector on successful completion of {@link Mono}.
135+
*/
136+
@Generated
137+
@ServiceMethod(returns = ReturnType.SINGLE)
138+
public Mono<List<Integer>> get() {
139+
// Generated convenience method for getWithResponse
140+
RequestOptions requestOptions = new RequestOptions();
141+
return getWithResponse(requestOptions).flatMap(FluxUtil::toMono)
142+
.map(protocolMethodData -> protocolMethodData.toObject(TYPE_REFERENCE_LIST_INTEGER));
143+
}
144+
145+
/**
146+
* put an embedding vector.
147+
*
148+
* @param body _.
149+
* @throws IllegalArgumentException thrown if parameters fail the validation.
150+
* @throws HttpResponseException thrown if the request is rejected by server.
151+
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
152+
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
153+
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
154+
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
155+
* @return A {@link Mono} that completes when a successful response is received.
156+
*/
157+
@Generated
158+
@ServiceMethod(returns = ReturnType.SINGLE)
159+
public Mono<Void> put(List<Integer> body) {
160+
// Generated convenience method for putWithResponse
161+
RequestOptions requestOptions = new RequestOptions();
162+
return putWithResponse(BinaryData.fromObject(body), requestOptions).flatMap(FluxUtil::toMono);
163+
}
164+
165+
/**
166+
* post a model which has an embeddingVector property.
167+
*
168+
* @param body _.
169+
* @throws IllegalArgumentException thrown if parameters fail the validation.
170+
* @throws HttpResponseException thrown if the request is rejected by server.
171+
* @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401.
172+
* @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404.
173+
* @throws ResourceModifiedException thrown if the request is rejected by server on status code 409.
174+
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
175+
* @return the response body on successful completion of {@link Mono}.
176+
*/
177+
@Generated
178+
@ServiceMethod(returns = ReturnType.SINGLE)
179+
public Mono<AzureEmbeddingModel> post(AzureEmbeddingModel body) {
180+
// Generated convenience method for postWithResponse
181+
RequestOptions requestOptions = new RequestOptions();
182+
return postWithResponse(BinaryData.fromObject(body), requestOptions).flatMap(FluxUtil::toMono)
183+
.map(protocolMethodData -> protocolMethodData.toObject(AzureEmbeddingModel.class));
184+
}
185+
186+
@Generated
187+
private static final TypeReference<List<Integer>> TYPE_REFERENCE_LIST_INTEGER = new TypeReference<List<Integer>>() {
188+
};
189+
}

0 commit comments

Comments
 (0)