Supported schemas¶
The generator understands OpenAPI 3.0.x and 3.1.x documents, as JSON
or — with the yaml extra installed — YAML. This page lists how each
construct maps to generated code, and what is (deliberately) out of
scope for now. Everything unsupported raises a clear error naming the
schema location; lesser omissions are reported as warnings.
Types¶
Schema |
Generated Python |
|---|---|
|
|
|
|
|
|
other string formats ( |
|
|
a generated |
|
|
object with |
a generated dataclass model |
object with only |
|
object with |
a model with a typed catch-all field ( |
object without properties, or an empty schema |
|
unrecognized |
|
3.0 |
|
|
a generated union: a type alias ( |
|
tag dispatch in the union’s converter; members without a mapping entry use their component name, the spec’s implicit convention |
3.1 multi-type arrays ( |
a union of the bare types |
|
unwrapped |
|
flattened into one model: |
|
the class docstring (a |
|
a |
Model fields keep the schema’s property order, except that fields
rendered with a = None default — optional or nullable ones — move
behind the default-less fields, as plain dataclasses require. A
required-but-nullable property therefore reads ... | None = None,
but its converter still expects the key in the payload.
The catch-all field is filled when parsing: the converter collects
every payload key outside the declared properties (APIs answering with
dynamic keys, like Open-Meteo’s ensemble member variables, stay fully
usable). It has no counterpart on the request side — a model serialized
into a JSON body sends the catch-all as a nested object, not flattened,
so leave it None there; a request body schema combining
properties with additionalProperties is reported as a warning.
Union members must be recognizable in a decoded payload — by JSON type
(a string \| object union), by the discriminator tag, or by a
required property no other member declares. A union whose members
cannot be told apart (two plain-string members, object members with
only shared optional properties, a member accepting anything) degrades
to an untyped value, with a warning naming the schema location — add a
discriminator to fix that.
Inline object and enum schemas are synthesized into named classes: an
inline response object of createToken becomes CreateTokenResponse,
an inline enum of a status property of Pet becomes PetStatus.
Names are converted to PEP 8 (petId → pet_id, classes PascalCase,
enum members UPPER_SNAKE); the original spelling is kept as the wire
name. Acronym runs count as one word, pluralized ones keep their s
(HTTPError → HttpError, numAPIs → num_apis), digits stay with
their word (GET /v1/forecast → GetV1Forecast → the converter
get_v1_forecast_response_from_json, SHA256Sum → sha256_sum), and
accented letters lose their accents instead of splitting the word
(PokéAPI → PokeApi). Python keywords and names reserved by
action0-client
operations get a trailing underscore.
Operations¶
Schema |
Generated Python |
|---|---|
path / query / header parameters |
|
array query parameter, exploded (the default: |
one |
array query parameter with |
the items join into one |
parameter with |
those keywords are treated as the parameter’s schema, with a warning |
required parameter / property |
field without default |
optional parameter / property |
|
JSON request body, inline object schema |
one |
JSON request body, |
a single |
|
one |
any other request media type (file uploads: |
a raw |
lowest documented 2xx response with JSON content |
the operation’s typed result (a result needing no conversion is returned through |
|
|
2xx with only non-JSON content |
|
documented 4xx/5xx (or |
an error model plus a generated |
operation |
the operation class docstring |
|
a |
Operation classes are named after the operationId (listPets →
ListPets), falling back to method + path (GET /pets/{petId} →
GetPetsPetId).
Operations documenting the same status with the same error model share
one exception class; the same status with a different model gets a
numbered name (BadRequestError2). An error body that turns out not to
be a JSON object at runtime falls back to the plain APIError, so the
generated check never masks an unparseable failure. Every generated
exception subclasses action0.client.APIError — existing
except APIError: handlers keep working.
Multi-file documents¶
Schemas split over several files — references like
$ref: './components/geo.yaml#/components/schemas/Point', with paths
relative to the referencing file — are bundled into one document before
translation:
A reference to another file’s
#/components/<section>/<name>moves that component (and, recursively, everything it references) into the root document’s matching section. It keeps its name; if the name is already taken by a different definition, a numbered name is picked (Tag→Tag2) and a warning reports the rename. An identical, reference-free definition is shared silently instead.A reference to anything that is not a component — a deep pointer like
other.yaml#/components/schemas/Pet/properties/name, or a whole-file reference to a bare schema file — is inlined in place, like an inline schema written there. A reference cycle through such anonymous nodes cannot be inlined and is an error; cycles through components are fine.
The schema itself may be an http(s):// URL, and references may point
at URLs too — relative references in a downloaded document resolve
against its URL, which also means a downloaded document can only ever
reference further URLs, never files on your disk. You named the root
URL, so it is fetched directly; referenced files you did not name
download only with consent: the CLI asks download <url>? [y/N] per
file (--download pre-approves all of them), the library API takes an
allow_download callback.
Security schemes¶
Schemes referenced by the document’s or any operation’s security become
constructor credentials of the generated client:
Scheme |
Client credential |
|---|---|
|
|
|
|
|
a header credential parameter |
|
a query credential added to every request |
OAuth2 and OpenID Connect flows are not generated — a warning tells you
to pass those credentials yourself (default headers or an
APIClient.prepare override).
Not supported (yet)¶
allOfparts that are not object schemas — flatten those by hand before generating. (Constraint-only keywords insideallOfparts, likeminProperties, are ignored.)Cookie parameters, content-typed parameters, and typed multipart bodies —
multipart/form-datagets the raw-bytes treatment, so you assemble the multipart payload yourself.Per-status response typing beyond the picked 2xx (other 2xx responses still pass the check and are parsed with the same converter).
Swagger 2.0 documents,
callbacks,linksandwebhooks.