RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.61k stars 1.22k forks source link

How to customize the order in which fields are displayed #4881

Open Boundless666 opened 2 months ago

Boundless666 commented 2 months ago
public class Pagination{
    public int start {get;}
    public int end {get;}
}

public class ReqDTO: Pagination{
    ///
    /// this is name
    ///
    [Required]
    public string Name {get; set;}

    ///
    /// this is count
    ///
    public string Count {get; set;}
}
public class TestController: ControllerBase
{
    [OpenApiBodyParameter("application/x-www-form-urlencoded")]
    [HttpPost]
    public IActionResult GetList(ReqDTO req){

    }
}

The JSON file generated by default is as follows:

"ReqDTO": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Pagination"
          },
          {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "Name"
            ],
            "properties": {
              "Name": {
                "type": "string",
                "description": "this is name",
                "minLength": 1
              },
              "Count": {
                "type": "integer",
                "description": "this is count",
                "nullable": true
              },
            }
          }
        ]
      },

in the redoc UI

// The order in which the fields are displaed in the redoc UI document
// default
Fields      Description

start       
end     
Name        this is name
Count       this is count
// I’d like to be able to control the order in which the fileds are displayed
// like this:
Fields      Description

Name        this is name
Count       this is count
start       
end     

I want the fields of the objects referenced in allOf to be ranked after the fields of the inheritance class at the time of the final rendering