Skip to content

Commit

Permalink
Merge pull request #1793 from openmeterio/feat/client-go-generate
Browse files Browse the repository at this point in the history
feat(client): go generate
  • Loading branch information
tothandras authored Nov 6, 2024
2 parents bae2570 + ec086a5 commit d15fc1d
Show file tree
Hide file tree
Showing 8 changed files with 17,350 additions and 1,362 deletions.
20 changes: 20 additions & 0 deletions .dagger/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,26 @@ func (m *Generate) Openapi() *dagger.File {
return file
}

// Generate OpenAPI from TypeSpec.
func (m *Generate) Openapicloud() *dagger.File {
file := typespecBase(m.Source.Directory("api/spec")).
WithExec([]string{"pnpm", "compile"}).
File("/work/output/openapi.OpenMeterCloud.yaml").
WithName("openapi.cloud.yaml")

// https://github.com/microsoft/typespec/issues/2154
file = dag.Container().
From("alpine").
WithFile("/work/openapi.cloud.yaml", file).
WithWorkdir("/work").
WithExec([]string{"sed", "-i", "s/ingestEvents_ingestEvents/ingestEvents/", "openapi.cloud.yaml"}).
WithExec([]string{"sed", "-i", "s/queryMeter_queryMeter/queryMeter/", "openapi.cloud.yaml"}).
WithExec([]string{"sed", "-i", "s/queryPortalMeter_queryPortalMeter/queryPortalMeter/", "openapi.cloud.yaml"}).
File("/work/openapi.cloud.yaml")

return file
}

func typespecBase(source *dagger.Directory) *dagger.Container {
return dag.Container().
From("node:22.8.0-alpine3.20").
Expand Down
15 changes: 11 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@ update-openapi: ## Update OpenAPI spec
dagger call --source .:default generate openapi -o ./api/openapi.yaml
go generate ./api/...


.PHONY: update-openapi-cloud
update-openapi-cloud: ## Update OpenAPI spec
$(call print-target)
dagger call --source .:default generate openapicloud -o ./api/openapi.cloud.yaml
go generate ./api/...

.PHONY: gen-api
gen-api: ## Generate API and SDKs
$(call print-target)
go generate ./api/...
# dagger call generate node-sdk -o api/client/node
# dagger call generate web-sdk -o api/client/web
# dagger call generate python-sdk -o api/client/python
$(MAKE) update-openapi-cloud
dagger call generate node-sdk -o api/client/node
# dagger call generate web-sdk -o api/client/web
# dagger call generate python-sdk -o api/client/python

.PHONY: migrate-check
migrate-check: ## Validate migrations
Expand Down
Loading

0 comments on commit d15fc1d

Please sign in to comment.