Skip to content

Commit 579f3a6

Browse files
committed
Merge branch 'main' into support-multiple-bodies
# Conflicts: # tests/test_parser/test_properties/test_init.py
2 parents 15b2c5d + 3253448 commit 579f3a6

File tree

155 files changed

+13848
-2449
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+13848
-2449
lines changed

.changeset/openapi_31_support.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
default: minor
3+
---
4+
5+
# OpenAPI 3.1 support
6+
7+
The generator will now attempt to generate code for OpenAPI documents with versions 3.1.x (previously, it would exit immediately on seeing a version other than 3.0.x). The following specific OpenAPI 3.1 features are now supported:
8+
9+
- `null` as a type
10+
- Arrays of types (e.g., `type: [string, null]`)
11+
- `const` (defines `Literal` types)
12+
13+
The generator does not currently validate that the OpenAPI document is valid for a specific version of OpenAPI, so it may be possible to generate code for documents that include both removed 3.0 syntax (e.g., `nullable`) and new 3.1 syntax (e.g., `null` as a type).
14+
15+
Thanks to everyone who helped make this possible with discussions and testing, including:
16+
17+
- @frco9
18+
- @vogre
19+
- @naddeoa
20+
- @staticdev
21+
- @philsturgeon
22+
- @johnthagen
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
default: major
3+
---
4+
5+
# Removed query parameter nullable/required special case
6+
7+
In previous versions, setting _either_ `nullable: true` or `required: false` on a query parameter would act like both were set, resulting in a type signature like `Union[None, Unset, YourType]`. This special case has been removed, query parameters will now act like all other types of parameters.

.github/sponsors/fern.png

-6.08 KB
Binary file not shown.

.github/workflows/checks.yml

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,33 +57,69 @@ jobs:
5757
- name: Lint
5858
run: poetry run ruff check .
5959

60-
- name: Run pytest
61-
run: poetry run pytest --cov=openapi_python_client --cov-report=term-missing tests end_to_end_tests/test_end_to_end.py --basetemp=tests/tmp
60+
- name: Run pytest without coverage
61+
if: matrix.os != 'ubuntu-latest'
62+
run: poetry run pytest tests end_to_end_tests/test_end_to_end.py --basetemp=tests/tmp
6263
env:
6364
TASKIPY: true
6465

65-
- name: Generate coverage report
66-
shell: bash
67-
run: poetry run coverage xml -o coverage-${{ matrix.os }}-${{ matrix.python }}.xml
66+
- name: Run pytest with coverage
67+
if: matrix.os == 'ubuntu-latest'
68+
run: poetry run pytest --cov=openapi_python_client --cov-report=term-missing tests end_to_end_tests/test_end_to_end.py --basetemp=tests/tmp
69+
env:
70+
TASKIPY: true
71+
72+
- run: mv .coverage .coverage.${{ matrix.python }}
73+
if: matrix.os == 'ubuntu-latest'
6874

6975
- name: Store coverage report
7076
uses: actions/[email protected]
77+
if: matrix.os == 'ubuntu-latest'
7178
with:
72-
name: coverage-${{ matrix.os }}-${{ matrix.python }}
73-
path: coverage-${{ matrix.os }}-${{ matrix.python }}.xml
79+
name: coverage-${{ matrix.python }}
80+
path: .coverage.${{ matrix.python }}
81+
if-no-files-found: error
7482

75-
upload_coverage:
83+
coverage:
84+
name: Combine & check coverage
7685
needs: test
7786
runs-on: ubuntu-latest
7887
steps:
7988
- uses: actions/[email protected]
89+
- uses: actions/setup-python@v5
90+
with:
91+
python-version: "3.12"
8092
- name: Download coverage reports
81-
uses: actions/download-artifact@v4.0.0
93+
uses: actions/download-artifact@v4.1.0
8294
with:
83-
path: coverage-report
84-
- uses: codecov/[email protected]
95+
merge-multiple: true
96+
97+
- name: Create Virtual Environment
98+
run: python -m venv .venv
99+
100+
- name: Combine coverage & fail if it's <100%.
101+
run: |
102+
# Install coverage
103+
.venv/bin/pip install --upgrade coverage[toml]
104+
105+
# Find all of the downloaded coverage reports and combine them
106+
.venv/bin/python -m coverage combine
107+
108+
# Create html report
109+
.venv/bin/python -m coverage html --skip-covered --skip-empty
110+
111+
# Report in Markdown and write to summary.
112+
.venv/bin/python -m coverage report --format=markdown >> $GITHUB_STEP_SUMMARY
113+
114+
# Report again and fail if under 100%.
115+
.venv/bin/python -m coverage report --fail-under=100
116+
117+
- name: Upload HTML report if check failed.
118+
uses: actions/[email protected]
85119
with:
86-
files: "coverage-report/**/*.xml"
120+
name: html-report
121+
path: htmlcov
122+
if: ${{ failure() }}
87123

