From 89b9a680519cfc3b93327707c3499ad095f54fdd Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Fri, 29 Nov 2024 11:50:08 +0800 Subject: [PATCH 1/4] client namespace --- .../specs/client/namespace/client.tsp | 31 +++++++++++ .../specs/client/namespace/main.tsp | 51 +++++++++++++++++++ .../specs/client/namespace/mockapi.ts | 30 +++++++++++ 3 files changed, 112 insertions(+) create mode 100644 packages/azure-http-specs/specs/client/namespace/client.tsp create mode 100644 packages/azure-http-specs/specs/client/namespace/main.tsp create mode 100644 packages/azure-http-specs/specs/client/namespace/mockapi.ts 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..6fd8e0b39c --- /dev/null +++ b/packages/azure-http-specs/specs/client/namespace/client.tsp @@ -0,0 +1,31 @@ +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") +interface ClientNamespaceFirstClient { + getFirst is First.getFirst; +} +@@clientNamespace(FirstModel, "client.clientnamespace.first", "java"); + +@client({ + name: "ClientNamespaceSecondClient", + service: Client.ClientNamespace, +}) +@clientNamespace("client.clientnamespace.second", "java") +namespace ClientNamespaceSecondClient { + op getSecond is Second.getSecond; +} +@@clientNamespace(Second.Model, "client.clientnamespace.second", "java"); +@@clientNamespace(Second.Model.SecondClientEnumType, "client.clientnamespace.second.sub", "java"); 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", + }, +]); From 95be0717dc68e2a7514f736dc12cfbfe00e8eee8 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Fri, 29 Nov 2024 12:07:05 +0800 Subject: [PATCH 2/4] summary --- packages/azure-http-specs/spec-summary.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/azure-http-specs/spec-summary.md b/packages/azure-http-specs/spec-summary.md index 200e433552..51f292707f 100644 --- a/packages/azure-http-specs/spec-summary.md +++ b/packages/azure-http-specs/spec-summary.md @@ -1381,6 +1381,23 @@ Expected response body: } ``` +### 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` From 55753d5cdddef65d04e89df8a26310b328d99173 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Fri, 29 Nov 2024 12:09:18 +0800 Subject: [PATCH 3/4] changelog --- ...azure-http-specs_client-namespace-2024-10-29-12-8-41.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .chronus/changes/azure-http-specs_client-namespace-2024-10-29-12-8-41.md 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 From 6c9609a0cde67754941574752b147d8d88f7f71c Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Mon, 2 Dec 2024 10:05:46 +0800 Subject: [PATCH 4/4] Update client.tsp --- packages/azure-http-specs/specs/client/namespace/client.tsp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/azure-http-specs/specs/client/namespace/client.tsp b/packages/azure-http-specs/specs/client/namespace/client.tsp index 6fd8e0b39c..d3958b5522 100644 --- a/packages/azure-http-specs/specs/client/namespace/client.tsp +++ b/packages/azure-http-specs/specs/client/namespace/client.tsp @@ -14,18 +14,23 @@ namespace ClientNameSpaceClient; 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");