From 42fb330674d546212d67d5944cfef8439b2a7023 Mon Sep 17 00:00:00 2001 From: tadelesh Date: Fri, 7 Jul 2023 16:57:44 +0800 Subject: [PATCH 1/5] Add test for @include over @internal --- .changeset/nine-otters-change.md | 5 ++++ .../cadl-ranch-specs/cadl-ranch-summary.md | 18 +++++++++++++ .../client-generator-core/internal/main.tsp | 26 +++++++++++++++++++ .../client-generator-core/internal/mockapi.ts | 20 ++++++++++---- 4 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 .changeset/nine-otters-change.md diff --git a/.changeset/nine-otters-change.md b/.changeset/nine-otters-change.md new file mode 100644 index 000000000..19ff142ca --- /dev/null +++ b/.changeset/nine-otters-change.md @@ -0,0 +1,5 @@ +--- +"@azure-tools/cadl-ranch-specs": patch +--- + +Add test for @include over @internal diff --git a/packages/cadl-ranch-specs/cadl-ranch-summary.md b/packages/cadl-ranch-specs/cadl-ranch-summary.md index d730d4eef..e819efd46 100644 --- a/packages/cadl-ranch-specs/cadl-ranch-summary.md +++ b/packages/cadl-ranch-specs/cadl-ranch-summary.md @@ -85,6 +85,24 @@ Expected response body: } ``` +### Azure_ClientGenerator_Core_Internal_postInternalOnly + +- Endpoint: `post /azure/client-generator-core/internal/internal` + +This scenario contains an internal operation. It should be generated but not exposed. +Expected body parameter: + +````json +{ + "name": +} +Expected response body: +```json +{ + "result": +} +```` + ### Azure_ClientGenerator_Core_Internal_publicOnly - Endpoint: `get /azure/client-generator-core/internal/public` diff --git a/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/main.tsp b/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/main.tsp index 3f85b928e..95d77b150 100644 --- a/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/main.tsp +++ b/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/main.tsp @@ -20,6 +20,12 @@ model InternalModel { name: string; } +@doc("This is a model only used by internal operation. Also, it is decorated with @include. It should be generated and exported.") +@global.Azure.ClientGenerator.Core.include +model InternaIncludelModel { + name: string; +} + @doc("This is a model used by both public and internal operation. It should be generated and exported.") model SharedModel { name: string; @@ -56,6 +62,26 @@ Expected response body: @global.Azure.ClientGenerator.Core.internal op internalOnly(@query name: string): InternalModel; +@scenario +@scenarioDoc(""" +This scenario contains an internal operation. It should be generated but not exposed. +Expected body parameter: +```json +{ + "name": +} +Expected response body: +```json +{ + "result": +} +``` +""") +@route("/internal") +@post +@global.Azure.ClientGenerator.Core.internal +op postInternalOnly(@body body: InternalModel): InternaIncludelModel; + @route("/shared") @global.Azure.ClientGenerator.Core.operationGroup @scenario diff --git a/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/mockapi.ts b/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/mockapi.ts index 7d6ceefa7..616a8e2a9 100644 --- a/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/mockapi.ts +++ b/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/mockapi.ts @@ -3,7 +3,7 @@ import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; export const Scenarios: Record = {}; -function createInternalMockApis(route: string): MockApi { +function createInternalGetMockApis(route: string): MockApi { const url = `/azure/client-generator-core/internal/${route}`; return mockapi.get(url, (req) => { if (!("name" in req.query)) { @@ -16,9 +16,19 @@ function createInternalMockApis(route: string): MockApi { }); } -Scenarios.Azure_ClientGenerator_Core_Internal_publicOnly = passOnSuccess(createInternalMockApis("public")); -Scenarios.Azure_ClientGenerator_Core_Internal_internalOnly = passOnSuccess(createInternalMockApis("internal")); +Scenarios.Azure_ClientGenerator_Core_Internal_publicOnly = passOnSuccess(createInternalGetMockApis("public")); +Scenarios.Azure_ClientGenerator_Core_Internal_internalOnly = passOnSuccess(createInternalGetMockApis("internal")); Scenarios.Azure_ClientGenerator_Core_Internal_Shared = passOnSuccess([ - createInternalMockApis("shared/public"), - createInternalMockApis("shared/internal"), + createInternalGetMockApis("shared/public"), + createInternalGetMockApis("shared/internal"), ]); + +Scenarios.Azure_ClientGenerator_Core_Internal_postInternalOnly = passOnSuccess( + mockapi.post("/azure/client-generator-core/internal/internal", (req) => { + req.expect.bodyNotEmpty(); + return { + status: 200, + body: json({ result: req.body["name"] }), + }; + }), +); From 0b97ec1a6eb0fc8e7de46b3349696a564fb5caaa Mon Sep 17 00:00:00 2001 From: tadelesh Date: Mon, 10 Jul 2023 10:23:13 +0800 Subject: [PATCH 2/5] review --- .changeset/nine-otters-change.md | 2 +- packages/cadl-ranch-specs/cadl-ranch-summary.md | 4 ++-- .../http/azure/client-generator-core/internal/main.tsp | 6 +++--- .../http/azure/client-generator-core/internal/mockapi.ts | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.changeset/nine-otters-change.md b/.changeset/nine-otters-change.md index 19ff142ca..4ad92bd4d 100644 --- a/.changeset/nine-otters-change.md +++ b/.changeset/nine-otters-change.md @@ -2,4 +2,4 @@ "@azure-tools/cadl-ranch-specs": patch --- -Add test for @include over @internal +Add test for `@include` over `@internal` diff --git a/packages/cadl-ranch-specs/cadl-ranch-summary.md b/packages/cadl-ranch-specs/cadl-ranch-summary.md index e819efd46..232fd87ef 100644 --- a/packages/cadl-ranch-specs/cadl-ranch-summary.md +++ b/packages/cadl-ranch-specs/cadl-ranch-summary.md @@ -85,7 +85,7 @@ Expected response body: } ``` -### Azure_ClientGenerator_Core_Internal_postInternalOnly +### Azure_ClientGenerator_Core_Internal_internalWithIncludeModel - Endpoint: `post /azure/client-generator-core/internal/internal` @@ -99,7 +99,7 @@ Expected body parameter: Expected response body: ```json { - "result": + "name": } ```` diff --git a/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/main.tsp b/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/main.tsp index 95d77b150..243fb0a84 100644 --- a/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/main.tsp +++ b/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/main.tsp @@ -22,7 +22,7 @@ model InternalModel { @doc("This is a model only used by internal operation. Also, it is decorated with @include. It should be generated and exported.") @global.Azure.ClientGenerator.Core.include -model InternaIncludelModel { +model InternalIncludeModel { name: string; } @@ -73,14 +73,14 @@ Expected body parameter: Expected response body: ```json { - "result": + "name": } ``` """) @route("/internal") @post @global.Azure.ClientGenerator.Core.internal -op postInternalOnly(@body body: InternalModel): InternaIncludelModel; +op internalWithIncludeModel(@body body: InternalIncludeModel): InternalIncludeModel; @route("/shared") @global.Azure.ClientGenerator.Core.operationGroup diff --git a/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/mockapi.ts b/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/mockapi.ts index 616a8e2a9..7b567d78f 100644 --- a/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/mockapi.ts +++ b/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/mockapi.ts @@ -28,7 +28,7 @@ Scenarios.Azure_ClientGenerator_Core_Internal_postInternalOnly = passOnSuccess( req.expect.bodyNotEmpty(); return { status: 200, - body: json({ result: req.body["name"] }), + body: json({ name: req.body["name"] }), }; }), ); From 8893755be78c237112138b28c9fb334bdcd9b36b Mon Sep 17 00:00:00 2001 From: tadelesh Date: Mon, 10 Jul 2023 10:25:17 +0800 Subject: [PATCH 3/5] fix --- .../http/azure/client-generator-core/internal/mockapi.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/mockapi.ts b/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/mockapi.ts index 7b567d78f..d4af07df8 100644 --- a/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/mockapi.ts +++ b/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/mockapi.ts @@ -23,7 +23,7 @@ Scenarios.Azure_ClientGenerator_Core_Internal_Shared = passOnSuccess([ createInternalGetMockApis("shared/internal"), ]); -Scenarios.Azure_ClientGenerator_Core_Internal_postInternalOnly = passOnSuccess( +Scenarios.Azure_ClientGenerator_Core_Internal_internalWithIncludeModel = passOnSuccess( mockapi.post("/azure/client-generator-core/internal/internal", (req) => { req.expect.bodyNotEmpty(); return { From 74c2561698caa717f10759ccf3e47736d6774f55 Mon Sep 17 00:00:00 2001 From: tadelesh Date: Mon, 10 Jul 2023 17:52:50 +0800 Subject: [PATCH 4/5] add nested model test --- .../http/azure/client-generator-core/internal/main.tsp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/main.tsp b/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/main.tsp index 243fb0a84..b7cfe8d50 100644 --- a/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/main.tsp +++ b/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/main.tsp @@ -24,6 +24,11 @@ model InternalModel { @global.Azure.ClientGenerator.Core.include model InternalIncludeModel { name: string; + nested: NestedIncludeModel; +} + +model NestedIncludeModel { + comment: string; } @doc("This is a model used by both public and internal operation. It should be generated and exported.") From ead78e60420a2f6e0a5063b307cd80c6522434c3 Mon Sep 17 00:00:00 2001 From: tadelesh Date: Mon, 10 Jul 2023 17:54:42 +0800 Subject: [PATCH 5/5] add doc --- .../http/azure/client-generator-core/internal/main.tsp | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/main.tsp b/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/main.tsp index b7cfe8d50..c313d7b56 100644 --- a/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/main.tsp +++ b/packages/cadl-ranch-specs/http/azure/client-generator-core/internal/main.tsp @@ -27,6 +27,7 @@ model InternalIncludeModel { nested: NestedIncludeModel; } +@doc("This is a model referred by model decorated with @include. It should be generated and exported.") model NestedIncludeModel { comment: string; }