-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 in XML comment doesn't work when using source generation for JSON serialization #2985
Comments
Looks like this was caused by #2727 which introduced the below line of code, which is not compatible with native AoT: Swashbuckle.AspNetCore/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsExampleHelper.cs Line 19 in f85abd4
Swashbuckle.AspNetCore.SwaggerGen doesn't currently support native AoT and is not marked as trim compatible (unlike Swashbuckle.AspNetCore.SwaggerUI) (and I'm not sure it ever will due to the amount of work it would likely entail). Fixing this specific line of code would need us to add a custom At the moment, any success with Swashbuckle in native AoT is an accident, rather than by design. |
These are all the errors (26) I get locally if I mark the library as needing to be AoT compatible:
Some of them can be trivially fixed (will try a PR shortly), but some of them might be too much effort to invest in fixing when the new OpenAPI support in ASP.NET Core 9 will support native AoT out of the box for people who care about such a use case: dotnet/aspnetcore#56023 |
Use the JSON source generator with `net8.0` to make XML comments generation compatible with native AoT. Relates to domaindrivendev#2985.
Taking a look at the warnings, only two of these look like they can be resolved - the rest would require significant refactoring as Swashbuckle is so heavily based on runtime reflection. I would have thought you will have received multiple warnings from the trimmer when you published your application before even trying to run it. Can you try out #2986 from source and see if it resolves your issue? If it does I'll be inclined to have it merged as it unblocks you, but if you just run into a different problem that it's probably not worth pursuing further. |
Hello, thank you very much. Actually I am not in a hurry at all. Having examples in swagger is not required for my project right now at all(It'll be nice, though). I guess I'll just wait for aot support. |
Would you like to try the fix out? Otherwise I don't have an easy way to validate the fix I just pushed. |
Closing as we don't intend to make SwaggerGen AoT compatible. |
Describe the bug
Hello, I can't get example value in XML comment to work in Swagger with this library. My project is an Web API based on Asp.net Core, Native AOT, .net 8 and Minimal API. JSON serializaion is source generation based.
Example:
If I delete
example="my name"
, swagger works, that is, XML comment is used, for example, summary "This is swash" is shown in Swagger page. Withexample="my name"
, opening the Swagger page throws an exception.Expected behavior
Show an example value in corresponding Swagger endpoint parameter.
Actual behavior
Throws an exception when I open swagger url.
Steps to reproduce
reproduce repo: https://github.com/hackerzhuli/TestSwash
Exception(s) (if any)
Swashbuckle.AspNetCore version
6.6.2
.NET Version
8.0.107
Anything else?
No response
The text was updated successfully, but these errors were encountered: