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

http-specs, test case on status code range #5577

Open
wants to merge 7 commits into from
Open
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@typespec/http-specs"
---

Add test case on status code range
21 changes: 18 additions & 3 deletions packages/http-specs/spec-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -1679,9 +1679,7 @@ Two requests need to be tested.
{ "id": "1", "name": "dog" },
{ "id": "2", "name": "cat" }
],
"links": {
"next": "http://[host]:[port]/payload/pageable/server-driven-pagination/link/nextPage"
}
"next": "http://[host]:[port]/payload/pageable/server-driven-pagination/link/nextPage"
}
```

Expand Down Expand Up @@ -2084,6 +2082,23 @@ Expected request body:
</SimpleModel>
```

### Response_StatusCodeRange_errorResponse

- Endpoint: `get /response/status-code-range/error-response`

Test case for range of status code in error response.

Verify that the result of the API is an error/exception in client, and the error response can be de-serialized to ErrorInRange model (instead of DefaultError model).

Expected status code 494 and response body:

```json
{
"code": "request-header-too-large",
"message": "Request header too large"
}
```

### Routes_fixed

- Endpoint: `get /routes/fixed`
Expand Down
45 changes: 45 additions & 0 deletions packages/http-specs/specs/response/status-code-range/main.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import "@typespec/http";
import "@typespec/spector";

using Http;
using Spector;

/**
* Test for range of status code.
*/
@scenarioService("/response/status-code-range")
namespace Response.StatusCodeRange;
weidongxu-microsoft marked this conversation as resolved.
Show resolved Hide resolved

@scenario
@scenarioDoc("""
Test case for range of status code in error response.

Verify that the result of the API is an error/exception in client, and the error response can be de-serialized to ErrorInRange model (instead of DefaultError model).

Expected status code 494 and response body:
```json
{
"code": "request-header-too-large",
"message": "Request header too large"
}
```
""")
@route("/error-response")
@get
op errorResponse(): 204 | ErrorInRange | DefaultError;
weidongxu-microsoft marked this conversation as resolved.
Show resolved Hide resolved
weidongxu-microsoft marked this conversation as resolved.
Show resolved Hide resolved

@error
model ErrorInRange {
@minValue(494)
@maxValue(499)
@statusCode
_: int32;

code: string;
message: string;
}

@error
model DefaultError {
code: string;
}
19 changes: 19 additions & 0 deletions packages/http-specs/specs/response/status-code-range/mockapi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { json, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";

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

Scenarios.Response_StatusCodeRange_errorResponse = passOnSuccess({
uri: "/response/status-code-range/error-response",
method: "get",
request: {
status: 494,
},
response: {
status: 494,
body: json({
code: "request-header-too-large",
message: "Request header too large",
}),
},
kind: "MockApiDefinition",
});
Loading