Skip to content

Commit

Permalink
fix: enum type returns 'UNRECOGNIZED' or '-1' in xxxToJSON/xxxToNumber (
Browse files Browse the repository at this point in the history
  • Loading branch information
xalanq authored May 18, 2022
1 parent 3541b50 commit 19911a1
Show file tree
Hide file tree
Showing 31 changed files with 132 additions and 55 deletions.
3 changes: 2 additions & 1 deletion integration/avoid-import-conflicts/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ export function simpleEnumToJSON(object: SimpleEnum): string {
return 'LOCAL_FOO';
case SimpleEnum.LOCAL_BAR:
return 'LOCAL_BAR';
case SimpleEnum.UNRECOGNIZED:
default:
return 'UNKNOWN';
return 'UNRECOGNIZED';
}
}

Expand Down
3 changes: 2 additions & 1 deletion integration/avoid-import-conflicts/simple2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ export function simpleEnumToJSON(object: SimpleEnum): string {
return 'IMPORT_FOO';
case SimpleEnum.IMPORT_BAR:
return 'IMPORT_BAR';
case SimpleEnum.UNRECOGNIZED:
default:
return 'UNKNOWN';
return 'UNRECOGNIZED';
}
}

Expand Down
6 changes: 4 additions & 2 deletions integration/const-enum/const-enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ export function dividerData_DividerTypeToJSON(object: DividerData_DividerType):
return 'DASHED';
case DividerData_DividerType.DOTTED:
return 'DOTTED';
case DividerData_DividerType.UNRECOGNIZED:
default:
return 'UNKNOWN';
return 'UNRECOGNIZED';
}
}

Expand All @@ -63,8 +64,9 @@ export function dividerData_DividerTypeToNumber(object: DividerData_DividerType)
return 2;
case DividerData_DividerType.DOTTED:
return 3;
case DividerData_DividerType.UNRECOGNIZED:
default:
return 0;
return -1;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ export function dividerData_DividerTypeToJSON(object: DividerData_DividerType):
return 'DASHED';
case DividerData_DividerType.DOTTED:
return 'DOTTED';
case DividerData_DividerType.UNRECOGNIZED:
default:
return 'UNKNOWN';
return 'UNRECOGNIZED';
}
}

Expand All @@ -64,8 +65,9 @@ export function dividerData_DividerTypeToNumber(object: DividerData_DividerType)
return 2;
case DividerData_DividerType.DOTTED:
return 3;
case DividerData_DividerType.UNRECOGNIZED:
default:
return 0;
return -1;
}
}

Expand Down
3 changes: 2 additions & 1 deletion integration/enums-as-literals/enums-as-literals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ export function dividerData_DividerTypeToJSON(object: DividerData_DividerType):
return 'DASHED';
case DividerData_DividerType.DOTTED:
return 'DOTTED';
case DividerData_DividerType.UNRECOGNIZED:
default:
return 'UNKNOWN';
return 'UNRECOGNIZED';
}
}

Expand Down
3 changes: 2 additions & 1 deletion integration/file-suffix/child.pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ export function childEnumToJSON(object: ChildEnum): string {
return 'DEFAULT';
case ChildEnum.FOO:
return 'FOO';
case ChildEnum.UNRECOGNIZED:
default:
return 'UNKNOWN';
return 'UNRECOGNIZED';
}
}

Expand Down
3 changes: 2 additions & 1 deletion integration/grpc-js/google/protobuf/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ export function nullValueToJSON(object: NullValue): string {
switch (object) {
case NullValue.NULL_VALUE:
return 'NULL_VALUE';
case NullValue.UNRECOGNIZED:
default:
return 'UNKNOWN';
return 'UNRECOGNIZED';
}
}

Expand Down
3 changes: 2 additions & 1 deletion integration/grpc-web-go-server/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ export function dashFlash_TypeToJSON(object: DashFlash_Type): string {
return 'Warn';
case DashFlash_Type.Error:
return 'Error';
case DashFlash_Type.UNRECOGNIZED:
default:
return 'UNKNOWN';
return 'UNRECOGNIZED';
}
}

