Skip to content

Commit 83f802c

Browse files
committed
fix(builder): handle requests and responses without a body correctly
See: sumup/go-sdk-gen#43
1 parent e61516d commit 83f802c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

codegen/pkg/builder/methods.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,15 @@ func (b *Builder) operationToMethod(method, path string, o *v3.Operation) (*Meth
127127
return nil, fmt.Errorf("build path parameters: %w", err)
128128
}
129129

130+
hasBody := false
130131
if o.RequestBody != nil {
131132
mt, ok := o.RequestBody.Content.Get("application/json")
132133
if ok && mt.Schema != nil {
133134
params = append(params, Parameter{
134135
Name: "body",
135136
Type: strcase.ToCamel(o.OperationId) + "Body",
136137
})
138+
hasBody = true
137139
}
138140
}
139141

@@ -193,7 +195,7 @@ func (b *Builder) operationToMethod(method, path string, o *v3.Operation) (*Meth
193195
Path: pathBuilder(path),
194196
PathParams: params,
195197
QueryParams: queryParams,
196-
HasBody: o.RequestBody != nil,
198+
HasBody: hasBody,
197199
Responses: responses,
198200
}, nil
199201
}
@@ -226,10 +228,12 @@ func (b *Builder) getSuccessResponseType(o *v3.Operation) (*string, error) {
226228
}
227229

228230
if content, ok := response.Content.Get("application/json"); ok {
229-
sucessResponses = append(sucessResponses, responseInfo{
230-
content: content,
231-
code: name,
232-
})
231+
if content.Schema != nil {
232+
sucessResponses = append(sucessResponses, responseInfo{
233+
content: content,
234+
code: name,
235+
})
236+
}
233237
}
234238
}
235239

0 commit comments

Comments
 (0)