Skip to content

Add 202 Accepted provider tests to cover non-200/201 2xx response types - #316

Merged
sergey-tihon merged 2 commits into
repo-assist/fix-2xx-response-handling-e5a50c1c7c7d0452from
copilot/sub-pr-313
Mar 11, 2026
Merged

sergey-tihon merged 2 commits into
repo-assist/fix-2xx-response-handling-e5a50c1c7c7d0452from
copilot/sub-pr-313

Conversation

Copilot AI commented Mar 11, 2026 •

Copy link
Copy Markdown
Contributor

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

  • New AcceptedController in NoContentControllers.fs — GET and POST endpoints returning HTTP 202 with a string body via StatusCode(202, "accepted-value")
  • v2 + v3 provider tests in Swashbuckle.NoContentControllers.Tests.fs — assert that GetApiAccepted() / PostApiAccepted() return "accepted-value", confirming the compiler emits Task<string> rather than Task<unit> for 202 responses
[<Fact>]
let ``Test 202 Accepted with GET returns string``() =
    task {
        let! result = api.GetApiAccepted()
        result |> shouldEqual "accepted-value"
    }

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…sponses

Co-authored-by: sergey-tihon <1197905+sergey-tihon@users.noreply.github.com>

Copilot AI commented Mar 11, 2026

Copy link
Copy Markdown
Contributor Author

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:

  • petstore.swagger.io
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet /usr/share/dotnet/sdk/10.0.102/FSharp/fsc.dll @/tmp/MSBuildTemp1qh69L/tmpae19ee51077841f287627c15b8e56657.rsp (dns block)
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet /usr/share/dotnet/sdk/10.0.102/FSharp/fsc.dll @/tmp/MSBuildTempItaJUg/tmp0a882f2d1c3646d382263ca7b7dd1bd6.rsp (dns block)
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet /usr/share/dotnet/sdk/10.0.102/FSharp/fsc.dll @/tmp/MSBuildTempoViz4d/tmpc0fe627d27d44629bd522a0e4d4b1217.rsp (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Address feedback on 2xx response handling in OperationCompilers Add 202 Accepted provider tests to cover non-200/201 2xx response types Mar 11, 2026
@sergey-tihon
sergey-tihon marked this pull request as ready for review March 11, 2026 16:26
Copilot AI review requested due to automatic review settings March 11, 2026 16:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 AcceptedController with GET/POST endpoints returning HTTP 202 and a string body.
  • 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.

Comment on lines +43 to +49
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>

Copilot AI Mar 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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"))

Copilot uses AI. Check for mistakes.
Comment on lines +43 to +49
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>

Copilot AI Mar 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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"))

Copilot uses AI. Check for mistakes.
@sergey-tihon
sergey-tihon merged commit aba3a6c into repo-assist/fix-2xx-response-handling-e5a50c1c7c7d0452 Mar 11, 2026
18 checks passed
@sergey-tihon
sergey-tihon deleted the copilot/sub-pr-313 branch March 11, 2026 16:29
sergey-tihon added a commit that referenced this pull request Mar 11, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants