Skip to content

Generated client imports but cannot make requests: empty URL without query params, list encoding, required optionals #2

Open

Description

@kinlane

We ran cdd-python-all (5259b4e) against our public contract, the APIs.io API (OpenAPI 3.1.0, 174 operations): https://artifacts.apis.io/apis-io/openapi/apis-io-v1-openapi.yml — happy for you to use it as a fixture. Generation succeeds and import client works (172 methods), but calling it shows these:

1. Empty URL whenever no query parameter is passed (blocking)

url = self.base_url + f"/providers/{slug}" + '?' + '&'.join(query_params) if query_params else ""

The conditional expression binds the whole concatenation, so with no query params url == "" and urllib3 raises LocationValueError: No host specified. Client(base).get_provider("stripe", None) fails; it only works if fields is passed. 92 of 168 methods are affected on this contract. Fix: url = self.base_url + path + (('?' + '&'.join(query_params)) if query_params else '').

2. Array query params serialised with str(list)

query_params.append('tags=' + str(tags)) sends tags=['Messaging']. For style: form, explode: false it should be tags=Messaging,Payments (and repeated keys for explode: true), URL-encoded.

3. Optional parameters generated as required positionals

list_apis(self, q, tags, providers, artifact_types, industry, region, include, band, min_score, fields, match=None, ...) — every one of those is required: false in the spec, so the caller has to pass ten Nones to list APIs.

4. Methods return the raw urllib3.HTTPResponse

The models in models.py aren't used to parse responses, and non-2xx statuses aren't raised.

5. pyproject.toml URLs point at github.com/offscale/<title-slug>

Homepage = "https://github.com/offscale/apis-io-api", which doesn't exist. Taking them from info.contact.url / externalDocs, or leaving them out, would be safer.

Repro: download the contract above, then python -m openapi_client.cli from_openapi to_sdk -i apis-io.json (converted to JSON) -o out and Client("https://apis.io/api/v1").get_provider("stripe", None).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions