Openapi-python-client

Latest version: v0.21.0

Safety actively analyzes 636669 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 1 of 12

1.2

This change switches the YAML parsing library to `ruamel.yaml` which follows the YAML 1.2 specification.
[There are breaking changes](https://yaml.readthedocs.io/en/latest/pyyaml/#defaulting-to-yaml-12-support) from YAML 1.1 to 1.2,
though they will not affect most use cases.

PR 1042 fixes 1041. Thanks rtaycher!

Features

- allow Ruff 0.4 (1031)

Fixes

Fix nullable and required properties in multipart bodies

Fixes 926.

> [!WARNING]
> This change is likely to break custom templates. Multipart body handling has been completely split from JSON bodies.

0.21.0

Breaking Changes

Removed the `update` command

The `update` command is no more, you can (mostly) replace its usage with some new flags on the `generate` command.

If you had a package named `my-api-client` in the current working directory, the `update` command previously would update the `my_api_client` module within it. You can now _almost_ perfectly replicate this behavior using `openapi-python-client generate --meta=none --output-path=my-api-client/my_api_client --overwrite`.

The only difference is that `my-api-client` would have run `post_hooks` in the `my-api-client` directory,
but `generate` will run `post_hooks` in the `output-path` directory.

Alternatively, you can now also run `openapi-python-client generate --meta=<your-meta-type> --overwrite` to regenerate
the entire client, if you don't care about keeping any changes you've made to the generated client.

Please comment on [discussion 824](https://github.com/openapi-generators/openapi-python-client/discussions/824)
(or a new discussion, as appropriate) to aid in designing future features that fill any gaps this leaves for you.

Features

Added an `--output-path` option to `generate`

Rather than changing directories before running `generate` you can now specify an output directory with `--output-path`.
Note that the project name will _not_ be appended to the `--output-path`, whatever path you specify is where the
generated code will be placed.

Added an `--overwrite` flag to `generate`

You can now tell `openapi-python-client` to overwrite an existing directory, rather than deleting it yourself before
running `generate`.

0.20

Some features of generated clients already failed at runtime when using httpx < 0.20, but now the minimum version is enforced at generation time.

Connections from clients no longer automatically close (PR [775](https://github.com/openapi-generators/openapi-python-client/pull/775))

`Client` and `AuthenticatedClient` now reuse an internal [`httpx.Client`](https://www.python-httpx.org/advanced/#client-instances) (or `AsyncClient`)—keeping connections open between requests. This will improve performance overall, but may cause resource leaking if clients are not closed properly. The new clients are intended to be used via context managers—though for compatibility they don't _have_ to be used with context managers. If not using a context manager, connections will probably leak. Note that once a client is closed (by leaving the context manager), it can no longer be used—and attempting to do so will raise an exception.

APIs should now be called like:

python
with client as client:
my_api.sync(client)
another_api.sync(client)
client is closed here and can no longer be used


Generated READMEs reflect the new syntax, but READMEs for existing generated clients should be updated manually. See [this diff](https://github.com/openapi-generators/openapi-python-client/pull/775/files#diff-62b50316369f84439d58f4981c37538f5b619d344393cb659080dadbda328547) for inspiration.

Generated clients and models now use the newer attrs `define` and `field` APIs

See [the attrs docs](https://www.attrs.org/en/stable/names.html#attrs-tng) for more information on how these may affect you.

Removed public attributes for `Client` and `AuthenticatedClient`

The following attributes have been removed from `Client` and `AuthenticatedClient`:

- `base_url`—this can now only be set via the initializer
- `cookies`—set at initialization or use `.with_cookies()`
- `headers`—set at initialization or use `.with_headers()`
- `timeout`—set at initialization or use `.with_timeout()`
- `verify_ssl`—this can now only be set via the initializer
- `follow_redirects`—this can now only be set via the initializer

The `timeout` param and `with_timeout` now take an `httpx.Timeout` instead of a float

`AuthenticatedClient` no longer inherits from `Client`

The API of `AuthenticatedClient` is still a superset of `Client`, but the two classes no longer share a common base class.

Features

Allow customizing the underlying `httpx` clients

There are many use-cases where customizing the underlying `httpx` client directly is necessary. Some examples are:

- [Event hooks](https://www.python-httpx.org/advanced/#event-hooks)
- [Proxies](https://www.python-httpx.org/advanced/#http-proxying)
- [Custom authentication](https://www.python-httpx.org/advanced/#customizing-authentication)
- [Retries](https://www.python-httpx.org/advanced/#usage_1)

The new `Client` and `AuthenticatedClient` classes come with several methods to customize underlying clients. You can pass arbitrary arguments to `httpx.Client` or `httpx.AsyncClient` when they are constructed:

python
client = Client(base_url="https://api.example.com", httpx_args={"proxies": {"https://": "https://proxy.example.com"}})


**The underlying clients are constructed lazily, only when needed. `httpx_args` are stored internally in a dictionary until the first request is made.**

You can force immediate construction of an underlying client in order to edit it directly:

python
import httpx
from my_api import Client

client = Client(base_url="https://api.example.com")
sync_client: httpx.Client = client.get_httpx_client()
sync_client.timeout = 10
async_client = client.get_async_httpx_client()
async_client.timeout = 15


You can also completely override the underlying clients:

python
import httpx
from my_api import Client

client = Client(base_url="https://api.example.com")
The params you put in here ^ are discarded when you call set_httpx_client or set_async_httpx_client
sync_client = httpx.Client(base_url="https://api.example.com", timeout=10)
client.set_httpx_client(sync_client)
async_client = httpx.AsyncClient(base_url="https://api.example.com", timeout=15)
client.set_async_httpx_client(async_client)


Clients now reuse connections between requests

This happens every time you use the same `Client` or `AuthenticatedClient` instance for multiple requests, however it is best to use a context manager (e.g., `with client as client:`) to ensure the client is closed properly.

Fixes

Stop showing Poetry instructions in generated READMEs when not appropriate

0.20.0

Breaking Changes

`const` values in responses are now validated at runtime

Prior to this version, `const` values returned from servers were assumed to always be correct. Now, if a server returns
an unexpected value, the client will raise a `ValueError`. This should enable better usage with `oneOf`.

PR 1024. Thanks peter-greenatlas!

0.19.1

Features

Add config option to override content types

You can now define a `content_type_overrides` field in your `config.yml`:

yaml
content_type_overrides:
application/zip: application/octet-stream


This allows `openapi-python-client` to generate code for content types it doesn't recognize.

PR 1010 closes 810. Thanks gaarutyunov!

Fixes

Add aliases to `Client` for pyright

This should resolve incompatibilities between the generated `Client` class and the pyright type checker.

PR 1009 closes 909. Thanks patrick91!

0.19.0

Breaking Changes

Update PDM metadata syntax

Metadata generated for PDM will now use the new `distribution = true` syntax instead of `package-type = "library"`.
New packages generated with `--meta pdm` will require PDM `2.12.0` or later to build.

Features

Add response content to `UnexpectedStatus` exception

The error message for `UnexpectedStatus` exceptions will now include the UTF-8 decoded (ignoring errors) body of the response.

PR 989 implements 840. Thanks harabat!

Fixes

Allow hyphens in path parameters

Before now, path parameters which were invalid Python identifiers were not allowed, and would fail generation with an
"Incorrect path templating" error. In particular, this meant that path parameters with hyphens were not allowed.
This has now been fixed!

PR 986 fixed issue 976. Thanks harabat!

> [!WARNING]
> This change may break custom templates, see [this diff](https://github.com/openapi-generators/openapi-python-client/pull/986/files#diff-0de8437b26075d8fe8454cf47d8d95d4835c7f827fa87328e03f690412be803e)
> if you have trouble upgrading.

Page 1 of 12

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.