Skip to content

Commit afa85d2

Browse files
committed
fix: fixed schema alias template to really generate type aliases
1 parent 5dc17ac commit afa85d2

File tree

9 files changed

+1388
-11737
lines changed

9 files changed

+1388
-11737
lines changed

examples/ex_github/oas_json_gen.go

Lines changed: 0 additions & 11175 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/ex_github/oas_schemas_gen.go

Lines changed: 1353 additions & 451 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/_template/json/encoders_alias.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{{- /*gotype: github.com/ogen-go/ogen/gen/ir.Type*/ -}}
22
{{- define "json/encoders_alias" }}
33
{{- $a := $.AliasTo }}
4+
{{- if ne $a.Kind "struct" }}
45
// Encode encodes {{ $.Name }} as json.
56
func (s {{ $.ReadOnlyReceiver }}) Encode(e *jx.Encoder) {
67
{{- if $a.DoPassByPointer }}
@@ -34,3 +35,4 @@ func (s *{{ $.Name }}) Decode(d *jx.Decoder) error {
3435
}
3536

3637
{{ end }}
38+
{{ end }}

gen/_template/request_decode.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func (s *{{ if $op.WebhookInfo }}Webhook{{ end }}Server) decode{{ $op.Name }}Req
188188
{
189189
var unwrapped {{ $t.AliasTo.Go -}}
190190
{{ template "decode_form_request" elem $t.AliasTo "unwrapped" }}
191-
{{ $v }} = {{ $t.Go }}(unwrapped)
191+
{{ $v }} = {{ $t.Go }}{unwrapped}
192192
}
193193
{{- else if $t.IsGeneric }}
194194
{

gen/_template/schema/alias.tmpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
{{- /*gotype: github.com/ogen-go/ogen/gen/ir.Type*/ -}}
22
{{- define "schema/alias" }}
3+
{{- if eq $.AliasTo.Kind "struct" }}
4+
type {{ $.Name }} struct {
5+
{{ $.AliasTo.Go }}
6+
}
7+
{{ else }}
38
type {{ $.Name }} {{ $.AliasTo.Go }}
9+
{{- end }}
410
{{ end }}

internal/integration/requests_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,17 @@ func TestRequests(t *testing.T) {
123123
t.Run("AllRequestBodies", func(t *testing.T) {
124124
reqs := []api.AllRequestBodiesReq{
125125
&api.AllRequestBodiesApplicationJSON{
126-
Name: testData,
126+
SimpleObject: api.SimpleObject{
127+
Name: testData,
128+
},
127129
},
128130
&api.AllRequestBodiesReqApplicationOctetStream{
129131
Data: strings.NewReader(testData),
130132
},
131133
&api.AllRequestBodiesApplicationXWwwFormUrlencoded{
132-
Name: testData,
134+
SimpleObject: api.SimpleObject{
135+
Name: testData,
136+
},
133137
},
134138
&api.SimpleObjectMultipart{
135139
Name: testData,
@@ -152,13 +156,17 @@ func TestRequests(t *testing.T) {
152156
t.Run("AllRequestBodiesOptional", func(t *testing.T) {
153157
reqs := []api.AllRequestBodiesOptionalReq{
154158
&api.AllRequestBodiesOptionalApplicationJSON{
155-
Name: testData,
159+
SimpleObject: api.SimpleObject{
160+
Name: testData,
161+
},
156162
},
157163
&api.AllRequestBodiesOptionalReqApplicationOctetStream{
158164
Data: strings.NewReader(testData),
159165
},
160166
&api.AllRequestBodiesOptionalApplicationXWwwFormUrlencoded{
161-
Name: testData,
167+
SimpleObject: api.SimpleObject{
168+
Name: testData,
169+
},
162170
},
163171
&api.SimpleObjectMultipart{
164172
Name: testData,

internal/integration/test_http_requests/oas_json_gen.go

Lines changed: 0 additions & 100 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/integration/test_http_requests/oas_request_decoders_gen.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/integration/test_http_requests/oas_schemas_gen.go

Lines changed: 12 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)