Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Do not mark repeated fields as optional #187

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/chrusty/protoc-gen-jsonschema
module github.com/ikstewa/protoc-gen-jsonschema

go 1.14

Expand Down
9 changes: 9 additions & 0 deletions internal/converter/testdata/payload_message_2.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ const PayloadMessage2 = `{
}
],
"title": "Topology"
},
"array": {
"items": {
"type": "integer"
},
"type": "array"
},
"opt_int": {
"type": "integer"
}
},
"additionalProperties": true,
Expand Down
14 changes: 8 additions & 6 deletions internal/converter/testdata/proto/PayloadMessage2.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ message PayloadMessage2 {
ARRAY_OF_MESSAGE = 5;
}

string name = 1;
string timestamp = 2;
int32 id = 3;
float rating = 4;
bool complete = 5;
Topology topology = 6;
string name = 1;
string timestamp = 2;
int32 id = 3;
float rating = 4;
bool complete = 5;
Topology topology = 6;
repeated int32 array = 7;
optional int32 opt_int = 8;
}
3 changes: 2 additions & 1 deletion internal/converter/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,8 @@ func (c *Converter) recursiveConvertMessageType(curPkg *ProtoPackage, msgDesc *d

// Enforce all_fields_required:
if messageFlags.AllFieldsRequired {
if fieldDesc.OneofIndex == nil && !fieldDesc.GetProto3Optional() {
if fieldDesc.OneofIndex == nil && !fieldDesc.GetProto3Optional() && fieldDesc.GetLabel() != descriptor.FieldDescriptorProto_LABEL_REPEATED {

if c.Flags.UseJSONFieldnamesOnly {
jsonSchemaType.Required = append(jsonSchemaType.Required, fieldDesc.GetJsonName())
} else {
Expand Down
11 changes: 10 additions & 1 deletion jsonschemas/PayloadMessage2.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@
}
],
"title": "Topology"
},
"array": {
"items": {
"type": "integer"
},
"type": "array"
},
"opt_int": {
"type": "integer"
}
},
"additionalProperties": true,
Expand All @@ -59,4 +68,4 @@
"description": "PayloadMessage2 contains some common types PayloadMessage2 is used throughout the test suite and can have multi-line comments"
}
}
}
}