Enable forcing non-pointer types using Nullable#823
Enable forcing non-pointer types using Nullable#823veleek wants to merge 1 commit intooapi-codegen:mainfrom
Conversation
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
|
May we consider adding this as a default behaviour? We have many YAML spec files, and annotating 1000s of properties with Technically, the generator should respect a built-in In other word for the sollowing schema: schema:
type: object
properties:
nonNullable:
type: string
nonNullableExplicit:
type: string
nullable: false
nullable:
type: string
nullable: trueThe 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"`
} |
|
Thank you for contributing, and I'm very sorry for taking so long to get to this PR. At this point, the code has changed so much that it's no longer relevant because the |
Proposed update to GoTypeDef to enable forcing a non pointer type. This is useful in go to avoid using
*stringinstead ofstringin most cases where the value is not required, but there's no need to differentiate betweenniland empty string values.There may need to be some more semantics around this in order to force the pointer in some cases where
p.Nullableis true. We probably need some discussion around this prior to merging.See also #479