Skip to content
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

Support deprecated annotation, closes #3 #21

Merged
merged 1 commit into from
May 12, 2024
Merged
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
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
1. [Support for well-known wrapper types](https://github.com/grpc-ecosystem/protoc-gen-grpc-gateway-ts/pull/50)
2. Updated to support gRPC gateway v2 and latest protoc-gen-go
3. Support for proto3 optional fields
4. Updated to satisfy strict TS and eslint checks
5. Generator options managed through standard flags
6. Fixes inconsistent field naming when fields contain numbers, e.g. `k8s_field` --> `k8sField`
7. Fixes module names when they contain dots or dashes
4. Support for deprecated message and field annotations
5. Updated to satisfy strict TS and eslint checks
6. Generator options managed through standard flags
7. Fixes inconsistent field naming when fields contain numbers, e.g. `k8s_field` --> `k8sField`
8. Fixes module names when they contain dots or dashes

## Getting Started:

Expand Down
4 changes: 4 additions & 0 deletions data/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ type Message struct {
Nested bool
// Name is the name of the Message
Name string
// Message has been marked as deprecated
IsDeprecated bool
//FQType is the fully qualified type name for the message itself
FQType string
// Enums is a list of NestedEnums inside
Expand Down Expand Up @@ -88,6 +90,8 @@ type Field struct {
IsOneOfField bool
// IsOptional indicates the field is flagged as optional.
IsOptional bool
// IsDeprecated indicates the field is deprecated.
IsDeprecated bool
// Message is the reference back to the parent message
Message *Message
// OneOfIndex is the index in the one of fields
Expand Down
23 changes: 22 additions & 1 deletion generator/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,37 @@ export enum {{.Name}} {

{{- define "messages" -}}
{{- range . -}}
{{- if .IsDeprecated -}}
/**
* @deprecated This message has been deprecated.
*/
{{end -}}
{{- if .HasOneOfFields -}}
type Base{{.Name}} = {
{{- range .NonOneOfFields}}
{{if .IsDeprecated -}}
/** @deprecated This field has been deprecated. */
{{end -}}
{{tsTypeKey .}}: {{tsTypeDef .}};
{{- end}}
{{- range .OptionalFields -}}
{{if .IsDeprecated -}}
/** @deprecated This field has been deprecated. */
{{end -}}
{{tsTypeKey .}}: {{tsTypeDef .}};
{{- end}}
};

export type {{.Name}} = Base{{.Name}}
{{- range $groupId, $fields := .OneOfFieldsGroups}} &
OneOf<{ {{range $index, $field := $fields}}{{fieldName $field.Name}}: {{tsType $field}}{{if (lt (add $index 1) (len $fields))}}; {{end}}{{end}} }>;
OneOf<{
{{- range $index, $field := $fields}}
{{if $field.IsDeprecated -}}
/** @deprecated This field has been deprecated. */
{{end -}}
{{fieldName $field.Name}}: {{tsType $field}};
{{- end}}
}>;
{{- end -}}

{{/* Standard, non oneof messages */}}
Expand All @@ -59,6 +77,9 @@ export type {{.Name}} = Base{{.Name}}
{{- else -}}
export type {{.Name}} = {
{{- range .Fields}}
{{if .IsDeprecated -}}
/** @deprecated This field has been deprecated. */
{{end -}}
{{tsTypeKey .}}: {{tsTypeDef .}};
{{- end}}
};
Expand Down
1 change: 1 addition & 0 deletions registry/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func (r *Registry) analyseField(fileData *data.File, msgData *data.Message, pack
IsExternal: isExternal,
IsOneOfField: f.OneofIndex != nil,
IsOptional: f.GetProto3Optional(),
IsDeprecated: f.GetOptions().GetDeprecated(),
Message: msgData,
}

Expand Down
1 change: 1 addition & 0 deletions registry/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (r *Registry) analyseMessage(fileData *data.File, packageName, fileName str
data := data.NewMessage()
data.Name = packageIdentifier
data.FQType = fqName
data.IsDeprecated = message.GetOptions().GetDeprecated()

newParents := append(parents, message.GetName())

Expand Down
Loading
Loading