Expand Down
3 changes: 2 additions & 1 deletion integration/grpc-web-no-streaming-observable/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ export function dashFlash_TypeToJSON(object: DashFlash_Type): string {
return 'Warn';
case DashFlash_Type.Error:
return 'Error';
case DashFlash_Type.UNRECOGNIZED:
default:
return 'UNKNOWN';
return 'UNRECOGNIZED';
}
}

Expand Down
3 changes: 2 additions & 1 deletion integration/grpc-web-no-streaming/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ export function dashFlash_TypeToJSON(object: DashFlash_Type): string {
return 'Warn';
case DashFlash_Type.Error:
return 'Error';
case DashFlash_Type.UNRECOGNIZED:
default:
return 'UNKNOWN';
return 'UNRECOGNIZED';
}
}

Expand Down
3 changes: 2 additions & 1 deletion integration/grpc-web/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ export function dashFlash_TypeToJSON(object: DashFlash_Type): string {
return 'Warn';
case DashFlash_Type.Error:
return 'Error';
case DashFlash_Type.UNRECOGNIZED:
default:
return 'UNKNOWN';
return 'UNRECOGNIZED';
}
}

Expand Down
3 changes: 2 additions & 1 deletion integration/nice-grpc/google/protobuf/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ export function nullValueToJSON(object: NullValue): string {
switch (object) {
case NullValue.NULL_VALUE:
return 'NULL_VALUE';
case NullValue.UNRECOGNIZED:
default:
return 'UNKNOWN';
return 'UNRECOGNIZED';
}
}

Expand Down
3 changes: 2 additions & 1 deletion integration/oneof-properties/oneof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ export function pleaseChoose_StateEnumToJSON(object: PleaseChoose_StateEnum): st
return 'ON';
case PleaseChoose_StateEnum.OFF:
return 'OFF';
case PleaseChoose_StateEnum.UNRECOGNIZED:
default:
return 'UNKNOWN';
return 'UNRECOGNIZED';
}
}

Expand Down
3 changes: 2 additions & 1 deletion integration/oneof-unions/google/protobuf/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ export function nullValueToJSON(object: NullValue): string {
switch (object) {
case NullValue.NULL_VALUE:
return 'NULL_VALUE';
case NullValue.UNRECOGNIZED:
default:
return 'UNKNOWN';
return 'UNRECOGNIZED';
}
}

Expand Down
3 changes: 2 additions & 1 deletion integration/oneof-unions/oneof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ export function pleaseChoose_StateEnumToJSON(object: PleaseChoose_StateEnum): st
return 'ON';
case PleaseChoose_StateEnum.OFF:
return 'OFF';
case PleaseChoose_StateEnum.UNRECOGNIZED:
default:
return 'UNKNOWN';
return 'UNRECOGNIZED';
}
}

Expand Down
9 changes: 6 additions & 3 deletions integration/simple-optionals/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ export function stateEnumToJSON(object: StateEnum): string {
return 'ON';
case StateEnum.OFF:
return 'OFF';
case StateEnum.UNRECOGNIZED:
default:
return 'UNKNOWN';
return 'UNRECOGNIZED';
}
}

Expand Down Expand Up @@ -106,8 +107,9 @@ export function child_TypeToJSON(object: Child_Type): string {
return 'GOOD';
case Child_Type.BAD:
return 'BAD';
case Child_Type.UNRECOGNIZED:
default:
return 'UNKNOWN';
return 'UNRECOGNIZED';
}
}

Expand Down Expand Up @@ -150,8 +152,9 @@ export function nested_InnerEnumToJSON(object: Nested_InnerEnum): string {
return 'GOOD';
case Nested_InnerEnum.BAD:
return 'BAD';
case Nested_InnerEnum.UNRECOGNIZED:
default:
return 'UNKNOWN';
return 'UNRECOGNIZED';
}
}

Expand Down
3 changes: 2 additions & 1 deletion integration/simple-proto2/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ export function enumWithoutZeroToJSON(object: EnumWithoutZero): string {
return 'A';
case EnumWithoutZero.B:
return 'B';
case EnumWithoutZero.UNRECOGNIZED:
default:
return 'UNKNOWN';
return 'UNRECOGNIZED';
}
}

