Skip to content

Commit

Permalink
feat: support deprecatedOnly option to make deprecated fields optional (
Browse files Browse the repository at this point in the history
#1010)

Add `deprecatedOnly` option for `useOptionals` option to make only
deprecated fields optional. This PR aims to address the issue
#993
  • Loading branch information
tufandevrim committed Mar 26, 2024
1 parent 088d5a6 commit db23004
Show file tree
Hide file tree
Showing 8 changed files with 776 additions and 5 deletions.
56 changes: 56 additions & 0 deletions integration/use-optionals-deprecated-only/optionals-test.ts
@@ -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",
},
});
});
})
1 change: 1 addition & 0 deletions integration/use-optionals-deprecated-only/parameters.txt
@@ -0,0 +1 @@
useOptionals=deprecatedOnly
Binary file not shown.
35 changes: 35 additions & 0 deletions integration/use-optionals-deprecated-only/test.proto
@@ -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;
}

0 comments on commit db23004

Please sign in to comment.