Skip to content

Commit

Permalink
Remove unnecessary prefixes from imports in generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
Mickey Reiss committed Mar 24, 2020
1 parent f3be79f commit 96bbca4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
12 changes: 12 additions & 0 deletions langs/go/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ const (
fileExtension = ".firemodel.go"
)

var (
importNames = map[string]string{
"github.com/visor-tax/firemodel/runtime": "runtime",
"google.golang.org/genproto/googleapis/type/latlng": "latlng",
"cloud.google.com/go/firestore": "firestore",
}
)

type GoModeler struct {
pkg string
clientNames []*ClientName
Expand Down Expand Up @@ -58,6 +66,7 @@ func (m *GoModeler) Model(schema *firemodel.Schema, sourceCoder firemodel.Source

func (m *GoModeler) writeManifest(sourceCoder firemodel.SourceCoder) error {
f := jen.NewFile(m.packageName())
f.ImportNames(importNames)
f.HeaderComment(fmt.Sprintf("DO NOT EDIT - Code generated by firemodel %s.", version.Version))

f.Type().Id("Client").StructFunc(func(g *jen.Group) {
Expand Down Expand Up @@ -94,6 +103,7 @@ func (m *GoModeler) writeManifest(sourceCoder firemodel.SourceCoder) error {

func (m *GoModeler) writeModel(model *firemodel.SchemaModel, sourceCoder firemodel.SourceCoder) error {
f := jen.NewFile(m.packageName())
f.ImportNames(importNames)
f.HeaderComment(fmt.Sprintf("DO NOT EDIT - Code generated by firemodel %s.", version.Version))

if model.Comment != "" {
Expand Down Expand Up @@ -344,6 +354,7 @@ func (m *GoModeler) writeModel(model *firemodel.SchemaModel, sourceCoder firemod
func (m *GoModeler) writeEnum(enum *firemodel.SchemaEnum, sourceCoder firemodel.SourceCoder) error {
enumName := strcase.ToCamel(enum.Name)
f := jen.NewFile(m.packageName())
f.ImportNames(importNames)
f.HeaderComment(fmt.Sprintf("DO NOT EDIT - Code generated by firemodel %s.", version.Version))

if enum.Comment != "" {
Expand Down Expand Up @@ -393,6 +404,7 @@ func (m *GoModeler) writeEnum(enum *firemodel.SchemaEnum, sourceCoder firemodel.
func (m *GoModeler) writeStruct(structType *firemodel.SchemaStruct, sourceCoder firemodel.SourceCoder) error {
structName := strcase.ToCamel(structType.Name)
f := jen.NewFile(m.packageName())
f.ImportNames(importNames)
f.HeaderComment(fmt.Sprintf("DO NOT EDIT - Code generated by firemodel %s.", version.Version))

if structType.Comment != "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package firemodel

import firestore "cloud.google.com/go/firestore"
import "cloud.google.com/go/firestore"

type Client struct {
Client *firestore.Client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
package firemodel

import (
firestore "cloud.google.com/go/firestore"
"cloud.google.com/go/firestore"
"context"
"errors"
"fmt"
runtime "github.com/visor-tax/firemodel/runtime"
latlng "google.golang.org/genproto/googleapis/type/latlng"
"github.com/visor-tax/firemodel/runtime"
"google.golang.org/genproto/googleapis/type/latlng"
"regexp"
"time"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package firemodel

import (
firestore "cloud.google.com/go/firestore"
"cloud.google.com/go/firestore"
"context"
"errors"
"fmt"
Expand Down

0 comments on commit 96bbca4

Please sign in to comment.