Skip to content

Rebase #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: prod/2.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 44 additions & 9 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ jobs:
test:
strategy:
matrix:
python: [ "3.8", "3.9", "3.10", "3.11", "3.12", "3.13" ]
python: [ "3.9", "3.10", "3.11", "3.12", "3.13" ]
os: [ ubuntu-latest, macos-latest, windows-latest ]
runs-on: ${{ matrix.os }}
steps:
@@ -51,27 +51,62 @@ jobs:
- name: Run pytest without coverage
if: matrix.os != 'ubuntu-latest'
run: pdm test
env:
TASKIPY: true

- name: Run pytest with coverage
if: matrix.os == 'ubuntu-latest'
run: pdm test_with_coverage
env:
TASKIPY: true


- run: mv .coverage .coverage.${{ matrix.python }}
if: matrix.os == 'ubuntu-latest'

- name: Store coverage report
uses: actions/upload-artifact@v4.4.3
uses: actions/upload-artifact@v4.5.0
if: matrix.os == 'ubuntu-latest'
with:
name: coverage-${{ matrix.python }}
path: .coverage.${{ matrix.python }}
if-no-files-found: error
include-hidden-files: true

test_min_deps:
strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/[email protected]
- name: Set up Python
uses: actions/[email protected]
with:
python-version: "3.9"

- name: Get Python Version
id: get_python_version
run: echo "python_version=$(python --version)" >> $GITHUB_OUTPUT
shell: bash

- name: Cache dependencies
uses: actions/cache@v4
with:
path: .venv
key: ${{ runner.os }}-${{ steps.get_python_version.outputs.python_version }}-min-dependencies-${{ hashFiles('**/pdm.lock') }}
restore-keys: |
${{ runner.os }}-${{ steps.get_python_version.outputs.python_version }}-min-dependencies
- name: Install PDM
run: pip install pdm

- name: Install minimum dependencies
run: pdm install -L pdm.minimal.lock

- name: Run mypy
run: pdm mypy --show-error-codes

- name: Lint
run: pdm run ruff check .

- name: Run unit tests only # snapshots are expected to fail
run: pdm unit_test

coverage:
name: Combine & check coverage
needs: test
@@ -107,7 +142,7 @@ jobs:
.venv/bin/python -m coverage report --fail-under=100

- name: Upload HTML report if check failed.
uses: actions/upload-artifact@v4.4.3
uses: actions/upload-artifact@v4.5.0
with:
name: html-report
path: htmlcov
@@ -131,7 +166,7 @@ jobs:
- name: Set up Python
uses: actions/[email protected]
with:
python-version: "3.8"
python-version: "3.9"
- name: Get Python Version
id: get_python_version
run: echo "python_version=$(python --version)" >> $GITHUB_OUTPUT
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -18,6 +18,6 @@ jobs:
- name: Build
run: hatchling build
- name: Push to PyPI
uses: pypa/gh-action-pypi-publish@v1.10.3
uses: pypa/gh-action-pypi-publish@v1.12.3
with:
attestations: true
66 changes: 66 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -13,6 +13,72 @@ Programmatic usage of this project (e.g., importing it as a Python module) and t

