Skip to content

Commit

Permalink
Fix module name and support goimports local prefix (#259)
Browse files Browse the repository at this point in the history
* go.mod: fix module and cleanup

Signed-off-by: Koichi Shiraishi <[email protected]>

* all: replace import path to 'github.com/google/gnostic'

Signed-off-by: Koichi Shiraishi <[email protected]>

* all: run goimports

$ goimports -w -local github.com/google/gnostic $(find . -type f -name '*.go' -not -iwholename '*vendor*' -not -name '*.pb.go')

Signed-off-by: Koichi Shiraishi <[email protected]>

* generate-gnostic: support goimports local prefix

Signed-off-by: Koichi Shiraishi <[email protected]>
  • Loading branch information
zchee authored Sep 30, 2021
1 parent 55aa1a4 commit c7a5e4f
Show file tree
Hide file tree
Showing 64 changed files with 184 additions and 142 deletions.
5 changes: 3 additions & 2 deletions apps/disco/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import (

"github.com/docopt/docopt-go"
"github.com/golang/protobuf/proto"
"github.com/googleapis/gnostic/conversions"
discovery "github.com/googleapis/gnostic/discovery"

"github.com/google/gnostic/conversions"
discovery "github.com/google/gnostic/discovery"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion apps/parse-linter-output/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"os"

lint "github.com/googleapis/gnostic/metrics/lint"
lint "github.com/google/gnostic/metrics/lint"
)

func main() {
Expand Down
4 changes: 2 additions & 2 deletions apps/petstore-builder/petstore-v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package main

import (
v2 "github.com/googleapis/gnostic/openapiv2"
v2 "github.com/google/gnostic/openapiv2"
)

func buildDocumentV2() *v2.Document {
Expand Down Expand Up @@ -252,7 +252,7 @@ func buildDocumentV2() *v2.Document {
&v2.NamedSchema{Name: "code", Value: &v2.Schema{
Type: &v2.TypeItem{Value: []string{"integer"}},
Format: "int32"}},
&v2.NamedSchema{Name: "message", Value: &v2.Schema{Type: &v2.TypeItem{Value:[]string{"string"}}}},
&v2.NamedSchema{Name: "message", Value: &v2.Schema{Type: &v2.TypeItem{Value: []string{"string"}}}},
},
},
}})
Expand Down
2 changes: 1 addition & 1 deletion apps/petstore-builder/petstore-v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package main

import (
v3 "github.com/googleapis/gnostic/openapiv3"
v3 "github.com/google/gnostic/openapiv3"
)

