Katia
Katia

Reputation: 729

Swagger documentation from XML doesn't show schema for in query object parameter

Using an example of REST api with a GET method that takes in an object query parameter. enter image description here

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 enter image description here

But, the object data model doesn't show in the Schema section
enter image description here

If the [FromQuery] gets removed from the method signature, the data model gets included in the schema
enter image description here

But the endpoint request body is used instead of query parameter which is not the wanted behavior.
enter image description here

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:
enter image description here
Is it against best practices to use DTOs as query parameters?

Upvotes: 1

Views: 1324

Answers (2)

CeritT
CeritT

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

Ivelin Ivanov
Ivelin Ivanov

Reputation: 168

enter image description here

Have you tried to explicitly include documentation in swagger?

Upvotes: 0

Related Questions