mirror of https://github.com/grpc/grpc-node.git
Don't allow `null` for enum field inputs/outputs
This commit is contained in:
parent
c7125fbdb5
commit
ef7b8e8f14
|
@ -209,14 +209,15 @@ function getTypeNamePermissive(fieldType: string, resolvedType: Protobuf.Type |
|
|||
throw new Error('Found field with no usable type');
|
||||
}
|
||||
const typeInterfaceName = getTypeInterfaceName(resolvedType);
|
||||
if (resolvedType instanceof Protobuf.Type || resolvedType instanceof Protobuf.Enum) {
|
||||
if (resolvedType instanceof Protobuf.Type) {
|
||||
if (repeated || map) {
|
||||
return inputName(typeInterfaceName);
|
||||
} else {
|
||||
return `${inputName(typeInterfaceName)} | null`;
|
||||
}
|
||||
} else {
|
||||
return '';
|
||||
// Enum
|
||||
return inputName(typeInterfaceName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -311,7 +312,7 @@ function getTypeNameRestricted(fieldType: string, resolvedType: Protobuf.Type |
|
|||
throw new Error('Found field with no usable type');
|
||||
}
|
||||
const typeInterfaceName = getTypeInterfaceName(resolvedType);
|
||||
if (resolvedType instanceof Protobuf.Type || resolvedType instanceof Protobuf.Enum) {
|
||||
if (resolvedType instanceof Protobuf.Type) {
|
||||
/* null is only used to represent absent message values if the defaults
|
||||
* option is set, and only for non-repeated, non-map fields. */
|
||||
if (options.defaults && !repeated && !map) {
|
||||
|
@ -320,7 +321,8 @@ function getTypeNameRestricted(fieldType: string, resolvedType: Protobuf.Type |
|
|||
return `${outputName(typeInterfaceName)}`;
|
||||
}
|
||||
} else {
|
||||
return '';
|
||||
// Enum
|
||||
return outputName(typeInterfaceName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,8 +87,8 @@ export interface IFieldDescriptorProto {
|
|||
'name'?: (string);
|
||||
'extendee'?: (string);
|
||||
'number'?: (number);
|
||||
'label'?: (I_google_protobuf_FieldDescriptorProto_Label | null);
|
||||
'type'?: (I_google_protobuf_FieldDescriptorProto_Type | null);
|
||||
'label'?: (I_google_protobuf_FieldDescriptorProto_Label);
|
||||
'type'?: (I_google_protobuf_FieldDescriptorProto_Type);
|
||||
'typeName'?: (string);
|
||||
'defaultValue'?: (string);
|
||||
'options'?: (I_google_protobuf_FieldOptions | null);
|
||||
|
@ -100,8 +100,8 @@ export interface OFieldDescriptorProto {
|
|||
'name': (string);
|
||||
'extendee': (string);
|
||||
'number': (number);
|
||||
'label': (O_google_protobuf_FieldDescriptorProto_Label | null);
|
||||
'type': (O_google_protobuf_FieldDescriptorProto_Type | null);
|
||||
'label': (O_google_protobuf_FieldDescriptorProto_Label);
|
||||
'type': (O_google_protobuf_FieldDescriptorProto_Type);
|
||||
'typeName': (string);
|
||||
'defaultValue': (string);
|
||||
'options': (O_google_protobuf_FieldOptions | null);
|
||||
|
|
|
@ -40,22 +40,22 @@ export type I_google_protobuf_FieldOptions_JSType =
|
|||
export type O_google_protobuf_FieldOptions_JSType = typeof _google_protobuf_FieldOptions_JSType[keyof typeof _google_protobuf_FieldOptions_JSType]
|
||||
|
||||
export interface IFieldOptions {
|
||||
'ctype'?: (I_google_protobuf_FieldOptions_CType | null);
|
||||
'ctype'?: (I_google_protobuf_FieldOptions_CType);
|
||||
'packed'?: (boolean);
|
||||
'deprecated'?: (boolean);
|
||||
'lazy'?: (boolean);
|
||||
'jstype'?: (I_google_protobuf_FieldOptions_JSType | null);
|
||||
'jstype'?: (I_google_protobuf_FieldOptions_JSType);
|
||||
'weak'?: (boolean);
|
||||
'uninterpretedOption'?: (I_google_protobuf_UninterpretedOption)[];
|
||||
'.google.api.field_behavior'?: (I_google_api_FieldBehavior)[];
|
||||
}
|
||||
|
||||
export interface OFieldOptions {
|
||||
'ctype': (O_google_protobuf_FieldOptions_CType | null);
|
||||
'ctype': (O_google_protobuf_FieldOptions_CType);
|
||||
'packed': (boolean);
|
||||
'deprecated': (boolean);
|
||||
'lazy': (boolean);
|
||||
'jstype': (O_google_protobuf_FieldOptions_JSType | null);
|
||||
'jstype': (O_google_protobuf_FieldOptions_JSType);
|
||||
'weak': (boolean);
|
||||
'uninterpretedOption': (O_google_protobuf_UninterpretedOption)[];
|
||||
'.google.api.field_behavior': (O_google_api_FieldBehavior)[];
|
||||
|
|
|
@ -23,7 +23,7 @@ export type O_google_protobuf_FileOptions_OptimizeMode = typeof _google_protobuf
|
|||
export interface IFileOptions {
|
||||
'javaPackage'?: (string);
|
||||
'javaOuterClassname'?: (string);
|
||||
'optimizeFor'?: (I_google_protobuf_FileOptions_OptimizeMode | null);
|
||||
'optimizeFor'?: (I_google_protobuf_FileOptions_OptimizeMode);
|
||||
'javaMultipleFiles'?: (boolean);
|
||||
'goPackage'?: (string);
|
||||
'ccGenericServices'?: (boolean);
|
||||
|
@ -41,7 +41,7 @@ export interface IFileOptions {
|
|||
export interface OFileOptions {
|
||||
'javaPackage': (string);
|
||||
'javaOuterClassname': (string);
|
||||
'optimizeFor': (O_google_protobuf_FileOptions_OptimizeMode | null);
|
||||
'optimizeFor': (O_google_protobuf_FileOptions_OptimizeMode);
|
||||
'javaMultipleFiles': (boolean);
|
||||
'goPackage': (string);
|
||||
'ccGenericServices': (boolean);
|
||||
|
|
|
@ -21,7 +21,7 @@ export interface IEchoRequest {
|
|||
/**
|
||||
* The severity to be echoed by the server.
|
||||
*/
|
||||
'severity'?: (I_google_showcase_v1beta1_Severity | null);
|
||||
'severity'?: (I_google_showcase_v1beta1_Severity);
|
||||
'response'?: "content"|"error";
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,6 @@ export interface OEchoRequest {
|
|||
/**
|
||||
* The severity to be echoed by the server.
|
||||
*/
|
||||
'severity': (O_google_showcase_v1beta1_Severity | null);
|
||||
'severity': (O_google_showcase_v1beta1_Severity);
|
||||
'response': "content"|"error";
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ export interface IEchoResponse {
|
|||
/**
|
||||
* The severity specified in the request.
|
||||
*/
|
||||
'severity'?: (I_google_showcase_v1beta1_Severity | null);
|
||||
'severity'?: (I_google_showcase_v1beta1_Severity);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -27,5 +27,5 @@ export interface OEchoResponse {
|
|||
/**
|
||||
* The severity specified in the request.
|
||||
*/
|
||||
'severity': (O_google_showcase_v1beta1_Severity | null);
|
||||
'severity': (O_google_showcase_v1beta1_Severity);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue