Skip to content
Merged
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 discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"regexp"
"strings"

"gopkg.in/yaml.v3"
"go.yaml.in/yaml/v3"

"github.com/google/gnostic/compiler"
)
Expand Down
24 changes: 11 additions & 13 deletions generate-gnostic/generate-extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
)

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

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

func toProtoPackageName(input string) string {
var out = ""
out := ""
nonAlphaNumeric := regexp.MustCompile("[^0-9A-Za-z_]+")
input = nonAlphaNumeric.ReplaceAllString(input, "")
for index, character := range input {
Expand All @@ -126,7 +126,6 @@ func toProtoPackageName(input string) string {
} else {
out += string(character)
}

}
return out
}
Expand All @@ -137,10 +136,10 @@ type primitiveTypeInfo struct {
}

var supportedPrimitiveTypeInfos = map[string]primitiveTypeInfo{
"string": primitiveTypeInfo{goTypeName: "String", wrapperProtoName: "StringValue"},
"number": primitiveTypeInfo{goTypeName: "Float", wrapperProtoName: "DoubleValue"},
"integer": primitiveTypeInfo{goTypeName: "Int", wrapperProtoName: "Int64Value"},
"boolean": primitiveTypeInfo{goTypeName: "Bool", wrapperProtoName: "BoolValue"},
"string": {goTypeName: "String", wrapperProtoName: "StringValue"},
"number": {goTypeName: "Float", wrapperProtoName: "DoubleValue"},
"integer": {goTypeName: "Int", wrapperProtoName: "Int64Value"},
"boolean": {goTypeName: "Bool", wrapperProtoName: "BoolValue"},
// TODO: Investigate how to support arrays. For now users will not be allowed to
// create extension handlers for arrays and they will have to use the
// plane yaml string as is.
Expand Down Expand Up @@ -245,7 +244,8 @@ func generateExtension(schemaFile string, outDir string) error {
// generate the protocol buffer description
protoOptions := append(protoOptionsForExtensions,
ProtoOption{Name: "java_package", Value: "org.openapi.extension." + strings.ToLower(protoPackage), Comment: "// The Java package name must be proto package name with proper prefix."},
ProtoOption{Name: "objc_class_prefix", Value: strings.ToLower(protoPackage),
ProtoOption{
Name: "objc_class_prefix", Value: strings.ToLower(protoPackage),
Comment: "// A reasonable prefix for the Objective-C symbols generated from the package.\n" +
"// It should at a minimum be 3 characters long, all uppercase, and convention\n" +
"// is to use an abbreviation of the package name. Something short, but\n" +
Expand Down Expand Up @@ -273,7 +273,7 @@ func generateExtension(schemaFile string, outDir string) error {
"regexp",
"strings",
"github.com/google/gnostic/compiler",
"gopkg.in/yaml.v3",
"go.yaml.in/yaml/v3",
})
goFilename := path.Join(protoOutDirectory, outFileBaseName+".go")
err = ioutil.WriteFile(goFilename, []byte(compiler), 0644)
Expand Down Expand Up @@ -313,14 +313,13 @@ func generateExtension(schemaFile string, outDir string) error {
extensionNameToMessageName[extensionName].optionalPrimitiveTypeInfo.goTypeName,
extensionNameToMessageName[extensionName].optionalPrimitiveTypeInfo.wrapperProtoName)
}

}
extMainCode := fmt.Sprintf(additionalCompilerCodeWithMain, cases)
imports := []string{
"github.com/google/gnostic/extensions",
"github.com/google/gnostic/compiler",
"google.golang.org/protobuf/proto",
"gopkg.in/yaml.v3",
"go.yaml.in/yaml/v3",
outDirRelativeToPackageRoot + "/" + "proto",
}
if wrapperTypeIncluded {
Expand All @@ -338,7 +337,6 @@ func generateExtension(schemaFile string, outDir string) error {
}

func generateExtensions() error {

outDir := ""
schemaFile := ""

Expand Down
16 changes: 8 additions & 8 deletions generate-gnostic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const License = "" +

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

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

ProtoOption{
{
Name: "java_package",
Value: "org." + packageName,
Comment: "// The Java package name must be proto package name with proper prefix.",
},

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

ProtoOption{
{
Name: "go_package",
Value: "./" + directoryName + ";" + packageName,
Comment: "// The Go package name.",
Expand Down Expand Up @@ -190,7 +190,7 @@ func generateOpenAPIModel(version string) error {

packageImports := []string{
"fmt",
"gopkg.in/yaml.v3",
"go.yaml.in/yaml/v3",
"strings",
"regexp",
"github.com/google/gnostic/compiler",
Expand Down Expand Up @@ -238,8 +238,8 @@ Options:
}

func main() {
var openapiVersion = ""
var shouldGenerateExtensions = false
openapiVersion := ""
shouldGenerateExtensions := false

for i, arg := range os.Args {
if i == 0 {
Expand Down
29 changes: 18 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
module github.com/google/gnostic

go 1.12
go 1.24.6

require (
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815
github.com/flowstack/go-jsonschema v0.1.1
github.com/golang/protobuf v1.5.3
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49
github.com/google/go-cmp v0.5.9
github.com/stoewer/go-strcase v1.2.0
golang.org/x/tools v0.6.0
google.golang.org/genproto v0.0.0-20230526161137-0005af68ea54 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230525234035-dd9d682886f9
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19
google.golang.org/protobuf v1.30.0
gopkg.in/yaml.v3 v3.0.1
github.com/golang/protobuf v1.5.4
github.com/google/gnostic-models v0.7.0
github.com/google/go-cmp v0.6.0
github.com/stoewer/go-strcase v1.3.1
go.yaml.in/yaml/v3 v3.0.4
golang.org/x/tools v0.36.0
google.golang.org/genproto/googleapis/api v0.0.0-20250811160224-6b04f9b4fc78
google.golang.org/genproto/googleapis/rpc v0.0.0-20250811160224-6b04f9b4fc78
google.golang.org/protobuf v1.36.7
)

require (
github.com/buger/jsonparser v1.1.1 // indirect
golang.org/x/mod v0.27.0 // indirect
golang.org/x/net v0.43.0 // indirect
golang.org/x/sync v0.16.0 // indirect
golang.org/x/text v0.28.0 // indirect
)
Loading