0

I'm working on a GET API in dotnet and I've been trying to document the query parameter being passed which is an aggregate object for the pagination of results (page size and page number). Comments/documentation for get method:

/// <param name="Id">ID used to identify a record</param> /// <param name="paginationParams">Request object that contains the pagination parameters <inheritdoc cref="PaginationParameters"/></param> 

As you can see above, I'm referring to the PaginationParameters aggregate object/model. Now, this doesn't seem to be working correctly, or has no affect as I can change the field to [Required] and the swagger then reflects that. However, it's worth noting the ID field is documenting fine.

Below is the method signature for the get method:

public async Task<IActionResult> GetStuff( [FromHeader][BindRequired] int Id, [FromQuery] PaginationParameters paginationParams) 

Finally, my model is as of below:

/// <summary> /// Pagination parameters /// </summary> public class PaginationParameters { /// <summary> /// PageNumber /// </summary> [Required] public int? PageNumber { get; set; } = null; /// <summary> /// PageSize /// </summary> [Required] public int? PageSize { get; set; } = null; } 

It's driving me up the wall that it's not working and I'm sure it would be a simple fix, it just seems to be ignoring my descriptions for page size and page number.

1 Answer 1

0

I had this exact issue, too!

You'll need to make sure that your .csproj file is generating documentation:

<GenerateDocumentationFile>True</GenerateDocumentationFile> 

And then when you're configuring Swagger, make sure you reference the namespace of the object with the XML comments:

var filePath = Path.Combine(AppContext.BaseDirectory, "Your.Api.Namespace.xml"); c.IncludeXmlComments(filePath); 

Part of my answer was taken from here.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.