Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/SwaggerProvider.DesignTime/v3/OperationCompiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ type OperationCompiler(schema: OpenApiDocument, defCompiler: DefinitionCompiler,
[ if not(isNull payloadMime) then
"Content-Type", payloadMime
if not(isNull retMime) then
"Accept", MediaTypes.ApplicationJson ]
"Accept", retMime ]
@>

// Locates parameters matching the arguments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,12 @@ let ``Return text/csv GET Test``() =
[<Fact>]
let ``Send & return text/plain POST Test``() =
api.PostApiConsumesText("hello") |> asyncEqual "hello"

// Test for https://github.com/fsprojects/SwaggerProvider/pull/290 to check for expected 'Accept' header values
[<Fact>]
let ``Return text/plain Accept header Test``() =
api.GetApiCheckAcceptsPlain() |> asyncEqual "Hello world"

[<Fact>]
let ``Return text/csv Accept header Test``() =
api.GetApiCheckAcceptsCsv() |> asyncEqual "Hello,world"
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,32 @@ type ReturnCsvController() =
member this.Get() =
"Hello,world" |> ActionResult<string>

// CheckAcceptsPlainController and CheckAcceptsCsvController are tests for https://github.com/fsprojects/SwaggerProvider/pull/290
// to test that the generated 'Accept' headers contain the expected values
[<Route("api/[controller]")>]
[<ApiController>]
type CheckAcceptsPlainController() =
inherit ControllerBase()

[<HttpGet; Produces("text/plain")>]
member this.Get() =
if this.Request.Headers.Accept.Equals("text/plain") then
"Hello world" |> ActionResult<string>
else
ActionResult<string>(UnsupportedMediaTypeResult())

[<Route("api/[controller]")>]
[<ApiController>]
type CheckAcceptsCsvController() =
inherit ControllerBase()

[<HttpGet; Produces("text/csv")>]
member this.Get() =
if this.Request.Headers.Accept.Equals("text/csv") then
"Hello,world" |> ActionResult<string>
else
ActionResult<string>(UnsupportedMediaTypeResult())

[<Route("api/[controller]")>]
[<ApiController>]
type ConsumesTextController() =
Expand Down
Loading