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

Optional Query Parameter Test #722

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
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/rich-comics-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@azure-tools/cadl-ranch-specs": minor
---

Add optional parameter ordering test in parameter\body-optionality.
35 changes: 35 additions & 0 deletions packages/cadl-ranch-specs/cadl-ranch-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -2488,6 +2488,41 @@ Expected request body for `set`

Expected no request body for `omit`

### Parameters_BodyOptionality_OptionalityOrdering

- Endpoints:
- `head /parameters/body-optionality/optional-ordering/startwithequired`
- `head /parameters/body-optionality/optional-ordering/startwithoptional`

Test scenario for using a combination of required parameters first and optional parameters later.

Should generate an operation like below:

```
orderingWithRequiredStart(start: string, end?: string)
```

Expected parameter: api-version=2022-12-01-preview
Expected request body:

```json
{ "start": "required" }
```

Another scenario using a combination of optional parameters first and required parameters later

Should generate an operation like below:

```
orderingWithOptionalStart(end: string, start?: string)
```

Expected request body:

```json
{ "end": "required" }
```

### Parameters_BodyOptionality_requiredExplicit

- Endpoint: `post /parameters/body-optionality/required-explicit`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,44 @@ namespace OptionalExplicit {
op omit(@body body?: BodyModel): NoContentResponse;
}

@scenario
@scenarioDoc("""
Test scenario for using a combination of required parameters first and optional parameters later.

Should generate an operation like below:
```
orderingWithRequiredStart(start: string, end?: string)
```

Expected parameter: api-version=2022-12-01-preview
Expected request body:
```json
{ "start": "required" }
```

Another scenario using a combination of optional parameters first and required parameters later

Should generate an operation like below:
```
orderingWithOptionalStart(end: string, start?: string)
```
Expected request body:
```json
{ "end": "required" }
```
""")
@operationGroup
@route("/optional-ordering")
namespace OptionalityOrdering {
@route("/startwithequired")
@head
op OrderingWithRequiredStart(start: string, end?: string): void;

@route("/startwithoptional")
@head
op OrderingWithOptionalStart(start?: string, end: string): void;
}

@scenario
@scenarioDoc("""
Scenario defining how an implicit required body parameter is specified.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,32 @@ Scenarios.Parameters_BodyOptionality_requiredImplicit = createServerTests(
name: "foo",
},
);

Scenarios.Parameters_BodyOptionality_OptionalityOrdering = passOnSuccess([
{
uri: "/parameters/body-optionality/optional-ordering/startwithequired",
method: "head",
request: {
body: {
start: "required",
},
},
response: {
status: 204,
},
kind: "MockApiDefinition",
},
{
uri: "/parameters/body-optionality/optional-ordering/startwithoptional",
method: "head",
request: {
body: {
end: "required",
},
},
response: {
status: 204,
},
kind: "MockApiDefinition",
},
]);
Loading