Don't allow `null` for enum field inputs/outputs

This commit is contained in:
install 2022-11-16 10:10:13 -05:00
parent c7125fbdb5
commit ef7b8e8f14
6 changed files with 20 additions and 18 deletions

View File

@ -209,14 +209,15 @@ function getTypeNamePermissive(fieldType: string, resolvedType: Protobuf.Type |
throw new Error('Found field with no usable type'); throw new Error('Found field with no usable type');
} }
const typeInterfaceName = getTypeInterfaceName(resolvedType); const typeInterfaceName = getTypeInterfaceName(resolvedType);
if (resolvedType instanceof Protobuf.Type || resolvedType instanceof Protobuf.Enum) { if (resolvedType instanceof Protobuf.Type) {
if (repeated || map) { if (repeated || map) {
return inputName(typeInterfaceName); return inputName(typeInterfaceName);
} else { } else {
return `${inputName(typeInterfaceName)} | null`; return `${inputName(typeInterfaceName)} | null`;
} }
} else { } 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'); throw new Error('Found field with no usable type');
} }
const typeInterfaceName = getTypeInterfaceName(resolvedType); 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 /* null is only used to represent absent message values if the defaults
* option is set, and only for non-repeated, non-map fields. */ * option is set, and only for non-repeated, non-map fields. */
if (options.defaults && !repeated && !map) { if (options.defaults && !repeated && !map) {
@ -320,7 +321,8 @@ function getTypeNameRestricted(fieldType: string, resolvedType: Protobuf.Type |
return `${outputName(typeInterfaceName)}`; return `${outputName(typeInterfaceName)}`;
} }
} else { } else {
return ''; // Enum
return outputName(typeInterfaceName);
} }
} }
} }

View File

@ -87,8 +87,8 @@ export interface IFieldDescriptorProto {
'name'?: (string); 'name'?: (string);
'extendee'?: (string); 'extendee'?: (string);
'number'?: (number); 'number'?: (number);
'label'?: (I_google_protobuf_FieldDescriptorProto_Label | null); 'label'?: (I_google_protobuf_FieldDescriptorProto_Label);
'type'?: (I_google_protobuf_FieldDescriptorProto_Type | null); 'type'?: (I_google_protobuf_FieldDescriptorProto_Type);
'typeName'?: (string); 'typeName'?: (string);
'defaultValue'?: (string); 'defaultValue'?: (string);
'options'?: (I_google_protobuf_FieldOptions | null); 'options'?: (I_google_protobuf_FieldOptions | null);
@ -100,8 +100,8 @@ export interface OFieldDescriptorProto {
'name': (string); 'name': (string);
'extendee': (string); 'extendee': (string);
'number': (number); 'number': (number);
'label': (O_google_protobuf_FieldDescriptorProto_Label | null); 'label': (O_google_protobuf_FieldDescriptorProto_Label);
'type': (O_google_protobuf_FieldDescriptorProto_Type | null); 'type': (O_google_protobuf_FieldDescriptorProto_Type);
'typeName': (string); 'typeName': (string);
'defaultValue': (string); 'defaultValue': (string);
'options': (O_google_protobuf_FieldOptions | null); 'options': (O_google_protobuf_FieldOptions | null);

View File

@ -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 type O_google_protobuf_FieldOptions_JSType = typeof _google_protobuf_FieldOptions_JSType[keyof typeof _google_protobuf_FieldOptions_JSType]
export interface IFieldOptions { export interface IFieldOptions {
'ctype'?: (I_google_protobuf_FieldOptions_CType | null); 'ctype'?: (I_google_protobuf_FieldOptions_CType);
'packed'?: (boolean); 'packed'?: (boolean);
'deprecated'?: (boolean); 'deprecated'?: (boolean);
'lazy'?: (boolean); 'lazy'?: (boolean);
'jstype'?: (I_google_protobuf_FieldOptions_JSType | null); 'jstype'?: (I_google_protobuf_FieldOptions_JSType);
'weak'?: (boolean); 'weak'?: (boolean);
'uninterpretedOption'?: (I_google_protobuf_UninterpretedOption)[]; 'uninterpretedOption'?: (I_google_protobuf_UninterpretedOption)[];
'.google.api.field_behavior'?: (I_google_api_FieldBehavior)[]; '.google.api.field_behavior'?: (I_google_api_FieldBehavior)[];
} }
export interface OFieldOptions { export interface OFieldOptions {
'ctype': (O_google_protobuf_FieldOptions_CType | null); 'ctype': (O_google_protobuf_FieldOptions_CType);
'packed': (boolean); 'packed': (boolean);
'deprecated': (boolean); 'deprecated': (boolean);
'lazy': (boolean); 'lazy': (boolean);
'jstype': (O_google_protobuf_FieldOptions_JSType | null); 'jstype': (O_google_protobuf_FieldOptions_JSType);
'weak': (boolean); 'weak': (boolean);
'uninterpretedOption': (O_google_protobuf_UninterpretedOption)[]; 'uninterpretedOption': (O_google_protobuf_UninterpretedOption)[];
'.google.api.field_behavior': (O_google_api_FieldBehavior)[]; '.google.api.field_behavior': (O_google_api_FieldBehavior)[];

View File

@ -23,7 +23,7 @@ export type O_google_protobuf_FileOptions_OptimizeMode = typeof _google_protobuf
export interface IFileOptions { export interface IFileOptions {
'javaPackage'?: (string); 'javaPackage'?: (string);
'javaOuterClassname'?: (string); 'javaOuterClassname'?: (string);
'optimizeFor'?: (I_google_protobuf_FileOptions_OptimizeMode | null); 'optimizeFor'?: (I_google_protobuf_FileOptions_OptimizeMode);
'javaMultipleFiles'?: (boolean); 'javaMultipleFiles'?: (boolean);
'goPackage'?: (string); 'goPackage'?: (string);
'ccGenericServices'?: (boolean); 'ccGenericServices'?: (boolean);
@ -41,7 +41,7 @@ export interface IFileOptions {
export interface OFileOptions { export interface OFileOptions {
'javaPackage': (string); 'javaPackage': (string);
'javaOuterClassname': (string); 'javaOuterClassname': (string);
'optimizeFor': (O_google_protobuf_FileOptions_OptimizeMode | null); 'optimizeFor': (O_google_protobuf_FileOptions_OptimizeMode);
'javaMultipleFiles': (boolean); 'javaMultipleFiles': (boolean);
'goPackage': (string); 'goPackage': (string);
'ccGenericServices': (boolean); 'ccGenericServices': (boolean);

View File

@ -21,7 +21,7 @@ export interface IEchoRequest {
/** /**
* The severity to be echoed by the server. * The severity to be echoed by the server.
*/ */
'severity'?: (I_google_showcase_v1beta1_Severity | null); 'severity'?: (I_google_showcase_v1beta1_Severity);
'response'?: "content"|"error"; 'response'?: "content"|"error";
} }
@ -43,6 +43,6 @@ export interface OEchoRequest {
/** /**
* The severity to be echoed by the server. * The severity to be echoed by the server.
*/ */
'severity': (O_google_showcase_v1beta1_Severity | null); 'severity': (O_google_showcase_v1beta1_Severity);
'response': "content"|"error"; 'response': "content"|"error";
} }

View File

@ -13,7 +13,7 @@ export interface IEchoResponse {
/** /**
* The severity specified in the request. * 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. * The severity specified in the request.
*/ */
'severity': (O_google_showcase_v1beta1_Severity | null); 'severity': (O_google_showcase_v1beta1_Severity);
} }