Skip to content

Commit 39aedcf

Browse files
authored
chore: migrate from gopkg.in/yaml.v3 to go.yaml.in/yaml/v3 (#454)
* chore: migrate from gopkg.in/yaml.v3 to go.yaml.in/yaml/v3 Replace deprecated gopkg.in/yaml.v3 import path with the new canonical go.yaml.in/yaml/v3 path across the codebase. This migration ensures compatibility with modern Go toolchain and dependency management. Changes include: - Update yaml import path in discovery, generate-gnostic, and tools - Upgrade Go version from 1.12 to 1.24.5 - Update dependencies: protobuf (1.36.6), gnostic-models (0.7.0), go-cmp (0.6.0) - Modernize code style with implicit struct literals and short variable declarations - Regenerate protobuf code with latest protoc-gen-go (1.36.6) and protoc (5.29.3) - Add performance optimizations using unsafe package in generated code This maintains backward compatibility while adopting the supported import path for yaml.v3 library going forward. * sync * sync * fix: improve code quality and security in plugins environment - Use proper format string in fmt.Fprintf to prevent format string vulnerabilities - Update file permissions to modern octal syntax (0755 -> 0o755) - Fix comment spacing to follow Go style conventions These changes address static analysis warnings and improve code maintainability while maintaining the same functionality. * refactor: improve code quality and use modern Go APIs - Remove unnecessary fmt.Sprintf calls for static error messages in OpenAPIv3 - Replace deprecated strings.Replace(-1) with strings.ReplaceAll for clarity - Simplify string formatting where no placeholders are used These changes improve code readability, performance, and follow modern Go best practices while maintaining identical functionality. * chore: update dependencies and regenerate protobuf files Update Go dependencies to latest versions: - golang.org/x/tools: v0.35.0 → v0.36.0 - google.golang.org/protobuf: v1.36.6 → v1.36.7 - google.golang.org/genproto: updated to 20250811160224 - golang.org/x/mod: v0.26.0 → v0.27.0 - golang.org/x/net: v0.42.0 → v0.43.0 - golang.org/x/text: v0.27.0 → v0.28.0 Regenerate protobuf files with protoc-gen-go v1.36.7 to reflect the updated dependency versions. This maintenance update ensures the project uses the latest stable versions of its dependencies with security fixes and improvements.
1 parent ad271d5 commit 39aedcf

20 files changed

Lines changed: 434 additions & 2245 deletions

File tree

discovery/discovery.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"regexp"
2222
"strings"
2323

24-
"gopkg.in/yaml.v3"
24+
"go.yaml.in/yaml/v3"
2525

2626
"github.com/google/gnostic/compiler"
2727
)

generate-gnostic/generate-extension.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
)
3333

