-
Notifications
You must be signed in to change notification settings - Fork 96
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
Allow CustomNameType
s to specify nillability
#220
Allow CustomNameType
s to specify nillability
#220
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #220 +/- ##
==========================================
- Coverage 76.58% 75.94% -0.65%
==========================================
Files 24 26 +2
Lines 1892 1646 -246
==========================================
- Hits 1449 1250 -199
+ Misses 354 298 -56
- Partials 89 98 +9 ☔ View full report in Codecov by Sentry. |
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.
hey @andrew-farries, thanks for the contribution! Very nice improvement! :)
Build on #344 to allow removing column comments by setting them to `null`. Make use of omissis/go-jsonschema#220 and use the [nullable](https://github.com/oapi-codegen/nullable) package so that it's possible to distingush between a missing `comment` field and one that is explicitly set to `null`. With omissis/go-jsonschema#220 not being part of a release yet, use a custom build of `go-jsonschema`. It should be possible to switch back to the official release images once omissis/go-jsonschema#220 is part of a release. Without this change it becomes impossible to remove a comment from a column using the 'set comment' 'alter column' sub-operation (#344).
Generate types from the JSON schema using the `omissis/go-jsonschema` image instead of the `surjection/go-jsonschema` image. We used the `surjection/go-jsonschema` image because we needed a feature that was not yet released in the `omissis/go-jsonschema` image: omissis/go-jsonschema#220 Now that the feature is available in the `omissis/go-jsonschema` `0.17` release we can switch back to using it.
Generate types from the JSON schema using the official`omissis/go-jsonschema` image instead of the custom `surjection/go-jsonschema` image. We built and used the `surjection/go-jsonschema` image because we needed a feature that was not yet released in `omissis/go-jsonschema`: omissis/go-jsonschema#220 Now that the feature is available in the `omissis/go-jsonschema` `0.17` [release](https://github.com/omissis/go-jsonschema/releases/tag/v0.17.0) we can switch back to using it.
Allow
CustomNameType
s to specify their nillability.Currently
CustomNameType
s are hard-coded to haveIsNillable
returnfalse
. This limitation means that fields in an object having a custom type are always wrapped in a pointer type when they are not required fields. For example:This results in the following Go code:
The
map[bool]string
is nillable, butgo-jsonschema
's schema generation generates a pointer type for thename
field.By extending the
GoJSONSchemaExtension
type with an extraNillable
field, custom types can specify their nillability in order to ensure they aren't wrapped in a pointer type when such fields are optional.The motivation for this change is to be able to use the nullable package to distinguish between set-to-null fields and missing fields.
This snippet:
Should generate a
name
field of typenullable.Nullable[string]
rather than*nullable.Nullable[string]
, in line with the documentation fornullable
which advises against using pointers to the type.