Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
bead61a
add nested test cases for client-initialization
kazrael2119 Dec 25, 2025
5177a0f
Create nested-test-cases-for-clientinit-2025-11-25-9-26-9.md
kazrael2119 Dec 25, 2025
ed2b358
format
kazrael2119 Dec 25, 2025
1e3e4c6
Merge branch 'main' into nested-test-cases-for-clientinit
kazrael2119 Dec 29, 2025
2da3356
Merge branch 'nested-test-cases-for-clientinit' of https://github.com…
kazrael2119 Dec 29, 2025
d1d043b
update
kazrael2119 Dec 29, 2025
7f6687d
update
kazrael2119 Dec 29, 2025
d152683
format
kazrael2119 Dec 29, 2025
e9fddda
update
kazrael2119 Dec 29, 2025
d2e7c40
Update client.tsp
kazrael2119 Dec 29, 2025
ec89909
Update client.tsp
kazrael2119 Dec 29, 2025
dfb7daa
update cases
kazrael2119 Dec 29, 2025
1d07a36
Update client.tsp
kazrael2119 Dec 29, 2025
33b24d1
Update mockapi.ts
kazrael2119 Dec 30, 2025
124e125
update java client namespace
kazrael2119 Jan 4, 2026
4074e21
update namespace
kazrael2119 Jan 4, 2026
8913621
update namespace
kazrael2119 Jan 4, 2026
520cfd7
Update mockapi.ts
kazrael2119 Jan 5, 2026
0efd089
resolve comments
kazrael2119 Jan 6, 2026
e30a4fd
resolve comment
kazrael2119 Jan 6, 2026
8390aab
format
kazrael2119 Jan 6, 2026
32e8da3
update mockapis
kazrael2119 Jan 6, 2026
7cbffcc
resolve copilot comments
kazrael2119 Jan 16, 2026
758620d
refactor client-initialization
kazrael2119 Jan 20, 2026
9d7b072
update
kazrael2119 Jan 20, 2026
e882e2a
Delete nested-test-cases-for-clientinit-2025-11-25-9-26-9.md
kazrael2119 Jan 20, 2026
3a55750
Create nested-test-cases-for-clientinit-2026-0-20-8-47-56.md
kazrael2119 Jan 20, 2026
70ace6c
Merge branch 'main' into nested-test-cases-for-clientinit
kazrael2119 Jan 20, 2026
49aaa46
update
kazrael2119 Jan 20, 2026
2bd71bc
revert chagne
kazrael2119 Jan 20, 2026
8b0bbd8
Delete nested-test-cases-for-clientinit-2026-0-20-8-47-56.md
kazrael2119 Jan 20, 2026
90003cc
Create nested-test-cases-for-clientinit-2026-0-20-9-55-29.md
kazrael2119 Jan 21, 2026
420e352
Merge branch 'main' into nested-test-cases-for-clientinit
kazrael2119 Jan 21, 2026
188e48d
Merge branch 'main' into nested-test-cases-for-clientinit
kazrael2119 Jan 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: fix
packages:
- "@azure-tools/azure-http-specs"
---

add nested test cases for client-initialization
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import "./main.tsp";
import "@azure-tools/typespec-client-generator-core";
import "@typespec/spector";
import "@typespec/http";
import "@typespec/spector";
import "@azure-tools/typespec-client-generator-core";

using Spector;
using Http;
using Spector;
using Azure.ClientGenerator.Core;

@route("/azure/client-generator-core/client-initialization")
namespace _Specs_.Azure.ClientGenerator.Core.ClientInitialization;
@doc("Test for client initialization decorator - moving parameters from method to client level")
@scenarioService("/azure/client-generator-core/client-initialization/default")
namespace _Specs_.Azure.ClientGenerator.Core.ClientInitialization.DefaultClient;

