Skip to content

Commit

Permalink
Add API version constant to generated code
Browse files Browse the repository at this point in the history
This commit introduces the "APIVersion" constant into the generated code. This addition enables the utilization of this value in configuring telemetry data, complementing the existing "ServiceName" constant.

Additionally if a version isn't explicitely set in the design it is now defaulted to "0.0.1".
  • Loading branch information
raphael committed Jan 7, 2024
1 parent 017fe5d commit d3704cc
Show file tree
Hide file tree
Showing 84 changed files with 235 additions and 91 deletions.
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
Loading

0 comments on commit d3704cc

Please sign in to comment.