Skip to content

feat: support [deprecated = true] for enums #183

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: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions protobuf/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ type Enum struct {
Name string
Values []*EnumValue

Deprecated bool

Up FileOrMessage // either *File or *Message
}

Expand Down
14 changes: 14 additions & 0 deletions protobuf/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,20 @@ func (p *parser) readEnum(enum *ast.Enum) *parseError {
}
ev.Number = int32(num) // TODO: validate

// an enum can either end with a semicolon or have a deprecated option then a semicolon "[deprecated = true];"
tok = p.next()
if tok.value == ";" {
// that's it, the enum value is done
continue
} else if tok.value == "[" {
deprecatedOptions := []string{"deprecated", "=", "true", "]"}
for _, wantToken := range deprecatedOptions {
if err := p.readToken(wantToken); err != nil {
return err
}
}
enum.Deprecated = true
}
if err := p.readToken(";"); err != nil {
return err
}
Expand Down