Skip to content

Add object-oriented client option #224

Closed as not planned
Closed as not planned
@fyhertz

Description

@fyhertz

First of all, thank you for this great project, the code is very nice and I think it really has a lot of potential.

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

As mentioned in #171, the current approach arguably needs a little too much boilerplate that could be avoided by adding a more object oriented Client.

Describe the solution you'd like

  • Add two new client interfaces, SyncClient and AsyncClient that would wrap the currently generated tag packages in objects, and expose them as properties.

With that approach, a developer could call an endpoint with as little code as:

from petstore_client import SyncPetstoreClient  # Named after the spec title, nicer if you import several auto-generated clients
client = SyncPetstoreClient("http://mypetstore")
pets = client.pets.list_pets()
  • One issue is that we loose the ability to statically tell the user that some endpoint requires an AuthenticatedClient or not... Some thinking required here I guess.

  • Additionally, a default base_url could be provided through an environment variable named after the spec title, for instance: SWAGGER_PETSTORE_BASE_URL. It could be nice to prevent microservices from using different naming conventions.

For reference, my crude attempt at implementing those interfaces is available here: https://github.com/upciti/openapi-python-client/tree/feature/0-boilerplate-clients.

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