From 1f8726c31e4847cb144899e1b498bf29f667018c Mon Sep 17 00:00:00 2001 From: Kevin McDonald Date: Sat, 25 Jan 2025 09:40:17 +0100 Subject: [PATCH] fix: enums will also be fully qualified with fully-qualified-message-names; add filter for services on tags --- internal/converter/converter.go | 2 +- internal/converter/schema.go | 7 ++++++- internal/converter/tags.go | 6 +++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/internal/converter/converter.go b/internal/converter/converter.go index 29da3b8..4fca0d0 100644 --- a/internal/converter/converter.go +++ b/internal/converter/converter.go @@ -243,7 +243,7 @@ func appendToSpec(opts options.Options, spec *v3.Document, fd protoreflect.FileD if err := addPathItemsFromFile(opts, fd, spec.Paths); err != nil { return err } - spec.Tags = append(spec.Tags, fileToTags(fd)...) + spec.Tags = append(spec.Tags, fileToTags(opts, fd)...) return nil } diff --git a/internal/converter/schema.go b/internal/converter/schema.go index 5a33756..e52ba55 100644 --- a/internal/converter/schema.go +++ b/internal/converter/schema.go @@ -146,8 +146,13 @@ func enumToSchema(state *State, tt protoreflect.EnumDescriptor) (string, *base.S children = append(children, utils.CreateIntNode(strconv.FormatInt(int64(value.Number()), 10))) } } + + title := string(tt.Name()) + if state.Opts.FullyQualifiedMessageNames { + title = string(tt.FullName()) + } s := &base.Schema{ - Title: string(tt.Name()), + Title: title, Description: util.FormatComments(tt.ParentFile().SourceLocations().ByDescriptor(tt)), Type: []string{"string"}, Enum: children, diff --git a/internal/converter/tags.go b/internal/converter/tags.go index 09d07a0..4804b9c 100644 --- a/internal/converter/tags.go +++ b/internal/converter/tags.go @@ -5,14 +5,18 @@ import ( highbase "github.com/pb33f/libopenapi/datamodel/high/base" "google.golang.org/protobuf/reflect/protoreflect" + "github.com/sudorandom/protoc-gen-connect-openapi/internal/converter/options" "github.com/sudorandom/protoc-gen-connect-openapi/internal/converter/util" ) -func fileToTags(fd protoreflect.FileDescriptor) []*base.Tag { +func fileToTags(opts options.Options, fd protoreflect.FileDescriptor) []*base.Tag { tags := []*highbase.Tag{} services := fd.Services() for i := 0; i < services.Len(); i++ { service := services.Get(i) + if !opts.HasService(service.FullName()) { + continue + } loc := fd.SourceLocations().ByDescriptor(service) description := util.FormatComments(loc)