Skip to content

Commit c7a5e4f

Browse files
authored
Fix module name and support goimports local prefix (#259)
* 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]>
1 parent 55aa1a4 commit c7a5e4f

File tree

64 files changed

+184
-142
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+184
-142
lines changed

apps/disco/main.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ import (
2323

2424
"github.com/docopt/docopt-go"
2525
"github.com/golang/protobuf/proto"
26-
"github.com/googleapis/gnostic/conversions"
27-
discovery "github.com/googleapis/gnostic/discovery"
26+
27+
"github.com/google/gnostic/conversions"
28+
discovery "github.com/google/gnostic/discovery"
2829
)
2930

3031
func main() {

apps/parse-linter-output/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"fmt"
66
"os"
77

8-
lint "github.com/googleapis/gnostic/metrics/lint"
8+
lint "github.com/google/gnostic/metrics/lint"
99
)
1010

1111
func main() {

apps/petstore-builder/petstore-v2.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
package main
1616

1717
import (
18-
v2 "github.com/googleapis/gnostic/openapiv2"
18+
v2 "github.com/google/gnostic/openapiv2"
1919
)
2020

2121
func buildDocumentV2() *v2.Document {
@@ -252,7 +252,7 @@ func buildDocumentV2() *v2.Document {
252252
&v2.NamedSchema{Name: "code", Value: &v2.Schema{
253253
Type: &v2.TypeItem{Value: []string{"integer"}},
254254
Format: "int32"}},
255-
&v2.NamedSchema{Name: "message", Value: &v2.Schema{Type: &v2.TypeItem{Value:[]string{"string"}}}},
255+
&v2.NamedSchema{Name: "message", Value: &v2.Schema{Type: &v2.TypeItem{Value: []string{"string"}}}},
256256
},
257257
},
258258
}})

apps/petstore-builder/petstore-v3.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
package main
1616

1717
import (
18-
v3 "github.com/googleapis/gnostic/openapiv3"
18+
v3 "github.com/google/gnostic/openapiv3"
1919
)
2020

