Skip to content

Commit cb988ec

Browse files
committed
Support deprecated annotation, closes #3
1 parent 53d2f39 commit cb988ec

File tree

7 files changed

+408
-89
lines changed

7 files changed

+408
-89
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
1. [Support for well-known wrapper types](https://github.com/grpc-ecosystem/protoc-gen-grpc-gateway-ts/pull/50)
1818
2. Updated to support gRPC gateway v2 and latest protoc-gen-go
1919
3. Support for proto3 optional fields
20-
4. Updated to satisfy strict TS and eslint checks
21-
5. Generator options managed through standard flags
22-
6. Fixes inconsistent field naming when fields contain numbers, e.g. `k8s_field` --> `k8sField`
23-
7. Fixes module names when they contain dots or dashes
20+
4. Support for deprecated message and field annotations
21+
5. Updated to satisfy strict TS and eslint checks
22+
6. Generator options managed through standard flags
23+
7. Fixes inconsistent field naming when fields contain numbers, e.g. `k8s_field` --> `k8sField`
24+
8. Fixes module names when they contain dots or dashes
2425

2526
## Getting Started:
2627

data/message.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ type Message struct {
66
Nested bool
77
// Name is the name of the Message
88
Name string
9+
// Message has been marked as deprecated
10+
IsDeprecated bool
911
//FQType is the fully qualified type name for the message itself
1012
FQType string
1113
// Enums is a list of NestedEnums inside
@@ -88,6 +90,8 @@ type Field struct {
8890
IsOneOfField bool
8991
// IsOptional indicates the field is flagged as optional.
9092
IsOptional bool
93+
// IsDeprecated indicates the field is deprecated.
94+
IsDeprecated bool
9195
// Message is the reference back to the parent message
9296
Message *Message
9397
// OneOfIndex is the index in the one of fields

generator/template.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,37 @@ export enum {{.Name}} {
3636
3737
{{- define "messages" -}}
3838
{{- range . -}}
39+
{{- if .IsDeprecated -}}
40+
/**
41+
* @deprecated This message has been deprecated.
42+
*/
43+
{{end -}}
3944
{{- if .HasOneOfFields -}}
4045
type Base{{.Name}} = {
4146
{{- range .NonOneOfFields}}
47+
{{if .IsDeprecated -}}
48+
/** @deprecated This field has been deprecated. */
49+
{{end -}}
4250
{{tsTypeKey .}}: {{tsTypeDef .}};
4351
{{- end}}
4452
{{- range .OptionalFields -}}
53+
{{if .IsDeprecated -}}
54+
/** @deprecated This field has been deprecated. */
55+
{{end -}}
4556
{{tsTypeKey .}}: {{tsTypeDef .}};
4657
{{- end}}
4758
};
4859
4960
export type {{.Name}} = Base{{.Name}}
5061
{{- range $groupId, $fields := .OneOfFieldsGroups}} &
51-
OneOf<{ {{range $index, $field := $fields}}{{fieldName $field.Name}}: {{tsType $field}}{{if (lt (add $index 1) (len $fields))}}; {{end}}{{end}} }>;
62+
OneOf<{
63+
{{- range $index, $field := $fields}}
64+
{{if $field.IsDeprecated -}}
65+
/** @deprecated This field has been deprecated. */
66+
{{end -}}
67+
{{fieldName $field.Name}}: {{tsType $field}};
68+
{{- end}}
69+
}>;
5270
{{- end -}}
5371
5472
{{/* Standard, non oneof messages */}}
@@ -59,6 +77,9 @@ export type {{.Name}} = Base{{.Name}}
5977
{{- else -}}
6078
export type {{.Name}} = {
6179
{{- range .Fields}}
80+
{{if .IsDeprecated -}}
81+
/** @deprecated This field has been deprecated. */
82+
{{end -}}
6283
{{tsTypeKey .}}: {{tsTypeDef .}};
6384
{{- end}}
6485
};

registry/field.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func (r *Registry) analyseField(fileData *data.File, msgData *data.Message, pack
6060
IsExternal: isExternal,
6161
IsOneOfField: f.OneofIndex != nil,
6262
IsOptional: f.GetProto3Optional(),
63+
IsDeprecated: f.GetOptions().GetDeprecated(),
6364
Message: msgData,
6465
}
6566

registry/message.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func (r *Registry) analyseMessage(fileData *data.File, packageName, fileName str
5555
data := data.NewMessage()
5656
data.Name = packageIdentifier
5757
data.FQType = fqName
58+
data.IsDeprecated = message.GetOptions().GetDeprecated()
5859

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

0 commit comments

Comments
 (0)