How to document Swagger/Swashbuckle parameter descriptions when using [FromQuery]
See original GitHub issueIn a standard .NET Core 2.2 Api project with Swashbuckle.AspNetCore 5.0.0-rc2:
[HttpGet]
public ActionResult GetSomeData([FromQuery] SomeDataRequest request) {
return File(returnImage(), "image/png");
}
The definition of SomeDataRequest
public class SomeDataRequest {
/// <summary>
/// Description 1
/// </summary>
[Description("description 1")]
public string foo;
/// <summary>
/// Description 2
/// </summary>
[Description("description 2")]
public string bar;
}
When I bring up the Swagger UI, it doesn’t show any kind of descriptions for the properties of SomeDataRequest.
As you can see I tried the Description attribute and the XML comments. Nothing seems to work.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
c# - Swashbuckle parameter descriptions
I'm using SwaggerResponse attributes to decorate my api controller actions, this all works fine, however when I look at the generated ...
Read more >Multiple example for parameters in Swagger with ASP.NET ...
A Short guide on how to add multiple example of route parameter in swagger doc.
Read more >Complex GET query param objects in Swashbuckle
Instead of listing these few parameters as separate query params, it's much easier to just go Filter([FromQuery]PagedCollectionFilter filter) ...
Read more >Swashbuckle.AspNetCore
AspNetCore. In the ConfigureServices method of Startup.cs , register the Swagger generator, defining one or more Swagger documents. using Microsoft.OpenApi.
Read more >How to make API documentation using Swagger and ReDoc
In this tutorial, I will show you how to generate API documentation using Swagger and ReDoc for your ASP.NET Core Web API (.NET...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@davidkmitrais So let’s say you have 2 projects.
api.csproj – this project has Controller actions for your API entities.csproj – this project contains entities that you either pass in or return to/from the API.
You generate the XML documentation file for both, which results in api.xml and entities.xml. These files get placed in their respective bin/debug directories. And then the Startup.cs in your Api.cs has Swagger declaration to read the xml documentation:
You can see the problem here, right? It’s only getting api.xml because that it’s in the executing directory. So you need to somehow bring entities.xml to the same directory. To do, that I defined a post-build step for the api project:
copy /Y $(ProjectDir)..\entities\bin\$(ConfigurationName)\netstandard2.0\entities.xml $(TargetDir)
You might have to fudge directory names a little bit if you are not using .net core 2.x
Now after every build, entities.xml will be in the same folder as api.xml. The last step is to let Swagger know about. We do this by extending
AddSwaggerGen
code a bit:I hope this helps.
@rgelb Thanks! I just add GenerateDocumentationFile to all of referencing .csproj files without post build setting. Once the main project is compiled, the all the xml files are copied to the same directory as the main project is.