Skip to content

Mirror the API responses in the returned values #277

@jooola

Description

@jooola

Feature Request

Is your feature request related to a problem? Please describe.

When returning data from an API call, we usually unwrap the single field that might be returned by the API. Sometimes we return a Response wrapper including the different fields returned by the API.

This makes our API a bit inconsistent, and not future-proof: if a new field is added to the response, we usually have to implement a new method to return the new desired fields inside a wrapper class.

#181 is an example where we have to implement some dirty work around to provide the missing field.

Describe the solution you'd like

Make the return object consistent with the API response, and ensure we wrap all the returned fields in an object where it makes sense.

If the API returns:

{
  "action": {}
}

we return a class with an action field:

class MyResponse:
    action: Action

Adding a new field should be easy

{
  "action": {}
  "root_password": "1234567890"
}
class MyResponse:
    action: Action
    root_password: str | None

Teachability, Documentation, Adoption, Migration Strategy

I wonder how this can be solved without asking too much effort to users, as this would be a decent amount of work.

Maybe using the trick with the return_response argument in #276 can solve this ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions