glideapps / quicktype

Generate types and converters from JSON, Schema, and GraphQL
https://app.quicktype.io
Apache License 2.0
11.79k stars 1.04k forks source link

Fixing failing unit test causing CI pipeline to fail #2494

Closed Adam724 closed 5 months ago

Adam724 commented 5 months ago

This PR introduced a new option to allow optional struct fields to be set to omitempty. However, it does not properly evaluate the boolean condition, and always behaves as if the option is set to true. This is causing some tests to fail unexpectedly when fields are set to null. The generated code contains the omitempty flag erroneously and thus ignores the null field when generating JSON output, causing the input/output JSON not to match. This PR fixes #2462.

dvdsgl commented 5 months ago

THANK YOU!

Adam724 commented 5 months ago

Glad it is working! If you could take a look at this PR when you get a chance, that'd be great. Realized while testing a bit more today that the logic for omitEmpty is not right. It needs to still check whether the field is optional first before adding the tag. Ideally there would be a test case to catch this, but doesn't look like the current capabilities support passing CLI options to tests. I am looking into adding this, but will include it in a different PR since it's more involved.