Skip to content

Improve logic for x-omitempty#1033

Merged
deepmap-marcinr merged 1 commit intooapi-codegen:masterfrom
veleek:omitempty
May 5, 2023
Merged

Improve logic for x-omitempty#1033
deepmap-marcinr merged 1 commit intooapi-codegen:masterfrom
veleek:omitempty

Conversation

@veleek
Copy link
Copy Markdown
Contributor

@veleek veleek commented Apr 25, 2023

Currently x-omitempty only enables you to force the absence of omitempty. This PR changes the logic so that the existance of x-omitempty will force omit empty to be whatever the user specifies.

The logic around omit empty is pretty confusing here though. For example, why is omitEmpty excluded by default if it's nullable (e.g. if p.Nullable then omitEmpty = false).

Currently x-omitempty only enables you to force the _absences_ of `omitempty`.  This PR changes the logic so that the existance of `x-omitempty` will force omit empty to be whatever the user specifies.

The logic around omit empty is pretty confusing here though.  For example, why is omitEmpty excluded by default if it's nullable (e.g. if `p.Nullable` then `omitEmpty = false`).
@ndbeals
Copy link
Copy Markdown

ndbeals commented May 2, 2023

I agree with the better logic to allow explicitly setting x-omitempty: true to force an omitempty tag, regardless of whether nullable: true is set.

why is omitEmpty excluded by default if it's nullable

Because if the omitempty tag is set when nullable is true then marshaling the struct to json where a nullable field is a pointer and that pointer is nil will cause the marshaled JSON to drop that field, where it should be "field": null.

@deepmap-marcinr deepmap-marcinr merged commit bb1cfe9 into oapi-codegen:master May 5, 2023
@deepmap-marcinr
Copy link
Copy Markdown
Contributor

Thank you.

adrianpk pushed a commit to foorester/oapi-codegen that referenced this pull request Jan 16, 2024
Currently x-omitempty only enables you to force the _absences_ of `omitempty`.  This PR changes the logic so that the existance of `x-omitempty` will force omit empty to be whatever the user specifies.

The logic around omit empty is pretty confusing here though.  For example, why is omitEmpty excluded by default if it's nullable (e.g. if `p.Nullable` then `omitEmpty = false`).
adrianpk added a commit to foorester/oapi-codegen that referenced this pull request May 31, 2024
Currently x-omitempty only enables you to force the _absences_ of `omitempty`.  This PR changes the logic so that the existance of `x-omitempty` will force omit empty to be whatever the user specifies.

The logic around omit empty is pretty confusing here though.  For example, why is omitEmpty excluded by default if it's nullable (e.g. if `p.Nullable` then `omitEmpty = false`).
danicc097 pushed a commit to danicc097/oapi-codegen that referenced this pull request Aug 31, 2024
Currently x-omitempty only enables you to force the _absences_ of `omitempty`.  This PR changes the logic so that the existance of `x-omitempty` will force omit empty to be whatever the user specifies.

The logic around omit empty is pretty confusing here though.  For example, why is omitEmpty excluded by default if it's nullable (e.g. if `p.Nullable` then `omitEmpty = false`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants