oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

Don't use pointer to slice of types

Open thatjames opened this issue 1 year ago • 2 comments

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)

thatjames avatar Apr 20 '24 11:04 thatjames

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.

jamietanna avatar Apr 20 '24 12:04 jamietanna

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...

thatjames avatar Apr 23 '24 13:04 thatjames

Related: https://github.com/oapi-codegen/runtime/pull/40

jamietanna avatar Aug 20 '24 20:08 jamietanna

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

jamietanna avatar Aug 20 '24 20:08 jamietanna