Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for @include over @internal #371

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nine-otters-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@azure-tools/cadl-ranch-specs": patch
---

Add test for `@include` over `@internal`
18 changes: 18 additions & 0 deletions packages/cadl-ranch-specs/cadl-ranch-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": <any string>
}
Expected response body:
```json
{
"name": <any string>
}
````

### Azure_ClientGenerator_Core_Internal_publicOnly

- Endpoint: `get /azure/client-generator-core/internal/public`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member

@weidongxu-microsoft weidongxu-microsoft Jul 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a nested model to also test transitivity?

Or, if we are not sure how transitivity works for @include, I am fine to leave as this.

Copy link
Member Author

@tadelesh tadelesh Jul 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think transitivity should be the work of isInclude (though it seems current TCGC has not implemented it yet). I've created an issue to track.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should figure out this issue now.

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;
Expand Down Expand Up @@ -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": <any string>
}
Expected response body:
```json
{
"name": <any string>
}
```
""")
@route("/internal")
@post
@global.Azure.ClientGenerator.Core.internal
op internalWithIncludeModel(@body body: InternalIncludeModel): InternalIncludeModel;

@route("/shared")
@global.Azure.ClientGenerator.Core.operationGroup
@scenario
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};

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)) {
Expand All @@ -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"] }),
};
}),
);