func buildDocumentV3() *v3.Document {
Expand Down
3 changes: 2 additions & 1 deletion apps/protoc-gen-openapi/generator/openapi-v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ import (
"sort"
"strings"

v3 "github.com/googleapis/gnostic/openapiv3"
"google.golang.org/genproto/googleapis/api/annotations"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"

v3 "github.com/google/gnostic/openapiv3"
)

const infoURL = "https://github.com/googleapis/gnostic/tree/master/apps/protoc-gen-openapi"
Expand Down
3 changes: 2 additions & 1 deletion apps/protoc-gen-openapi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
package main

import (
"github.com/googleapis/gnostic/apps/protoc-gen-openapi/generator"
"google.golang.org/protobuf/compiler/protogen"

"github.com/google/gnostic/apps/protoc-gen-openapi/generator"
)

func main() {
Expand Down
17 changes: 9 additions & 8 deletions apps/report-messages/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import (
"os"

"github.com/golang/protobuf/proto"
"github.com/googleapis/gnostic/printer"

plugins "github.com/googleapis/gnostic/plugins"
"github.com/google/gnostic/printer"

plugins "github.com/google/gnostic/plugins"
)

func readMessagesFromFileWithName(filename string) *plugins.Messages {
Expand All @@ -43,13 +44,13 @@ func readMessagesFromFileWithName(filename string) *plugins.Messages {

func printMessages(code *printer.Code, messages *plugins.Messages) {
for _, message := range messages.Messages {
line := fmt.Sprintf("%-7s %-14s %s %+v",
message.Level,
message.Code,
message.Text,
message.Keys)
line := fmt.Sprintf("%-7s %-14s %s %+v",
message.Level,
message.Code,
message.Text,
message.Keys)
code.Print(line)
}
}
}

func main() {
Expand Down
5 changes: 3 additions & 2 deletions apps/report/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import (
"os"

"github.com/golang/protobuf/proto"
"github.com/googleapis/gnostic/printer"

pb "github.com/googleapis/gnostic/openapiv2"
"github.com/google/gnostic/printer"

pb "github.com/google/gnostic/openapiv2"
)

func readDocumentFromFileWithName(filename string) (*pb.Document, error) {
Expand Down
5 changes: 3 additions & 2 deletions apps/vocabulary-operations/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import (
"strings"

"github.com/golang/protobuf/proto"
metrics "github.com/googleapis/gnostic/metrics"
vocabulary "github.com/googleapis/gnostic/metrics/vocabulary"

metrics "github.com/google/gnostic/metrics"
vocabulary "github.com/google/gnostic/metrics/vocabulary"
)

// openVocabularyFiles uses standard input to create a slice of
Expand Down
3 changes: 2 additions & 1 deletion compiler/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import (

"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes/any"
extensions "github.com/googleapis/gnostic/extensions"
yaml "gopkg.in/yaml.v3"

extensions "github.com/google/gnostic/extensions"
)

// ExtensionHandler describes a binary that is called by the compiler to handle specification extensions.
Expand Down
3 changes: 2 additions & 1 deletion compiler/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import (
"sort"
"strconv"

"github.com/googleapis/gnostic/jsonschema"
"gopkg.in/yaml.v3"

"github.com/google/gnostic/jsonschema"
)

// compiler helper functions, usually called from generated code
Expand Down
4 changes: 2 additions & 2 deletions conversions/openapiv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"log"
"net/url"

openapi2 "github.com/googleapis/gnostic/openapiv2"
discovery "github.com/googleapis/gnostic/discovery"
discovery "github.com/google/gnostic/discovery"
openapi2 "github.com/google/gnostic/openapiv2"
)

func addOpenAPI2SchemaForSchema(d *openapi2.Document, name string, schema *discovery.Schema) {
Expand Down
4 changes: 2 additions & 2 deletions conversions/openapiv3.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"net/url"
"strings"

openapi3 "github.com/googleapis/gnostic/openapiv3"
discovery "github.com/googleapis/gnostic/discovery"
discovery "github.com/google/gnostic/discovery"
openapi3 "github.com/google/gnostic/openapiv3"
)

func pathForMethod(path string) string {
Expand Down
6 changes: 4 additions & 2 deletions discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ package discovery_v1

import (
"fmt"
"github.com/googleapis/gnostic/compiler"
"gopkg.in/yaml.v3"
"regexp"
"strings"

"gopkg.in/yaml.v3"

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

// Version returns the package name (and OpenAPI version).
Expand Down
2 changes: 1 addition & 1 deletion discovery/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package discovery_v1

import (
"github.com/googleapis/gnostic/compiler"
"github.com/google/gnostic/compiler"
)

// FetchDocumentBytes downloads the bytes of a discovery document from a URL.
Expand Down
2 changes: 1 addition & 1 deletion discovery/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"errors"
"strings"

"github.com/googleapis/gnostic/compiler"
"github.com/google/gnostic/compiler"
)

// APIsListServiceURL is the URL for the Google APIs Discovery Service
Expand Down
2 changes: 1 addition & 1 deletion generate-gnostic/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"sort"
"strings"

"github.com/googleapis/gnostic/jsonschema"
"github.com/google/gnostic/jsonschema"
)

// Domain models a collection of types that is defined by a schema.
Expand Down
2 changes: 1 addition & 1 deletion generate-gnostic/generate-compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"sort"
"strings"

"github.com/googleapis/gnostic/printer"
"github.com/google/gnostic/printer"
)

// patternNames hands out unique names for a given string.
Expand Down
14 changes: 7 additions & 7 deletions generate-gnostic/generate-extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (
"sort"
"strings"

"github.com/googleapis/gnostic/compiler"
"github.com/googleapis/gnostic/jsonschema"
"github.com/googleapis/gnostic/printer"
"github.com/google/gnostic/compiler"
"github.com/google/gnostic/jsonschema"
"github.com/google/gnostic/printer"
)

var protoOptionsForExtensions = []ProtoOption{
Expand Down Expand Up @@ -272,7 +272,7 @@ func generateExtension(schemaFile string, outDir string) error {
"fmt",
"regexp",
"strings",
"github.com/googleapis/gnostic/compiler",
"github.com/google/gnostic/compiler",
"gopkg.in/yaml.v3",
})
goFilename := path.Join(protoOutDirectory, outFileBaseName+".go")
Expand All @@ -287,7 +287,7 @@ func generateExtension(schemaFile string, outDir string) error {
// TODO: This path is currently fixed to the location of the samples.
// Can we make it relative, perhaps with an option or by generating
// a go.mod file for the generated extension handler?
outDirRelativeToPackageRoot := "github.com/googleapis/gnostic/extensions/sample/" + outDir
outDirRelativeToPackageRoot := "github.com/google/gnostic/extensions/sample/" + outDir

var extensionNameKeys []string
for k := range extensionNameToMessageName {
Expand Down Expand Up @@ -315,8 +315,8 @@ func generateExtension(schemaFile string, outDir string) error {
extMainCode := fmt.Sprintf(additionalCompilerCodeWithMain, cases)
imports := []string{
"github.com/golang/protobuf/proto",
"github.com/googleapis/gnostic/extensions",
"github.com/googleapis/gnostic/compiler",
"github.com/google/gnostic/extensions",
"github.com/google/gnostic/compiler",
"gopkg.in/yaml.v3",
outDirRelativeToPackageRoot + "/" + "proto",
}
Expand Down
2 changes: 1 addition & 1 deletion generate-gnostic/generate-proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"fmt"
"strings"

"github.com/googleapis/gnostic/printer"
"github.com/google/gnostic/printer"
)

// ProtoOption represents an option to be added to generated .proto files.
Expand Down
24 changes: 16 additions & 8 deletions generate-gnostic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import (
"io/ioutil"
"log"
"os"
"os/exec"
"path"
"runtime"
"strings"

"github.com/googleapis/gnostic/jsonschema"
"golang.org/x/tools/imports"

"github.com/google/gnostic/jsonschema"
)

// License is the software license applied to generated code.
Expand Down Expand Up @@ -193,19 +193,27 @@ func generateOpenAPIModel(version string) error {
"gopkg.in/yaml.v3",
"strings",
"regexp",
"github.com/googleapis/gnostic/compiler",
"github.com/google/gnostic/compiler",
}
// generate the compiler
log.Printf("Generating compiler support code")
compiler := cc.GenerateCompiler(goPackageName, License, packageImports)
goFileName := projectRoot + directoryName + "/" + filename + ".go"
err = ioutil.WriteFile(goFileName, []byte(compiler), 0644)

// format the compiler
log.Printf("Formatting compiler support code")
imports.LocalPrefix = "github.com/google/gnostic"
data, err := imports.Process(goFileName, []byte(compiler), &imports.Options{
TabWidth: 8,
TabIndent: true,
Comments: true,
Fragment: true,
})
if err != nil {
return err
}
// format the compiler
log.Printf("Formatting compiler support code")
return exec.Command(runtime.GOROOT()+"/bin/gofmt", "-w", goFileName).Run()

return ioutil.WriteFile(goFileName, []byte(data), 0644)
}

func usage() string {
Expand Down
2 changes: 1 addition & 1 deletion generate-gnostic/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"fmt"
"strings"

"github.com/googleapis/gnostic/jsonschema"
"github.com/google/gnostic/jsonschema"
)

/// Type Modeling
Expand Down
2 changes: 1 addition & 1 deletion gnostic.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
"fmt"
"os"

"github.com/googleapis/gnostic/lib"
"github.com/google/gnostic/lib"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion gnostic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"strings"
"testing"

"github.com/googleapis/gnostic/lib"
"github.com/google/gnostic/lib"
)

func isURL(path string) bool {
Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
module github.com/googleapis/gnostic
module github.com/google/gnostic

go 1.12

require (
github.com/davecgh/go-spew v1.1.1
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815
github.com/golang/protobuf v1.5.2
github.com/kr/pretty v0.2.0 // indirect
github.com/stoewer/go-strcase v1.2.0
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/genproto v0.0.0-20201019141844-1ed22bb0c154
google.golang.org/protobuf v1.26.0
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15
Expand Down
6 changes: 3 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.1 h1:jAbXjIeW2ZSW2AwFxlGTDoc2CjI2XujLkV3ArsZFCvc=
github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
Expand Down Expand Up @@ -62,9 +60,11 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135 h1:5Beo0mZN8dRzgrMMkDp0jc8YXQKx9DiJ2k1dkvGsn5A=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
Expand Down
Loading

0 comments on commit c7a5e4f

Please sign in to comment.