diff --git a/.changeset/nasty-fishes-itch.md b/.changeset/nasty-fishes-itch.md new file mode 100644 index 000000000..cb2b21387 --- /dev/null +++ b/.changeset/nasty-fishes-itch.md @@ -0,0 +1,5 @@ +--- +"@azure-tools/cadl-ranch-specs": patch +--- + +Add test case for client initialization diff --git a/packages/cadl-ranch-specs/cadl-ranch-summary.md b/packages/cadl-ranch-specs/cadl-ranch-summary.md index fbaf634ef..39a7022e8 100644 --- a/packages/cadl-ranch-specs/cadl-ranch-summary.md +++ b/packages/cadl-ranch-specs/cadl-ranch-summary.md @@ -1452,6 +1452,15 @@ Expected response body: } ``` +### Client_Initialization_Basic + +- Endpoint: `post /client/initialization/basic/sub-client/{name}:action` + +Testing that "SubClient" be initialized with "name" client property, +and that the "action" API under "SubClient" does not take "name" parameter in method signature. + +Use "subclient1" as "name" parameter in test. + ### Client_Naming_Header_request - Endpoint: `post /client/naming/header` diff --git a/packages/cadl-ranch-specs/http/client/initialization/basic/main.tsp b/packages/cadl-ranch-specs/http/client/initialization/basic/main.tsp new file mode 100644 index 000000000..0bd7f5c69 --- /dev/null +++ b/packages/cadl-ranch-specs/http/client/initialization/basic/main.tsp @@ -0,0 +1,31 @@ +import "@typespec/http"; +import "@azure-tools/cadl-ranch-expect"; +import "@azure-tools/typespec-client-generator-core"; + +using TypeSpec.Http; +using Azure.ClientGenerator.Core; + +/** + * Describe client with `@clientInitialization` + */ +@supportedBy("dpg") +@scenarioService("/client/initialization/basic") +@scenario +@scenarioDoc(""" + Testing that "SubClient" be initialized with "name" client property, + and that the "action" API under "SubClient" does not take "name" parameter in method signature. + + Use "subclient1" as "name" parameter in test. + """) +namespace Client.Initialization.Basic; + +model SubClientOptions { + name: string; +} + +@clientInitialization(SubClientOptions) +interface SubClient { + @post + @route("/sub-client/{name}:action") + action(@path name: string): void; +} diff --git a/packages/cadl-ranch-specs/http/client/initialization/basic/mockapi.ts b/packages/cadl-ranch-specs/http/client/initialization/basic/mockapi.ts new file mode 100644 index 000000000..dc28479d3 --- /dev/null +++ b/packages/cadl-ranch-specs/http/client/initialization/basic/mockapi.ts @@ -0,0 +1,14 @@ +import { passOnSuccess, mockapi } from "@azure-tools/cadl-ranch-api"; +import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; + +export const Scenarios: Record = {}; + +Scenarios.Client_Initialization_Basic = passOnSuccess({ + uri: "/client/initialization/basic/sub-client/subclient1:action", + method: "post", + request: {}, + response: { + status: 204, + }, + kind: "MockApiDefinition", +});