88124
integration:
89125
name: Integration Tests

.github/workflows/preview_release_pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
git config user.email [email protected]
1818
- uses: knope-dev/[email protected]
1919
with:
20-
version: 0.13.2
20+
version: 0.13.3
2121
- run: knope prepare-release --verbose
2222
env:
2323
GITHUB_TOKEN: ${{ secrets.PAT }}

.github/workflows/release-dry-run.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ jobs:
1313
- name: Install Knope
1414
uses: knope-dev/[email protected]
1515
with:
16-
version: 0.13.2
16+
version: 0.13.3
1717
- run: knope prepare-release --dry-run

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Install Knope
1818
uses: knope-dev/[email protected]
1919
with:
20-
version: 0.13.2
20+
version: 0.13.3
2121
- name: Install Poetry
2222
run: pip install --upgrade poetry
2323
- name: Push to PyPI

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ htmlcov/
2727

2828
# Generated end to end test data
2929
my-test-api-client/
30-
custom-e2e/
30+
custom-e2e/
31+
3-1-features-client

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ Programmatic usage of this project (e.g., importing it as a Python module) and t
1313

1414
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).
1515

16+
## 0.16.1 (2023-12-23)
17+
18+
### Features
19+
20+
#### Support httpx 0.26 (#913)
21+
1622
## 0.16.0 (2023-12-07)
1723

1824
### Breaking Changes

