Skip to content

Commit 09f577a

Browse files
Do not generate doc comments for virtual oneOfs
1 parent ccd640e commit 09f577a

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

cli/targets/static.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,19 @@ function isOptional(field, syntax) {
379379
return field.optional && !(field.partOf || field.repeated || field.map);
380380
}
381381

382+
function isOptionalOneOf(oneof, syntax) {
383+
384+
if (syntax !== "proto3")
385+
return false;
386+
387+
if (oneof.fieldsArray == null || oneof.fieldsArray.length !== 1)
388+
return false;
389+
390+
var field = oneof.fieldsArray[0];
391+
392+
return field.options != null && field.options["proto3_optional"] === true;
393+
}
394+
382395
function buildType(ref, type) {
383396

384397
var syntax = syntaxForType(type);
@@ -494,12 +507,17 @@ function buildType(ref, type) {
494507
}
495508
oneof.resolve();
496509
push("");
497-
pushComment([
498-
oneof.comment || type.name + " " + oneof.name + ".",
499-
"@member {" + oneof.oneof.map(JSON.stringify).join("|") + "|undefined} " + escapeName(oneof.name),
500-
"@memberof " + exportName(type),
501-
"@instance"
502-
]);
510+
if (isOptionalOneOf(oneof, syntax)) {
511+
push("// Virtual OneOf for proto3 optional field");
512+
}
513+
else {
514+
pushComment([
515+
oneof.comment || type.name + " " + oneof.name + ".",
516+
"@member {" + oneof.oneof.map(JSON.stringify).join("|") + "|undefined} " + escapeName(oneof.name),
517+
"@memberof " + exportName(type),
518+
"@instance"
519+
]);
520+
}
503521
push("Object.defineProperty(" + escapeName(type.name) + ".prototype, " + JSON.stringify(oneof.name) +", {");
504522
++indent;
505523
push("get: $util.oneOfGetter($oneOfFields = [" + oneof.oneof.map(JSON.stringify).join(", ") + "]),");

0 commit comments

Comments
 (0)