You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The C# client code which is generated for an operation with optional parameters of value types causes the parameters to be sent with default values if not specified by the user, instead of not sending the parameter if not specified. This is surprising and can prevent API use (if there is no value for the parameter which behaves the same as not specifying the parameter at all).
openapi-generator version
4.1.3
I am unsure if it is a regression.
OpenAPI declaration file content or url
(Click to expand) OpenAPI 3 example with optional parameters of struct type.
openapi: '3.0.2'info:
title: Example APIdescription: API with non-required, no-default parametersversion: '1.0.0'servers:
- url: https://example.com/apicomponents:
schemas:
ChangeType:
type: stringenum:
- Create
- Delete
- Insert
- Updatepaths:
/count:
get:
operationId: getCountparameters:
- name: typein: querydescription: Only count changes of a given typeschema:
$ref: '#/components/schemas/ChangeType'
- name: afterin: querydescription: Only count changes after a given date/timeschema:
type: stringformat: date-time
- name: beforein: querydescription: Only count changes before a given date/timeschema:
type: stringformat: date-time
- name: errorsin: querydescription: Include errors in count?schema:
type: boolean
- name: limitin: querydescription: Maximum countschema:
type: integerresponses:
'200':
description: Successcontent:
application/json:
schema:
type: integer
which will add all of the query parameters to the request with (C#) default values, which is not intended by the user.
Suggest a fix
I believe struct method argument types should be Nullable<T> when not required: true, as done by Autorest. For reference, the signature generated by Autorest for the same OpenAPI doc is:
@kevinoid thanks for finding this. I'm running into the same issue and plan to use the string type until the date-time struct type can be generated as a Nullable.
Bug Report Checklist
Description
The C# client code which is generated for an operation with optional parameters of value types causes the parameters to be sent with default values if not specified by the user, instead of not sending the parameter if not specified. This is surprising and can prevent API use (if there is no value for the parameter which behaves the same as not specifying the parameter at all).
openapi-generator version
4.1.3
I am unsure if it is a regression.
OpenAPI declaration file content or url
(Click to expand) OpenAPI 3 example with optional parameters of struct type.
Command line used for generation
Steps to reproduce
Observe the signature
which will add all of the query parameters to the request with (C#) default values, which is not intended by the user.
Suggest a fix
I believe struct method argument types should be
Nullable<T>
when notrequired: true
, as done by Autorest. For reference, the signature generated by Autorest for the same OpenAPI doc is:Thanks for considering,
Kevin
The text was updated successfully, but these errors were encountered: