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

Malformed response w/ ProblemDetails (AutoWrapper 4.5) #136

Open
nwoolls opened this issue May 10, 2022 · 0 comments
Open

Malformed response w/ ProblemDetails (AutoWrapper 4.5) #136

nwoolls opened this issue May 10, 2022 · 0 comments

Comments

@nwoolls
Copy link

nwoolls commented May 10, 2022

I am attempting to work around the issues reported in #135 and #133 by using AutoWrapper 4.5 w/ the ProblemDetails response. However, I am running into issues with that configuration. Specifically, when the .NET stack / middleware returns ProblemDetails rather than my own controller code, the response is malformed.

You can reproduce this with the following steps.

From the command line:

dotnet --version
6.0.101
mkdir autowrapper-problemdetails-issue
cd autowrapper-problemdetails-issue/
dotnet new webapi
dotnet add package AutoWrapper.Core --version 4.5.0

Edit Program.cs and add:

var options = new AutoWrapperOptions
{
    IsDebug = app.Environment.IsDevelopment(),
    UseApiProblemDetailsException = true
};
app.UseApiResponseAndExceptionWrapper(options);

Edit WeatherForecastController.cs and add:

public class InputModel
{
    [Required(AllowEmptyStrings = false)]
    public string? FirstName { get; set; }
}

[HttpPost]
public IActionResult Post(InputModel inputModel)
{
    return StatusCode(StatusCodes.Status201Created);
}

Example 1 - response is malformed

curl -X 'POST' \
  'https://localhost:7265/WeatherForecast' \
  -H 'accept: */*' \
  -H 'Content-Type: application/json' \
  -d '{}'
{
  "type": [],
  "title": [],
  "status": [],
  "traceId": [],
  "errors": [
    [
      [
        []
      ]
    ]
  ]
}

Example 2 - response is malformed

curl -X 'POST' \
  'https://localhost:7265/WeatherForecast' \
  -H 'accept: */*' \
  -d '{
  "firstName": "string"
}'
{
  "type": [],
  "title": [],
  "status": [],
  "traceId": []
}

Thanks in advance for your guidance!

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

No branches or pull requests

1 participant