-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support deprecatedOnly option to make deprecated fields optional (
#1010) Add `deprecatedOnly` option for `useOptionals` option to make only deprecated fields optional. This PR aims to address the issue #993
- Loading branch information
1 parent
088d5a6
commit db23004
Showing
8 changed files
with
776 additions
and
5 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
integration/use-optionals-deprecated-only/optionals-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { OptionalsTest, StateEnum } from './test' | ||
|
||
describe('useOptionals=deprecatedOnly', () => { | ||
it('has deprecated fields optional members', () => { | ||
const test: OptionalsTest = { | ||
id: 1, | ||
long: 10, | ||
repId: [1, 2], | ||
repStateV2: [StateEnum.ON, StateEnum.OFF], | ||
repLong: [11, 12], | ||
repTruth: [true, false], | ||
repDescription: ["hello", "world"], | ||
repData: [Buffer.alloc(3).fill(0x33), Buffer.alloc(4).fill(0x34), Buffer.alloc(5).fill(0x35)], | ||
|
||
optId: 2, | ||
optLong: 13, | ||
optTruth: true, | ||
optDescription: "mumble", | ||
optData: Buffer.alloc(6).fill(0x36), | ||
|
||
translations: { | ||
"hello": "hallo", | ||
"world": "wereld", | ||
}, | ||
}; | ||
const data = OptionalsTest.encode(test).finish(); | ||
const test2 = OptionalsTest.decode(data); | ||
expect(test2).toEqual({ | ||
id: 1, | ||
state: StateEnum.UNKNOWN, | ||
long: 10, | ||
truth: false, | ||
description: "", | ||
data: new Uint8Array(0), | ||
|
||
repId: [1, 2], | ||
repState: [], | ||
repStateV2: [StateEnum.ON, StateEnum.OFF], | ||
repLong: [11, 12], | ||
repTruth: [true, false], | ||
repDescription: ["hello", "world"], | ||
repData: [Buffer.alloc(3).fill(0x33), Buffer.alloc(4).fill(0x34), Buffer.alloc(5).fill(0x35)], | ||
|
||
optId: 2, | ||
optLong: 13, | ||
optTruth: true, | ||
optDescription: "mumble", | ||
optData: Buffer.alloc(6).fill(0x36), | ||
|
||
translations: { | ||
"hello": "hallo", | ||
"world": "wereld", | ||
}, | ||
}); | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
useOptionals=deprecatedOnly |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
syntax = "proto3"; | ||
package optionalstest; | ||
|
||
message OptionalsTest { | ||
int32 id = 1; | ||
StateEnum state = 2 [deprecated = true]; | ||
int64 long = 3; | ||
bool truth = 4 [deprecated = true]; | ||
string description = 5 [deprecated = true]; | ||
bytes data = 6 [deprecated = true]; | ||
|
||
repeated int32 rep_id = 7; | ||
repeated StateEnum rep_state = 8 [deprecated = true]; | ||
repeated StateEnum rep_state_v2 = 9; | ||
repeated int64 rep_long = 10; | ||
repeated bool rep_truth = 11; | ||
repeated string rep_description = 12; | ||
repeated bytes rep_data = 13; | ||
|
||
optional int32 opt_id = 14; | ||
optional StateEnum opt_state = 15 [deprecated = true]; | ||
optional int64 opt_long = 16; | ||
optional bool opt_truth = 17; | ||
optional string opt_description = 18; | ||
optional bytes opt_data = 19; | ||
|
||
map<string, string> translations = 20; | ||
} | ||
|
||
enum StateEnum { | ||
option deprecated = true; | ||
UNKNOWN = 0; | ||
ON = 1; | ||
OFF = 2; | ||
} |
Oops, something went wrong.