Skip to content
This repository has been archived by the owner on Jan 21, 2025. It is now read-only.

Add test for templated type #650

Merged
merged 26 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e96bfca
Add model test
melina5656 Jul 26, 2024
2b49d1c
update
melina5656 Jul 29, 2024
230eeaa
Update mockapi.ts
melina5656 Jul 29, 2024
e2c3466
update
melina5656 Jul 30, 2024
64aa44c
update
melina5656 Jul 31, 2024
2bd8ca6
Merge remote-tracking branch 'upstream/main' into test-ModelTypespec
melina5656 Jul 31, 2024
802b2ba
Update mockapi.ts
melina5656 Jul 31, 2024
1980445
Update main.tsp
melina5656 Aug 2, 2024
0c23b81
Update main.tsp
melina5656 Aug 2, 2024
1197e8e
Update main.tsp
melina5656 Aug 2, 2024
36fc037
Update main.tsp
melina5656 Aug 2, 2024
1da4343
update
melina5656 Aug 2, 2024
7d8df90
Merge remote-tracking branch 'upstream/main' into test-ModelTypespec
melina5656 Aug 5, 2024
282a86b
update
melina5656 Aug 5, 2024
c909f0c
Merge remote-tracking branch 'upstream/main' into test-ModelTypespec
melina5656 Aug 5, 2024
718a318
Update main.tsp
melina5656 Aug 5, 2024
d0cd3c4
resolve comments
melina5656 Aug 8, 2024
bb768e2
Merge remote-tracking branch 'upstream/main' into test-ModelTypespec
melina5656 Aug 8, 2024
e993e0d
Merge remote-tracking branch 'upstream/main' into test-ModelTypespec
melina5656 Aug 23, 2024
58624b5
Update main.tsp
melina5656 Aug 23, 2024
d9a10ab
update
melina5656 Aug 29, 2024
f8db6a6
Merge remote-tracking branch 'upstream/main' into test-ModelTypespec
melina5656 Aug 29, 2024
2a7d4f3
update
melina5656 Aug 30, 2024
7dfcfbc
update
melina5656 Sep 4, 2024
69e702a
Merge remote-tracking branch 'upstream/main' into test-ModelTypespec
melina5656 Sep 4, 2024
f991d2a
update
melina5656 Sep 6, 2024
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/young-doors-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@azure-tools/cadl-ranch-specs": patch
---

Added Type_Model_Generic_templatedType test scenarios and corresponding Mock API implementations for type/model/templated
24 changes: 24 additions & 0 deletions packages/cadl-ranch-specs/cadl-ranch-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -5540,6 +5540,30 @@ Expected input body:
}
```

### Type_Model_Templated_templatedType

- Endpoint: `put /type/model/templated/templatedType`

Expected input body:

```json
{
"kind": "Int32Values",
"values": [1234],
"value": 1234
}
```

Expected response body:

```json
{
"kind": "Int32Values",
"values": [1234],
"value": 1234
}
```

### Type_Model_Usage_input

- Endpoint: `get /type/model/usage/input`
Expand Down
72 changes: 72 additions & 0 deletions packages/cadl-ranch-specs/http/type/model/templated/main.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import "@typespec/http";
import "@azure-tools/cadl-ranch-expect";
import "@azure-tools/typespec-client-generator-core";

using TypeSpec.Http;
using Azure.ClientGenerator.Core;

/**
* Illustrates the model templated cases. There is a base templated type and an instantiated type extending from it.
*/
@scenarioService("/type/model/templated")
namespace Type.Model.Templated;

@friendlyName("{name}Type", T)
model NumericType<T extends numeric> {
/**
* An array of numeric values.
*/
values: T[];

value: T;
}

/**
* An instantiated type representing int32 type.
*/
model Int32Type extends NumericType<int32> {
melina5656 marked this conversation as resolved.
Show resolved Hide resolved
/**
* The Kind of the Int32Type.
*/
kind: "Int32Values";
}
melina5656 marked this conversation as resolved.
Show resolved Hide resolved

/**
* An instantiated type representing float type.
*/
model FloatType extends NumericType<float> {
melina5656 marked this conversation as resolved.
Show resolved Hide resolved
/**
* The Kind of the FloatType.
*/
kind: "FloatValues";
}

@scenario
@scenarioDoc("""
Expected input body:
```json
{
"kind": "Int32Values",
"values":
[
1234
],
"value": 1234
}
```

Expected response body:
```json
{
"kind": "Int32Values",
"values":
[
1234
],
"value": 1234
}
```
""")
@route("/templatedType")
@put
op templatedType(@body input: Int32Type): Int32Type;
melina5656 marked this conversation as resolved.
Show resolved Hide resolved
20 changes: 20 additions & 0 deletions packages/cadl-ranch-specs/http/type/model/templated/mockapi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { passOnSuccess, mockapi, json } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";

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

const body = {
kind: "Int32Values",
values: [1234],
value: 1234,
};

Scenarios.Type_Model_Templated_templatedType = passOnSuccess(
mockapi.put("/type/model/templated/templatedType", (req) => {
req.expect.bodyEquals(body);
return {
status: 200,
body: json(body),
};
}),
);
Loading