diff --git a/_examples/golang-basics/example.gen.go b/_examples/golang-basics/example.gen.go index 9154787..6350703 100644 --- a/_examples/golang-basics/example.gen.go +++ b/_examples/golang-basics/example.gen.go @@ -1,4 +1,4 @@ -// example golang-basics@v0.0.1 bd2f9fc6bee7f200ba8b56fe1f287193bc5208de +// example v0.0.1 69fb8a2ad786d98bfaab0b4997bff9619f8fa9a8 // -- // Code generated by webrpc-gen@v0.19.3 with ../../../gen-golang generator. DO NOT EDIT. // @@ -28,49 +28,55 @@ func WebRPCVersion() string { // Schema version of your RIDL schema func WebRPCSchemaVersion() string { - return "golang-basics@v0.0.1" + return "v0.0.1" } // Schema hash generated from your RIDL schema func WebRPCSchemaHash() string { - return "bd2f9fc6bee7f200ba8b56fe1f287193bc5208de" + return "69fb8a2ad786d98bfaab0b4997bff9619f8fa9a8" } type WebRPCGenVersions struct { WebRPCGenVersion string TmplTarget string TmplVersion string + SchemaName string SchemaVersion string } // WebRPCHeader // TmplVersion might be empty when generated from local template folder func WebRPCHeader() string { - return "webrpc@v0.19.3;gen-golang@unknown;golang-basics@v0.0.1" + return "webrpc@v0.19.3;gen-golang@unknown;example@v0.0.1" } func ParseWebRPCGenVersions(header string) (*WebRPCGenVersions, error) { versions := strings.Split(header, ";") - - if len(versions) != 3 { - return nil, fmt.Errorf("expected 3 parts while parsing webrpc header: %s", header) + if len(versions) < 3 { + return nil, fmt.Errorf("expected at least 3 parts while parsing webrpc header: %s", header) } _, webrpcGenVersion, ok := strings.Cut(versions[0], "@") if !ok { - return nil, fmt.Errorf("webrpc gen version could not be parsed from: %s", header) + return nil, fmt.Errorf("webrpc gen version could not be parsed from: %s", versions[0]) } tmplTarget, tmplVersion, ok := strings.Cut(versions[1], "@") if !ok { - return nil, fmt.Errorf("tmplTarget and tmplVersion could not be parsed from: %s", header) + return nil, fmt.Errorf("tmplTarget and tmplVersion could not be parsed from: %s", versions[1]) + } + + schemaName, schemaVersion, ok := strings.Cut(versions[2], "@") + if !ok { + return nil, fmt.Errorf("schema name and schema version could not be parsed from: %s", versions[2]) } return &WebRPCGenVersions{ WebRPCGenVersion: webrpcGenVersion, TmplTarget: tmplTarget, TmplVersion: tmplVersion, - SchemaVersion: versions[2], + SchemaName: schemaName, + SchemaVersion: schemaVersion, }, nil } diff --git a/_examples/golang-basics/example.ridl b/_examples/golang-basics/example.ridl index c5ce2ea..56e7d2b 100644 --- a/_examples/golang-basics/example.ridl +++ b/_examples/golang-basics/example.ridl @@ -1,7 +1,7 @@ webrpc = v1 # version of webrpc schema format (ridl or json) name = example # name of your backend app -version = golang-basics@v0.0.1 # version of your schema +version = v0.0.1 # version of your schema # user role # which defines which type of operations user can do diff --git a/_examples/golang-imports/api.gen.go b/_examples/golang-imports/api.gen.go index d7c35c4..7567a23 100644 --- a/_examples/golang-imports/api.gen.go +++ b/_examples/golang-imports/api.gen.go @@ -37,37 +37,43 @@ type WebRPCGenVersions struct { WebRPCGenVersion string TmplTarget string TmplVersion string + SchemaName string SchemaVersion string } // WebRPCHeader // TmplVersion might be empty when generated from local template folder func WebRPCHeader() string { - return "webrpc@v0.19.3;gen-golang@unknown;v1.0.0" + return "webrpc@v0.19.3;gen-golang@unknown;example-api-service@v1.0.0" } func ParseWebRPCGenVersions(header string) (*WebRPCGenVersions, error) { versions := strings.Split(header, ";") - - if len(versions) != 3 { - return nil, fmt.Errorf("expected 3 parts while parsing webrpc header: %s", header) + if len(versions) < 3 { + return nil, fmt.Errorf("expected at least 3 parts while parsing webrpc header: %s", header) } _, webrpcGenVersion, ok := strings.Cut(versions[0], "@") if !ok { - return nil, fmt.Errorf("webrpc gen version could not be parsed from: %s", header) + return nil, fmt.Errorf("webrpc gen version could not be parsed from: %s", versions[0]) } tmplTarget, tmplVersion, ok := strings.Cut(versions[1], "@") if !ok { - return nil, fmt.Errorf("tmplTarget and tmplVersion could not be parsed from: %s", header) + return nil, fmt.Errorf("tmplTarget and tmplVersion could not be parsed from: %s", versions[1]) } + schemaName, schemaVersion, ok := strings.Cut(versions[2], "@") + if !ok { + return nil, fmt.Errorf("schema name and schema version could not be parsed from: %s", versions[2]) + } + return &WebRPCGenVersions{ WebRPCGenVersion: webrpcGenVersion, TmplTarget: tmplTarget, TmplVersion: tmplVersion, - SchemaVersion: versions[2], + SchemaName: schemaName, + SchemaVersion: schemaVersion, }, nil } diff --git a/main.go.tmpl b/main.go.tmpl index 97cb137..e235391 100644 --- a/main.go.tmpl +++ b/main.go.tmpl @@ -100,37 +100,43 @@ type WebRPCGenVersions struct { WebRPCGenVersion string TmplTarget string TmplVersion string + SchemaName string SchemaVersion string } // WebRPCHeader // TmplVersion might be empty when generated from local template folder func WebRPCHeader() string { - return "webrpc@{{.WebrpcGenVersion}};{{.TmplTarget}}@{{ if eq .TmplVersion "" }}unknown{{ else }}{{.TmplVersion}}{{end}};{{.SchemaVersion}}" + return "webrpc@{{.WebrpcGenVersion}};{{.TmplTarget}}@{{ if eq .TmplVersion "" }}unknown{{ else }}{{.TmplVersion}}{{end}};{{.SchemaName}}@{{.SchemaVersion}}" } func ParseWebRPCGenVersions(header string) (*WebRPCGenVersions, error) { versions := strings.Split(header, ";") - if len(versions) < 3 { return nil, fmt.Errorf("expected at least 3 parts while parsing webrpc header: %s", header) } _, webrpcGenVersion, ok := strings.Cut(versions[0], "@") if !ok { - return nil, fmt.Errorf("webrpc gen version could not be parsed from: %s", header) + return nil, fmt.Errorf("webrpc gen version could not be parsed from: %s", versions[0]) } tmplTarget, tmplVersion, ok := strings.Cut(versions[1], "@") if !ok { - return nil, fmt.Errorf("tmplTarget and tmplVersion could not be parsed from: %s", header) + return nil, fmt.Errorf("tmplTarget and tmplVersion could not be parsed from: %s", versions[1]) } + schemaName, schemaVersion, ok := strings.Cut(versions[2], "@") + if !ok { + return nil, fmt.Errorf("schema name and schema version could not be parsed from: %s", versions[2]) + } + return &WebRPCGenVersions{ WebRPCGenVersion: webrpcGenVersion, TmplTarget: tmplTarget, TmplVersion: tmplVersion, - SchemaVersion: versions[2], + SchemaName: schemaName, + SchemaVersion: schemaVersion, }, nil }