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

feat: optional one of properties #705

Merged
merged 4 commits into from
Nov 20, 2022
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
12 changes: 6 additions & 6 deletions integration/grpc-js/google/protobuf/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,27 @@ export interface Struct_FieldsEntry {
*/
export interface Value {
/** Represents a null value. */
nullValue:
nullValue?:
| NullValue
| undefined;
/** Represents a double value. */
numberValue:
numberValue?:
| number
| undefined;
/** Represents a string value. */
stringValue:
stringValue?:
| string
| undefined;
/** Represents a boolean value. */
boolValue:
boolValue?:
| boolean
| undefined;
/** Represents a structured value. */
structValue:
structValue?:
| { [key: string]: any }
| undefined;
/** Represents a repeated `Value`. */
listValue: Array<any> | undefined;
listValue?: Array<any> | undefined;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions integration/meta-typings/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ export interface Nested_InnerMessage_DeepMessage {
}

export interface OneOfMessage {
first: string | undefined;
last: string | undefined;
first?: string | undefined;
last?: string | undefined;
}

export interface SimpleWithWrappers {
Expand Down
12 changes: 6 additions & 6 deletions integration/nice-grpc/google/protobuf/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,27 @@ export interface Struct_FieldsEntry {
*/
export interface Value {
/** Represents a null value. */
nullValue:
nullValue?:
| NullValue
| undefined;
/** Represents a double value. */
numberValue:
numberValue?:
| number
| undefined;
/** Represents a string value. */
stringValue:
stringValue?:
| string
| undefined;
/** Represents a boolean value. */
boolValue:
boolValue?:
| boolean
| undefined;
/** Represents a structured value. */
structValue:
structValue?:
| { [key: string]: any }
| undefined;
/** Represents a repeated `Value`. */
listValue: Array<any> | undefined;
listValue?: Array<any> | undefined;
}

/**
Expand Down
8 changes: 8 additions & 0 deletions integration/oneof-properties/oneof-properties-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,12 @@ describe('oneof=properties (default)', () => {
let fromJson = PleaseChoose.fromJSON(pbjsJson);
expect(fromJson).toEqual(debbie);
});

it('should allow to omit oneOf fields', () => {
const msg: PleaseChoose = {
name: 'foo',
age: 42,
};
expect(msg).toBeDefined();
});
});
18 changes: 9 additions & 9 deletions integration/oneof-properties/oneof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ export interface PleaseChoose {
* Use this if you want a number. Numbers are great. Who doesn't
* like them?
*/
aNumber:
aNumber?:
| number
| undefined;
/**
* Use this if you want a string. Strings are also nice. Not as
* nice as numbers, but what are you going to do...
*/
aString: string | undefined;
aMessage:
aString?: string | undefined;
aMessage?:
| PleaseChoose_Submessage
| undefined;
/**
* We also added a bool option! This was added after the 'age'
* field, so it has a higher number.
*/
aBool: boolean | undefined;
bunchaBytes: Uint8Array | undefined;
anEnum: PleaseChoose_StateEnum | undefined;
aBool?: boolean | undefined;
bunchaBytes?: Uint8Array | undefined;
anEnum?: PleaseChoose_StateEnum | undefined;
age: number;
either: string | undefined;
or: string | undefined;
thirdOption: string | undefined;
either?: string | undefined;
or?: string | undefined;
thirdOption?: string | undefined;
}

export enum PleaseChoose_StateEnum {
Expand Down
2 changes: 1 addition & 1 deletion integration/options/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface MyMessage {
foo?: number | undefined;
foo2?: number | undefined;
bar?: string | undefined;
quux: string | undefined;
quux?: string | undefined;
}

export interface RequestType {
Expand Down
4 changes: 2 additions & 2 deletions integration/simple-optionals/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ export interface Nested_InnerMessage_DeepMessage {
}

export interface OneOfMessage {
first: string | undefined;
last: string | undefined;
first?: string | undefined;
last?: string | undefined;
}

export interface SimpleWithWrappers {
Expand Down
4 changes: 2 additions & 2 deletions integration/simple-prototype-defaults/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ export interface Nested_InnerMessage_DeepMessage {
}

export interface OneOfMessage {
first: string | undefined;
last: string | undefined;
first?: string | undefined;
last?: string | undefined;
}

export interface SimpleWithWrappers {
Expand Down
12 changes: 6 additions & 6 deletions integration/simple-snake/google/protobuf/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,27 @@ export interface Struct_FieldsEntry {
*/
export interface Value {
/** Represents a null value. */
null_value:
null_value?:
| NullValue
| undefined;
/** Represents a double value. */
number_value:
number_value?:
| number
| undefined;
/** Represents a string value. */
string_value:
string_value?:
| string
| undefined;
/** Represents a boolean value. */
bool_value:
bool_value?:
| boolean
| undefined;
/** Represents a structured value. */
struct_value:
struct_value?:
| { [key: string]: any }
| undefined;
/** Represents a repeated `Value`. */
list_value: Array<any> | undefined;
list_value?: Array<any> | undefined;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions integration/simple-snake/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ export interface Nested_InnerMessage_DeepMessage {
}

export interface OneOfMessage {
first: string | undefined;
last: string | undefined;
first?: string | undefined;
last?: string | undefined;
}

export interface SimpleWithWrappers {
Expand Down
12 changes: 6 additions & 6 deletions integration/simple-string-enums/google/protobuf/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,27 @@ export interface Struct_FieldsEntry {
*/
export interface Value {
/** Represents a null value. */
nullValue:
nullValue?:
| NullValue
| undefined;
/** Represents a double value. */
numberValue:
numberValue?:
| number
| undefined;
/** Represents a string value. */
stringValue:
stringValue?:
| string
| undefined;
/** Represents a boolean value. */
boolValue:
boolValue?:
| boolean
| undefined;
/** Represents a structured value. */
structValue:
structValue?:
| { [key: string]: any }
| undefined;
/** Represents a repeated `Value`. */
listValue: Array<any> | undefined;
listValue?: Array<any> | undefined;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions integration/simple-unrecognized-enum/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ export interface Nested_InnerMessage_DeepMessage {
}

export interface OneOfMessage {
first: string | undefined;
last: string | undefined;
first?: string | undefined;
last?: string | undefined;
}

export interface SimpleWithWrappers {
Expand Down
4 changes: 2 additions & 2 deletions integration/simple/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ export interface Nested_InnerMessage_DeepMessage {
}

export interface OneOfMessage {
first: string | undefined;
last: string | undefined;
first?: string | undefined;
last?: string | undefined;
}

export interface SimpleWithWrappers {
Expand Down
12 changes: 6 additions & 6 deletions integration/struct/google/protobuf/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,27 @@ export interface Struct_FieldsEntry {
*/
export interface Value {
/** Represents a null value. */
nullValue:
nullValue?:
| NullValue
| undefined;
/** Represents a double value. */
numberValue:
numberValue?:
| number
| undefined;
/** Represents a string value. */
stringValue:
stringValue?:
| string
| undefined;
/** Represents a boolean value. */
boolValue:
boolValue?:
| boolean
| undefined;
/** Represents a structured value. */
structValue:
structValue?:
| { [key: string]: any }
| undefined;
/** Represents a repeated `Value`. */
listValue: Array<any> | undefined;
listValue?: Array<any> | undefined;
}

/**
Expand Down
12 changes: 6 additions & 6 deletions integration/type-registry/google/protobuf/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,27 @@ export interface Struct_FieldsEntry {
export interface Value {
$type: "google.protobuf.Value";
/** Represents a null value. */
nullValue:
nullValue?:
| NullValue
| undefined;
/** Represents a double value. */
numberValue:
numberValue?:
| number
| undefined;
/** Represents a string value. */
stringValue:
stringValue?:
| string
| undefined;
/** Represents a boolean value. */
boolValue:
boolValue?:
| boolean
| undefined;
/** Represents a structured value. */
structValue:
structValue?:
| { [key: string]: any }
| undefined;
/** Represents a repeated `Value`. */
listValue: Array<any> | undefined;
listValue?: Array<any> | undefined;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion integration/types-with-underscores/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as _m0 from "protobufjs/minimal";
export const protobufPackage = "";

export interface Baz {
foo: FooBar | undefined;
foo?: FooBar | undefined;
}

export interface FooBar {
Expand Down
2 changes: 1 addition & 1 deletion integration/unknown-fields/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface MyMessage {
foo?: number | undefined;
foo2?: number | undefined;
bar?: string | undefined;
quux: string | undefined;
quux?: string | undefined;
}

export interface RequestType {
Expand Down
12 changes: 6 additions & 6 deletions integration/use-numeric-enum-json/google/protobuf/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,27 @@ export interface Struct_FieldsEntry {
*/
export interface Value {
/** Represents a null value. */
nullValue:
nullValue?:
| NullValue
| undefined;
/** Represents a double value. */
numberValue:
numberValue?:
| number
| undefined;
/** Represents a string value. */
stringValue:
stringValue?:
| string
| undefined;
/** Represents a boolean value. */
boolValue:
boolValue?:
| boolean
| undefined;
/** Represents a structured value. */
structValue:
structValue?:
| { [key: string]: any }
| undefined;
/** Represents a repeated `Value`. */
listValue: Array<any> | undefined;
listValue?: Array<any> | undefined;
}

/**
Expand Down
Loading