marcoceppi / python-spacetraders

A Python SpaceTraders library for interacting with the API
13 stars 2 forks source link

feat!: Allow passing body_json as keyword arguments #1

Closed marcoceppi closed 1 year ago

marcoceppi commented 1 year ago

This is a breaking change but allows a more reasonable approach to interacting with the API

Before:

from spacetraders import Client
from spacetraders.models.register_json_body import RegisterJsonBody
from spacetraders.models.register_json_body_faction import RegisterJsonBodyFaction

client = Client(base_url="https://api.spacetraders.io/v2")
register_body = RegisterJsonBody(symbol="Marco-Test", faction=RegisterJsonBodyFaction.COSMIC)
resp = client.default.register(json_body=register_body)
print(resp)

After:

from spacetraders import Client

client = Client(base_url="https://api.spacetraders.io/v2")
resp = client.default.register(faction="COSMIC", symbol="marco-test")
print(resp)

This doesn't resolve type-hinting, but changes json_body to be **json_body and adds a normalize step in the body of each method. openapi-python-client doesn't seem to directly expose a way to interrogate the model properties, only the model name from the template. This means we'll need more work to get the TypeHinting correct though even now it's not wired up due to how APIStub works. I'll tackle the APIStub issue in another update.