@@global.Azure.ClientGenerator.Core.clientNamespace(_Specs_.Azure.ClientGenerator.Core.ClientInitialization,
"azure.clientgenerator.core.clientinitialization",
"java"
);
@@global.Azure.ClientGenerator.Core.clientNamespace(Service,
"azure.clientgenerator.core.clientinitialization",
@global.Azure.ClientGenerator.Core.clientNamespace(
"azure.clientgenerator.core.clientinitialization.defaultclient",
"java"
);

)
model HeaderParamClientOptions {
@doc("The name of the client. This parameter is used as a header in all operations.")
name: string;
Expand Down Expand Up @@ -47,6 +43,32 @@ model ParamAliasClientOptions {
blobName: string;
}

model BlobQueryParamClientOptions {
@doc("The blob name to use for operations")
blobName: string;
}

// Common parameter types and models

model NameHeaderParam {
@header("name")
name: string;
}

model RegionQueryParam {
@query
region: string;
}

model Input {
name: string;
}

model BlobQueryParam {
@query
blobName: string;
}

// Scenario 1: Header parameter moved to client level
@scenarioDoc("""
Client for testing header parameter moved to client level.
Expand All @@ -68,13 +90,17 @@ model ParamAliasClientOptions {
@doc("Client for testing header parameter moved to client level.")
@global.Azure.ClientGenerator.Core.client({
name: "HeaderParamClient",
service: Service,
})
@global.Azure.ClientGenerator.Core.clientInitialization(HeaderParamClientOptions)
@route("/header-param")
interface HeaderParam {
withQuery is Service.HeaderParam.withQuery;
withBody is Service.HeaderParam.withBody;
@route("/with-query")
@get
withQuery(...NameHeaderParam, @query id: string): void;

@route("/with-body")
@post
withBody(...NameHeaderParam, @body body: Input): void;
}

// Scenario 2: Multiple parameters (header and query) moved to client level
Expand All @@ -97,47 +123,63 @@ interface HeaderParam {
```
""")
@scenario
@doc("Client for testing multiple parameters (header and query) moved to client level.")
@global.Azure.ClientGenerator.Core.client({
name: "MultipleParamsClient",
service: Service,
})
@global.Azure.ClientGenerator.Core.clientInitialization(MultipleParamsClientOptions)
@route("/multiple-params")
interface MultipleParams {
withQuery is Service.MultipleParams.withQuery;
withBody is Service.MultipleParams.withBody;
@route("/with-query")
@get
withQuery(...NameHeaderParam, ...RegionQueryParam, @query id: string): void;

@route("/with-body")
@post
withBody(...NameHeaderParam, ...RegionQueryParam, @body body: Input): void;
}

// Scenario 3: Mix of client-level and method-level parameters
@scenarioDoc("""
Client for testing a mix of client-level and method-level parameters.
Parameters elevated to client level:
- name: "test-name-value" (header parameter)
Parameters remaining at method level:
- region: "us-west" (query parameter)
Expected client usage:
```ts
const client = new MixedParamsClient({
name: "test-name-value"
});
client.withQuery(region: "us-west", id: "test-id"); // region stays as method param
client.withBody( region: "us-west", body: { name: "test-name" }); // region stays as method param
```
Client for testing a mix of client-level and method-level parameters.

Parameters elevated to client level:
- name: "test-name-value" (header parameter)

Parameters remaining at method level:
- region: "us-west" (query parameter)

Expected client usage:
```ts
const client = new MixedParamsClient({
name: "test-name-value"
});

client.withQuery(region: "us-west", id: "test-id"); // region stays as method param
client.withBody(region: "us-west", body: { name: "test-name" }); // region stays as method param
```
""")
@scenario
@doc("Client for testing a mix of client-level and method-level parameters.")
@global.Azure.ClientGenerator.Core.client({
name: "MixedParamsClient",
service: Service,
})
@global.Azure.ClientGenerator.Core.clientInitialization(MixedParamsClientOptions)
@route("/mixed-params")
interface MixedParams {
withQuery is Service.MixedParams.withQuery;
withBody is Service.MixedParams.withBody;
@route("/with-query")
@get
withQuery(...NameHeaderParam, ...RegionQueryParam, @query id: string): void;

@route("/with-body")
@post
withBody(
...NameHeaderParam,
...RegionQueryParam,
@body body: {
name: string;
},
): void;
}

// Scenario 4: Path parameter moved to client level
Expand All @@ -160,87 +202,111 @@ interface MixedParams {
```
""")
@scenario
@doc("Blob operations with path parameter that should be moved to client level")
@global.Azure.ClientGenerator.Core.client({
name: "PathParamClient",
service: Service,
})
@global.Azure.ClientGenerator.Core.clientInitialization(PathParamClientOptions)
@route("/path")
interface PathParam {
withQuery is Service.PathParam.withQuery;
getStandalone is Service.PathParam.getStandalone;
deleteStandalone is Service.PathParam.deleteStandalone;
@route("/{blobName}/with-query")
@get
withQuery(@path blobName: string, @query format?: string): void;

@route("/{blobName}/get-standalone")
@get
getStandalone(@path blobName: string): BlobProperties;

@route("/{blobName}")
@delete
deleteStandalone(@path blobName: string): void;
}

// Scenario 5: Parameter aliases for better client API names
@scenarioDoc("""
Client for testing the @paramAlias decorator for renaming parameters in client code.

Parameters elevated to client level:
- blobName: "sample-blob" (path parameter)
- blobName: "sample-blob" (path parameter with @paramAlias("blob"))

Expected client usage:
```ts
// Elevated to client level via alias
client.withAliasedName();
const client = new ParamAliasClient({
blobName: "sample-blob"
});

// Elevated to client level via original name
// Operations don't need blob/blobName parameter
client.withAliasedName();
client.withOriginalName();
```
""")
@scenario
@global.Azure.ClientGenerator.Core.clientInitialization(ParamAliasClientOptions)
@doc("Operations demonstrating the @paramAlias decorator for renaming parameters in client code")
@global.Azure.ClientGenerator.Core.client({
name: "ParamAliasClient",
service: Service,
})
@global.Azure.ClientGenerator.Core.clientInitialization(ParamAliasClientOptions)
@route("/param-alias")
interface ParamAlias {
withAliasedName is Service.ParamAlias.withAliasedName;
withOriginalName is Service.ParamAlias.withOriginalName;
@route("/{blob}/with-aliased-name")
@get
withAliasedName(
@path
blob: string,
): void;

@route("/{blobName}/with-original-name")
@get
withOriginalName(
@path
blobName: string,
): void;
}

@doc("Properties of a blob")
model BlobProperties {
name: string;
size: int64;
contentType: string;
createdOn: utcDateTime;
}

// Scenario 6: Query parameter moved to client level
@scenarioDoc("""
Client for testing query parameter moved to client level.

Parameters elevated to client level:
- blobName: "test-blob" (query parameter)

Expected client usage:
```ts
const client = new QueryParamClient({
blobName: "test-blob"
});

// Operations don't need blobName parameter
client.withQuery(format: "text");
client.getStandalone();
client.deleteStandalone();
```
""")
@scenario
@doc("Blob operations with query parameter that should be moved to client level")
@global.Azure.ClientGenerator.Core.client({
name: "ParentClient",
service: Service,
name: "QueryParamClient",
})
namespace ParentClient {
@scenarioDoc("""
Client for testing a path parameter (blobName) moved to client level, in child client.

The child client can be initialized individually, or via its parent client.

Parameters elevated to client level:
- blobName: "sample-blob" (path parameter)

Expected client usage:
```ts
// via ParentClient
const client = new ParentClient.getChildClient({
blobName: "sample-blob"
});

// directly
const client = new ChildClient({
blobName: "sample-blob"
});

// No need to pass blobName to any operations
client.withQuery(format: "text");
client.getStandalone();
client.deleteStandalone();
```
""")
@scenario
@global.Azure.ClientGenerator.Core.operationGroup
@global.Azure.ClientGenerator.Core.clientInitialization({
parameters: PathParamClientOptions,
initializedBy: global.Azure.ClientGenerator.Core.InitializedBy.individually | global.Azure.ClientGenerator.Core.InitializedBy.parent,
})
@route("/child-client")
interface ChildClient {
withQuery is Service.ChildClient.withQuery;
getStandalone is Service.ChildClient.getStandalone;
deleteStandalone is Service.ChildClient.deleteStandalone;
}
@global.Azure.ClientGenerator.Core.clientInitialization(BlobQueryParamClientOptions)
@route("/query")
interface QueryParam {
@route("/with-query")
@get
withQuery(...BlobQueryParam, @query format?: string): void;

@route("/get-standalone")
@get
getStandalone(...BlobQueryParam): BlobProperties;

@route("/delete-resource")
@delete
deleteStandalone(...BlobQueryParam): void;
}
Loading
Loading