Expand Down
9 changes: 6 additions & 3 deletions integration/simple-prototype-defaults/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ export function stateEnumToJSON(object: StateEnum): string {
return 'ON';
case StateEnum.OFF:
return 'OFF';
case StateEnum.UNRECOGNIZED:
default:
return 'UNKNOWN';
return 'UNRECOGNIZED';
}
}

Expand Down Expand Up @@ -110,8 +111,9 @@ export function child_TypeToJSON(object: Child_Type): string {
return 'GOOD';
case Child_Type.BAD:
return 'BAD';
case Child_Type.UNRECOGNIZED:
default:
return 'UNKNOWN';
return 'UNRECOGNIZED';
}
}

Expand Down Expand Up @@ -154,8 +156,9 @@ export function nested_InnerEnumToJSON(object: Nested_InnerEnum): string {
return 'GOOD';
case Nested_InnerEnum.BAD:
return 'BAD';
case Nested_InnerEnum.UNRECOGNIZED:
default:
return 'UNKNOWN';
return 'UNRECOGNIZED';
}
}

Expand Down
9 changes: 6 additions & 3 deletions integration/simple-snake/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ export function stateEnumToJSON(object: StateEnum): string {
return 'ON';
case StateEnum.OFF:
return 'OFF';
case StateEnum.UNRECOGNIZED:
default:
return 'UNKNOWN';
return 'UNRECOGNIZED';
}
}

Expand Down Expand Up @@ -106,8 +107,9 @@ export function child_TypeToJSON(object: Child_Type): string {
return 'GOOD';
case Child_Type.BAD:
return 'BAD';
case Child_Type.UNRECOGNIZED:
default:
return 'UNKNOWN';
return 'UNRECOGNIZED';
}
}

Expand Down Expand Up @@ -150,8 +152,9 @@ export function nested_InnerEnumToJSON(object: Nested_InnerEnum): string {
return 'GOOD';
case Nested_InnerEnum.BAD:
return 'BAD';
case Nested_InnerEnum.UNRECOGNIZED:
default:
return 'UNKNOWN';
return 'UNRECOGNIZED';
}
}

Expand Down
6 changes: 4 additions & 2 deletions integration/simple-string-enums/google/protobuf/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ export function nullValueToJSON(object: NullValue): string {
switch (object) {
case NullValue.NULL_VALUE:
return 'NULL_VALUE';
case NullValue.UNRECOGNIZED:
default:
return 'UNKNOWN';
return 'UNRECOGNIZED';
}
}

export function nullValueToNumber(object: NullValue): number {
switch (object) {
case NullValue.NULL_VALUE:
return 0;
case NullValue.UNRECOGNIZED:
default:
return 0;
return -1;
}
}

Expand Down
6 changes: 4 additions & 2 deletions integration/simple-string-enums/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ export function stateEnumToJSON(object: StateEnum): string {
return 'ON';
case StateEnum.OFF:
return 'OFF';
case StateEnum.UNRECOGNIZED:
default:
return 'UNKNOWN';
return 'UNRECOGNIZED';
}
}

Expand All @@ -51,8 +52,9 @@ export function stateEnumToNumber(object: StateEnum): number {
return 2;
case StateEnum.OFF:
return 3;
case StateEnum.UNRECOGNIZED:
default:
return 0;
return -1;
}
}

Expand Down
6 changes: 3 additions & 3 deletions integration/simple-unrecognized-enum/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function stateEnumToJSON(object: StateEnum): string {
case StateEnum.OFF:
return 'OFF';
default:
return 'UNKNOWN';
throw new globalThis.Error('Unrecognized enum value ' + object + ' for enum StateEnum');
}
}

Expand Down Expand Up @@ -101,7 +101,7 @@ export function child_TypeToJSON(object: Child_Type): string {
case Child_Type.BAD:
return 'BAD';
default:
return 'UNKNOWN';
throw new globalThis.Error('Unrecognized enum value ' + object + ' for enum Child_Type');
}
}

Expand Down Expand Up @@ -142,7 +142,7 @@ export function nested_InnerEnumToJSON(object: Nested_InnerEnum): string {
case Nested_InnerEnum.BAD:
return 'BAD';
default:
return 'UNKNOWN';
throw new globalThis.Error('Unrecognized enum value ' + object + ' for enum Nested_InnerEnum');
}
}

Expand Down
Loading

0 comments on commit 19911a1

Please sign in to comment.