Skip to content

Commit

Permalink
Merge pull request #11 from eclipse/feat/configurable_reqname
Browse files Browse the repository at this point in the history
feat: configurable request type name suffix.
  • Loading branch information
veith committed Sep 14, 2021
2 parents bc1d86c + e47d05b commit dbabdbd
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 17 deletions.
29 changes: 27 additions & 2 deletions docs/furo/content/docs/commands/furo_muSpec2Spec.md
Expand Up @@ -10,12 +10,37 @@ Updates or creates the specs with the definitions from the µSpecs.
Renaming and restructuring your spec folder is ok, furo will always update the correct file. Also a reordering of the fields in your spec,
to get nicer protos of for other reasons, is also ok. Furo works with a internal AST and is not interested in order or file names.

> if you have set the config option `muSpec.forceSync: true` in your furo config,
> the command will always enable the `-d` option.

{{< hint warning >}}
**Attention:**
if you have set the config option `muSpec.forceSync: true` in your furo config,
the command will always enable the `-d` option.
{{< /hint >}}


Because the specs have a higher information density then the µSpecs, furo will fill in calculated default
values on the first time it creates a spec file. Later calls of this command will not touch the prefilled fields of the spec.

### Config

```yaml
muSpec:
types: # define a set of globs which matches your type definitions
- "./muspecs/**/*types.yaml"
- "./muspecs/*types.yaml"
services: # define a set of globs which matches your service definitions
- "./muspecs/**/*services.yaml"
- "./muspecs/*services.yaml"
goPackageBase: "github.com/yourname/sample-specs/dist/pb/" # this is used to prefix the go package option
javaPackagePrefix: "com.example.tutorial."
dir: "muspecs" # the folder where you save the µSpecs
forceSync: true # This will delete specs which are deleted in muSpec, this is very useful during prototyping
requestTypeSuffix: "Request" # Suffix for the generated request type specs

```



### Options

