Repository navigation
Add 202 Accepted provider tests to cover non-200/201 2xx response types - #316
Conversation
…sponses Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Pull request overview
Adds provider test coverage to ensure the v2/v3 operation compilers correctly treat any 2xx (specifically 202 Accepted) response with a body as the success type, rather than defaulting to unit.
Changes:
- Added a new
AcceptedControllerwith GET/POST endpoints returning HTTP 202 and astringbody. - Added v2 provider tests validating
GetApiAccepted()/PostApiAccepted()return"accepted-value". - Added v3 provider tests validating
GetApiAccepted()/PostApiAccepted()return"accepted-value".
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/Swashbuckle.WebApi.Server/Controllers/NoContentControllers.fs | Adds an AcceptedController returning 202 with a string payload to exercise non-200/201 2xx success selection. |
| tests/SwaggerProvider.ProviderTests/v3/Swashbuckle.NoContentControllers.Tests.fs | Adds v3 OpenAPI provider tests asserting 202 responses return a string. |
| tests/SwaggerProvider.ProviderTests/v2/Swashbuckle.NoContentControllers.Tests.fs | Adds v2 Swagger provider tests asserting 202 responses return a string. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| x.StatusCode(202, "accepted-value") |> ActionResult<string> | ||
|
|
||
| [<HttpPost>] | ||
| [<Produces("application/json")>] | ||
| [<ProducesResponseType(typeof<string>, 202)>] | ||
| member x.Post() : ActionResult<string> = | ||
| x.StatusCode(202, "accepted-value") |> ActionResult<string> |
There was a problem hiding this comment.
ActionResult<string> cannot be created by piping an IActionResult (from StatusCode(202, ...)) into ActionResult<string>. This pattern only works when the piped value is the response body (e.g., a string). Wrap the StatusCode(...) result with the ActionResult<string>(...) constructor, or use Accepted("accepted-value") and wrap it similarly, to keep the 202 status while returning a string body.
| x.StatusCode(202, "accepted-value") |> ActionResult<string> | |
| [<HttpPost>] | |
| [<Produces("application/json")>] | |
| [<ProducesResponseType(typeof<string>, 202)>] | |
| member x.Post() : ActionResult<string> = | |
| x.StatusCode(202, "accepted-value") |> ActionResult<string> | |
| ActionResult<string>(x.StatusCode(202, "accepted-value")) | |
| [<HttpPost>] | |
| [<Produces("application/json")>] | |
| [<ProducesResponseType(typeof<string>, 202)>] | |
| member x.Post() : ActionResult<string> = | |
| ActionResult<string>(x.StatusCode(202, "accepted-value")) |
| x.StatusCode(202, "accepted-value") |> ActionResult<string> | ||
|
|
||
| [<HttpPost>] | ||
| [<Produces("application/json")>] | ||
| [<ProducesResponseType(typeof<string>, 202)>] | ||
| member x.Post() : ActionResult<string> = | ||
| x.StatusCode(202, "accepted-value") |> ActionResult<string> |
There was a problem hiding this comment.
Same issue as the GET action: StatusCode(202, ...) returns an IActionResult, so |> ActionResult<string> is not a valid conversion. Use ActionResult<string>(x.StatusCode(202, "accepted-value")) (or ActionResult<string>(x.Accepted("accepted-value"))) so this compiles and preserves the 202 response with a body.
| x.StatusCode(202, "accepted-value") |> ActionResult<string> | |
| [<HttpPost>] | |
| [<Produces("application/json")>] | |
| [<ProducesResponseType(typeof<string>, 202)>] | |
| member x.Post() : ActionResult<string> = | |
| x.StatusCode(202, "accepted-value") |> ActionResult<string> | |
| ActionResult<string>(x.StatusCode(202, "accepted-value")) | |
| [<HttpPost>] | |
| [<Produces("application/json")>] | |
| [<ProducesResponseType(typeof<string>, 202)>] | |
| member x.Post() : ActionResult<string> = | |
| ActionResult<string>(x.StatusCode(202, "accepted-value")) |
aba3a6c
into
repo-assist/fix-2xx-response-handling-e5a50c1c7c7d0452
…rs (#313) * Fix 2xx response handling in v2 and v3 OperationCompilers v2: Expand success response selector from 200/201-only to all 2xx codes (200–299). APIs that document only 202 Accepted (or another 2xx) as their success response now generate a correctly-typed return instead of Task<unit>. v3: Add explicit guard for retTy = Some(typeof<unit>) so that operations whose schema yields a unit return type (e.g. 204 No Content with an application/json content type annotation but no schema) skip JSON deserialization and simply return unit. This prevents a JsonException when the response body is empty. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * ci: trigger checks * Add v2 integration tests for 204 No Content responses (#314) * Initial plan * Add v2 NoContent (204) integration test cases Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com> * Add 202 Accepted provider tests to cover non-200/201 2xx response types (#316) * Initial plan * Add 202 Accepted controller and provider tests for non-200/201 2xx responses Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com> * Prefer 200 > other 2xx > `default` in OperationCompilers (#317) * Initial plan * Prefer explicit 2xx responses over default in v2 and v3 OperationCompilers Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com> * Prefer 200 > 20x > default in OperationCompilers, fix formatting Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com> * Update src/SwaggerProvider.DesignTime/v3/OperationCompiler.fs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com> Co-authored-by: Sergey Tihon <sergey.tihon@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Remove redundant `| Some t when t = typeof<unit>` guards in v3 OperationCompiler (#320) * Initial plan * Remove redundant unit type guards in v3 OperationCompiler Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com> Co-authored-by: Sergey Tihon <sergey.tihon@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
The v2/v3 OperationCompilers were updated to select any 2xx response (not just 200/201) as the success type, but there were no tests exercising a 2xx response other than 200/201 with a meaningful body — leaving the regression risk unguarded.
Changes
AcceptedControllerinNoContentControllers.fs— GET and POST endpoints returning HTTP 202 with astringbody viaStatusCode(202, "accepted-value")Swashbuckle.NoContentControllers.Tests.fs— assert thatGetApiAccepted()/PostApiAccepted()return"accepted-value", confirming the compiler emitsTask<string>rather thanTask<unit>for 202 responses💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.