CONTRIBUTING.md

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ A bug is one of:
1212
2. The generated code is invalid or incorrect
1313
3. An error message is unclear or incorrect
1414
4. Something which used to work no longer works, except:
15-
1. Intentional breaking changes, which are documented in the [changelog](https://github.com/openapi-generators/openapi-python-client/blob/main/CHANGELOG.md)
16-
2. Breaking changes to unstable features, like custom templates
15+
1. Intentional breaking changes, which are documented in the [changelog](https://github.com/openapi-generators/openapi-python-client/blob/main/CHANGELOG.md)
16+
2. Breaking changes to unstable features, like custom templates
1717

1818
If your issue does not fall under one of the above, it is not a bug; check out "[Requesting a feature](#requesting-a-feature).
1919

@@ -27,14 +27,14 @@ A feature is usually:
2727

2828
1. An improvement to the way the generated code works
2929
2. A feature of the generator itself which makes its use easier (e.g., a new config option)
30-
3. **Support for part of the OpenAPI spec**; this generate _does not yet_ support every OpenAPI feature, these missing features **are not bugs**.
30+
3. **Support for part of the OpenAPI spec**; this generator _does not yet_ support every OpenAPI feature, these missing features **are not bugs**.
3131

3232
To request a feature:
3333

3434
1. Search through [discussions](https://github.com/openapi-generators/openapi-python-client/discussions/categories/feature-request) to see if the feature you want has already been requested. If it has:
35-
1. Upvote it with the little arrow on the original post. This enables code contributors to prioritize the most-demanded features.
36-
2. Optionally leave a comment describing why _you_ want the feature, if no existing thread already covers your use-case
37-
3. If a relevant discussion does not already exist, create a new one. If you are not requesting support for part of the OpenAPI spec, **you must** describe _why_ you want the feature. What real-world use-case does it improve? For example, "raise exceptions for invalid responses" might have a description of "it's not worth the effort to check every error case by hand for the one-off scripts I'm writing".
35+
1. Upvote it with the little arrow on the original post. This enables code contributors to prioritize the most-demanded features.
36+
2. Optionally leave a comment describing why _you_ want the feature, if no existing thread already covers your use-case
37+
2. If a relevant discussion does not already exist, create a new one. If you are not requesting support for part of the OpenAPI spec, **you must** describe _why_ you want the feature. What real-world use-case does it improve? For example, "raise exceptions for invalid responses" might have a description of "it's not worth the effort to check every error case by hand for the one-off scripts I'm writing".
3838

3939
## Contributing Code
4040

@@ -45,36 +45,41 @@ To request a feature:
4545
3. Use `poetry install` in the project directory to create a virtual environment with the relevant dependencies.
4646
4. Enter a `poetry shell` to make running commands easier.
4747

48-
### Writing Code
48+
### Writing tests
4949

50-
1. Write some code and make sure it's covered by unit tests. All unit tests are in the `tests` directory and the file structure should mirror the structure of the source code in the `openapi_python_client` directory.
50+
All changes must be tested, I recommend writing the test first, then writing the code to make it pass. 100% code coverage is enforced in CI, a check will fail in GitHub if your code does not have 100% coverage. An HTML report will be added to the test artifacts in this case to help you locate missed lines.
5151

52-
#### Run Checks and Tests
52+
If you think that some of the added code is not testable (or testing it would add little value), mention that in your PR and we can discuss it.
5353

54-
2. When in a Poetry shell (`poetry shell`) run `task check` in order to run most of the same checks CI runs. This will auto-reformat the code, check type annotations, run unit tests, check code coverage, and lint the code.
54+
1. If you're adding support for a new OpenAPI feature or covering a new edge case, add an [end-to-end test](#end-to-end-tests)
55+
2. If you're modifying the way an existing feature works, make sure an existing test generates the _old_ code in `end_to_end_tests/golden-record`. You'll use this to check for the new code once your changes are complete.
56+
3. If you're improving an error or adding a new error, add a [unit test](#unit-tests)
5557

56-
#### Rework end-to-end tests
58+
#### End-to-end tests
5759

58-
3. If you're writing a new feature, try to add it to the end-to-end test.
59-
1. If adding support for a new OpenAPI feature, add it somewhere in `end_to_end_tests/openapi.json`
60-
2. Regenerate the "golden records" with `task regen`. This client is generated from the OpenAPI document used for end-to-end testing.
61-
3. Check the changes to `end_to_end_tests/golden-record` to confirm only what you intended to change did change and that the changes look correct.
62-
4. **If you added a test above OR modified the templates**: Run the end-to-end tests with `task e2e`. This will generate clients against `end_to_end_tests/openapi.json` and compare them with the golden record. The tests will fail if **anything is different**. The end-to-end tests are not included in `task check` as they take longer to run and don't provide very useful feedback in the event of failure. If an e2e test does fail, the easiest way to check what's wrong is to run `task regen` and check the diffs. You can also use `task re` which will run `regen` and `e2e` in that order.
60+
This project aims to have all "happy paths" (types of code which _can_ be generated) covered by end to end tests (snapshot tests). In order to check code changes against the previous set of snapshots (called a "golden record" here), you can run `poetry run task e2e`. To regenerate the snapshots, run `poetry run task regen`.
6361

62+
There are 4 types of snapshots generated right now, you may have to update only some or all of these depending on the changes you're making. Within the `end_to_end_tets` directory:
6463

65-
### Creating a Pull Request
64+
1. `baseline_openapi_3.0.json` creates `golden-record` for testing OpenAPI 3.0 features
65+
2. `baseline_openapi_3.1.yaml` is checked against `golden-record` for testing OpenAPI 3.1 features (and ensuring consistency with 3.0)
66+
3. `test_custom_templates` are used with `baseline_openapi_3.0.json` to generate `custom-templates-golden-record` for testing custom templates
67+
4. `3.1_specific.openapi.yaml` is used to generate `test-3-1-golden-record` and test 3.1-specific features (things which do not have a 3.0 equivalent)
68+
69+
#### Unit tests
6670

67-
Once you've written the code and run the checks, the next step is to create a pull request against the `main` branch of this repository. This repository uses [conventional commits] squashed on each PR, then uses [Knope] to auto-generate CHANGELOG.md entries for release. So the title of your PR should be in the format of a conventional commit written in plain english as it will end up in the CHANGELOG. Some example PR titles:
71+
> **NOTE**: Several older-style unit tests using mocks exist in this project. These should be phased out rather than updated, as the tests are brittle and difficult to maintain. Only error cases should be tests with unit tests going forward.
6872
69-
- feat: Support for `allOf` in OpenAPI documents (closes #123).
70-
- refactor!: Removed support for Python 3.5
71-
- fix: Data can now be passed to multipart bodies along with files.
73+
In some cases, we need to test things which cannot be generated—like validating that errors are caught and handled correctly. These should be tested via unit tests in the `tests` directory, using the `pytest` framework.
74+
75+
### Creating a Pull Request
7276

73-
Once your PR is created, a series of automated checks should run. If any of them fail, try your best to fix them.
77+
Once you've written the tests and code and run the checks, the next step is to create a pull request against the `main` branch of this repository. This repository uses [Knope] to auto-generate release notes and version numbers. This can either be done by setting the title of the PR to a [conventional commit] (for simple changes) or by adding [changesets]. If the changes are not documented yet, a check will fail on GitHub. The details of this check will have suggestions for documenting the change (including an example change file for changesets).
7478

7579
### Wait for Review
7680

7781
As soon as possible, your PR will be reviewed. If there are any changes requested there will likely be a bit of back and forth. Once this process is done, your changes will be merged into main and included in the next release. If you need your changes available on PyPI by a certain time, please mention it in the PR, and we'll do our best to accommodate.
7882

79-
[Conventional Commits]: https://www.conventionalcommits.org/en/v1.0.0/
80-
[Knope]: https://knope-dev.github.io/knope/
83+
[Knope]: https://knope.tech
84+
[changesets]: https://knope.tech/reference/concepts/changeset/
85+
[Conventional Commits]: https://knope.tech/reference/concepts/conventional-commits/

0 commit comments

Comments
 (0)