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: CONTRIBUTING.md
+29-24
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.
0 commit comments