Skip to content

Commit

Permalink
generate unions (#505)
Browse files Browse the repository at this point in the history
* generate unions

* drop unused TagOwner enums

* union tpl clean up
  • Loading branch information
davidbloss authored and rocktavious committed Jan 28, 2025
1 parent 1fe42e7 commit 626ba3c
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 21 deletions.
5 changes: 0 additions & 5 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ import (
"github.com/relvacode/iso8601"
)

type CheckOwner struct {
Team TeamId `graphql:"... on Team"`
// User User `graphql:"... on User"` // TODO: will this be public?
}

type CheckInputConstructor func() any

var CheckCreateConstructors = map[CheckType]CheckInputConstructor{
Expand Down
5 changes: 0 additions & 5 deletions document.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package opslevel

type ServiceDocumentSource struct {
IntegrationId `graphql:"... on ApiDocIntegration"`
ServiceRepository `graphql:"... on ServiceRepository"`
}

type ServiceDocument struct {
Id ID `graphql:"id" json:"id"`
HtmlURL string `graphql:"htmlUrl" json:"htmUrl,omitempty"`
Expand Down
4 changes: 0 additions & 4 deletions owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ type EntityOwnerTeam struct {
Id ID `json:"id"`
}

type EntityOwner struct {
OnTeam EntityOwnerTeam `graphql:"... on Team"`
}

func (entityOwner *EntityOwner) Alias() string {
return entityOwner.OnTeam.Alias
}
Expand Down
7 changes: 0 additions & 7 deletions tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ import (
"slices"
)

type TagOwner string

const (
TagOwnerService TagOwner = "Service"
TagOwnerRepository TagOwner = "Repository"
)

type TaggableResourceInterface interface {
GetTags(*Client, *PayloadVariables) (*TagConnection, error)
ResourceId() ID
Expand Down
40 changes: 40 additions & 0 deletions templates/unions.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{{- define "union" }}
// {{ title .Name }} {{.Desc | clean | endSentence}}
{{- if eq "CheckOwner" .Name }}
{{ template "check_owner" }}
{{- else if eq "EntityOwner" .Name }}
{{ template "entity_owner" }}
{{- else if eq "ServiceDocumentSource" .Name }}
{{ template "service_document_source" }}
{{- else }}
type {{.Name}} struct {
{{ range .TypeNames }}
{{- if not (contains "Group" . ) }}
{{.}} {{. -}}
{{- if not (contains . (list "ApiDocIntegration" "InfrastructureResource" "ServiceRepository" | join " " )) -}}Id
{{- end }} `graphql:"... on {{.}}"`
{{- end }}
{{- end }}
}
{{- end }}
{{- end -}}

{{- define "check_owner" -}}
type CheckOwner struct {
Team TeamId `graphql:"... on Team"`
// User UserId `graphql:"... on User"` // TODO: will this be public?
}
{{ end }}

{{- define "entity_owner" -}}
type EntityOwner struct {
OnTeam EntityOwnerTeam `graphql:"... on Team"`
}
{{ end }}

{{- define "service_document_source" -}}
type ServiceDocumentSource struct {
IntegrationId `graphql:"... on ApiDocIntegration"`
ServiceRepository `graphql:"... on ServiceRepository"`
}
{{ end }}
56 changes: 56 additions & 0 deletions union.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 626ba3c

Please sign in to comment.