You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
# 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.
Copy file name to clipboardExpand all lines: CHANGELOG.md
+6Lines changed: 6 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,12 @@ Programmatic usage of this project (e.g., importing it as a Python module) and t
13
13
14
14
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).
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+29-24Lines changed: 29 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -12,8 +12,8 @@ A bug is one of:
12
12
2. The generated code is invalid or incorrect
13
13
3. An error message is unclear or incorrect
14
14
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
17
17
18
18
If your issue does not fall under one of the above, it is not a bug; check out "[Requesting a feature](#requesting-a-feature).
19
19
@@ -27,14 +27,14 @@ A feature is usually:
27
27
28
28
1. An improvement to the way the generated code works
29
29
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**.
31
31
32
32
To request a feature:
33
33
34
34
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".
38
38
39
39
## Contributing Code
40
40
@@ -45,36 +45,41 @@ To request a feature:
45
45
3. Use `poetry install` in the project directory to create a virtual environment with the relevant dependencies.
46
46
4. Enter a `poetry shell` to make running commands easier.
47
47
48
-
### Writing Code
48
+
### Writing tests
49
49
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.
51
51
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.
53
53
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)
55
57
56
-
#### Rework end-to-end tests
58
+
#### End-to-end tests
57
59
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`.
63
61
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:
64
63
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
66
70
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.
68
72
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
72
76
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).
74
78
75
79
### Wait for Review
76
80
77
81
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.
Copy file name to clipboardExpand all lines: README.md
+9-22Lines changed: 9 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@
7
7
8
8
# openapi-python-client
9
9
10
-
Generate modern Python clients from OpenAPI 3.x documents.
10
+
Generate modern Python clients from OpenAPI 3.0 and 3.1 documents.
11
11
12
12
_This generator does not support OpenAPI 2.x FKA Swagger. If you need to use an older document, try upgrading it to
13
13
version 3 first with one of many available converters._
@@ -22,10 +22,6 @@ This tool focuses on creating the best developer experience for Python developer
22
22
2. Having documentation and usage instructions specific to this one generator.
23
23
3. Being written in Python with Jinja2 templates, making it easier to improve and extend for Python developers. It's also much easier to install and use if you already have Python.
24
24
25
-
## Sponsors
26
-
27
-
<ahref="https://www.devmark.ai/fern/?utm_source=openapi-python-client&utm_loc=readme&utm_type=logo"target="_blank"title="Fern | SDKs and API docs"><imgsrc="https://raw.githubusercontent.com/openapi-generators/openapi-python-client/main/.github/sponsors/fern.png"></a>
28
-
29
25
## Installation
30
26
31
27
I recommend you install with [pipx](https://pipxproject.github.io/pipx/) so you don't conflict with any other packages you might have: `pipx install openapi-python-client --include-deps`.
@@ -73,25 +69,16 @@ _Be forewarned, this is a beta-level feature in the sense that the API exposed i
73
69
## What You Get
74
70
75
71
1. A `pyproject.toml` file with some basic metadata intended to be used with [Poetry].
76
-
1. A `README.md` you'll most definitely need to update with your project's details
77
-
1. A Python module named just like the auto-generated project name (e.g. "my_api_client") which contains:
72
+
2. A `README.md` you'll most definitely need to update with your project's details
73
+
3. A Python module named just like the auto-generated project name (e.g. "my_api_client") which contains:
78
74
1. A `client` module which will have both a `Client` class and an `AuthenticatedClient` class. You'll need these
79
75
for calling the functions in the `api` module.
80
-
1. An `api` module which will contain one module for each tag in your OpenAPI spec, as well as a `default` module
76
+
2. An `api` module which will contain one module for each tag in your OpenAPI spec, as well as a `default` module
81
77
for endpoints without a tag. Each of these modules in turn contains one function for calling each endpoint.
82
-
1. A `models` module which has all the classes defined by the various schemas in your OpenAPI spec
83
-
84
-
For a full example you can look at the `end_to_end_tests` directory which has an `openapi.json` file.
85
-
"golden-record" in that same directory is the generated client from that OpenAPI document.
86
-
87
-
## OpenAPI features supported
78
+
3. A `models` module which has all the classes defined by the various schemas in your OpenAPI spec
88
79
89
-
1. All HTTP Methods
90
-
1. JSON and form bodies, path and query parameters
91
-
1. File uploads with multipart/form-data bodies
92
-
1. float, string, int, date, datetime, string enums, and custom schemas or lists containing any of those
93
-
1. html/text or application/json responses containing any of the previous types
94
-
1. Bearer token security
80
+
For a full example you can look at the `end_to_end_tests` directory which has `baseline_openapi_3.0.json` and `baseline_openapi_3.1.yaml` files.
81
+
The "golden-record" in that same directory is the generated client from either of those OpenAPI documents.
95
82
96
83
## Configuration
97
84
@@ -102,7 +89,7 @@ The following parameters are supported:
102
89
103
90
Used to change the name of generated model classes. This param should be a mapping of existing class name
104
91
(usually a key in the "schemas" section of your OpenAPI document) to class_name and module_name. As an example, if the
105
-
name of the a model in OpenAPI (and therefore the generated class name) was something like "\_PrivateInternalLongName"
92
+
name of a model in OpenAPI (and therefore the generated class name) was something like "_PrivateInternalLongName"
106
93
and you want the generated client's model to be called "ShortName" in a module called "short_name" you could do this:
107
94
108
95
Example:
@@ -114,7 +101,7 @@ class_overrides:
114
101
module_name: short_name
115
102
```
116
103
117
-
The easiest way to find what needs to be overridden is probably to generate your client and go look at everything in the models folder.
104
+
The easiest way to find what needs to be overridden is probably to generate your client and go look at everything in the `models` folder.
118
105
119
106
### project_name_override and package_name_override
0 commit comments