Skip to content

Commit 8c97476

Browse files
committed
fix: barry quick fix, 2025-07-01 22:44:48
1 parent f281b2a commit 8c97476

File tree

8 files changed

+147
-89
lines changed

8 files changed

+147
-89
lines changed

auth-base.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
openapi: 3.1.0
2+
info:
3+
title: MyProject
4+
description: "My Project Description"
5+
version: v1.0.0
6+
# 1) Define the security scheme type (HTTP bearer)
7+
components:
8+
securitySchemes:
9+
bearerAuth: # arbitrary name for the security scheme
10+
type: http
11+
scheme: bearer
12+
bearerFormat: JWT # optional, arbitrary value for documentation purposes
13+
# 2) Apply the security globally to all operations
14+
security:
15+
- bearerAuth: [] # use the same name as above

generator/service.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,45 @@ module github.com/pubgo/protoc-gen-openapi
33
go 1.24
44

55
require (
6-
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.5-20250219170025-d39267d9df8f.1
7-
github.com/bufbuild/protovalidate-go v0.9.2
6+
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.6-20250613105001-9f2d3c737feb.1
7+
buf.build/go/protovalidate v0.13.1
88
github.com/google/gnostic v0.7.0
9-
github.com/google/gnostic-models v0.6.9
10-
github.com/lmittmann/tint v1.0.7
11-
github.com/pb33f/libopenapi v0.21.5
9+
github.com/lmittmann/tint v1.1.2
10+
github.com/pb33f/libopenapi v0.22.3
1211
github.com/pubgo/funk v0.5.66
13-
github.com/samber/lo v1.49.1
12+
github.com/samber/lo v1.51.0
1413
github.com/stretchr/testify v1.10.0
15-
google.golang.org/genproto/googleapis/api v0.0.0-20250218202821-56aae31c358a
16-
google.golang.org/protobuf v1.36.5
14+
google.golang.org/genproto/googleapis/api v0.0.0-20250505200425-f936aa4a68b2
15+
google.golang.org/protobuf v1.36.6
1716
gopkg.in/yaml.v3 v3.0.1
1817
)
1918

2019
require (
20+
cel.dev/expr v0.23.1 // indirect
21+
github.com/antlr4-go/antlr/v4 v4.13.1 // indirect
2122
github.com/bahlo/generic-list-go v0.2.0 // indirect
2223
github.com/buger/jsonparser v1.1.1 // indirect
2324
github.com/davecgh/go-spew v1.1.1 // indirect
25+
github.com/google/cel-go v0.25.0 // indirect
26+
github.com/google/gnostic-models v0.6.9 // indirect
2427
github.com/k0kubun/pp/v3 v3.2.0 // indirect
2528
github.com/kr/pretty v0.3.1 // indirect
2629
github.com/kr/text v0.2.0 // indirect
27-
github.com/mailru/easyjson v0.7.7 // indirect
30+
github.com/mailru/easyjson v0.9.0 // indirect
2831
github.com/mattn/go-colorable v0.1.13 // indirect
2932
github.com/mattn/go-isatty v0.0.20 // indirect
3033
github.com/phuslu/goid v1.0.0 // indirect
3134
github.com/pmezard/go-difflib v1.0.0 // indirect
3235
github.com/rogpeppe/go-internal v1.9.0 // indirect
3336
github.com/rs/xid v1.5.0 // indirect
3437
github.com/rs/zerolog v1.33.0 // indirect
35-
github.com/speakeasy-api/jsonpath v0.6.1 // indirect
38+
github.com/speakeasy-api/jsonpath v0.6.2 // indirect
39+
github.com/stoewer/go-strcase v1.3.0 // indirect
3640
github.com/wk8/go-ordered-map/v2 v2.1.9-0.20240815153524-6ea36470d1bd // indirect
37-
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect
38-
golang.org/x/net v0.33.0 // indirect
39-
golang.org/x/sys v0.28.0 // indirect
40-
golang.org/x/text v0.21.0 // indirect
41-
google.golang.org/genproto/googleapis/rpc v0.0.0-20250212204824-5a70512c5d8b // indirect
42-
google.golang.org/grpc v1.67.1 // indirect
41+
golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 // indirect
42+
golang.org/x/net v0.37.0 // indirect
43+
golang.org/x/sys v0.31.0 // indirect
44+
golang.org/x/text v0.25.0 // indirect
45+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250505200425-f936aa4a68b2 // indirect
46+
google.golang.org/grpc v1.71.0 // indirect
4347
)

