From 00f2e2ac456042f11af7b4dc45dad79d15440e9b Mon Sep 17 00:00:00 2001 From: Marc Bir Date: Wed, 22 Oct 2025 10:23:50 -0700 Subject: [PATCH] Drop usage of version in templates, update readme with guidance to commit code --- README.md | 9 ++++++--- foji/enum.go.tpl | 2 +- foji/fields.go.tpl | 2 +- foji/openapi/docs.go.tpl | 2 +- foji/openapi/handler.go.tpl | 2 +- foji/openapi/model.go.tpl | 2 +- foji/openapi/service.go.tpl | 9 ++++++++- foji/pgx/db.go.tpl | 2 +- foji/pgx/model.go.tpl | 2 +- foji/pgx/table.go.tpl | 2 +- foji/sqlRepo.go.tpl | 2 +- go.sum | 2 -- tests/auth/http_handler_gen.go | 2 +- tests/auth/model_gen.go | 2 +- tests/auth/service_gen.go | 9 ++++++++- tests/csvresponse/http_handler_gen.go | 2 +- tests/csvresponse/model_gen.go | 2 +- tests/example/http_handler_gen.go | 3 ++- tests/example/model_gen.go | 2 +- 19 files changed, 38 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 343b2e6..479db91 100644 --- a/README.md +++ b/README.md @@ -186,18 +186,21 @@ Generated go files should have "Code generated" comments as the first line, with a standard in the community, with editors giving warnings not to modify. An example ```gotemplate -// Code generated by foji {{ version }}, template: {{ templateFile }}; DO NOT EDIT. +// Code generated by foji, template: {{ templateFile }}; DO NOT EDIT. ``` Example output: ```go -// Code generated by foji 0.3, template: foji/openapi/model.go.tpl; DO NOT EDIT. +// Code generated by foji, template: foji/openapi/model.go.tpl; DO NOT EDIT. ``` -`version` (string version of the foji tool) and `templateFile` (the currently executing template file) are part of the +`templateFile` (the currently executing template file) is part of the standard template func set (available to all templates). +`version` (string version of the foji cli) is also available. Note that we no longer recommend injecting the version +into the generated code. Instead, commit the generated code and manage changes with git. + An exception to the above naming and comment rules are when you generate a file as a "starting point". For example openAPI generates a project `main.go` as an example service. Once this file is generated, it should never be replaced Prefix the file name with `!` to disable generation on existing files. diff --git a/foji/enum.go.tpl b/foji/enum.go.tpl index ad05905..7312f3f 100644 --- a/foji/enum.go.tpl +++ b/foji/enum.go.tpl @@ -1,4 +1,4 @@ -// Code generated by foji {{ version }}, template: {{ templateFile }}; DO NOT EDIT. +// Code generated by foji, template: {{ templateFile }}; DO NOT EDIT. package {{ .PackageName }} diff --git a/foji/fields.go.tpl b/foji/fields.go.tpl index 6313f14..331930a 100644 --- a/foji/fields.go.tpl +++ b/foji/fields.go.tpl @@ -1,4 +1,4 @@ -// Code generated by foji {{ version }}, template: {{ templateFile }}; DO NOT EDIT. +// Code generated by foji, template: {{ templateFile }}; DO NOT EDIT. package {{ .PackageName }} diff --git a/foji/openapi/docs.go.tpl b/foji/openapi/docs.go.tpl index edf2b2e..708291b 100644 --- a/foji/openapi/docs.go.tpl +++ b/foji/openapi/docs.go.tpl @@ -1,4 +1,4 @@ -// Code generated by foji {{ version }}, template: {{ templateFile }}; DO NOT EDIT. +// Code generated by foji, template: {{ templateFile }}; DO NOT EDIT. package {{ .PackageName }} diff --git a/foji/openapi/handler.go.tpl b/foji/openapi/handler.go.tpl index 0131080..fe64ee8 100644 --- a/foji/openapi/handler.go.tpl +++ b/foji/openapi/handler.go.tpl @@ -131,7 +131,7 @@ {{- end -}} {{- $package := $.PackageName }} -// Code generated by foji {{ version }}, template: {{ templateFile }}; DO NOT EDIT. +// Code generated by foji, template: {{ templateFile }}; DO NOT EDIT. package {{ $package }} diff --git a/foji/openapi/model.go.tpl b/foji/openapi/model.go.tpl index 64bec02..d3a92db 100644 --- a/foji/openapi/model.go.tpl +++ b/foji/openapi/model.go.tpl @@ -489,7 +489,7 @@ func (p {{ pascal $key }}) Validate() error { {{- end -}} {{- end -}} -// Code generated by foji {{ version }}, template: {{ templateFile }}; DO NOT EDIT. +// Code generated by foji, template: {{ templateFile }}; DO NOT EDIT. package {{ .PackageName }} diff --git a/foji/openapi/service.go.tpl b/foji/openapi/service.go.tpl index 6980a57..84357a2 100644 --- a/foji/openapi/service.go.tpl +++ b/foji/openapi/service.go.tpl @@ -34,7 +34,14 @@ import ( {{- end }} ) -// GenService holds all Unsupported mock endpoints {{ .PackageName }}. +// GenService holds all Unsupported mock endpoints. You can embed the mock service in real code. +// Simple example: +// +// type Service struct { +// GenService +// } +// +// This allows you to mock the service for a quick start and eventually delete this stub. type GenService struct { } diff --git a/foji/pgx/db.go.tpl b/foji/pgx/db.go.tpl index 0bc1302..7212792 100644 --- a/foji/pgx/db.go.tpl +++ b/foji/pgx/db.go.tpl @@ -1,4 +1,4 @@ -// Code generated by foji {{ version }}, template: {{ templateFile }}; DO NOT EDIT. +// Code generated by foji, template: {{ templateFile }}; DO NOT EDIT. package pg diff --git a/foji/pgx/model.go.tpl b/foji/pgx/model.go.tpl index d93d862..9f5d169 100644 --- a/foji/pgx/model.go.tpl +++ b/foji/pgx/model.go.tpl @@ -1,4 +1,4 @@ -// Code generated by foji {{ version }}, template: {{ templateFile }}; DO NOT EDIT. +// Code generated by foji, template: {{ templateFile }}; DO NOT EDIT. package {{ .PackageName }} diff --git a/foji/pgx/table.go.tpl b/foji/pgx/table.go.tpl index 1854f6a..df4fd83 100644 --- a/foji/pgx/table.go.tpl +++ b/foji/pgx/table.go.tpl @@ -1,4 +1,4 @@ -// Code generated by foji {{ version }}, template: {{ templateFile }}; DO NOT EDIT. +// Code generated by foji, template: {{ templateFile }}; DO NOT EDIT. {{- $pkgName := "pg" }} {{- $table := .Table.Name}} {{- $schema := .Table.Schema.Name}} diff --git a/foji/sqlRepo.go.tpl b/foji/sqlRepo.go.tpl index a64317b..87b8336 100644 --- a/foji/sqlRepo.go.tpl +++ b/foji/sqlRepo.go.tpl @@ -1,4 +1,4 @@ -// Code generated by foji {{ version }}, template: {{ templateFile }}; DO NOT EDIT. +// Code generated by foji, template: {{ templateFile }}; DO NOT EDIT. package {{ $.PackageName }} diff --git a/go.sum b/go.sum index 435240f..4603b00 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,6 @@ github.com/gobuffalo/plush/v5 v5.0.10/go.mod h1:C08u/VEqzzPBXFF/yqs40P/5Cvc/zlZs github.com/gobuffalo/tags/v3 v3.1.4 h1:X/ydLLPhgXV4h04Hp2xlbI2oc5MDaa7eub6zw8oHjsM= github.com/gobuffalo/tags/v3 v3.1.4/go.mod h1:ArRNo3ErlHO8BtdA0REaZxijuWnWzF6PUXngmMXd2I0= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/gofoji/plates v0.3.2 h1:JSkN4Fwvy196tAsWau1W8wetAbCMkaEsxXooJGqEtL4= -github.com/gofoji/plates v0.3.2/go.mod h1:dMu4ksz2zTMiXjTPjKQ5KVbqPc7mAHucGGmLsMmlaeE= github.com/gofoji/plates v0.3.3 h1:MfBu5TtWHxxEBKoGngi1FA2MhcRfjm0odl6ouis9rhs= github.com/gofoji/plates v0.3.3/go.mod h1:KOsI6hw+5gWEc/9Igg7bAbauc3IhKQwdOAMgv+FYeMo= github.com/gofoji/plates/plush v0.3.4 h1:bIfDe7lyeiorGT0dfKtADTAyl78qFT8wvxqf+bQfsr0= diff --git a/tests/auth/http_handler_gen.go b/tests/auth/http_handler_gen.go index c2574a5..4b8d4c4 100644 --- a/tests/auth/http_handler_gen.go +++ b/tests/auth/http_handler_gen.go @@ -1,4 +1,4 @@ -// Code generated by foji (dev build), template: foji/openapi/handler.go.tpl; DO NOT EDIT. +// Code generated by foji, template: foji/openapi/handler.go.tpl; DO NOT EDIT. package auth diff --git a/tests/auth/model_gen.go b/tests/auth/model_gen.go index f9796f5..e31fa6b 100644 --- a/tests/auth/model_gen.go +++ b/tests/auth/model_gen.go @@ -1,4 +1,4 @@ -// Code generated by foji (dev build), template: foji/openapi/model.go.tpl; DO NOT EDIT. +// Code generated by foji, template: foji/openapi/model.go.tpl; DO NOT EDIT. package auth diff --git a/tests/auth/service_gen.go b/tests/auth/service_gen.go index b89878d..f71ffa7 100644 --- a/tests/auth/service_gen.go +++ b/tests/auth/service_gen.go @@ -7,7 +7,14 @@ import ( "tests/example" ) -// GenService holds all Unsupported mock endpoints auth. +// GenService holds all Unsupported mock endpoints. You can embed the mock service in real code. +// Simple example: +// +// type Service struct { +// GenService +// } +// +// This allows you to mock the service for a quick start and eventually delete this stub. type GenService struct{} // ListAdminUsers diff --git a/tests/csvresponse/http_handler_gen.go b/tests/csvresponse/http_handler_gen.go index 642af40..951c8a5 100644 --- a/tests/csvresponse/http_handler_gen.go +++ b/tests/csvresponse/http_handler_gen.go @@ -1,4 +1,4 @@ -// Code generated by foji (dev build), template: foji/openapi/handler.go.tpl; DO NOT EDIT. +// Code generated by foji, template: foji/openapi/handler.go.tpl; DO NOT EDIT. package csvresponse diff --git a/tests/csvresponse/model_gen.go b/tests/csvresponse/model_gen.go index 08cb4a7..f6b088d 100644 --- a/tests/csvresponse/model_gen.go +++ b/tests/csvresponse/model_gen.go @@ -1,4 +1,4 @@ -// Code generated by foji (dev build), template: foji/openapi/model.go.tpl; DO NOT EDIT. +// Code generated by foji, template: foji/openapi/model.go.tpl; DO NOT EDIT. package csvresponse diff --git a/tests/example/http_handler_gen.go b/tests/example/http_handler_gen.go index 8cca784..9854bf3 100644 --- a/tests/example/http_handler_gen.go +++ b/tests/example/http_handler_gen.go @@ -1,4 +1,4 @@ -// Code generated by foji (dev build), template: foji/openapi/handler.go.tpl; DO NOT EDIT. +// Code generated by foji, template: foji/openapi/handler.go.tpl; DO NOT EDIT. package example @@ -689,6 +689,7 @@ func (h OpenAPIHandlers) GetExampleQuery(w http.ResponseWriter, r *http.Request) func (h OpenAPIHandlers) GetRawBody(w http.ResponseWriter, r *http.Request) { var err error + logctx.SetOperation(r.Context(), "getRawBody") logctx.AddStrToContext(r.Context(), "op", "getRawBody") body := r.Body diff --git a/tests/example/model_gen.go b/tests/example/model_gen.go index a349ed8..b04ae0e 100644 --- a/tests/example/model_gen.go +++ b/tests/example/model_gen.go @@ -1,4 +1,4 @@ -// Code generated by foji (dev build), template: foji/openapi/model.go.tpl; DO NOT EDIT. +// Code generated by foji, template: foji/openapi/model.go.tpl; DO NOT EDIT. package example