Skip to content
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 Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ build: install-deps
run:
rm -fr $(OUTPUTDIR)
mkdir -p $(OUTPUTDIR)
protoc --plugin=./$(BINDIR)/protoc-gen-openapi --openapi_out=single_file=true,use_ref=true:$(OUTPUTDIR)/. -Itestdata testdata/testpkg/test1.proto testdata/testpkg/test2.proto testdata/testpkg/test6.proto testdata/testpkg2/test3.proto
protoc --plugin=./$(BINDIR)/protoc-gen-openapi --openapi_out=single_file=true,use_ref=true:$(OUTPUTDIR)/. -Itestdata testdata/testpkg/test1.proto testdata/testpkg/test2.proto testdata/testpkg/test6.proto testdata/testpkg2/test3.proto testdata/testpkg/test_proto3_optional.proto

gotest:
PATH=$(BINDIR):$(PATH) go test -v ./...
Expand Down
8 changes: 7 additions & 1 deletion openapiGenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,13 @@ func (g *openapiGenerator) generateMessageSchema(message *protomodel.MessageDesc

oneOfFields := make(map[int32][]string)
var requiredFields []string
// Handle proto3 optional fields - they should not be required
for _, field := range message.Fields {
if field.Proto3Optional != nil && *field.Proto3Optional {
repeated := field.IsRepeated()
// Proto3 optional fields are never required
fieldName := g.fieldName(field)
} else if g.markerRegistry.IsRequired(fieldRules) {
fieldDesc := g.generateDescription(field)
fieldRules := g.validationRules(field)

Expand All @@ -436,9 +440,10 @@ func (g *openapiGenerator) generateMessageSchema(message *protomodel.MessageDesc
oneOfFields[idx] = append(oneOfFields[idx], fieldName)
}

if g.markerRegistry.IsRequired(fieldRules) {
// Field is required by marker
requiredFields = append(requiredFields, fieldName)
}
}

schemaType := g.markerRegistry.GetSchemaType(fieldRules, markers.TargetField)
if schemaType != "" {
Expand Down Expand Up @@ -827,3 +832,4 @@ func isIgnoredKubeMarker(regexp *regexp.Regexp, l string) bool {

return regexp.MatchString(l)
}