Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved handling of optional parameters #448

Open
frogcrush opened this issue Aug 28, 2024 · 2 comments
Open

Improved handling of optional parameters #448

frogcrush opened this issue Aug 28, 2024 · 2 comments
Assignees
Labels
enhancement New feature, bug fix, or request

Comments

@frogcrush
Copy link

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 frogcrush added the enhancement New feature, bug fix, or request label Aug 28, 2024
@christianhelle
Copy link
Owner

@frogcrush Thanks for taking the time to report this. I'm a bit busy with other stuff these days but I'll see what I can do in the next few days

@JeremyBP
Copy link
Contributor

Reading this makes me think that we should improve our #417 Dynamic Querystring Parameters feature so that it would offers a constructor with all requiered parameters and let all other as properties. Or maybe all parameters in constructor with default/null values for optional ones, especially when using records.
Will take a look at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature, bug fix, or request
Projects
None yet
Development

No branches or pull requests

3 participants