Skip to content

Commit 063e117

Browse files
committed
go: Update api_resource template to support sub-resources
1 parent c93c0ef commit 063e117

11 files changed

+22
-13
lines changed

go/application.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type Application struct {
1313

1414
func newApplication(client *SvixHttpClient) *Application {
1515
return &Application{
16-
client,
16+
client: client,
1717
}
1818
}
1919

go/authentication.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type Authentication struct {
1313

1414
func newAuthentication(client *SvixHttpClient) *Authentication {
1515
return &Authentication{
16-
client,
16+
client: client,
1717
}
1818
}
1919

go/background_task.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type BackgroundTask struct {
1313

1414
func newBackgroundTask(client *SvixHttpClient) *BackgroundTask {
1515
return &BackgroundTask{
16-
client,
16+
client: client,
1717
}
1818
}
1919

go/endpoint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type Endpoint struct {
1414

1515
func newEndpoint(client *SvixHttpClient) *Endpoint {
1616
return &Endpoint{
17-
client,
17+
client: client,
1818
}
1919
}
2020

go/event_type.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type EventType struct {
1313

1414
func newEventType(client *SvixHttpClient) *EventType {
1515
return &EventType{
16-
client,
16+
client: client,
1717
}
1818
}
1919

go/integration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type Integration struct {
1313

1414
func newIntegration(client *SvixHttpClient) *Integration {
1515
return &Integration{
16-
client,
16+
client: client,
1717
}
1818
}
1919

go/message.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type Message struct {
1414

1515
func newMessage(client *SvixHttpClient) *Message {
1616
return &Message{
17-
client,
17+
client: client,
1818
}
1919
}
2020

go/message_attempt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type MessageAttempt struct {
1414

1515
func newMessageAttempt(client *SvixHttpClient) *MessageAttempt {
1616
return &MessageAttempt{
17-
client,
17+
client: client,
1818
}
1919
}
2020

go/operational_webhook_endpoint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type OperationalWebhookEndpoint struct {
1313

1414
func newOperationalWebhookEndpoint(client *SvixHttpClient) *OperationalWebhookEndpoint {
1515
return &OperationalWebhookEndpoint{
16-
client,
16+
client: client,
1717
}
1818
}
1919

go/statistics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type Statistics struct {
1313

1414
func newStatistics(client *SvixHttpClient) *Statistics {
1515
return &Statistics{
16-
client,
16+
client: client,
1717
}
1818
}
1919

openapi-templates/go/api_resource.go.jinja

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,29 @@ import (
1414

1515

1616
type {{ resource_type_name }} struct {
17+
{% if resource.operations | length > 0 -%}
1718
client *SvixHttpClient
19+
{%- endif %}
20+
{%- for name, sub in resource.subresources | items %}
21+
{{ name | to_upper_camel_case }} *{{ sub.name | to_upper_camel_case }}
22+
{%- endfor %}
1823
}
1924

2025
func new{{ resource_type_name }}(client *SvixHttpClient) *{{ resource_type_name }} {
2126
return &{{ resource_type_name }}{
22-
client,
27+
{% if resource.operations | length > 0 -%}
28+
client: client,
29+
{%- endif %}
30+
{%- for name, sub in resource.subresources | items %}
31+
{{ name | to_lower_camel_case }}: new{{ sub.name | to_upper_camel_case }}(client),
32+
{%- endfor %}
2333
}
2434
}
2535

2636
{% for op in resource.operations -%}
2737
{% if op | has_query_or_header_params -%}
2838
{% set opt_struct_name %}{{ resource_type_name }}{{ op.name | to_upper_camel_case }}Options{% endset %}
29-
type {{ opt_struct_name }} struct{
39+
type {{ opt_struct_name }} struct {
3040
{% for p in op.query_params -%}
3141
{% set p_ty = p.type.to_go() -%}
3242
{% if p.type.is_schema_ref() -%}
@@ -41,7 +51,6 @@ type {{ opt_struct_name }} struct{
4151
{% for p in op.header_params -%}
4252
{{ p.name | to_upper_camel_case }} *string
4353
{% endfor -%}
44-
4554
}
4655
{% endif -%}
4756
{% endfor -%}

0 commit comments

Comments
 (0)