-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
[crystal][client] Make optional properties nillable in models #10723
[crystal][client] Make optional properties nillable in models #10723
Conversation
Only REQUIRED and NOT NULLABLE variables can NOT have type Nil All OPTIONAL and NULLABLE-REQUIRED variables have type Nil Only NULLABLE-REQUIRED variables should emit keys with null values when they are serialized, json example: property name : String? = nil; the json representation for this property is {"name": null} For all OPTIONAL variables having Nil values, their variable keys would be skipped during serialization. The json representation for OPTIONAL property name : String? = nil; would be: {}
For any required property, assigning nil value to it will result in compilation error The datatype simply can not hold value nil, so there's no need to check it
@wing328 I have updated this PR to remove nullable checks. I'm not sure whether I should target it to the 6.0.x branch. |
Crystal lang doesn't have method equal? We should use method same? instead of ruby's equal? method Reference: https://crystal-lang.org/api/master/Reference.html#same?(other:Reference):Bool-instance-method
Setting Pet optional properties to nil values is allowed by add_pet api endpoint
Test model initializations Test compilation error when model is initialized without required properties
@wing328 I've added quite a few integration tests to cover the code changes and also found and fixed a comparison bug while I was writing those tests. Without this PR, users of the generated crystal clients would have to set all properties of models with none null values. Crystal lang usually doesn't have any official SDK support from vendors. I'm hoping OpenAPI-Generator could be a feasible option for generating SDKs. Could you please take a look at this PR and provide feedback so that I can improve it and get it merged? Thanks. |
Tested locally and the result is good.
Let's consider this a bug fix. We'll then see if people need the old (current) behaviour somehow. |
Closes #10721
Mark model properties as nillable when applicable, and also handle property serialization correctly.
@wing328 The model initializers are already using nillable types for parameters, this PR allows setting legitimate nil values to model properties
PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.For Windows users, please run the script in Git BASH.
master
(5.3.0),6.0.x