go.sum

Lines changed: 58 additions & 31 deletions
Large diffs are not rendered by default.

internal/converter/paths.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package converter
22

33
import (
4-
openapiv3 "github.com/google/gnostic-models/openapiv3"
4+
openapiv3 "github.com/google/gnostic/openapiv3"
55
"github.com/pb33f/libopenapi/datamodel/high/base"
66
v3 "github.com/pb33f/libopenapi/datamodel/high/v3"
77
"github.com/pb33f/libopenapi/orderedmap"

internal/converter/protovalidate/schema.go

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
package protovalidate
22

33
import (
4+
"log/slog"
45
"strconv"
56
"strings"
67

78
"buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go/buf/validate"
8-
"github.com/bufbuild/protovalidate-go/resolve"
9+
"buf.build/go/protovalidate"
910
"github.com/pb33f/libopenapi/datamodel/high/base"
1011
"github.com/pb33f/libopenapi/utils"
11-
"google.golang.org/protobuf/reflect/protoreflect"
12-
"gopkg.in/yaml.v3"
13-
1412
"github.com/pubgo/protoc-gen-openapi/internal/converter/options"
1513
"github.com/pubgo/protoc-gen-openapi/internal/converter/util"
14+
"google.golang.org/protobuf/reflect/protoreflect"
15+
"gopkg.in/yaml.v3"
1616
)
1717

1818
func SchemaWithMessageAnnotations(opts options.Options, schema *base.Schema, desc protoreflect.MessageDescriptor) *base.Schema {
19-
constraints := resolve.MessageConstraints(desc)
19+
constraints, err := protovalidate.ResolveMessageRules(desc)
20+
if err != nil {
21+
slog.Warn("unable to resolve message rules", slog.Any("error", err))
22+
return schema
23+
}
2024
if constraints == nil || constraints.GetDisabled() {
2125
return schema
2226
}
@@ -25,7 +29,11 @@ func SchemaWithMessageAnnotations(opts options.Options, schema *base.Schema, des
2529
}
2630

2731
func SchemaWithFieldAnnotations(opts options.Options, schema *base.Schema, desc protoreflect.FieldDescriptor, onlyScalar bool) *base.Schema {
28-
constraints := resolve.FieldConstraints(desc)
32+
constraints, err := protovalidate.ResolveFieldRules(desc)
33+
if err != nil {
34+
slog.Warn("unable to resolve field rules", slog.Any("error", err))
35+
return schema
36+
}
2937
if constraints == nil {
3038
return schema
3139
}
@@ -36,15 +44,19 @@ func SchemaWithFieldAnnotations(opts options.Options, schema *base.Schema, desc
3644
parent.Required = util.AppendStringDedupe(parent.Required, util.MakeFieldName(opts, desc))
3745
}
3846
}
39-
updateSchemaWithFieldConstraints(schema, constraints, onlyScalar)
47+
updateSchemaWithFieldRules(schema, constraints, onlyScalar)
4048
return schema
4149
}
4250

4351
func PopulateParentProperties(opts options.Options, parent *base.Schema, desc protoreflect.FieldDescriptor) *base.Schema {
4452
if parent == nil {
4553
return parent
4654
}
47-
constraints := resolve.FieldConstraints(desc)
55+
constraints, err := protovalidate.ResolveFieldRules(desc)
56+
if err != nil {
57+
slog.Warn("unable to resolve field rules", slog.Any("error", err))
58+
return parent
59+
}
4860
if constraints == nil {
4961
return parent
5062
}
@@ -55,62 +67,62 @@ func PopulateParentProperties(opts options.Options, parent *base.Schema, desc pr
5567
}
5668

5769
//gocyclo:ignore
58-
func updateSchemaWithFieldConstraints(schema *base.Schema, constraints *validate.FieldConstraints, onlyScalar bool) {
70+
func updateSchemaWithFieldRules(schema *base.Schema, constraints *validate.FieldRules, onlyScalar bool) {
5971
if constraints == nil {
6072
return
6173
}
6274
switch t := constraints.Type.(type) {
63-
case *validate.FieldConstraints_Float:
75+
case *validate.FieldRules_Float:
6476
updateSchemaFloat(schema, t.Float)
65-
case *validate.FieldConstraints_Double:
77+
case *validate.FieldRules_Double:
6678
updateSchemaDouble(schema, t.Double)
67-
case *validate.FieldConstraints_Int32:
79+
case *validate.FieldRules_Int32:
6880
updateSchemaInt32(schema, t.Int32)
69-
case *validate.FieldConstraints_Int64:
81+
case *validate.FieldRules_Int64:
7082
updateSchemaInt64(schema, t.Int64)
71-
case *validate.FieldConstraints_Uint32:
83+
case *validate.FieldRules_Uint32:
7284
updateSchemaUint32(schema, t.Uint32)
73-
case *validate.FieldConstraints_Uint64:
85+
case *validate.FieldRules_Uint64:
7486
updateSchemaUint64(schema, t.Uint64)
75-
case *validate.FieldConstraints_Sint32:
87+
case *validate.FieldRules_Sint32:
7688
updateSchemaSint32(schema, t.Sint32)
77-
case *validate.FieldConstraints_Sint64:
89+
case *validate.FieldRules_Sint64:
7890
updateSchemaSint64(schema, t.Sint64)
79-
case *validate.FieldConstraints_Fixed32:
91+
case *validate.FieldRules_Fixed32:
8092
updateSchemaFixed32(schema, t.Fixed32)
81-
case *validate.FieldConstraints_Fixed64:
93+
case *validate.FieldRules_Fixed64:
8294
updateSchemaFixed64(schema, t.Fixed64)
83-
case *validate.FieldConstraints_Sfixed32:
95+
case *validate.FieldRules_Sfixed32:
8496
updateSchemaSfixed32(schema, t.Sfixed32)
85-
case *validate.FieldConstraints_Sfixed64:
97+
case *validate.FieldRules_Sfixed64:
8698
updateSchemaSfixed64(schema, t.Sfixed64)
87-
case *validate.FieldConstraints_Bool:
99+
case *validate.FieldRules_Bool:
88100
updateSchemaBool(schema, t.Bool)
89-
case *validate.FieldConstraints_String_:
101+
case *validate.FieldRules_String_:
90102
updateSchemaString(schema, t.String_)
91-
case *validate.FieldConstraints_Bytes:
103+
case *validate.FieldRules_Bytes:
92104
updateSchemaBytes(schema, t.Bytes)
93-
case *validate.FieldConstraints_Enum:
105+
case *validate.FieldRules_Enum:
94106
updateSchemaEnum(schema, t.Enum)
95-
case *validate.FieldConstraints_Any:
107+
case *validate.FieldRules_Any:
96108
updateSchemaAny(schema, t.Any)
97-
case *validate.FieldConstraints_Duration:
109+
case *validate.FieldRules_Duration:
98110
updateSchemaDuration(schema, t.Duration)
99-
case *validate.FieldConstraints_Timestamp:
111+
case *validate.FieldRules_Timestamp:
100112
updateSchemaTimestamp(schema, t.Timestamp)
101113
}
102114

103115
if !onlyScalar {
104116
switch t := constraints.Type.(type) {
105-
case *validate.FieldConstraints_Repeated:
117+
case *validate.FieldRules_Repeated:
106118
updateSchemaRepeated(schema, t.Repeated)
107-
case *validate.FieldConstraints_Map:
119+
case *validate.FieldRules_Map:
108120
updateSchemaMap(schema, t.Map)
109121
}
110122
}
111123
}
112124

113-
func updateWithCEL(schema *base.Schema, constraints []*validate.Constraint) {
125+
func updateWithCEL(schema *base.Schema, constraints []*validate.Rule) {
114126
if len(constraints) == 0 {
115127
return
116128
}
@@ -178,18 +190,18 @@ func updateSchemaDouble(schema *base.Schema, constraint *validate.DoubleRules) {
178190
}
179191
switch tt := constraint.LessThan.(type) {
180192
case *validate.DoubleRules_Lt:
181-
v := tt.Lt
193+
v := float64(tt.Lt)
182194
schema.ExclusiveMaximum = &base.DynamicValue[bool, float64]{N: 1, B: v}
183195
case *validate.DoubleRules_Lte:
184-
v := tt.Lte
196+
v := float64(tt.Lte)
185197
schema.Maximum = &v
186198
}
187199
switch tt := constraint.GreaterThan.(type) {
188200
case *validate.DoubleRules_Gt:
189-
v := tt.Gt
201+
v := float64(tt.Gt)
190202
schema.ExclusiveMinimum = &base.DynamicValue[bool, float64]{N: 1, B: v}
191203
case *validate.DoubleRules_Gte:
192-
v := tt.Gte
204+
v := float64(tt.Gte)
193205
schema.Minimum = &v
194206
}
195207
if len(constraint.In) > 0 {
@@ -801,7 +813,7 @@ func updateSchemaRepeated(schema *base.Schema, constraint *validate.RepeatedRule
801813
schema.MaxItems = &v
802814
}
803815
if constraint.Items != nil && schema.Items != nil && schema.Items.A != nil && !schema.Items.A.IsReference() {
804-
updateSchemaWithFieldConstraints(schema.Items.A.Schema(), constraint.Items, false)
816+
updateSchemaWithFieldRules(schema.Items.A.Schema(), constraint.Items, false)
805817
}
806818
}
807819

@@ -815,9 +827,9 @@ func updateSchemaMap(schema *base.Schema, constraint *validate.MapRules) {
815827
schema.MaxProperties = &v
816828
}
817829
// NOTE: Most of these properties don't make sense for object keys
818-
// updateSchemaWithFieldConstraints(schema, constraint.Keys)
830+
// updateSchemaWithFieldRules(schema, constraint.Keys)
819831
if schema.AdditionalProperties != nil && constraint.Values != nil {
820-
updateSchemaWithFieldConstraints(schema.AdditionalProperties.A.Schema(), constraint.Values, false)
832+
updateSchemaWithFieldRules(schema.AdditionalProperties.A.Schema(), constraint.Values, false)
821833
}
822834
}
823835

proto/openapiv3/annotations.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ option java_package = "org.openapi_v3";
4141
option objc_class_prefix = "OAS";
4242

4343
// The Go package name.
44-
option go_package = "github.com/google/gnostic-models/openapiv3;openapi_v3";
44+
option go_package = "github.com/google/gnostic/openapiv3";
4545

4646
extend google.protobuf.FileOptions {
4747
Document document = 1143;

proto/openapiv3/openapi.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ option java_package = "org.openapi_v3";
4242
option objc_class_prefix = "OAS";
4343

4444
// The Go package name.
45-
option go_package = "github.com/google/gnostic-models/openapiv3;openapi_v3";
45+
option go_package = "github.com/google/gnostic/openapiv3";
4646

4747
message AdditionalPropertiesItem {
4848
oneof oneof {

0 commit comments

Comments
 (0)