2121
func buildDocumentV3() *v3.Document {

apps/protoc-gen-openapi/generator/openapi-v3.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ import (
2222
"sort"
2323
"strings"
2424

25-
v3 "github.com/googleapis/gnostic/openapiv3"
2625
"google.golang.org/genproto/googleapis/api/annotations"
2726
"google.golang.org/protobuf/compiler/protogen"
2827
"google.golang.org/protobuf/proto"
2928
"google.golang.org/protobuf/reflect/protoreflect"
29+
30+
v3 "github.com/google/gnostic/openapiv3"
3031
)
3132

3233
const infoURL = "https://github.com/googleapis/gnostic/tree/master/apps/protoc-gen-openapi"

apps/protoc-gen-openapi/main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
package main
1717

1818
import (
19-
"github.com/googleapis/gnostic/apps/protoc-gen-openapi/generator"
2019
"google.golang.org/protobuf/compiler/protogen"
20+
21+
"github.com/google/gnostic/apps/protoc-gen-openapi/generator"
2122
)
2223

2324
func main() {

apps/report-messages/main.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ import (
2222
"os"
2323

2424
"github.com/golang/protobuf/proto"
25-
"github.com/googleapis/gnostic/printer"
2625

27-
plugins "github.com/googleapis/gnostic/plugins"
26+
"github.com/google/gnostic/printer"
27+
28+
plugins "github.com/google/gnostic/plugins"
2829
)
2930

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

4445
func printMessages(code *printer.Code, messages *plugins.Messages) {
4546
for _, message := range messages.Messages {
46-
line := fmt.Sprintf("%-7s %-14s %s %+v",
47-
message.Level,
48-
message.Code,
49-
message.Text,
50-
message.Keys)
47+
line := fmt.Sprintf("%-7s %-14s %s %+v",
48+
message.Level,
49+
message.Code,
50+
message.Text,
51+
message.Keys)
5152
code.Print(line)
52-
}
53+
}
5354
}
5455

5556
func main() {

apps/report/main.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ import (
2424
"os"
2525

2626
"github.com/golang/protobuf/proto"
27-
"github.com/googleapis/gnostic/printer"
2827

29-
pb "github.com/googleapis/gnostic/openapiv2"
28+
"github.com/google/gnostic/printer"
29+
30+
pb "github.com/google/gnostic/openapiv2"
3031
)
3132

3233
func readDocumentFromFileWithName(filename string) (*pb.Document, error) {

apps/vocabulary-operations/main.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ import (
2323
"strings"
2424

2525
"github.com/golang/protobuf/proto"
26-
metrics "github.com/googleapis/gnostic/metrics"
27-
vocabulary "github.com/googleapis/gnostic/metrics/vocabulary"
26+
27+
metrics "github.com/google/gnostic/metrics"
28+
vocabulary "github.com/google/gnostic/metrics/vocabulary"
2829
)
2930

3031
// openVocabularyFiles uses standard input to create a slice of

compiler/extensions.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ import (
2222

2323
"github.com/golang/protobuf/proto"
2424
"github.com/golang/protobuf/ptypes/any"
25-
extensions "github.com/googleapis/gnostic/extensions"
2625
yaml "gopkg.in/yaml.v3"
26+
27+
extensions "github.com/google/gnostic/extensions"
2728
)
2829

2930
// ExtensionHandler describes a binary that is called by the compiler to handle specification extensions.

compiler/helpers.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ import (
2020
"sort"
2121
"strconv"
2222

23-
"github.com/googleapis/gnostic/jsonschema"
2423
"gopkg.in/yaml.v3"
24+
25+
"github.com/google/gnostic/jsonschema"
2526
)
2627

2728
// compiler helper functions, usually called from generated code

conversions/openapiv2.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import (
1818
"log"
1919
"net/url"
2020

21-
openapi2 "github.com/googleapis/gnostic/openapiv2"
22-
discovery "github.com/googleapis/gnostic/discovery"
21+
discovery "github.com/google/gnostic/discovery"
22+
openapi2 "github.com/google/gnostic/openapiv2"
2323
)
2424

2525
func addOpenAPI2SchemaForSchema(d *openapi2.Document, name string, schema *discovery.Schema) {

conversions/openapiv3.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import (
1919
"net/url"
2020
"strings"
2121

22-
openapi3 "github.com/googleapis/gnostic/openapiv3"
23-
discovery "github.com/googleapis/gnostic/discovery"
22+
discovery "github.com/google/gnostic/discovery"
23+
openapi3 "github.com/google/gnostic/openapiv3"
2424
)
2525

2626
func pathForMethod(path string) string {

discovery/discovery.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ package discovery_v1
1818

1919
import (
2020
"fmt"
21-
"github.com/googleapis/gnostic/compiler"
22-
"gopkg.in/yaml.v3"
2321
"regexp"
2422
"strings"
23+
24+
"gopkg.in/yaml.v3"
25+
26+
"github.com/google/gnostic/compiler"
2527
)
2628

2729
// Version returns the package name (and OpenAPI version).

discovery/document.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
package discovery_v1
1616

1717
import (
18-
"github.com/googleapis/gnostic/compiler"
18+
"github.com/google/gnostic/compiler"
1919
)
2020

2121
// FetchDocumentBytes downloads the bytes of a discovery document from a URL.

discovery/list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"errors"
2020
"strings"
2121

22-
"github.com/googleapis/gnostic/compiler"
22+
"github.com/google/gnostic/compiler"
2323
)
2424

2525
// APIsListServiceURL is the URL for the Google APIs Discovery Service

generate-gnostic/domain.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"sort"
2222
"strings"
2323

24-
"github.com/googleapis/gnostic/jsonschema"
24+
"github.com/google/gnostic/jsonschema"
2525
)
2626

2727
// Domain models a collection of types that is defined by a schema.

generate-gnostic/generate-compiler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"sort"
2121
"strings"
2222

23-
"github.com/googleapis/gnostic/printer"
23+
"github.com/google/gnostic/printer"
2424
)
2525

2626
// patternNames hands out unique names for a given string.

generate-gnostic/generate-extension.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ import (
2626
"sort"
2727
"strings"
2828

29-
"github.com/googleapis/gnostic/compiler"
30-
"github.com/googleapis/gnostic/jsonschema"
31-
"github.com/googleapis/gnostic/printer"
29+
"github.com/google/gnostic/compiler"
30+
"github.com/google/gnostic/jsonschema"
31+
"github.com/google/gnostic/printer"
3232
)
3333

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

292292
var extensionNameKeys []string
293293
for k := range extensionNameToMessageName {
@@ -315,8 +315,8 @@ func generateExtension(schemaFile string, outDir string) error {
315315
extMainCode := fmt.Sprintf(additionalCompilerCodeWithMain, cases)
316316
imports := []string{
317317
"github.com/golang/protobuf/proto",
318-
"github.com/googleapis/gnostic/extensions",
319-
"github.com/googleapis/gnostic/compiler",
318+
"github.com/google/gnostic/extensions",
319+
"github.com/google/gnostic/compiler",
320320
"gopkg.in/yaml.v3",
321321
outDirRelativeToPackageRoot + "/" + "proto",
322322
}

generate-gnostic/generate-proto.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"fmt"
1919
"strings"
2020

21-
"github.com/googleapis/gnostic/printer"
21+
"github.com/google/gnostic/printer"
2222
)
2323

2424
// ProtoOption represents an option to be added to generated .proto files.

generate-gnostic/main.go

+16-8
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ import (
2323
"io/ioutil"
2424
"log"
2525
"os"
26-
"os/exec"
2726
"path"
28-
"runtime"
2927
"strings"
3028

31-
"github.com/googleapis/gnostic/jsonschema"
29+
"golang.org/x/tools/imports"
30+
31+
"github.com/google/gnostic/jsonschema"
3232
)
3333

3434
// License is the software license applied to generated code.
@@ -193,19 +193,27 @@ func generateOpenAPIModel(version string) error {
193193
"gopkg.in/yaml.v3",
194194
"strings",
195195
"regexp",
196-
"github.com/googleapis/gnostic/compiler",
196+
"github.com/google/gnostic/compiler",
197197
}
198198
// generate the compiler
199199
log.Printf("Generating compiler support code")
200200
compiler := cc.GenerateCompiler(goPackageName, License, packageImports)
201201
goFileName := projectRoot + directoryName + "/" + filename + ".go"
202-
err = ioutil.WriteFile(goFileName, []byte(compiler), 0644)
202+
203+
// format the compiler
204+
log.Printf("Formatting compiler support code")
205+
imports.LocalPrefix = "github.com/google/gnostic"
206+
data, err := imports.Process(goFileName, []byte(compiler), &imports.Options{
207+
TabWidth: 8,
208+
TabIndent: true,
209+
Comments: true,
210+
Fragment: true,
211+
})
203212
if err != nil {
204213
return err
205214
}
206-
// format the compiler
207-
log.Printf("Formatting compiler support code")
208-
return exec.Command(runtime.GOROOT()+"/bin/gofmt", "-w", goFileName).Run()
215+
216+
return ioutil.WriteFile(goFileName, []byte(data), 0644)
209217
}
210218

211219
func usage() string {

generate-gnostic/types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"fmt"
1919
"strings"
2020

21-
"github.com/googleapis/gnostic/jsonschema"
21+
"github.com/google/gnostic/jsonschema"
2222
)
2323

2424
/// Type Modeling

gnostic.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
"fmt"
3636
"os"
3737

38-
"github.com/googleapis/gnostic/lib"
38+
"github.com/google/gnostic/lib"
3939
)
4040

4141
func main() {

gnostic_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"strings"
2323
"testing"
2424

25-
"github.com/googleapis/gnostic/lib"
25+
"github.com/google/gnostic/lib"
2626
)
2727

2828
func isURL(path string) bool {

go.mod

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
module github.com/googleapis/gnostic
1+
module github.com/google/gnostic
22

33
go 1.12
44

55
require (
6-
github.com/davecgh/go-spew v1.1.1
6+
github.com/davecgh/go-spew v1.1.1 // indirect
77
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815
88
github.com/golang/protobuf v1.5.2
99
github.com/kr/pretty v0.2.0 // indirect
1010
github.com/stoewer/go-strcase v1.2.0
11+
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135
12+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
1113
google.golang.org/genproto v0.0.0-20201019141844-1ed22bb0c154
1214
google.golang.org/protobuf v1.26.0
1315
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15

go.sum

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W
2020
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
2121
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
2222
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
23-
github.com/golang/protobuf v1.5.1 h1:jAbXjIeW2ZSW2AwFxlGTDoc2CjI2XujLkV3ArsZFCvc=
24-
github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM=
2523
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
2624
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
2725
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
@@ -62,9 +60,11 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
6260
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
6361
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
6462
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
63+
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135 h1:5Beo0mZN8dRzgrMMkDp0jc8YXQKx9DiJ2k1dkvGsn5A=
6564
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
66-
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
6765
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
66+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
67+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
6868
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
6969
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
7070
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=

0 commit comments

Comments
 (0)