Skip to content

Commit

Permalink
Do not assume string key and value
Browse files Browse the repository at this point in the history
  • Loading branch information
tresabhi committed Oct 5, 2024
1 parent b876c8f commit 419eca6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,7 @@ function generateBaseInstanceFactory(
let val;

if (keyValuePair) {
val = '""';
val = defaultValue(ctx, { ...field, label: FieldDescriptorProto_Label.LABEL_REQUIRED });
} else if (isWithinOneOf(field)) {
val = nullOrUndefined(options);
} else if (isMapType(ctx, messageDesc, field)) {
Expand Down Expand Up @@ -2759,7 +2759,7 @@ function generateFromPartial(ctx: Context, fullName: string, messageDesc: Descri
let fallback

if (keyValuePair) {
fallback = '""'
fallback = defaultValue(ctx, { ...field, label: FieldDescriptorProto_Label.LABEL_REQUIRED })
} else {
fallback = isWithinOneOf(field) || noDefaultValue ? "undefined" : defaultValue(ctx, field);
}
Expand Down
2 changes: 0 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,9 @@ export function isKeyValuePair(fields: FieldDescriptorProto[]) {
return fields.length === 2 &&
fields[0].name === "key" &&
fields[0].number === 1 &&
fields[0].type === FieldDescriptorProto_Type.TYPE_STRING &&
fields[0].label === FieldDescriptorProto_Label.LABEL_OPTIONAL &&
fields[1].name === "value" &&
fields[1].number === 2 &&
fields[1].type === FieldDescriptorProto_Type.TYPE_STRING &&
fields[1].label === FieldDescriptorProto_Label.LABEL_OPTIONAL;
}

Expand Down

0 comments on commit 419eca6

Please sign in to comment.