Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// {{{classname}}} {{{description}}}{{^description}}the model '{{{classname}}}'{{/description}}
type {{{classname}}} {{{format}}}{{^format}}{{dataType}}{{/format}}
type {{{classname}}} {{dataType}}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for spec with a correct format, would this PR break those use cases?\

what about fixing the spec instead by removing format: enum?

StatusEnum:
  type: string
  description: The current lifecycle status of the item
  enum:
    - active
    - inactive
    - archived
  format: enum

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me int32/int64 enums still work as intended with this adjustment.

what about fixing the spec instead by removing format: enum?

We already discussed this in #24336 . I agree in general but e.g. for the Java and Python generator it works flawlessly when format: enum is set so I thought it would be worth a fix for Golang :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear, we're not against fixing anything and thanks for contributing a fix.

I was worried some use cases of format may break if it's removed completely.

The format part was added 5 years ago.

We can go with your fix and provide a fallback if needed to our users.


// List of {{{name}}}
const (
Expand All @@ -22,7 +22,7 @@ var Allowed{{{classname}}}EnumValues = []{{{classname}}}{
}

func (v *{{{classname}}}) UnmarshalJSON(src []byte) error {
var value {{{format}}}{{^format}}{{dataType}}{{/format}}
var value {{dataType}}
err := json.Unmarshal(src, &value)
if err != nil {
return err
Expand Down Expand Up @@ -52,7 +52,7 @@ func (v *{{{classname}}}) UnmarshalJSON(src []byte) error {

// New{{{classname}}}FromValue returns a pointer to a valid {{{classname}}}
// for the value passed as argument, or an error if the value passed is not allowed by the enum
func New{{{classname}}}FromValue(v {{{format}}}{{^format}}{{dataType}}{{/format}}) (*{{{classname}}}, error) {
func New{{{classname}}}FromValue(v {{dataType}}) (*{{{classname}}}, error) {
ev := {{{classname}}}(v)
if ev.IsValid() {
return &ev, nil
Expand Down
Loading