3434
var protoOptionsForExtensions = []ProtoOption{
35-
ProtoOption{
35+
{
3636
Name: "java_multiple_files",
3737
Value: "true",
3838
Comment: "// This option lets the proto compiler generate Java code inside the package\n" +
@@ -41,7 +41,7 @@ var protoOptionsForExtensions = []ProtoOption{
4141
"// consistent with most programming languages that don't support outer classes.",
4242
},
4343

44-
ProtoOption{
44+
{
4545
Name: "java_outer_classname",
4646
Value: "VendorExtensionProto",
4747
Comment: "// The Java outer classname should be the filename in UpperCamelCase. This\n" +
@@ -114,7 +114,7 @@ func getBaseFileNameWithoutExt(filePath string) string {
114114
}
115115

116116
func toProtoPackageName(input string) string {
117-
var out = ""
117+
out := ""
118118
nonAlphaNumeric := regexp.MustCompile("[^0-9A-Za-z_]+")
119119
input = nonAlphaNumeric.ReplaceAllString(input, "")
120120
for index, character := range input {
@@ -126,7 +126,6 @@ func toProtoPackageName(input string) string {
126126
} else {
127127
out += string(character)
128128
}
129-
130129
}
131130
return out
132131
}
@@ -137,10 +136,10 @@ type primitiveTypeInfo struct {
137136
}
138137

139138
var supportedPrimitiveTypeInfos = map[string]primitiveTypeInfo{
140-
"string": primitiveTypeInfo{goTypeName: "String", wrapperProtoName: "StringValue"},
141-
"number": primitiveTypeInfo{goTypeName: "Float", wrapperProtoName: "DoubleValue"},
142-
"integer": primitiveTypeInfo{goTypeName: "Int", wrapperProtoName: "Int64Value"},
143-
"boolean": primitiveTypeInfo{goTypeName: "Bool", wrapperProtoName: "BoolValue"},
139+
"string": {goTypeName: "String", wrapperProtoName: "StringValue"},
140+
"number": {goTypeName: "Float", wrapperProtoName: "DoubleValue"},
141+
"integer": {goTypeName: "Int", wrapperProtoName: "Int64Value"},
142+
"boolean": {goTypeName: "Bool", wrapperProtoName: "BoolValue"},
144143
// TODO: Investigate how to support arrays. For now users will not be allowed to
145144
// create extension handlers for arrays and they will have to use the
146145
// plane yaml string as is.
@@ -245,7 +244,8 @@ func generateExtension(schemaFile string, outDir string) error {
245244
// generate the protocol buffer description
246245
protoOptions := append(protoOptionsForExtensions,
247246
ProtoOption{Name: "java_package", Value: "org.openapi.extension." + strings.ToLower(protoPackage), Comment: "// The Java package name must be proto package name with proper prefix."},
248-
ProtoOption{Name: "objc_class_prefix", Value: strings.ToLower(protoPackage),
247+
ProtoOption{
248+
Name: "objc_class_prefix", Value: strings.ToLower(protoPackage),
249249
Comment: "// A reasonable prefix for the Objective-C symbols generated from the package.\n" +
250250
"// It should at a minimum be 3 characters long, all uppercase, and convention\n" +
251251
"// is to use an abbreviation of the package name. Something short, but\n" +
@@ -273,7 +273,7 @@ func generateExtension(schemaFile string, outDir string) error {
273273
"regexp",
274274
"strings",
275275
"github.com/google/gnostic/compiler",
276-
"gopkg.in/yaml.v3",
276+
"go.yaml.in/yaml/v3",
277277
})
278278
goFilename := path.Join(protoOutDirectory, outFileBaseName+".go")
279279
err = ioutil.WriteFile(goFilename, []byte(compiler), 0644)
@@ -313,14 +313,13 @@ func generateExtension(schemaFile string, outDir string) error {
313313
extensionNameToMessageName[extensionName].optionalPrimitiveTypeInfo.goTypeName,
314314
extensionNameToMessageName[extensionName].optionalPrimitiveTypeInfo.wrapperProtoName)
315315
}
316-
317316
}
318317
extMainCode := fmt.Sprintf(additionalCompilerCodeWithMain, cases)
319318
imports := []string{
320319
"github.com/google/gnostic/extensions",
321320
"github.com/google/gnostic/compiler",
322321
"google.golang.org/protobuf/proto",
323-
"gopkg.in/yaml.v3",
322+
"go.yaml.in/yaml/v3",
324323
outDirRelativeToPackageRoot + "/" + "proto",
325324
}
326325
if wrapperTypeIncluded {
@@ -338,7 +337,6 @@ func generateExtension(schemaFile string, outDir string) error {
338337
}
339338

340339
func generateExtensions() error {
341-
342340
outDir := ""
343341
schemaFile := ""
344342

generate-gnostic/main.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const License = "" +
4949

5050
func protoOptions(directoryName string, packageName string) []ProtoOption {
5151
return []ProtoOption{
52-
ProtoOption{
52+
{
5353
Name: "java_multiple_files",
5454
Value: "true",
5555
Comment: "// This option lets the proto compiler generate Java code inside the package\n" +
@@ -58,21 +58,21 @@ func protoOptions(directoryName string, packageName string) []ProtoOption {
5858
"// consistent with most programming languages that don't support outer classes.",
5959
},
6060

61-
ProtoOption{
61+
{
6262
Name: "java_outer_classname",
6363
Value: "OpenAPIProto",
6464
Comment: "// The Java outer classname should be the filename in UpperCamelCase. This\n" +
6565
"// class is only used to hold proto descriptor, so developers don't need to\n" +
6666
"// work with it directly.",
6767
},
6868

69-
ProtoOption{
69+
{
7070
Name: "java_package",
7171
Value: "org." + packageName,
7272
Comment: "// The Java package name must be proto package name with proper prefix.",
7373
},
7474

75-
ProtoOption{
75+
{
7676
Name: "objc_class_prefix",
7777
Value: "OAS",
7878
Comment: "// A reasonable prefix for the Objective-C symbols generated from the package.\n" +
@@ -82,7 +82,7 @@ func protoOptions(directoryName string, packageName string) []ProtoOption {
8282
"// the future. 'GPB' is reserved for the protocol buffer implementation itself.",
8383
},
8484

85-
ProtoOption{
85+
{
8686
Name: "go_package",
8787
Value: "./" + directoryName + ";" + packageName,
8888
Comment: "// The Go package name.",
@@ -190,7 +190,7 @@ func generateOpenAPIModel(version string) error {
190190

191191
packageImports := []string{
192192
"fmt",
193-
"gopkg.in/yaml.v3",
193+
"go.yaml.in/yaml/v3",
194194
"strings",
195195
"regexp",
196196
"github.com/google/gnostic/compiler",
@@ -238,8 +238,8 @@ Options:
238238
}
239239

240240
func main() {
241-
var openapiVersion = ""
242-
var shouldGenerateExtensions = false
241+
openapiVersion := ""
242+
shouldGenerateExtensions := false
243243

244244
for i, arg := range os.Args {
245245
if i == 0 {

go.mod

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
module github.com/google/gnostic
22

3-
go 1.12
3+
go 1.24.6
44

55
require (
66
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815
77
github.com/flowstack/go-jsonschema v0.1.1
8-
github.com/golang/protobuf v1.5.3
9-
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49
10-
github.com/google/go-cmp v0.5.9
11-
github.com/stoewer/go-strcase v1.2.0
12-
golang.org/x/tools v0.6.0
13-
google.golang.org/genproto v0.0.0-20230526161137-0005af68ea54 // indirect
14-
google.golang.org/genproto/googleapis/api v0.0.0-20230525234035-dd9d682886f9
15-
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19
16-
google.golang.org/protobuf v1.30.0
17-
gopkg.in/yaml.v3 v3.0.1
8+
github.com/golang/protobuf v1.5.4
9+
github.com/google/gnostic-models v0.7.0
10+
github.com/google/go-cmp v0.6.0
11+
github.com/stoewer/go-strcase v1.3.1
12+
go.yaml.in/yaml/v3 v3.0.4
13+
golang.org/x/tools v0.36.0
14+
google.golang.org/genproto/googleapis/api v0.0.0-20250811160224-6b04f9b4fc78
15+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250811160224-6b04f9b4fc78
16+
google.golang.org/protobuf v1.36.7
17+
)
18+
19+
require (
20+
github.com/buger/jsonparser v1.1.1 // indirect
21+
golang.org/x/mod v0.27.0 // indirect
22+
golang.org/x/net v0.43.0 // indirect
23+
golang.org/x/sync v0.16.0 // indirect
24+
golang.org/x/text v0.28.0 // indirect
1825
)

0 commit comments

Comments
 (0)