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 all 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
7 changes: 7 additions & 0 deletions .changeset/young-doors-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@azure-tools/cadl-ranch-specs": patch
---

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

### Type_Model_Templated_float32Type

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

Expected input body:

```json
{
"kind": "Float32Values",
"values": [0.5],
"value": 0.5
}
```

Expected response body:

```json
{
"kind": "Float32Values",
"values": [0.5],
"value": 0.5
}
```

### Type_Model_Templated_int32Type

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

Expected input body:

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

Expected response body:

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

### Type_Model_Templated_numericType

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

Expected input body:

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

Expected response body:

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

### Type_Model_Usage_input

- Endpoint: `get /type/model/usage/input`
Expand Down
131 changes: 131 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,131 @@
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 values type.
*/
model Int32ValuesType extends NumericType<int32> {
/**
* The Kind of the Int32ValuesType.
*/
kind: "Int32Values";
}

/**
* An instantiated type representing float32 values type.
*/
model Float32ValuesType extends NumericType<float32> {
/**
* The Kind of the Float32ValuesType.
*/
kind: "Float32Values";
}

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

Expected response body:
```json
{
"values":
[
1234
],
"value": 1234
}
```
""")
@route("/numericType")
@put
op numericType(@body input: NumericType<int32>): NumericType<int32>;

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

Expected response body:
```json
{
"kind": "Float32Values",
"values":
[
0.5
],
"value": 0.5
}
```
""")
@route("/float32ValuesType")
@put
op float32Type(@body input: Float32ValuesType): Float32ValuesType;

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

Expected response body:
```json
{
"kind": "Int32Values",
"values":
[
1234
],
"value": 1234
}
```
""")
@route("/int32ValuesType")
@put
op int32Type(@body input: Int32ValuesType): Int32ValuesType;
49 changes: 49 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,49 @@
import { passOnSuccess, mockapi, json } from "@azure-tools/cadl-ranch-api";
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api";

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

Scenarios.Type_Model_Templated_numericType = passOnSuccess(
mockapi.put("/type/model/templated/numericType", (req) => {
const body = {
kind: "Int32Values",
values: [1234],
value: 1234,
};
req.expect.bodyEquals(body);
return {
status: 200,
body: json(body),
};
}),
);

Scenarios.Type_Model_Templated_float32Type = passOnSuccess(
mockapi.put("/type/model/templated/float32ValuesType", (req) => {
const body = {
kind: "Float32Values",
values: [0.5],
value: 0.5,
};
req.expect.bodyEquals(body);
return {
status: 200,
body: json(body),
};
}),
);

Scenarios.Type_Model_Templated_int32Type = passOnSuccess(
mockapi.put("/type/model/templated/int32ValuesType", (req) => {
const body = {
kind: "Int32Values",
values: [1234],
value: 1234,
};
req.expect.bodyEquals(body);
return {
status: 200,
body: json(body),
};
}),
);
Loading