This repository has been archived by the owner on Jan 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
436 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
packages/cadl-ranch-specs/http/type/model/templated/main.tsp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
49
packages/cadl-ranch-specs/http/type/model/templated/mockapi.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}; | ||
}), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.