```
Expand Down
1 change: 1 addition & 0 deletions docs/furo/content/docs/configuration.md
Expand Up @@ -34,6 +34,7 @@ muSpec:
javaPackagePrefix: "com.example.tutorial."
dir: "muspecs" # the folder where you save the µSpecs
forceSync: true # This will delete specs which are deleted in muSpec, this is very useful during prototyping
requestTypeSuffix: "Request" # Suffix for the generated request type specs
commands: #camelCase is not allowed, command scripts can only be executed from a flow
gen_transcoder: "./scripts/gprcgateway/generate.sh" # shell script to generate a half grpc gateway
buf_generate: "./scripts/buf_generate.sh"
Expand Down
2 changes: 1 addition & 1 deletion furo/cmd/root.go
Expand Up @@ -50,7 +50,7 @@ Modify your default flow in the .furo config file to your needs. You can set any
Run: func(cmd *cobra.Command, args []string) {
runner.Run(cmd, args)
},
Version: "1.28.6",
Version: "1.29.0",
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand Down
4 changes: 2 additions & 2 deletions furo/flow_test.go
Expand Up @@ -18,11 +18,11 @@ func TestRunCommand(t *testing.T) {
rco.Execute()

require.Equal(t, true, test.FileExist(path.Join(dir, ".furo")))
require.Equal(t, "f4ba32ae7424570c4b7520432ce89e94", test.MustMd5Sum(path.Join(dir, ".furo")))
require.Equal(t, "d8a9dbdca98179d9a7d3ebbdcb2c3fa8", test.MustMd5Sum(path.Join(dir, ".furo")))

err := test.CopyTestFile("test/testdata/.furo", path.Join(dir, ".furo"))
require.NoError(t, err, "Must Copy .furo file")
require.Equal(t, "e7b51c770c547d672201af43e001a61f", test.MustMd5Sum(path.Join(dir, ".furo")))
require.Equal(t, "8493075c067f312d3ffd760363e3e0f6", test.MustMd5Sum(path.Join(dir, ".furo")))

os.Args = []string{"cmd", "install"}
rco.Execute()
Expand Down
2 changes: 1 addition & 1 deletion furo/init_test.go
Expand Up @@ -18,6 +18,6 @@ func TestInitCommand(t *testing.T) {
rco.Execute()

require.Equal(t, true, test.FileExist(path.Join(dir, ".furo")))
require.Equal(t, "f4ba32ae7424570c4b7520432ce89e94", test.MustMd5Sum(path.Join(dir, ".furo")))
require.Equal(t, "d8a9dbdca98179d9a7d3ebbdcb2c3fa8", test.MustMd5Sum(path.Join(dir, ".furo")))

}
2 changes: 1 addition & 1 deletion furo/installer_test.go
Expand Up @@ -18,7 +18,7 @@ func TestInstallCommand(t *testing.T) {
rco.Execute()

require.Equal(t, true, test.FileExist(path.Join(dir, ".furo")))
require.Equal(t, "f4ba32ae7424570c4b7520432ce89e94", test.MustMd5Sum(path.Join(dir, ".furo")))
require.Equal(t, "d8a9dbdca98179d9a7d3ebbdcb2c3fa8", test.MustMd5Sum(path.Join(dir, ".furo")))

os.Args = []string{"cmd", "install"}
rco.Execute()
Expand Down
Expand Up @@ -107,7 +107,7 @@ func Run(cmd *cobra.Command, args []string) {
r, found := s.Services.Get("Update")
if found {
rpc := r.(*specSpec.Rpc)
reqType := protoTplDataServicelist[filepath].Package + "." + rpc.RpcName + "FuroGrpcRqst"
reqType := protoTplDataServicelist[filepath].Package + "." + rpc.RpcName + viper.GetString("muSpec.requestTypeSuffix")
// Services.sampleservice.UpdateSampleRequest
_, ok := Typelist.AllAvailabeTypes[reqType].TypeSpec.Fields.Get("update_mask")
if ok {
Expand Down
2 changes: 1 addition & 1 deletion furo/internal/cmd/genServiceProtos/genServiceProtos.go
Expand Up @@ -94,7 +94,7 @@ func Run(cmd *cobra.Command, args []string) {
r, found := s.Services.Get("Update")
if found {
rpc := r.(*specSpec.Rpc)
reqType := protoTplData[filepath].Package + "." + rpc.RpcName + "FuroGrpcRqst"
reqType := protoTplData[filepath].Package + "." + rpc.RpcName + viper.GetString("muSpec.requestTypeSuffix")
// Services.sampleservice.UpdateSampleRequest
_, ok := Typelist.AllAvailabeTypes[reqType].TypeSpec.Fields.Get("update_mask")
if ok {
Expand Down
3 changes: 2 additions & 1 deletion furo/internal/cmd/spec2muSpec/associator.go
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/eclipse/eclipsefuro/furo/pkg/microservices"
"github.com/eclipse/eclipsefuro/furo/pkg/microtypes"
"github.com/eclipse/eclipsefuro/furo/pkg/specSpec"
"github.com/spf13/viper"
"strings"
)

Expand Down Expand Up @@ -37,7 +38,7 @@ func NewUTShadowList() UTShadowList {

func (s *UTShadowList) AddTypeNode(fullTypeName string, ast *typeAst.TypeAst) *UTshadowNode {

if strings.HasSuffix(fullTypeName, "FuroGrpcRqst") {
if strings.HasSuffix(fullTypeName, viper.GetString("muSpec.requestTypeSuffix")) {
return s.AddRequestTypeNode(ast)
}

Expand Down
2 changes: 1 addition & 1 deletion furo/internal/cmd/spec2muSpec/serviceupdater.go
Expand Up @@ -124,7 +124,7 @@ func updateAndStoreMicroServices(serviceItems map[string]*UTshadowNode) {
func findRequestType(rpcName string, node *UTshadowNode) *typeAst.TypeAst {
// node is in node.edgeRequestTypeNode array
for _, n := range node.edgeRequestTypeNode {
if n.TypeSpec.Name == rpcName+"FuroGrpcRqst" {
if n.TypeSpec.Name == rpcName+viper.GetString("muSpec.requestTypeSuffix") {
return n
}
}
Expand Down
2 changes: 1 addition & 1 deletion furo/pkg/microservices/microservices.go
Expand Up @@ -179,7 +179,7 @@ func (l *MicroServiceList) UpateServicelist(servicelist *serviceAst.Servicelist,
// maybe this is incorrect, if someone needs streams with query params
if !strings.HasPrefix(targetRPC.Data.Request, "stream ") {
requestType := &microtypes.MicroType{
Type: microServiceAst.Package + "." + targetRPC.RpcName + "FuroGrpcRqst #request message for " + targetRPC.RpcName,
Type: microServiceAst.Package + "." + targetRPC.RpcName + viper.GetString("muSpec.requestTypeSuffix") + " #request message for " + targetRPC.RpcName,
Fields: fields,
Target: "reqmsgs.proto",
}
Expand Down
3 changes: 2 additions & 1 deletion furo/pkg/protoTemplates/sprig.go
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/Masterminds/sprig"
"github.com/eclipse/eclipsefuro/furo/pkg/orderedmap"
"github.com/eclipse/eclipsefuro/furo/pkg/specSpec"
"github.com/spf13/viper"
"html/template"
"regexp"
"strings"
Expand Down Expand Up @@ -114,7 +115,7 @@ func rpcRequest(method *specSpec.Rpc) string {
if strings.HasPrefix(method.Data.Request, "stream ") {
return method.Data.Request
}
return method.RpcName + "FuroGrpcRqst"
return method.RpcName + viper.GetString("muSpec.requestTypeSuffix")
}

func isNotStream(method *specSpec.Rpc) bool {
Expand Down

0 comments on commit dbabdbd

Please sign in to comment.