Reputation: 729
Using an example of REST api with a GET method that takes in an object query parameter.
VSCode is configured to generate XML documentation and feed it into Swagger like in here.
The result swagger page shows documentation for the respective field in the input object
But, the object data model doesn't show in the Schema section
If the [FromQuery]
gets removed from the method signature, the data model gets included in the schema
But the endpoint request body is used instead of query parameter which is not the wanted behavior.
The XML file generated in both scenarios is the same
<?xml version="1.0"?>
<doc>
<assembly>
<name>DateTimeServiceAPI</name>
</assembly>
<members>
<member name="P:DateTimeServiceAPI.DTOs.GetCurrentTimeDTO.TenantId">
<summary>
indentifer of the tenant
</summary>
</member>
</members>
</doc>
Any idea why is this difference in generating the documentation? I couldn't find anything relevant while searching about this.
How can I (force) include all data models in the schema section? Any pointers or resources are highly appreciated.
Thank you
Update:
In the RESTfull api guide here, section 7. REST Basics - URLs:
Is it against best practices to use DTOs as query parameters?
Upvotes: 1
Views: 1324
Reputation: 532
You should check your GetCurrentTimeDTO
model, the properties of a DTO that's used as a parameter to a controller method should have public
set, if it is internal
or private
Swagger won't show it.
public class MyDto
{
public Guid Id { get; internal set; } // Not shown
public DateTime Date { get; set; } //shown
}
Upvotes: 1
Reputation: 168
Have you tried to explicitly include documentation in swagger?
Upvotes: 0