Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper function to get header fields #822

Merged
merged 2 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions httpclient/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ func injectHeaders(response any, body *common.ResponseWrapper) error {
return fmt.Errorf("failed to parse header %s as int: %w", headerTag.name, err)
}
value.Field(i).Set(reflect.ValueOf(intValue))
case reflect.Int64:
intValue, err := strconv.ParseInt(headerValue, 10, 64)
if err != nil {
return fmt.Errorf("failed to parse header %s as int: %w", headerTag.name, err)
}
value.Field(i).Set(reflect.ValueOf(intValue))
default:
// Do not fail the request if the header is not supported to avoid breaking changes.
logger.Warnf(context.Background(), "unsupported header type %s for field %s", field.Type.Kind(), field.Name)
Expand Down
1 change: 1 addition & 0 deletions internal/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func TestUcAccFilesAPI(t *testing.T) {
})
require.NoError(t, err)
require.Equal(t, fileHead.ContentType, "application/octet-stream")
require.Equal(t, fileHead.ContentLength, int64(4))
t.Cleanup(func() {
err = w.Files.DeleteByFilePath(ctx, filePath)
assert.NoError(t, err)
Expand Down
12 changes: 12 additions & 0 deletions openapi/code/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ func (m *Method) pathParams() (params []Field) {
return params
}

func (m *Method) ResponseHeaders() (headers []Field) {
if m.Response == nil {
return headers
}
for _, field := range m.Response.Fields() {
if field.IsHeader {
headers = append(headers, *field)
}
}
return headers
}

func (m *Method) allowShortcut() bool {
if m.shortcut {
return true
Expand Down