diff --git a/.changeset/nine-otters-change.md b/.changeset/nine-otters-change.md new file mode 100644 index 000000000..4ad92bd4d --- /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..232fd87ef 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_internalWithIncludeModel + +- 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 +{ + "name": +} +```` + ### 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..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 @@ -20,6 +20,18 @@ 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 InternalIncludeModel { + name: string; + nested: NestedIncludeModel; +} + +@doc("This is a model referred by model decorated with @include. It should be generated and exported.") +model NestedIncludeModel { + comment: 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 +68,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 +{ + "name": +} +``` +""") +@route("/internal") +@post +@global.Azure.ClientGenerator.Core.internal +op internalWithIncludeModel(@body body: InternalIncludeModel): InternalIncludeModel; + @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..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 @@ -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_internalWithIncludeModel = passOnSuccess( + mockapi.post("/azure/client-generator-core/internal/internal", (req) => { + req.expect.bodyNotEmpty(); + return { + status: 200, + body: json({ name: req.body["name"] }), + }; + }), +);