Skip to content

Consider adding Nullable wrapper for non-required nullable properties #1039

@emarcotte

Description

@emarcotte

When using the "strict" server types for a simple object definition like:

TestCase:
  type: object
  properties:
    hello:
      type: string

It renders to something like:

type TestCase struct {
	Hello *string `json:"hello,omitempty"`
}

This construction does not naturally let you determine if the field hello was included in a payload or if it was explicitly set to null.

The current best work around I can see for dealing with this is to set x-go-type to a json.RawMessage and define my own wrapper struct containing an Optional[string] as described here:
https://stackoverflow.com/questions/36601367/json-field-set-to-null-vs-field-not-there

Would it be reasonable to add a configurable alternative to generate something like this automatically so that both null and absent can be detected in a strict server?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions