Introduce a new command-line parameter for "generate spec" allowing to set "x-nullable: true" by default for each Go field having a pointer type and not having JSON 'omitempty' option set #3128
+219
−55
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With this new feature, we can skip unnecessary annotations for pointer-type fields as they are almost always nullable. So instead of
we can simply write
with the same effect when running
instead of usual
Although rarely needed, it is still possible to mark a field as non-nullable explicitly:
Also,
x-nullable: true
will not be set automatically for fields having the JSON 'omitempty' option set:It works even for fields pointing to embedded structures.
Then, it's possible to convert the generated spec to OpenAPI 3.0 preserving the
x-nullable
tags and converting them tonullable
tags:and preview the documentation:
and build the documentation:
The field in the documentation will look as