Skip to content

Enable forcing non-pointer types using Nullable #823

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

veleek
Copy link
Contributor

@veleek veleek commented Oct 26, 2022

Proposed update to GoTypeDef to enable forcing a non pointer type. This is useful in go to avoid using *string instead of string in most cases where the value is not required, but there's no need to differentiate between nil and empty string values.

There may need to be some more semantics around this in order to force the pointer in some cases where p.Nullable is true. We probably need some discussion around this prior to merging.

See also #479

Proposed update to GoTypeDef to enable forcing a non pointer type.
This is useful in go to avoid using `*string` instead of `string` in most cases where the value is not required, but there's no need to differentiate between `nil` and empty string values.

See also oapi-codegen#479
@jamietanna
Copy link
Member

Thanks @veleek for this! This may no longer be necessary, especially as with #1404, we'll be introducing a separate type that can be opted-in for better Nullable support 🤞

@ghen
Copy link

ghen commented Jun 19, 2024

May we consider adding this as a default behaviour?
At least have an option in generator output configuration to enable this as a default behaviour.

We have many YAML spec files, and annotating 1000s of properties with x-go-type-skip-optional-pointer is a no go.

Technically, the generator should respect a built-in nullable spec that it ignores at the moment, even when it is set explicitly.

In other word for the sollowing schema:

schema:
  type: object
  properties:
      nonNullable:
          type: string
      nonNullableExplicit:
          type: string
          nullable: false
      nullable:
          type: string
          nullable: true

The expected struct:

type JSONBody struct {
        nonNullable          string `json:"nonNullable,omitempty"`
	nonNullableExplicit  string `json:"nonNullableExplicit,omitempty"`
        nullable             *string `json:"nullable,omitempty"`
}

Instead it produces pointers everywhere:

type JSONBody struct {
        nonNullable         *string `json:"nonNullable,omitempty"`
	nonNullableExplicit *string `json:"nonNullableExplicit,omitempty"`
        nullable            *string `json:"nullable,omitempty"`
}

@jamietanna jamietanna added this to the v2.5.0 milestone May 7, 2025
@jamietanna jamietanna modified the milestones: v2.5.0, v2.6.0 Jul 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy