unchase / Unchase.Swashbuckle.AspNetCore.Extensions

:hammer: A library contains a bunch of extensions (filters) for Swashbuckle.AspNetCore.
https://www.nuget.org/packages/Unchase.Swashbuckle.AspNetCore.Extensions
Apache License 2.0
115 stars 16 forks source link

Throws when using IncludeXmlCommentsWithRemarks #16

Closed lonix1 closed 3 years ago

lonix1 commented 3 years ago

I want enum descriptions from <summary> xml comments (not [Description]).

So I did this:

options.IncludeXmlComments(xmlFilePath);                // works even without this
options.AddEnumsWithValuesFixFilters(services, x => {
  x.DescriptionSource = DescriptionSources.XmlComments;
  x.IncludeXmlCommentsFrom(xmlFilePath);
  // etc...
});

That works! (However it shows both <summary> AND <remarks>.)

But if I use this instead:

options.IncludeXmlCommentsWithRemarks(xmlFilePath);

Then it throws:

System.InvalidOperationException: A suitable constructor for type 'Unchase.Swashbuckle.AspNetCore.Extensions.Filters.XmlCommentsWithRemarksParameterFilter' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.

So:

lonix1 commented 3 years ago

Okay the docs are a little confusing, but I figured it out!

To get enum descriptions from <summary>, this is the minimum required config:

options.IncludeXmlComments(xmlFilePath);
options.AddEnumsWithValuesFixFilters(services, x => {
  x.IncludeDescriptions = true; 
  x.DescriptionSource = DescriptionSources.XmlComments;
  x.IncludeXmlCommentsFrom(xmlFilePath);
});

The IncludeXmlCommentsWithRemarks still throws, but now I understand that it is part of swashbuckle, not this library.

Thanks!