refitter icon indicating copy to clipboard operation
refitter copied to clipboard

Improved handling of optional parameters

Open frogcrush opened this issue 5 months ago • 2 comments

Is your feature request related to a problem? Please describe.

Some of my API endpoints use optional parameters, eg "includeCancelled" which defaults to true. When refitter generates endpoints, it includes these as required (but nullable) properties, or using the optionalParameters flag sets them to default (which is different than the default specified in the OpenAPI doc).

Describe the solution you'd like Either set them to the default in the OpenAPI doc (if specified) or add multiple signatures for optional parameters.

Describe alternatives you've considered Just passing null into optional arguments, as they are then not sent to the server, but this feels messy to me.

Additional context

Take for example the following controller:

[HttpGet("list")]
public async Task<ActionResult<List<ProjectScheduleItemModel>>> GetScheduleForPeriod([Required] DateOnly start, [Required] DateOnly end, [DefaultValue(true)] bool includeCancelled = true)

The following code is generated:

[Headers("Accept: text/plain, application/json, text/json")]
[Get("/api/schedule/list")]
Task<IApiResponse<ICollection<ProjectScheduleItemModel>>> List([Query] System.DateOnly start, [Query] System.DateOnly end, [Query] bool? includeCancelled);

Refitter settings:

{
    "returnIApiResponse": true,
    "optionalParameters": true,
    "codeGeneratorSettings": {
        "dateType": "System.DateOnly",
        "dateTimeType": "System.DateTimeOffset",
        "timeType": "System.TimeOnly",
        "timeSpanType": "System.TimeSpan"
    }
}

Loving the project by the way!

frogcrush avatar Aug 28 '24 18:08 frogcrush