From acb590f2cfc17f6586dee715f35b953a5f9ee641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20-=20=E3=82=A2=E3=83=AC=E3=83=83=E3=82=AF=E3=82=B9?= Date: Fri, 19 Jun 2026 13:24:22 +0200 Subject: [PATCH] feat: make schema hash and version constants opt-in via -schemaHash 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 them behind a new -schemaHash 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 -schemaHash: restores today's output exactly (hash in the header plus all three constants). Regenerated _examples to reflect the new default. --- _examples/hello-webrpc/webapp/client.gen.js | 11 +---------- main.go.tmpl | 5 ++++- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/_examples/hello-webrpc/webapp/client.gen.js b/_examples/hello-webrpc/webapp/client.gen.js index 4fd4fa7..f4c3a69 100644 --- a/_examples/hello-webrpc/webapp/client.gen.js +++ b/_examples/hello-webrpc/webapp/client.gen.js @@ -1,18 +1,9 @@ -// hello-webrpc v1.0.0 949b00a8db9810c69295f9dd9f02587a65d3c497 +// hello-webrpc v1.0.0 // -- // Code generated by webrpc-gen@v0.37.0 with ../../ generator. DO NOT EDIT. // // webrpc-gen -schema=hello-api.ridl -target=../../ -exports=false -client -out=./webapp/client.gen.js -// WebRPC description and code-gen version -const WebRPCVersion = "v1" - -// Schema version of your RIDL schema -const WebRPCSchemaVersion = "v1.0.0" - -// Schema hash generated from your RIDL schema -const WebRPCSchemaHash = "949b00a8db9810c69295f9dd9f02587a65d3c497" - // // Types // diff --git a/main.go.tmpl b/main.go.tmpl index ea313df..e9c9d3c 100644 --- a/main.go.tmpl +++ b/main.go.tmpl @@ -5,6 +5,7 @@ {{- set $opts "client" (ternary (in .Opts.client "" "true") true false) -}} {{- set $opts "server" (ternary (in .Opts.server "" "true") true false) -}} {{- set $opts "exports" (ternary (in .Opts.exports "false") false true) -}} +{{- set $opts "schemaHash" (ternary (in .Opts.schemaHash "" "true") true false) -}} {{- /* Print help on -help. */ -}} {{- if exists .Opts "help" -}} @@ -52,12 +53,13 @@ {{- set $typeMap "string" "string" -}} {{- set $typeMap "timestamp" "string" -}} -// {{.SchemaName}} {{.SchemaVersion}} {{.SchemaHash}} +// {{.SchemaName}} {{.SchemaVersion}}{{if $opts.schemaHash}} {{.SchemaHash}}{{end}} // -- // Code generated by webrpc-gen@{{.WebrpcGenVersion}} with {{.WebrpcTarget}} generator. DO NOT EDIT. // // {{.WebrpcGenCommand}} +{{- if $opts.schemaHash }} // WebRPC description and code-gen version {{if $opts.exports}}export {{end}}const WebRPCVersion = "{{.WebrpcVersion}}" @@ -66,6 +68,7 @@ // Schema hash generated from your RIDL schema {{if $opts.exports}}export {{end}}const WebRPCSchemaHash = "{{.SchemaHash}}" +{{- end }} {{template "types" dict "Services" .Services "Types" .Types "Opts" $opts}} {{- if $opts.client}}