-
-
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
Ruby client nullable #4391
Ruby client nullable #4391
Conversation
cc @wing328 |
@slemrmartin Thanks for PR, I'll review it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@slemrmartin This PR seems to solve original issue. However, the reverse problem appears to occur.
Even if nullable attribute is omitted, null is always sent to server.
I think we can solve both problems by using instance_variable_defined?
instead of openapi_nullable
.
How about that?
@autopp If nullable attribute is omitted, then |
@slemrmartin Sorry for the incomprehension. Foo:
type: object
properties:
x:
type: integer
nullable: true On current master: p OpenapiClient::Foo.new({ x: 1 }).to_hash #=> {:x=>1}
p OpenapiClient::Foo.new({ x: nil }).to_hash #=> {} <- always empty
p OpenapiClient::Foo.new({}).to_hash #=> {} And on this branch: p OpenapiClient::Foo.new({ x: 1 }).to_hash #=> {:x=>1}
p OpenapiClient::Foo.new({ x: nil }).to_hash #=> {:x=>nil}
p OpenapiClient::Foo.new({}).to_hash #=> {:x=>nil} <- always nil For these, I think the following are expected: p OpenapiClient::Foo.new({ x: 1 }).to_hash #=> {:x=>1}
p OpenapiClient::Foo.new({ x: nil }).to_hash #=> {:x=>nil}
p OpenapiClient::Foo.new({}).to_hash #=> {} Please let me know if I misunderstand. |
@autopp now I understand, thanks for clarification.
, but
I don't know openapi specification to the depth so correct me if I'm wrong |
[ | ||
{{#vars}} | ||
{{#isNullable}} | ||
:'{{{name}}}'{{#hasMore}},{{/hasMore}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indent seems to be too depth.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And what about defining it as a hash instead similar to self.openapi_types?
If an object contains a lot of nullable properties, using include?
may result in performance issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see usage for key-value, but what about using Set
instead of Array
, it should have better performance for include?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the format
def self.openapi_nullable
Set.new([
])
end
is it possible to define it in template in a way that empty set won't generate new line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... it seems to be difficult because there is no way to directly enumerate nullable attributes in template.
@wing328 Do you have any ideas?
By the way, I don't like this format, but it's acceptable (Rubocop also allows this), so I think this PR can be merged.
Isn't it okay to make another PR for reformatting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set is definitely better than array in this case.
About empty set, I think it's acceptable for day 1 requirement. We can always improve it later with another PR.
@slemrmartin your suggestion sounds good 👍 |
9834265
to
ccc0f79
Compare
* master: (28 commits) [meta] Support Kotlin meta generator (OpenAPITools#4156) [Go][Server] minor enhancement to the template (OpenAPITools#4417) Replace the old ResourceSupport (OpenAPITools#4426) [Core, Rust Server, ASP.NET Core] Fix Codegen Operation Scope Consistency (OpenAPITools#3495) Add Go Server featureCORS option (OpenAPITools#4400) Fix treatment of nullable types in a few more places (OpenAPITools#4315) prefix local variable with localVar (OpenAPITools#4402) [kotlin][client] gson complete integration (OpenAPITools#4332) [kotlin] [bugfix] [maven-plugin]: prevent ClassCastException with boolean config options (OpenAPITools#4361) add sbt, bazel to integration (OpenAPITools#4416) Add a blog post tutorial about generating Java clients using OpenAPI v3 (OpenAPITools#4405) add freshcells to company list (OpenAPITools#4414) Update isSet when the object is received from callback. (OpenAPITools#4385) Ruby client nullable (OpenAPITools#4391) Fixes Kotlin client property names that include a dollar sign for template override (OpenAPITools#4351) [Python] [Performance] Avoid unnessacary checks inside the loop (OpenAPITools#4305) Add QEDIT as a company that's using OpenAPI Generator (OpenAPITools#4392) update cpp flag for pistache (OpenAPITools#4386) Feature optional emit default values (OpenAPITools#4347) skip the test as async call may have finished (OpenAPITools#4377) ...
@slemrmartin thanks for the PR, which has been included in the v4.2.1 release: https://twitter.com/oas_generator/status/1195339336922759168 |
@wing328 thanks for your help |
This PR fixes Ruby clients on columns with "nullable": true. Attribute's key with nil value isn't skipped, but sent to server with nil value.
Issue: #4363 (comment)
PR checklist
./bin/
(or Windows batch scripts under.\bin\windows
) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run./bin/{LANG}-petstore.sh
,./bin/openapi3/{LANG}-petstore.sh
if updating the code or mustache templates for a language ({LANG}
) (e.g. php, ruby, python, etc).master
,4.3.x
,5.0.x
. Default:master
.