Skip to content

Commit 1652622

Browse files
committed
feat: make version constants and schema hash opt-in via -versionFuncs
The schema hash in the file header comment and the WebRPCSchemaHash constant change on every schema edit, producing perpetual git merge conflicts in generated files. The version constants (WebRPCVersion, WebRPCSchemaVersion, WebRPCSchemaHash) are rarely consumed. Gate the whole block behind a new -versionFuncs target option (default false), flipping the previous always-on behavior: - default: header comment carries only the name and version (no hash), and no version constants are emitted. The "Code generated by ... DO NOT EDIT." line stays. - with -versionFuncs: restores today's output exactly (hash in the header plus all three constants). The flag name is shared across all webrpc generators for consistency (gen-golang emits helper functions; this target emits constants). Regenerated _examples to reflect the new default.
1 parent 112f40e commit 1652622

2 files changed

Lines changed: 5 additions & 11 deletions

File tree

_examples/hello-webrpc/webapp/client.gen.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
1-
// hello-webrpc v1.0.0 949b00a8db9810c69295f9dd9f02587a65d3c497
1+
// hello-webrpc v1.0.0
22
// --
33
// Code generated by webrpc-gen@v0.37.0 with ../../ generator. DO NOT EDIT.
44
//
55
// webrpc-gen -schema=hello-api.ridl -target=../../ -exports=false -client -out=./webapp/client.gen.js
66

7-
// WebRPC description and code-gen version
8-
const WebRPCVersion = "v1"
9-
10-
// Schema version of your RIDL schema
11-
const WebRPCSchemaVersion = "v1.0.0"
12-
13-
// Schema hash generated from your RIDL schema
14-
const WebRPCSchemaHash = "949b00a8db9810c69295f9dd9f02587a65d3c497"
15-
167
//
178
// Types
189
//

main.go.tmpl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{{- set $opts "client" (ternary (in .Opts.client "" "true") true false) -}}
66
{{- set $opts "server" (ternary (in .Opts.server "" "true") true false) -}}
77
{{- set $opts "exports" (ternary (in .Opts.exports "false") false true) -}}
8+
{{- set $opts "versionFuncs" (ternary (in .Opts.versionFuncs "" "true") true false) -}}
89

910
{{- /* Print help on -help. */ -}}
1011
{{- if exists .Opts "help" -}}
@@ -52,12 +53,13 @@
5253
{{- set $typeMap "string" "string" -}}
5354
{{- set $typeMap "timestamp" "string" -}}
5455

55-
// {{.SchemaName}} {{.SchemaVersion}} {{.SchemaHash}}
56+
// {{.SchemaName}} {{.SchemaVersion}}{{if $opts.versionFuncs}} {{.SchemaHash}}{{end}}
5657
// --
5758
// Code generated by webrpc-gen@{{.WebrpcGenVersion}} with {{.WebrpcTarget}} generator. DO NOT EDIT.
5859
//
5960
// {{.WebrpcGenCommand}}
6061

62+
{{- if $opts.versionFuncs }}
6163
// WebRPC description and code-gen version
6264
{{if $opts.exports}}export {{end}}const WebRPCVersion = "{{.WebrpcVersion}}"
6365

@@ -66,6 +68,7 @@
6668

6769
// Schema hash generated from your RIDL schema
6870
{{if $opts.exports}}export {{end}}const WebRPCSchemaHash = "{{.SchemaHash}}"
71+
{{- end }}
6972

7073
{{template "types" dict "Services" .Services "Types" .Types "Opts" $opts}}
7174
{{- if $opts.client}}

0 commit comments

Comments
 (0)