1

Swagger is adding three extra parameters in the UI. It only does it with two methods. The other three are fine. All are defined pretty much the same way. The only difference I can see is the order of parameters ([FromBody] is first on the offending methods).

I have been researching on Google and cannot find anyone having the same issue. The only thing I could think to try was rearranging the order of the parameters.

// Does not have the parameters
[HttpPost]
[Route ( "api/Processor/GetHtmlWithByteArrays" )]
public JsonResult GetHtmlWithByteArrays ( [FromQuery] List<string> roles, [FromBody] List<byte[ ]> files ) => new JsonResult ( Processor.GetHtml ( roles, files ) );

// Has the extra parameters
[HttpPost]
[Route ( "api/Processor/GetDocFromHtmlString" )]
public JsonResult GetDocFromHtmlString ( [FromBody] string htmlString, [FromQuery] DocType docType, [FromQuery] bool includeToc = true,
bool includeFooter = false ) => new JsonResult ( Processor.GetDocFromHtmlString ( htmlString, docType, includeToc, includeFooter ) );

I would expect the SwaggerUI to just show the parameters I have defined. However, for two of my methods, the following parameters are being added:

Provider.SupportedExtensions
Provider.CanImport
Provider.CanExport

1 Answers1

2

I finally figured out that this was caused because I am referencing an abstract class (DocType). I resolved it by referencing Newtonsoft.Json and setting up the class with the necessary decorations to let Json know how to resolve it. The known types are the objects that inherit the abstract class. I hope this helps anyone having a similar issue.

[ JsonConverter ( typeof ( JsonInheritanceConverter ), "discriminator" ) ]
[ KnownType ( typeof ( Docx ) ) ]
[ KnownType ( typeof ( Html ) ) ]
[ KnownType ( typeof ( Pdf ) ) ]
[ KnownType ( typeof ( Rtf ) ) ]
[ KnownType ( typeof ( Txt ) ) ]