feat: add code generation for Unifi client interface (#11)

* feat: add code generation for Unifi client interface

* chore: apply linter hints

* chore: add tests

* fix: nondeterministic client function signature due to iteration of map params

* chore: add move version tests

* chore: add more generator tests

* chore: lint
This commit is contained in:
Mateusz Filipowicz
2025-02-11 16:28:29 +01:00
committed by GitHub
parent c6e20b675c
commit 6016a3d34a
9 changed files with 1548 additions and 616 deletions

40
codegen/client.go.tmpl Normal file
View File

@@ -0,0 +1,40 @@
// Code generated from ace.jar fields *.json files
// DO NOT EDIT.
package unifi
import (
"context"
{{ range $k, $v := .Imports }}"{{ $v }}"{{- end }}
)
type {{ .Name }} interface {
/* custom method signatures */
{{ range $k, $v := .CustomFunctions }}
{{ $v.Signature }}
{{- end }}
/* client methods generated based on resource generation */
{{- range $k, $v := .Functions }}
/* client methods for {{ $v.Name }} API */
// Get{{ $v.Name }} returns {{ $v.Name }} resource{{ if not $v.IsSetting }} by its ID{{ end }}
Get{{ $v.Name }}(ctx context.Context, site{{ if not $v.IsSetting }}, id{{ end }} string) (*{{ $v.Name }}, error)
// Update{{ $v.Name }} updates {{ $v.Name }} resource{{ if not $v.IsSetting }} by its ID{{ end }}
Update{{ $v.Name }}(ctx context.Context, site string, d *{{ $v.Name }}) (*{{ $v.Name }}, error)
{{- if not $v.IsSetting }}
// List{{ $v.Name }} returns list of {{ $v.Name }} resources
List{{ $v.Name }}(ctx context.Context, site string) ([]{{ $v.Name }}, error)
// Delete{{ $v.Name }} deletes {{ $v.Name }} resource by its ID
Delete{{ $v.Name }}(ctx context.Context, site, id string) error
// Create{{ $v.Name }} creates new {{ $v.Name }} resource
Create{{ $v.Name }}(ctx context.Context, site string, d *{{ $v.Name }}) (*{{ $v.Name }}, error)
{{ end }}
{{- end }}
}