Skip to content

Commit

Permalink
Add API version constant to generated code (#3439)
Browse files Browse the repository at this point in the history
* Add API version constant to generated code

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".

* Update to latest v3
  • Loading branch information
raphael committed Jan 7, 2024
1 parent e11f83d commit 97467d7
Show file tree
Hide file tree
Showing 88 changed files with 239 additions and 95 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

0 comments on commit 97467d7

Please sign in to comment.