Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API version constant to generated code #3439

Merged
merged 2 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions codegen/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ type Auther interface {
// key.
const ServiceName = {{ printf "%q" .Name }}

// APIVersion is the version of the API as defined in the design.
const APIVersion = {{ printf "%q" .APIVersion }}

// MethodNames lists the service method names as defined in the design. These
// are the same values that are set in the endpoint request contexts under the
// MethodKey key.
Expand Down
3 changes: 3 additions & 0 deletions codegen/service/service_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type (
Name string
// Description is the service description.
Description string
// APIVersion is the API version.
APIVersion string
// StructName is the service struct name.
StructName string
// VarName is the service variable name (first letter in lowercase).
Expand Down Expand Up @@ -747,6 +749,7 @@ func (d ServicesData) analyze(service *expr.ServiceExpr) *Data {
data := &Data{
Name: service.Name,
Description: desc,
APIVersion: expr.Root.API.Version,
VarName: varName,
PathName: codegen.SnakeCase(varName),
StructName: codegen.Goify(service.Name, true),
Expand Down