domaindrivendev / Swashbuckle.AspNetCore

Swagger tools for documenting API's built on ASP.NET Core
MIT License
5.25k stars 1.31k forks source link

Object type Parameters not showing on swagger page #1921

Closed EllinaExt closed 3 years ago

EllinaExt commented 3 years ago

I have the following contract, used as the request body

public class Vehicle { public object id {get;set;} } Public class Car:Vehicle { public string Name {get;set;} }

With 5.6.3 version of Swashbuckle.AspNetCore and Swashbuckle.AspNetCore.swagger Below Json is generating "Car": { "type": "object", "properties": { "Name": { "type": "string", "description": "Model Name", "nullable": true }, "id": { "description": "Unique identifier for the Vehicle.", "nullable": true } }, "additionalProperties": false, "description": "desciption text" } However with 5.3.3 version of Swashbuckle.AspNetCore and Swashbuckle.AspNetCore.swagger "id": { "type": "object", "description": "Unique identifier for the Vehicle.", "nullable": true } with which swagger page shows Id property on request body correctly.

Same case with JsonPatchDocument.Value which doesnt show up on swagger page with 5.6.3 version of Swashbuckle.AspNetCore and Swashbuckle.AspNetCore.swagger.

Please let me know, how can I fix this issue ?

domaindrivendev commented 3 years ago

I need more information to fully understand this issue. Please create minimal app (i.e. starting from empty project) that repro's the issue and post to github where I can pull it down and troubleshoot?

Jabberrwocky commented 3 years ago

@domaindrivendev

I am running into this same issue. Here is what I am finding:

"furColor": {
   "type": "object",
  "additionalProperties": false,
  "nullable": true
}

Now the same property is outputted to the swagger.json file like this:

"furColor": {
  "nullable": true
}

In my C# code the FurColor property is defined like this:

public object FurColor { get; set; }

Is this a bug?

The main reason I care is that we use openapi-generator (https://openapi-generator.tech/) and this change to the swagger.json output is breaking the openapi-generator generated code.

Thank you for your time.

tanukus commented 3 years ago

Hello @domaindrivendev

ASP.NET Core 3.1.11 Swashbuckle.AspNetCore 5.6.3

Similar issue:

public class SearchFilter
{
        public string Operator { get; set; }
        public string PropertyName { get; set; }
        public object PropertyValue { get; set; }
        public bool IsCaseSensitive { get; set; } = false;
}

shows as below in SwaggerUI. Please note that PropertyValue is not present :

{
      "operator": "string",
      "propertyName": "string",
      "isCaseSensitive": true
 }

Thanks for your work on the library!

domaindrivendev commented 3 years ago

This is essentially a dup of #1890. See my comments at the bottom of that issue for an explanation of this behavior (as it's by design) and a workaround if you need to revert to the old behavior

domaindrivendev commented 3 years ago

@tanukus your issue looks like something different - could you please create a separate issue for it. With that said, I can't repro with the example you gave ... if you do create an issue, please also create a minimal app (i.e. starting from an empty project) that does repro it and post to github where I can pull down and troubleshoot.

Jabberrwocky commented 3 years ago

@domaindrivendev Thank you for taking the time to respond. Will check out that solution.