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

[Bug]: Example value isn't wrapped with the type of the parameter anymore. #3176

Open
EunjeongChoi414 opened this issue Nov 26, 2024 · 2 comments
Labels
bug help-wanted A change up for grabs for contributions from the community

Comments

@EunjeongChoi414
Copy link

EunjeongChoi414 commented Nov 26, 2024

Describe the bug

Before the package was upgraded to 7.0.0,
the example value used to show the the type of the parameter and now it doesn't.
So it's prone to getting null exception because the argument is not passed to the server.

Expected behavior

for example when api looks like this

void TestAsync(TestParam testParam)

'example value' in swagger should be looking like this, "testParam" the type of the dto wrapping its properties.

{
  "testParam": {
    "value1": "string",
    "value2": "string",
    "value3": 0
  }
}

Actual behavior

instead, it looks like this without the dto wrapping. So when you 'try out' with below format then you get null parameter.

{
  "value1": "string",
  "value2": "string",
  "value3": 0
}

Steps to reproduce

Make an api that takes a dto as a parameter like this.

public Task TestAsync(TestParam testParam, CancellationToken cancel = default);

public record TestParam(string Value1, string Value2, bool Value3);

upgrade SwashBuckle packages to 7.0.0 or 7.0.1

<PackageReference Include="Swashbuckle.AspNetCore" Version="7.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="7.0.0" />

and check the actual behavior explained above but when trying with 6.9.0 version it works like the expected behavior.

Exception(s) (if any)

No response

Swashbuckle.AspNetCore version

7.0.0 and 7.1.0

.NET Version

net8.0

Anything else?

No response

@martincostello
Copy link
Collaborator

Does the OpenAPI document for the endpoint look the same between the 6.9.0 version and the 7.0.x version? If so, then this will be an issue in SwaggerUI rather than Swashbuckle.

@EunjeongChoi414
Copy link
Author

Does the OpenAPI document for the endpoint look the same between the 6.9.0 version and the 7.0.x version? If so, then this will be an issue in SwaggerUI rather than Swashbuckle.

'look the same' meaning same as I described above?

I checked and the OpenApi documents between 6.9.0 and 7.0.x versions look different.
6.9.0 document has a "type" : "object" under "schema" and 7.0.0 doesn't.

@martincostello martincostello added the help-wanted A change up for grabs for contributions from the community label Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help-wanted A change up for grabs for contributions from the community
Projects
None yet
Development

No branches or pull requests

2 participants