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

[FEATURE] Make all response structs their own type #585

Open
Jakob3xD opened this issue Jul 9, 2024 · 2 comments
Open

[FEATURE] Make all response structs their own type #585

Jakob3xD opened this issue Jul 9, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@Jakob3xD
Copy link
Collaborator

Jakob3xD commented Jul 9, 2024

Is your feature request related to a problem?

For example the SnapshotGetResp struct has a field named Snapshots which is an array of struct.
I want to write a functions that uses this struct, but it can't be used as it is not its own type.
So it can't be referenced in the function arguments.
https://github.com/opensearch-project/opensearch-go/blob/main/opensearchapi/api_snapshot-get.go#L43

What solution would you like?

All structs inside Resp types should become their own type.

What alternatives have you considered?

Otherwise I need to redefine the struct on my end instead of using the lib.

Do you have any additional context?

resp, _ := client.Snapshot.Get(ctx, opensearchapi.SnapshotGetReq{xyz})
for _, snapshot := range resp.Snapshots {
    err := someFunction(snapshot)
    if err != nil {
        return err
    }
}

func someFunction(???) error {
    return nil
}
@Jakob3xD Jakob3xD added enhancement New feature or request untriaged labels Jul 9, 2024
@Caladrel65
Copy link

I'm running into this when trying to create mocked unit tests. I end up needing to define the inline struct of a SearchResp (which leads to defining the "total" field twice) every time I try to instantiate the SearchResp. Everything below is before I put any meaningful data into the response.

expectedSearchOutput: &opensearchapi.SearchResp{
	Hits: struct {
		Total struct {
			Value int `json:"value"`
			Relation string `json:"relation"`
		} `json:"total"`
		MaxScore float32 `json:"max_score"`
		Hits []opensearchapi.SearchHit `json:"hits"`
	}{
		Total: struct {
			Value    int    `json:"value"`
			Relation string `json:"relation"`
		}{
			Value:    0,
			Relation: "",
		},
		MaxScore: 0.0,
		Hits:     nil,
	},
},

@dblock
Copy link
Member

dblock commented Nov 7, 2024

I am secretly hoping someone do this as part of picking up #284 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants