diff --git a/.chronus/changes/azure-http-specs_client-namespace-2024-10-29-12-8-41.md b/.chronus/changes/azure-http-specs_client-namespace-2024-10-29-12-8-41.md new file mode 100644 index 0000000000..8616a0116b --- /dev/null +++ b/.chronus/changes/azure-http-specs_client-namespace-2024-10-29-12-8-41.md @@ -0,0 +1,7 @@ +--- +changeKind: feature +packages: + - "@azure-tools/azure-http-specs" +--- + +Add test scenario for clientNamespace \ No newline at end of file diff --git a/packages/azure-http-specs/spec-summary.md b/packages/azure-http-specs/spec-summary.md index 899eb39c5a..05c7a8e808 100644 --- a/packages/azure-http-specs/spec-summary.md +++ b/packages/azure-http-specs/spec-summary.md @@ -1717,6 +1717,23 @@ Expected header parameters: Expected response header: - x-ms-client-request-id= +### Client_ClientNamespace + +- Endpoints: + - `get /client/client-namespace/second` + - `get /client/client-namespace/first` + +Expected client namespace for clients: + +- ClientNamespaceFirstClient: Client.ClientNamespace +- ClientNamespaceSecondClient: Client.ClientNamespace.Second + +Expected client namespace for models: + +- FirstClientResult: Client.ClientNamespace.First +- SecondClientResult: Client.ClientNamespace.Second +- SecondClientEnumType: Client.ClientNamespace.Second.Sub + ### Client_Naming_Header_request - Endpoint: `post /client/naming/header` diff --git a/packages/azure-http-specs/specs/client/namespace/client.tsp b/packages/azure-http-specs/specs/client/namespace/client.tsp new file mode 100644 index 0000000000..d3958b5522 --- /dev/null +++ b/packages/azure-http-specs/specs/client/namespace/client.tsp @@ -0,0 +1,36 @@ +import "./main.tsp"; +import "@azure-tools/typespec-client-generator-core"; + +using TypeSpec.Http; +using Spector; +using Azure.ClientGenerator.Core; +using Client.ClientNamespace; + +@route("/client/client-namespace") +namespace ClientNameSpaceClient; + +@client({ + name: "ClientNamespaceFirstClient", + service: Client.ClientNamespace, +}) +@clientNamespace("client.clientnamespace", "java") +@clientNamespace("client.clientnamespace", "python") +interface ClientNamespaceFirstClient { + getFirst is First.getFirst; +} +@@clientNamespace(FirstModel, "client.clientnamespace.first", "java"); +@@clientNamespace(FirstModel, "client.clientnamespace.first", "python"); + +@client({ + name: "ClientNamespaceSecondClient", + service: Client.ClientNamespace, +}) +@clientNamespace("client.clientnamespace.second", "java") +@clientNamespace("client.clientnamespace.second", "python") +namespace ClientNamespaceSecondClient { + op getSecond is Second.getSecond; +} +@@clientNamespace(Second.Model, "client.clientnamespace.second", "java"); +@@clientNamespace(Second.Model, "client.clientnamespace.second", "python"); +@@clientNamespace(Second.Model.SecondClientEnumType, "client.clientnamespace.second.sub", "java"); +@@clientNamespace(Second.Model.SecondClientEnumType, "client.clientnamespace.second.sub", "python"); diff --git a/packages/azure-http-specs/specs/client/namespace/main.tsp b/packages/azure-http-specs/specs/client/namespace/main.tsp new file mode 100644 index 0000000000..fd8efdbd5d --- /dev/null +++ b/packages/azure-http-specs/specs/client/namespace/main.tsp @@ -0,0 +1,51 @@ +import "@typespec/http"; +import "@typespec/spector"; + +using TypeSpec.Http; +using Spector; + +/** Illustrates the clientNamespace cases. */ +@scenarioService("/client/client-namespace") +@scenario +@scenarioDoc(""" + Expected client namespace for clients: + - ClientNamespaceFirstClient: Client.ClientNamespace + - ClientNamespaceSecondClient: Client.ClientNamespace.Second + + Expected client namespace for models: + - FirstClientResult: Client.ClientNamespace.First + - SecondClientResult: Client.ClientNamespace.Second + - SecondClientEnumType: Client.ClientNamespace.Second.Sub + """) +namespace Client.ClientNamespace; + +interface First { + #suppress "@azure-tools/cadl-ranch-expect/missing-scenario" "scenario defined in client.tsp" + @route("/first") + @get + getFirst(): FirstModel.FirstClientResult; +} + +namespace FirstModel { + model FirstClientResult { + name: string; + } +} + +namespace Second { + #suppress "@azure-tools/cadl-ranch-expect/missing-scenario" "scenario defined in client.tsp" + @route("/second") + @get + op getSecond(): Model.SecondClientResult; + + namespace Model { + model SecondClientResult { + type: SecondClientEnumType; + } + + union SecondClientEnumType { + string, + Second: "second", + } + } +} diff --git a/packages/azure-http-specs/specs/client/namespace/mockapi.ts b/packages/azure-http-specs/specs/client/namespace/mockapi.ts new file mode 100644 index 0000000000..d588623451 --- /dev/null +++ b/packages/azure-http-specs/specs/client/namespace/mockapi.ts @@ -0,0 +1,30 @@ +import { json, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api"; + +export const Scenarios: Record = {}; + +Scenarios.Client_ClientNamespace = passOnSuccess([ + { + uri: "/client/client-namespace/first", + method: "get", + request: { + body: {}, + }, + response: { + status: 200, + body: json({ name: "first" }), + }, + kind: "MockApiDefinition", + }, + { + uri: "/client/client-namespace/second", + method: "get", + request: { + body: {}, + }, + response: { + status: 200, + body: json({ type: "second" }), + }, + kind: "MockApiDefinition", + }, +]);