The 0.x prefix used in versions for this project is to indicate that breaking changes are expected frequently (several times a year). Breaking changes will increment the minor number, all other changes will increment the patch number. You can track the progress toward 1.0 [here](https://github.com/openapi-generators/openapi-python-client/projects/2).

## 0.23.0 (2024-12-24)

### Breaking Changes

#### Delete fewer files with `--overwrite`

`--overwrite` will no longer delete the entire output directory before regenerating. Instead, it will only delete
specific, known directories within that directory. Right now, that is only the generated `models` and `api` directories.

Other generated files, like `README.md`, will be overwritten. Extra files and directories outside of those listed above
will be left untouched, so you can any extra modules or files around while still updating `pyproject.toml` automatically.

Closes #1105.

### Features

- Support httpx 0.28 (#1172)

#### Add `generate_all_tags` config option

You can now, optionally, generate **duplicate** endpoint functions/modules using _every_ tag for an endpoint,
not just the first one, by setting `generate_all_tags: true` in your configuration file.

### Fixes

- Support Typer 0.14 and 0.15 (#1173)

#### Fix minimum `attrs` version

The minimum `attrs` dependency version was incorrectly set to 21.3.0. This has been corrected to 22.2.0, the minimum
supported version since `openapi-python-client` 0.19.1.

Closes #1084, thanks @astralblue!

#### Fix compatibility with Pydantic 2.10+

##1176 by @Viicos

Set `defer_build` to models that we know will fail to build, and call `model_rebuild`
in the `__init__.py` file.

## 0.22.0 (2024-11-23)

### Breaking Changes

#### Drop support for Python 3.8

Python 3.8 is no longer supported. "New" 3.9 syntax, like generics on builtin collections, is used both in the generator
and the generated code.

#### `type` is now a reserved field name

Because `type` is used in type annotations now, it is no longer a valid field name. Fields which were previously named
`type` will be renamed to `type_`.

### Features

- Support Ruff 0.8 (#1169)

## 0.21.7 (2024-10-28)

### Fixes

- allow required fields list to be specified as empty (#651) (#1149)
- import cast for required const properties, since it's used in the template (#1153)

## 0.21.6 (2024-10-20)

### Features
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ To request a feature:
### Setting up a Dev Environment

1. Make sure you have [PDM](https://pdm-project.org) installed and up to date.
2. Make sure you have a supported Python version (e.g. 3.8) installed.
2. Make sure you have a supported Python version (e.g. 3.13) installed.
3. Use `pdm install` in the project directory to create a virtual environment with the relevant dependencies.

### Writing tests
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -108,6 +108,16 @@ literal_enums: true

This is especially useful if enum values, when transformed to their Python names, end up conflicting due to case sensitivity or special symbols.

### generate_all_tags

`openapi-python-client` generates module names within the `api` module based on the OpenAPI `tags` of each endpoint.
By default, only the _first_ tag is generated. If you want to generate **duplicate** endpoint functions using _every_ tag
listed, you can enable this option:

```yaml
generate_all_tags: true
```

### project_name_override and package_name_override

Used to change the name of generated client library project/package. If the project name is changed but an override for the package name
14 changes: 14 additions & 0 deletions end_to_end_tests/__snapshots__/test_end_to_end.ambr
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
# serializer version: 1
# name: test_documents_with_errors[bad-status-code]
'''
Generating /test-documents-with-errors
Warning(s) encountered while generating. Client was generated, but some pieces may be missing

WARNING parsing GET / within default.

Invalid response status code abcdef (not a valid HTTP status code), response will be omitted from generated client


If you believe this was a mistake or this tool is missing a feature you need, please open an issue at https://github.com/openapi-generators/openapi-python-client/issues/new/choose

'''
# ---
# name: test_documents_with_errors[circular-body-ref]
'''
Generating /test-documents-with-errors
4 changes: 1 addition & 3 deletions end_to_end_tests/baseline_openapi_3.0.json
Original file line number Diff line number Diff line change
@@ -1149,9 +1149,7 @@
},
"/tag_with_number": {
"get": {
"tags": [
"1"
],
"tags": ["1", "2"],
"responses": {
"200": {
"description": "Success"
4 changes: 1 addition & 3 deletions end_to_end_tests/baseline_openapi_3.1.yaml
Original file line number Diff line number Diff line change
@@ -1141,9 +1141,7 @@ info:
},
"/tag_with_number": {
"get": {
"tags": [
"1"
],
"tags": ["1", "2"],
"responses": {
"200": {
"description": "Success"
1 change: 1 addition & 0 deletions end_to_end_tests/config.yml
Original file line number Diff line number Diff line change
@@ -11,3 +11,4 @@ class_overrides:
field_prefix: attr_
content_type_overrides:
openapi/python/client: application/json
generate_all_tags: true
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Contains methods for accessing the API"""

from typing import Type

from .bodies import BodiesEndpoints
from .config import ConfigEndpoints
from .default import DefaultEndpoints
@@ -13,59 +11,64 @@
from .parameters import ParametersEndpoints
from .responses import ResponsesEndpoints
from .tag1 import Tag1Endpoints
from .tag2 import Tag2Endpoints
from .tests import TestsEndpoints
from .true_ import True_Endpoints


class MyTestApiClientApi:
@classmethod
def bodies(cls) -> Type[BodiesEndpoints]:
def bodies(cls) -> type[BodiesEndpoints]:
return BodiesEndpoints

@classmethod
def tests(cls) -> Type[TestsEndpoints]:
def tests(cls) -> type[TestsEndpoints]:
return TestsEndpoints

@classmethod
def defaults(cls) -> Type[DefaultsEndpoints]:
def defaults(cls) -> type[DefaultsEndpoints]:
return DefaultsEndpoints

@classmethod
def enums(cls) -> Type[EnumsEndpoints]:
def enums(cls) -> type[EnumsEndpoints]:
return EnumsEndpoints

@classmethod
def responses(cls) -> Type[ResponsesEndpoints]:
def responses(cls) -> type[ResponsesEndpoints]:
return ResponsesEndpoints

@classmethod
def default(cls) -> Type[DefaultEndpoints]:
def default(cls) -> type[DefaultEndpoints]:
return DefaultEndpoints

@classmethod
def parameters(cls) -> Type[ParametersEndpoints]:
def parameters(cls) -> type[ParametersEndpoints]:
return ParametersEndpoints

@classmethod
def tag1(cls) -> Type[Tag1Endpoints]:
def tag1(cls) -> type[Tag1Endpoints]:
return Tag1Endpoints

@classmethod
def location(cls) -> Type[LocationEndpoints]:
def tag2(cls) -> type[Tag2Endpoints]:
return Tag2Endpoints

@classmethod
def location(cls) -> type[LocationEndpoints]:
return LocationEndpoints

@classmethod
def true_(cls) -> Type[True_Endpoints]:
def true_(cls) -> type[True_Endpoints]:
return True_Endpoints

@classmethod
def naming(cls) -> Type[NamingEndpoints]:
def naming(cls) -> type[NamingEndpoints]:
return NamingEndpoints

@classmethod
def parameter_references(cls) -> Type[ParameterReferencesEndpoints]:
def parameter_references(cls) -> type[ParameterReferencesEndpoints]:
return ParameterReferencesEndpoints

@classmethod
def config(cls) -> Type[ConfigEndpoints]:
def config(cls) -> type[ConfigEndpoints]:
return ConfigEndpoints
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""Contains methods for accessing the API Endpoints"""

import types

from . import get_tag_with_number


class Tag2Endpoints:
@classmethod
def get_tag_with_number(cls) -> types.ModuleType:
return get_tag_with_number
14 changes: 14 additions & 0 deletions end_to_end_tests/documents_with_errors/bad-status-code.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
openapi: "3.1.0"
info:
title: "There's something wrong with me"
version: "0.1.0"
paths:
"/":
get:
responses:
"abcdef":
description: "Successful Response"
content:
"application/json":
schema:
const: "Why have a fixed response? I dunno"
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from http import HTTPStatus
from typing import Any, Dict, Optional, Union
from typing import Any, Optional, Union

import httpx

@@ -12,10 +12,10 @@
def _get_kwargs(
*,
body: JsonLikeBody,
) -> Dict[str, Any]:
headers: Dict[str, Any] = {}
) -> dict[str, Any]:
headers: dict[str, Any] = {}

_kwargs: Dict[str, Any] = {
_kwargs: dict[str, Any] = {
"method": "post",
"url": "/bodies/json-like",
}
Loading