Skip to content

Commit a0e9fe7

Browse files
tsp, spread implicit request body (#2821)
1 parent aa25c93 commit a0e9fe7

26 files changed

+677
-730
lines changed

typespec-extension/changelog.md

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

3+
## 0.18.0 (2024-07-10)
4+
5+
Compatible with compiler 0.57.
6+
7+
### Breaking Changes
8+
9+
- Request body without `@body` or `@bodyRoot`: the properties of the request body is flattened into method signature.
10+
311
## 0.17.1 (2024-07-03)
412

513
Compatible with compiler 0.57.

typespec-extension/package-lock.json

Lines changed: 306 additions & 575 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: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@azure-tools/typespec-java",
3-
"version": "0.17.1",
3+
"version": "0.18.0",
44
"description": "TypeSpec library for emitting Java client from the TypeSpec REST protocol binding",
55
"keywords": [
66
"TypeSpec"
@@ -49,7 +49,7 @@
4949
"@azure-tools/typespec-azure-resource-manager": ">=0.43.0 <1.0.0",
5050
"@azure-tools/typespec-autorest": ">=0.43.0 <1.0.0",
5151
"@azure-tools/typespec-azure-rulesets": ">=0.43.0 <1.0.0",
52-
"@azure-tools/typespec-client-generator-core": ">=0.43.1 <1.0.0",
52+
"@azure-tools/typespec-client-generator-core": ">=0.43.2 <1.0.0",
5353
"@typespec/compiler": ">=0.57.0 <1.0.0",
5454
"@typespec/http": ">=0.57.0 <1.0.0",
5555
"@typespec/openapi": ">=0.57.0 <1.0.0",
@@ -67,25 +67,25 @@
6767
"@azure-tools/typespec-azure-resource-manager": "0.43.0",
6868
"@azure-tools/typespec-autorest": "0.43.0",
6969
"@azure-tools/typespec-azure-rulesets": "0.43.0",
70-
"@azure-tools/typespec-client-generator-core": "0.43.1",
70+
"@azure-tools/typespec-client-generator-core": "0.43.2",
7171
"@types/js-yaml": "~4.0.9",
72-
"@types/lodash": "~4.17.1",
73-
"@types/mocha": "~10.0.6",
74-
"@types/node": "~20.12.10",
75-
"@typescript-eslint/eslint-plugin": "~7.8.0",
76-
"@typescript-eslint/parser": "~7.8.0",
72+
"@types/lodash": "~4.17.6",
73+
"@types/mocha": "~10.0.7",
74+
"@types/node": "~20.14.10",
75+
"@typescript-eslint/eslint-plugin": "~7.16.0",
76+
"@typescript-eslint/parser": "~7.16.0",
7777
"@typespec/compiler": "0.57.0",
7878
"@typespec/http": "0.57.0",
7979
"@typespec/openapi": "0.57.0",
8080
"@typespec/rest": "0.57.0",
8181
"@typespec/versioning": "0.57.0",
8282
"@typespec/xml": "0.57.0",
83-
"c8": "~9.1.0",
83+
"c8": "~10.1.2",
8484
"eslint": "~8.57.0",
85-
"eslint-plugin-deprecation": "~2.0.0",
86-
"mocha": "~10.4.0",
87-
"prettier": "~3.2.5",
88-
"rimraf": "~5.0.5",
89-
"typescript": "~5.4.5"
85+
"eslint-plugin-deprecation": "~3.0.0",
86+
"mocha": "~10.6.0",
87+
"prettier": "~3.3.2",
88+
"rimraf": "~6.0.0",
89+
"typescript": "~5.5.3"
9090
}
9191
}

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ export class CodeModelBuilder {
801801
this.processParameterBody(codeModelOperation, op, op.parameters.body.property);
802802
}
803803
} else if (op.parameters.body.type) {
804-
let bodyType = this.getEffectiveSchemaType(op.parameters.body.type);
804+
let bodyType = op.parameters.body.type;
805805

806806
if (bodyType.kind === "Model") {
807807
// try use resource type as round-trip model
@@ -1345,7 +1345,11 @@ export class CodeModelBuilder {
13451345
schema = this.processSchemaFromSdkType(sdkType, body.name);
13461346
}
13471347

1348-
const isAnonymousModel = sdkType.kind === "model" && sdkType.isGeneratedName === true;
1348+
// Explicit body parameter @body or @bodyRoot would result to body.kind === "ModelProperty"
1349+
// Implicit body parameter would result to body.kind === "Model"
1350+
// see https://typespec.io/docs/libraries/http/cheat-sheet#data-types
1351+
const bodyParameterFlatten = sdkType.kind === "model" && body.kind === "Model" && !this.isArm();
1352+
13491353
const parameterName = body.kind === "Model" ? (sdkType.kind === "model" ? sdkType.name : "") : this.getName(body);
13501354
const parameter = new Parameter(parameterName, this.getDoc(body), schema, {
13511355
summary: this.getSummary(body),
@@ -1371,8 +1375,8 @@ export class CodeModelBuilder {
13711375
this.trackSchemaUsage(schema, { serializationFormats: [KnownMediaType.Multipart] });
13721376
}
13731377

1374-
if (schema instanceof ObjectSchema && isAnonymousModel) {
1375-
// anonymous model
1378+
if (schema instanceof ObjectSchema && bodyParameterFlatten) {
1379+
// flatten body parameter
13761380

13771381
// name the schema for documentation
13781382
schema.language.default.name = pascalCase(op.language.default.name) + "Request";

typespec-tests/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
},
1111
"dependencies": {
1212
"@azure-tools/cadl-ranch-specs": "0.34.3",
13-
"@azure-tools/typespec-java": "file:/../typespec-extension/azure-tools-typespec-java-0.17.1.tgz"
13+
"@azure-tools/typespec-java": "file:/../typespec-extension/azure-tools-typespec-java-0.18.0.tgz"
1414
},
1515
"devDependencies": {
1616
"@typespec/prettier-plugin-typespec": "~0.57.0",
17-
"prettier-plugin-organize-imports": "3.2.4",
18-
"prettier": "~3.2.5"
17+
"prettier-plugin-organize-imports": "4.0.0",
18+
"prettier": "~3.3.2"
1919
},
2020
"overrides": {
2121
"@typespec/compiler": ">=0.57.0 <1.0.0",
@@ -25,7 +25,7 @@
2525
"@typespec/openapi": ">=0.57.0 <1.0.0",
2626
"@typespec/xml": ">=0.57.0 <1.0.0",
2727
"@azure-tools/typespec-azure-core": ">=0.43.0 <1.0.0",
28-
"@azure-tools/typespec-client-generator-core": ">=0.43.1 <1.0.0",
28+
"@azure-tools/typespec-client-generator-core": "0.43.2",
2929
"@azure-tools/typespec-azure-resource-manager": ">=0.43.0 <1.0.0",
3030
"@azure-tools/typespec-autorest": ">=0.43.0 <1.0.0"
3131
},

typespec-tests/src/main/java/com/client/naming/ModelAsyncClient.java renamed to typespec-tests/src/main/java/com/client/naming/ClientModelAsyncClient.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import com.azure.core.http.rest.Response;
1717
import com.azure.core.util.BinaryData;
1818
import com.azure.core.util.FluxUtil;
19-
import com.client.naming.implementation.ModelsImpl;
19+
import com.client.naming.implementation.ClientModelsImpl;
2020
import com.client.naming.models.ClientModel;
2121
import com.client.naming.models.JavaModel;
2222
import reactor.core.publisher.Mono;
@@ -25,17 +25,17 @@
2525
* Initializes a new instance of the asynchronous NamingClient type.
2626
*/
2727
@ServiceClient(builder = NamingClientBuilder.class, isAsync = true)
28-
public final class ModelAsyncClient {
28+
public final class ClientModelAsyncClient {
2929
@Generated
30-
private final ModelsImpl serviceClient;
30+
private final ClientModelsImpl serviceClient;
3131

3232
/**
33-
* Initializes an instance of ModelAsyncClient class.
33+
* Initializes an instance of ClientModelAsyncClient class.
3434
*
3535
* @param serviceClient the service client implementation.
3636
*/
3737
@Generated
38-
ModelAsyncClient(ModelsImpl serviceClient) {
38+
ClientModelAsyncClient(ClientModelsImpl serviceClient) {
3939
this.serviceClient = serviceClient;
4040
}
4141

typespec-tests/src/main/java/com/client/naming/ModelClient.java renamed to typespec-tests/src/main/java/com/client/naming/ClientModelClient.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@
1515
import com.azure.core.http.rest.RequestOptions;
1616
import com.azure.core.http.rest.Response;
1717
import com.azure.core.util.BinaryData;
18-
import com.client.naming.implementation.ModelsImpl;
18+
import com.client.naming.implementation.ClientModelsImpl;
1919
import com.client.naming.models.ClientModel;
2020
import com.client.naming.models.JavaModel;
2121

2222
/**
2323
* Initializes a new instance of the synchronous NamingClient type.
2424
*/
2525
@ServiceClient(builder = NamingClientBuilder.class)
26-
public final class ModelClient {
26+
public final class ClientModelClient {
2727
@Generated
28-
private final ModelsImpl serviceClient;
28+
private final ClientModelsImpl serviceClient;
2929

3030
/**
31-
* Initializes an instance of ModelClient class.
31+
* Initializes an instance of ClientModelClient class.
3232
*
3333
* @param serviceClient the service client implementation.
3434
*/
3535
@Generated
36-
ModelClient(ModelsImpl serviceClient) {
36+
ClientModelClient(ClientModelsImpl serviceClient) {
3737
this.serviceClient = serviceClient;
3838
}
3939

typespec-tests/src/main/java/com/client/naming/NamingClientBuilder.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
@ServiceClientBuilder(
4343
serviceClients = {
4444
NamingClient.class,
45-
ModelClient.class,
45+
ClientModelClient.class,
4646
UnionEnumClient.class,
4747
NamingAsyncClient.class,
48-
ModelAsyncClient.class,
48+
ClientModelAsyncClient.class,
4949
UnionEnumAsyncClient.class })
5050
public final class NamingClientBuilder
5151
implements HttpTrait<NamingClientBuilder>, ConfigurationTrait<NamingClientBuilder> {
@@ -262,13 +262,13 @@ public NamingAsyncClient buildAsyncClient() {
262262
}
263263

264264
/**
265-
* Builds an instance of ModelAsyncClient class.
265+
* Builds an instance of ClientModelAsyncClient class.
266266
*
267-
* @return an instance of ModelAsyncClient.
267+
* @return an instance of ClientModelAsyncClient.
268268
*/
269269
@Generated
270-
public ModelAsyncClient buildModelAsyncClient() {
271-
return new ModelAsyncClient(buildInnerClient().getModels());
270+
public ClientModelAsyncClient buildClientModelAsyncClient() {
271+
return new ClientModelAsyncClient(buildInnerClient().getClientModels());
272272
}
273273

274274
/**
@@ -292,13 +292,13 @@ public NamingClient buildClient() {
292292
}
293293

294294
/**
295-
* Builds an instance of ModelClient class.
295+
* Builds an instance of ClientModelClient class.
296296
*
297-
* @return an instance of ModelClient.
297+
* @return an instance of ClientModelClient.
298298
*/
299299
@Generated
300-
public ModelClient buildModelClient() {
301-
return new ModelClient(buildInnerClient().getModels());
300+
public ClientModelClient buildClientModelClient() {
301+
return new ClientModelClient(buildInnerClient().getClientModels());
302302
}
303303

304304
/**

typespec-tests/src/main/java/com/client/naming/implementation/ModelsImpl.java renamed to typespec-tests/src/main/java/com/client/naming/implementation/ClientModelsImpl.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,37 @@
2626
import reactor.core.publisher.Mono;
2727

2828
/**
29-
* An instance of this class provides access to all the operations defined in Models.
29+
* An instance of this class provides access to all the operations defined in ClientModels.
3030
*/
31-
public final class ModelsImpl {
31+
public final class ClientModelsImpl {
3232
/**
3333
* The proxy service used to perform REST calls.
3434
*/
35-
private final ModelsService service;
35+
private final ClientModelsService service;
3636

3737
/**
3838
* The service client containing this operation class.
3939
*/
4040
private final NamingClientImpl client;
4141

4242
/**
43-
* Initializes an instance of ModelsImpl.
43+
* Initializes an instance of ClientModelsImpl.
4444
*
4545
* @param client the instance of the service client containing this operation class.
4646
*/
47-
ModelsImpl(NamingClientImpl client) {
48-
this.service = RestProxy.create(ModelsService.class, client.getHttpPipeline(), client.getSerializerAdapter());
47+
ClientModelsImpl(NamingClientImpl client) {
48+
this.service
49+
= RestProxy.create(ClientModelsService.class, client.getHttpPipeline(), client.getSerializerAdapter());
4950
this.client = client;
5051
}
5152

5253
/**
53-
* The interface defining all the services for NamingClientModels to be used by the proxy service to perform REST
54-
* calls.
54+
* The interface defining all the services for NamingClientClientModels to be used by the proxy service to perform
55+
* REST calls.
5556
*/
5657
@Host("http://localhost:3000")
57-
@ServiceInterface(name = "NamingClientModels")
58-
public interface ModelsService {
58+
@ServiceInterface(name = "NamingClientClientMo")
59+
public interface ClientModelsService {
5960
@Post("/client/naming/model/client")
6061
@ExpectedResponses({ 204 })
6162
@UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 })

typespec-tests/src/main/java/com/client/naming/implementation/NamingClientImpl.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,17 @@ public SerializerAdapter getSerializerAdapter() {
7171
}
7272

7373
/**
74-
* The ModelsImpl object to access its operations.
74+
* The ClientModelsImpl object to access its operations.
7575
*/
76-
private final ModelsImpl models;
76+
private final ClientModelsImpl clientModels;
7777

7878
/**
79-
* Gets the ModelsImpl object to access its operations.
79+
* Gets the ClientModelsImpl object to access its operations.
8080
*
81-
* @return the ModelsImpl object.
81+
* @return the ClientModelsImpl object.
8282
*/
83-
public ModelsImpl getModels() {
84-
return this.models;
83+
public ClientModelsImpl getClientModels() {
84+
return this.clientModels;
8585
}
8686

8787
/**
@@ -124,7 +124,7 @@ public NamingClientImpl(HttpPipeline httpPipeline) {
124124
public NamingClientImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter) {
125125
this.httpPipeline = httpPipeline;
126126
this.serializerAdapter = serializerAdapter;
127-
this.models = new ModelsImpl(this);
127+
this.clientModels = new ClientModelsImpl(this);
128128
this.unionEnums = new UnionEnumsImpl(this);
129129
this.service = RestProxy.create(NamingClientService.class, this.httpPipeline, this.getSerializerAdapter());
130130
}

0 commit comments

Comments
 (0)