-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update test cases for spread * Update the spread test cases * Add changelog * Add test case * Update summery * Update summary * Remove the test case for quantum model considerint we are still under discussion over them * Update the comments * Update the comments * Update the docs * Remove this case considering we have no clear conscencus on what it should do * Update the summery doc * Update the summery doc * Update the sumary * Reorgnized to sub-namespaces * Update the summary * Update the summary * Reorganize the test cases' positions
- Loading branch information
Showing
4 changed files
with
280 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@azure-tools/cadl-ranch-specs": patch | ||
--- | ||
|
||
Add test case for spread operator |
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
141 changes: 141 additions & 0 deletions
141
packages/cadl-ranch-specs/http/parameters/spread/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,141 @@ | ||
import "@typespec/http"; | ||
import "@azure-tools/cadl-ranch-expect"; | ||
import "@azure-tools/typespec-client-generator-core"; | ||
|
||
using TypeSpec.Http; | ||
using Azure.ClientGenerator.Core; | ||
|
||
@doc("Test for the spread operator.") | ||
@supportedBy("dpg") | ||
@scenarioService("/parameters/spread") | ||
namespace Parameters.Spread; | ||
|
||
@route("/model") | ||
@operationGroup | ||
namespace Model { | ||
@doc("This is a simple model.") | ||
model BodyParameter { | ||
name: string; | ||
} | ||
|
||
@scenario | ||
@scenarioDoc(""" | ||
Test case for spread named model. | ||
|
||
Should generate request body model named `BodyParameter`. | ||
Should generate an operation like below: | ||
``` | ||
spreadAsRequestBody(bodyParameter: BodyParameter) | ||
``` | ||
Note the parameter name is guessed from the model name and it may vary by language. | ||
|
||
Expected request body: | ||
```json | ||
{ "name": "foo" } | ||
``` | ||
""") | ||
@route("/request-body") | ||
@put | ||
op spreadAsRequestBody(...BodyParameter): NoContentResponse; | ||
} | ||
|
||
@route("/alias") | ||
@operationGroup | ||
namespace Alias { | ||
alias BodyParameter = { | ||
name: string; | ||
}; | ||
|
||
@scenario | ||
@scenarioDoc(""" | ||
Test case for spread alias. | ||
|
||
Should not generate any model named `BodyParameter`. | ||
Should generate an operation like: | ||
``` | ||
spreadAsRequestBody(name: string) | ||
``` | ||
|
||
Expected request body: | ||
```json | ||
{ "name": "foo" } | ||
``` | ||
""") | ||
@route("/request-body") | ||
@put | ||
op spreadAsRequestBody(...BodyParameter): NoContentResponse; | ||
|
||
alias RequestParameter = { | ||
@path | ||
id: string; | ||
|
||
@header | ||
`x-ms-test-header`: string; | ||
name: string; | ||
}; | ||
|
||
@scenario | ||
@scenarioDoc(""" | ||
Test case for spread alias with path and header parameter. | ||
|
||
Should not generate any model named `RequestParameter`. | ||
Should generate an operation like below: | ||
``` | ||
spreadAsRequestParameter(id: string, x_ms_test_header: string, name: string) | ||
``` | ||
Note the parameter name may be normalized and vary by language. | ||
|
||
Expected path parameter: id="1" | ||
Expected header parameter: x-ms-test-header="bar" | ||
Expected request body: | ||
```json | ||
{ "name": "foo" } | ||
``` | ||
""") | ||
@route("/request-parameter/{id}") | ||
@put | ||
op spreadAsRequestParameter(...RequestParameter): NoContentResponse; | ||
|
||
alias MultipleRequestParameters = { | ||
@path | ||
id: string; | ||
|
||
@header | ||
`x-ms-test-header`: string; | ||
prop1: string; | ||
prop2: string; | ||
prop3: string; | ||
prop4: string; | ||
prop5: string; | ||
prop6: string; | ||
}; | ||
|
||
@scenario | ||
@scenarioDoc(""" | ||
Test case for spread alias including 6 parameters. May handle as property bag for these parameters. | ||
|
||
Should not generate any model named `AliasMultipleRequestParameters`. | ||
Should generate an operation like below: | ||
``` | ||
spreadWithMultipleParameters(id: string, x_ms_test_header: string, prop1: string, prop2: string, prop3: string, prop4: string, prop5: string, prop6: string) | ||
``` | ||
Note it's also acceptable if some languages handle it as property bag. | ||
|
||
Expected path parameter: id="1" | ||
Expected header parameter: x-ms-test-header="bar" | ||
Expected request body: | ||
```json | ||
{ | ||
"prop1":"foo1", | ||
"prop2":"foo2", | ||
"prop3":"foo3", | ||
"prop4":"foo4", | ||
"prop5":"foo5", | ||
"prop6":"foo6" | ||
} | ||
``` | ||
""") | ||
@route("/multiple-parameters/{id}") | ||
@put | ||
op spreadWithMultipleParameters(...MultipleRequestParameters): NoContentResponse; | ||
} |
41 changes: 41 additions & 0 deletions
41
packages/cadl-ranch-specs/http/parameters/spread/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,41 @@ | ||
import { passOnSuccess, mockapi } from "@azure-tools/cadl-ranch-api"; | ||
import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; | ||
|
||
export const Scenarios: Record<string, ScenarioMockApi> = {}; | ||
|
||
Scenarios.Parameters_Spread_Model_spreadAsRequestBody = passOnSuccess( | ||
mockapi.put("/parameters/spread/model/request-body", (req) => { | ||
req.expect.bodyEquals({ name: "foo" }); | ||
return { status: 204 }; | ||
}), | ||
); | ||
|
||
Scenarios.Parameters_Spread_Alias_spreadAsRequestBody = passOnSuccess( | ||
mockapi.put("/parameters/spread/alias/request-body", (req) => { | ||
req.expect.bodyEquals({ name: "foo" }); | ||
return { status: 204 }; | ||
}), | ||
); | ||
|
||
Scenarios.Parameters_Spread_Alias_spreadAsRequestParameter = passOnSuccess( | ||
mockapi.put("/parameters/spread/alias/request-parameter/1", (req) => { | ||
req.expect.containsHeader("x-ms-test-header", "bar"); | ||
req.expect.bodyEquals({ name: "foo" }); | ||
return { status: 204 }; | ||
}), | ||
); | ||
|
||
Scenarios.Parameters_Spread_Alias_spreadWithMultipleParameters = passOnSuccess( | ||
mockapi.put("/parameters/spread/alias/multiple-parameters/1", (req) => { | ||
req.expect.containsHeader("x-ms-test-header", "bar"); | ||
req.expect.bodyEquals({ | ||
prop1: "foo1", | ||
prop2: "foo2", | ||
prop3: "foo3", | ||
prop4: "foo4", | ||
prop5: "foo5", | ||
prop6: "foo6", | ||
}); | ||
return { status: 204 }; | ||
}), | ||
); |