Skip to content

Don't use pointer to slice of types #1561

Closed

Description

@thatjames

Currently, the oapi-codegen tool will generate a pointer to a slice of types.

This is unnecessary, as slices are already reference values, per the language spec

This gives the ability to distinguish between an empty slice (len ==0) and an unset field (array == nil)

Activity

  1. jamietanna commented on Apr 20, 2024

    @jamietanna
    Member

    This is something I've considered before, too.

    I think this keeps in line with the fact that if there's an optional value, it has a pointer associated with it.

    However, I think adding an opt-in configuration via output-options would be reasonable, allowing folks to choose whether they want it or not.

  2. added
    enhancement
    help wanted
    on Apr 20, 2024
  3. thatjames commented on Apr 23, 2024

    @thatjames
    Author

    That's a fair point, there are certainly valid reasons to use pointers to slices (beyond verifying if they are set or not).

    I need to read up more on the output-options config items, sheepishly admitting I completely misunderstood that in my first read through...

  4. jamietanna commented on Aug 20, 2024

    @jamietanna
    Member
  5. jamietanna commented on Aug 20, 2024

    @jamietanna
    Member

    Having discussed this today with someone, I just want to clarify my opinion here - I agree that it doesn't make sense to have i.e. *[]strng and instead having us using []string. Using this as an opt-in change is needed so we can make it backwards-compatible, but this is a good one that we should also make a default when we come to a v3 release

  6. jamietanna commented on May 10, 2025

    @jamietanna
    Member

    Related: #609

  7. jamietanna commented on May 10, 2025

    @jamietanna
    Member

    I'm making a start with this in #1979

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions