diff --git a/.changeset/const_values_are_now_validated_at_runtime.md b/.changeset/const_values_are_now_validated_at_runtime.md deleted file mode 100644 index 0987d18ce..000000000 --- a/.changeset/const_values_are_now_validated_at_runtime.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -default: major ---- - -# `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! diff --git a/.github/renovate.json b/.github/renovate.json index d0cc4a064..a41a99a8f 100644 --- a/.github/renovate.json +++ b/.github/renovate.json @@ -1,10 +1,12 @@ { "extends": [ - "config:base", - ":semanticCommitTypeAll(chore)" + "config:recommended", + ":semanticCommitTypeAll(chore)", + "helpers:pinGitHubActionDigestsToSemver" ], "rangeStrategy": "widen", "lockFileMaintenance": { "enabled": true, "automerge": true }, + "minimumReleaseAge": "7 days", "regexManagers": [ { "fileMatch": [ diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 0bc039feb..948d11c65 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -11,13 +11,13 @@ jobs: test: strategy: matrix: - python: [ "3.8", "3.9", "3.10", "3.11", "3.12" ] + python: [ "3.11", "3.12", "3.13", "3.14" ] os: [ ubuntu-latest, macos-latest, windows-latest ] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v4.1.3 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Set up Python - uses: actions/setup-python@v5.1.0 + uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 with: python-version: ${{ matrix.python }} @@ -27,7 +27,7 @@ jobs: shell: bash - name: Cache dependencies - uses: actions/cache@v4 + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: .venv key: ${{ runner.os }}-${{ steps.get_python_version.outputs.python_version }}-dependencies-${{ hashFiles('**/pdm.lock') }} @@ -37,14 +37,11 @@ jobs: run: pip install pdm - name: Install Dependencies - run: pdm install + run: pdm sync --clean - name: Check formatting run: pdm run ruff format . --check - - name: Run safety - run: pdm safety_check - - name: Run mypy run: pdm mypy --show-error-codes @@ -54,37 +51,70 @@ 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.3.3 + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 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/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - name: Set up Python + uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + with: + python-version: "3.11" + + - name: Get Python Version + id: get_python_version + run: echo "python_version=$(python --version)" >> $GITHUB_OUTPUT + shell: bash + + - name: Cache dependencies + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + 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 sync --clean -L pdm.minimal.lock + + - name: Run mypy + run: pdm mypy --show-error-codes + + - name: Run unit tests only # snapshots are expected to fail + run: pdm unit_test coverage: name: Combine & check coverage needs: test runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4.1.3 - - uses: actions/setup-python@v5 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7 with: python-version: "3.12" - name: Download coverage reports - uses: actions/download-artifact@v4.1.6 + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: merge-multiple: true @@ -98,18 +128,18 @@ jobs: # Find all of the downloaded coverage reports and combine them .venv/bin/python -m coverage combine - + # Create html report .venv/bin/python -m coverage html --skip-covered --skip-empty - + # Report in Markdown and write to summary. .venv/bin/python -m coverage report --format=markdown >> $GITHUB_STEP_SUMMARY - + # Report again and fail if under 100%. - .venv/bin/python -m coverage report --fail-under=100 + .venv/bin/python -m coverage report --fail-under=100 - name: Upload HTML report if check failed. - uses: actions/upload-artifact@v4.3.3 + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: html-report path: htmlcov @@ -120,51 +150,35 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - httpx_version: - - "0.20.0" - - "" + lockfile: + - "pdm.lock" + - "pdm.minimal.lock" services: openapi-test-server: - image: ghcr.io/openapi-generators/openapi-test-server:0.0.1 + image: ghcr.io/openapi-generators/openapi-test-server:0.2.1 ports: - "3000:3000" steps: - - uses: actions/checkout@v4.1.3 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Set up Python - uses: actions/setup-python@v5.1.0 + uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 with: - python-version: "3.8" + python-version: "3.11" - name: Get Python Version id: get_python_version run: echo "python_version=$(python --version)" >> $GITHUB_OUTPUT - - name: Cache dependencies - uses: actions/cache@v4 - with: - path: .venv - key: ${{ runner.os }}-${{ steps.get_python_version.outputs.python_version }}-dependencies-${{ hashFiles('**/pdm.lock') }} - restore-keys: | - ${{ runner.os }}-${{ steps.get_python_version.outputs.python_version }}-dependencies - - name: Install dependencies - run: | - pip install pdm - python -m venv .venv - pdm install - name: Cache Generated Client Dependencies - uses: actions/cache@v4 + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 with: path: integration-tests/.venv - key: ${{ runner.os }}-${{ steps.get_python_version.outputs.python_version }}-integration-dependencies-${{ hashFiles('**/pdm.lock') }} + key: ${{ runner.os }}-${{ steps.get_python_version.outputs.python_version }}-integration-dependencies-${{ hashFiles('integration-tests/pdm*.lock') }} restore-keys: | ${{ runner.os }}-${{ steps.get_python_version.outputs.python_version }}-integration-dependencies - - name: Set httpx version - if: matrix.httpx_version != '' - run: | - cd integration-tests - pdm add httpx==${{ matrix.httpx_version }} - name: Install Integration Dependencies run: | cd integration-tests - pdm install + pip install pdm + pdm sync --clean -L ${{ matrix.lockfile }} - name: Run Tests run: | cd integration-tests diff --git a/.github/workflows/fuzz.yml b/.github/workflows/fuzz.yml new file mode 100644 index 000000000..02e1be675 --- /dev/null +++ b/.github/workflows/fuzz.yml @@ -0,0 +1,33 @@ +name: Fuzz code generation + +permissions: + contents: read + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + schedule: + - cron: "23 8 * * *" + workflow_dispatch: + +jobs: + fuzz: + runs-on: ubuntu-latest + timeout-minutes: 20 + env: + OPENAPI_PYTHON_CLIENT_FUZZ_EXAMPLES: ${{ github.event_name == 'schedule' && '1000' || '100' }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - name: Set up Python + uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 + with: + python-version: "3.14" + cache: pip + - name: Install PDM + run: pip install pdm + - name: Install dependencies + run: pdm sync --clean + - name: Fuzz generated Python + run: pdm fuzz diff --git a/.github/workflows/preview_release_pr.yml b/.github/workflows/preview_release_pr.yml deleted file mode 100644 index 0a4edffef..000000000 --- a/.github/workflows/preview_release_pr.yml +++ /dev/null @@ -1,24 +0,0 @@ -on: - push: - branches: [main] -name: Create Release PR -jobs: - prepare-release: - if: "!contains(github.event.head_commit.message, 'chore: prepare release')" # Skip merges from releases - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4.1.3 - with: - fetch-depth: 0 - token: ${{ secrets.PAT }} - - name: Configure Git - run: | - git config --global user.name GitHub Actions - git config user.email github-actions@github.com - - uses: knope-dev/action@v2.1.0 - with: - version: 0.16.2 - - run: knope prepare-release --verbose - env: - GITHUB_TOKEN: ${{ secrets.PAT }} - continue-on-error: true diff --git a/.github/workflows/release-dry-run.yml b/.github/workflows/release-dry-run.yml deleted file mode 100644 index 0ba9806b0..000000000 --- a/.github/workflows/release-dry-run.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: Release Dry Run - -on: - pull_request: -jobs: - release: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4.1.3 - with: - fetch-depth: 0 - token: ${{ secrets.GITHUB_TOKEN }} - - name: Install Knope - uses: knope-dev/action@v2.1.0 - with: - version: 0.16.2 - - run: knope prepare-release --dry-run diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 576a5bded..163bb4ab5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,26 +7,17 @@ on: jobs: release: - if: github.head_ref == 'release' && github.event.pull_request.merged == true + if: github.head_ref == 'knope/release' && github.event.pull_request.merged == true runs-on: ubuntu-latest permissions: id-token: write steps: - - uses: actions/checkout@v4.1.3 - with: - fetch-depth: 0 - token: ${{ secrets.PAT }} - - name: Install Knope - uses: knope-dev/action@v2.1.0 - with: - version: 0.16.2 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Install Hatchling run: pip install --upgrade hatchling - name: Build run: hatchling build - name: Push to PyPI - uses: pypa/gh-action-pypi-publish@v1.8.14 - - name: Create GitHub Release - run: knope release - env: - GITHUB_TOKEN: ${{ secrets.PAT }} + uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2 + with: + attestations: true diff --git a/.gitignore b/.gitignore index 5689da19b..f7fcfaff6 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,9 @@ dmypy.json # JetBrains .idea/ +# Visual Studio Code +.vscode/ + test-reports/ /coverage.xml @@ -31,6 +34,5 @@ test-reports/ htmlcov/ # Generated end to end test data -my-test-api-client/ -custom-e2e/ -3-1-features-client \ No newline at end of file +tests/tmp +end_to_end_tests/tmp/* \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 18722b79d..449f5f0a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,642 @@ 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.29.1 (2026-08-30) + +### 🚨Security + +#### Arbitrary code generation vulnerability + +Prior to this release, malicious OpenAPI documents could cause openapi-python-client to generate arbitrary code, which +would then be executed by consumers of the generated client. + +If you generate code from OpenAPI documents you don't control, you should upgrade to this release as **soon as possible** +and validate any previously-generated code. + +See [the GitHub advisory](https://github.com/openapi-generators/openapi-python-client/security/advisories/GHSA-5293-mq8x-g3xj) for more details. + +### 🚀 Features + +- Update `uv_build` to 0.12 when using `--meta=uv` (#1473) + +### 🐛 Fixes + +- Apply PEP 639 for improved license metadata (#1459) +- update generated code to use `StrEnum` and `-> Self` (#1474) +- Remove trailing spaces in README example code (#1475) +- Stopped generating empty docstrings for models with no description + +#### Fixed invalid Python identifiers when resolving naming conflicts + +When two property or parameter names conflicted after conversion to `snake_case` (e.g. `foo-bar` and `fooBar`), the conflict-resolution path preserved delimiters like `-`, `.`, and spaces in the generated Python identifiers, producing invalid code which failed generation. Conflicting names now keep their original casing but have any characters which are invalid in Python identifiers stripped (e.g. `foobar` and `fooBar`). + +#### Improve readability of error messages + +Errors and warnings which include a snippet of your OpenAPI document now render that snippet as JSON, making them much easier to read. + +### 📝Notes + +#### Breaking changes for all custom templates + +**ALL** custom templates are expected to break with this version as a result of the security fix. + +1. The `utils` global has been renamed to `strings` +2. Most string values can no longer be rendered directly into templates, + you must describe how the value is being used so it can be properly escaped using either a Python function or Jinja filter: + 1. `strings.snake_case()` / `| snakecase` (existing) + 2. `strings.kebab_case()` / `| kebabcase` (existing) + 3. `strings.pascal_case()` / `| pascalcase` (existing) + 4. `python_identifier()` (existing) + 5. `class_name()` (existing) + 6. `strings.safe_for_docstring()` / `| safe_for_docstring` for values which get injected into a `"""` docstring + 7. `strings.in_f_string_literal()` / `| in_f_string_literal` for values that go into `f""` f-strings + 8. `strings.in_double_quote_literal()` / `| in_double_quote_literal` for values that go into **non-f-string** `""` literals + 9. `.as_unembedded_code()` / `| as_unembedded_code` ONLY for `PythonCode` values—those that are intended to be Python code which is not embedded into any string/docstring. Examples include usages of `.python_code`, `.get_type_string()`, `.get_instance_type_string()`, `.get_type_strings_in_union()`. You *should not* assume these values are safe to put in docstrings, string literals, or f-string literals. Use the dedicated helpers for those. +As always, you can check the diff of the built in templates for examples. You will also want to check generated output +for "UntrustedString", which is how any string now requiring one of those functions will appear. + +#### Many control characters now stripped from string literals + +Out of an abundance of caution, most Unicode control characters are now stripped from string literals. +If your API uses control characters as part of const values, enums, or JSON body property names you may have issues +with this new version. + +Most APIs are not expected to be affected by this change. + +## 0.29.0 (2026-05-30) + +### Breaking Changes + +- Drop support for Python 3.10 +- Raise minimum httpx version to 0.23.1 + +### Features + +- replace python-dateutil with stdlib datetime.fromisoformat (#1429) + +### Fixes + +- Remove some generated casts that aren't necessary with mypy v2 (#1436) +- Explicitly set boundary for multipart/form-data (#1005) + +## 0.28.4 (2026-05-11) + +### Features + +- Update `uv_build` to 0.11 when using `--meta=uv` (#1434) + +#### Add support for x-enum-varnames to string enums + +##1358 by @mbbush + +You can now customize the variable names of the generated string enumerations using the x-enum-varnames openapi extension. Previously, this was only possible for integer enumerations. + +## 0.28.3 (2026-02-17) + +### Fixes + +- sort remaining lazy imports in model template (#1400) + +## 0.28.2 (2026-02-09) + +### Features + +- Update `uv_build` 0.10 when using `--meta=uv` (#1396) + +## 0.28.1 (2026-01-10) + +### Fixes + +- Apply required overrides from allOf schemas (#1384) +- Sort lazy imports to increase stability of generated code (#1378) + +## 0.28.0 (2025-12-03) + +### Breaking Changes + +- URL-encode path parameters in generated endpoints (#1349) + +### Fixes + +#### Fix bad code generation + +##1360 by @EricAtORS + +This fixes: +- missing parenthesis in to_multipart + #1338 #1318 +- missing imports in the lazy eval in to_multipart: +##931 and #1051 + +#### Fix optional bodies + +If a body is not required (the default), it will now: + +1. Have `Unset` as part of its type annotation. +2. Default to a value of `UNSET` +3. Not be included in the request if it is `UNSET` + +Thanks @orelmaliach for the report! Fixes #1354 + +## 0.27.1 (2025-11-03) + +### Fixes + +- Remove non-existent CHANGELOG.md references from UV and Poetry templates (#1344) +- Initialize optional lists as UNSET, not [] (#1346) +- Correct docstring typos in client template (#1347) +- Replace bare except blocks with specific exception types (#1348) + +#### Update `uv_build` to 0.9 + +##1352 by @johnthagen + +`uv` has been in the `0.9.x` release cycle for a while, so update templates to use the corresponding `uv_build` range. + +## 0.27.0 (2025-10-28) + +### Breaking Changes + +#### Drop support for Python 3.9 + +Both `openapi-python-client` itself and any generated clients no longer support Python 3.9. + +#### Generated models now use `from __future__ import annotations` + +This simplifies using forward references with the newer union syntax. + +### Features + +#### Upgrade generated clients to 3.10 union syntax + +All generated types now use the `A | B` syntax instead of `Union[A, B]` or `Optional[A]`. + +### Fixes + +- Drop generated `requires-python` upper bounds for uv and PDM (#1329) + +#### Change default Ruff hook to `--fix-only` + +This should enable `openapi-python-client` to keep auto-fixing lints (like removing unused imports) but _not_ fail to +generate when unfixable lints are violated. + +Since it's now unlikely for breaking changes to affect our usage (and by popular request), the upper bound of `ruff` +has been lifted. Newer versions of `openapi-python-client` should no longer be required to support newer versions of `ruff`. + +### Notes + +- Minimum Typer version is now 0.16 + +## 0.26.2 (2025-10-06) + +### Fixes + +- ambigious tilde specifier requires-python with`--meta=uv` (#1321) + +## 0.26.1 (2025-09-13) + +### Features + +- Reference schema support (#800) (#1307) +- Support Ruff 0.13 + +## 0.26.0 (2025-08-26) + +### Breaking Changes + +#### Change some union variant names + +When creating a union with `oneOf`, `anyOf`, or a list of `type`, the name of each variant used to be `type_{index}` +where the index is based on the order of the types in the union. + +This made some modules difficult to understand, what is a `my_type_type_0` after all? +It also meant that reordering union members, while not a breaking change to the API, _would_ be a breaking change +for generated clients. + +Now, if an individual variant has a `title` attribute, that `title` will be used in the name instead. +This is only an enhancement for documents which use `title` in union variants, and only a breaking change for +_inline models_ (not `#/components/schemas` which should already have used more descriptive names). + +Thanks @wallagib for PR #962! + +### Features + +#### Support patterned and default HTTP statuses + +HTTP statuses like `2XX` and `default` are now supported! + +A big thank you to: +- @PSU3D0 for PR #973 (eons ago 😅) +- @obs-gh-peterkolloch for PR #1300 +- @goodsonjr for PR #1304 + +Closes #1271 and #832 + +> [!NOTE] +> Custom template users: the `endpoint.responses` type has changed quite a bit. Check out #1303 for the changes. + +## 0.25.3 (2025-07-21) + +### Features + +- Add --meta uv for generating astral-sh/uv compatible packages. (#1286) +- Switch to `uv_build` build backend. (#1290) + +## 0.25.2 (2025-07-03) + +### Fixes + +- Import error for `types.FileType` (#1274) (#1278) + +## 0.25.1 (2025-06-19) + +### Fixes + +- Support ruff 0.12 (#1270) + +## 0.25.0 (2025-06-06) + +### Breaking Changes + +- Raise minimum httpx version to 0.23 + +#### Removed ability to set an array as a multipart body + +Previously, when defining a request's body as `multipart/form-data`, the generator would attempt to generate code +for both `object` schemas and `array` schemas. However, most arrays could not generate valid multipart bodies, as +there would be no field names (required to set the `Content-Disposition` headers). + +The code to generate any body for `multipart/form-data` where the schema is `array` has been removed, and any such +bodies will be skipped. This is not _expected_ to be a breaking change in practice, since the code generated would +probably never work. + +If you have a use-case for `multipart/form-data` with an `array` schema, please [open a new discussion](https://github.com/openapi-generators/openapi-python-client/discussions) with an example schema and the desired functional Python code. + +#### Change default multipart array serialization + +Previously, any arrays of values in a `multipart/form-data` body would be serialized as an `application/json` part. +This matches the default behavior specified by OpenAPI and supports arrays of files (`binary` format strings). +However, because this generator doesn't yet support specifying `encoding` per property, this may result in +now-incorrect code when the encoding _was_ explicitly set to `application/json` for arrays of scalar values. + +PR #938 fixes #692. Thanks @micha91 for the fix, @ratgen and @FabianSchurig for testing, and @davidlizeng for the original report... many years ago 😅. + +## 0.24.3 (2025-03-31) + +### Features + +#### Adding support for named integer enums + +##1214 by @barrybarrette + +Adding support for named integer enums via an optional extension, `x-enum-varnames`. + +This extension is added to the schema inline with the `enum` definition: +``` +"MyEnum": { + "enum": [ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 99 + ], + "type": "integer", + "format": "int32", + "x-enum-varnames": [ + "Deinstalled", + "Installed", + "Upcoming_Site", + "Lab_Site", + "Pending_Deinstall", + "Suspended", + "Install_In_Progress", + "Unknown" + ] +} +``` + +The result: +![image](https://github.com/user-attachments/assets/780880b3-2f1f-49be-823b-f9abb713a3e1) + +## 0.24.2 (2025-03-22) + +### Fixes + +#### Make lists of models and enums work correctly in custom templates + +Lists of model and enum classes should be available to custom templates via the Jinja +variables `openapi.models` and `openapi.enums`, but these were being passed in a way that made +them always appear empty. This has been fixed so a custom template can now iterate over them. + +Closes #1188. + +## 0.24.1 (2025-03-15) + +### Features + +- allow Ruff to 0.10 (#1220) +- allow Ruff 0.11 (#1222) +- Allow any `Mapping` in generated `from_dict` functions (#1211) + +### Fixes + +#### Always parse `$ref` as a reference + +If additional attributes were included with a `$ref` (for example `title` or `description`), the property could be +interpreted as a new type instead of a reference, usually resulting in `Any` in the generated code. +Now, any sibling properties to `$ref` will properly be ignored, as per the OpenAPI specification. + +Thanks @nkrishnaswami! + +## 0.24.0 (2025-03-03) + +### Breaking Changes + +#### Support `$ref` in responses + +Previously, using a `$ref` to define a response was ignored, the code to call the endpoint was still generated, but +the response would not be parsed. Now, responses defined with `$ref` will be used to generate the response model, which +will parse the response at runtime. + +If a `$ref` is incorrect or uses a feature that is not supported by the generator, these endpoints will start failing to +generate. + +### Features + +#### Make `config` available in custom templates + +The configuration options object is now exposed as a variable called `config` in Jinja2 templates. + +#### Add `docstrings_on_attributes` config setting + +Setting this option to `true` changes the docstring behavior in model classes: for any attribute that have a non-empty `description`, instead of describing the attribute as part of the class's docstring, the description will appear in an individual docstring for that attribute. + +## 0.23.1 (2025-01-13) + +### Features + +- allow Ruff 0.9 (#1192) + +## 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 + +- update Ruff to >=0.2,<0.8 (#1137) +- Add UUID string format. Thanks @estyrke! (#1140) +- Support OpenAPI 3.1 prefixItems property for arrays. Thanks @estyrke! (#1141) + +#### Add `literal_enums` config setting + +Instead of the default `Enum` classes for enums, you can now generate `Literal` sets wherever `enum` appears in the OpenAPI spec by setting `literal_enums: true` in your config file. + +```yaml +literal_enums: true +``` + +Thanks to @emosenkis for PR #1114 closes #587, #725, #1076, and probably many more. +Thanks also to @eli-bl, @expobrain, @theorm, @chrisguillory, and anyone else who helped getting to this design! + +### Fixes + +- Typo in docstring (#1128) + +#### Use literal value instead of `HTTPStatus` enum when checking response statuses + +Python 3.13 renamed some of the `HTTPStatus` enum members, which means clients generated with Python 3.13 may not work +with older versions of Python. This change stops using the `HTTPStatus` enum directly when checking response statuses. + +Statuses will still be checked for validity at generation time, and transformed into `HTTPStatus` _after_ being checked +at runtime. + +This may cause some linters to complain. + +## 0.21.5 (2024-09-07) + +### Features + +#### Improved property-merging behavior with `allOf` + +When using `allOf` to extend a base object type, `openapi-python-client` is now able to handle some kinds of modifications to an existing property that would have previously caused an error: + +- Overriding attributes that do not affect validation, such as `description`. +- Combining properties that this generator ignores, like `maxLength` or `pattern`. +- Combining a generic numeric type with `int` (resulting in `int`). +- Adding a `format` to a string. +- Combining `any` with a specific type (resulting in that specific type). +- Adding or overriding a `default` + +> [!NOTE] +> `pattern` and `max_length` are no longer fields on `StringProperty`, which may impact custom templates. + +This also fixes a bug where properties of inline objects (as opposed to references) were not using the +merge logic, but were simply overwriting previous definitions of the same property. + +### Fixes + +- Allow default values for properties of `Any` type + +#### Produce valid code for an object that has no properties at all + +Fixed by PR #1109. Thanks @eli-bl! + +## 0.21.4 (2024-08-25) + +### Fixes + +#### Allow OpenAPI 3.1-style `exclusiveMinimum` and `exclusiveMaximum` + +Fixed by PR #1092. Thanks @mikkelam! + +#### Add missing `cast` import when using `const` + +Fixed by PR #1072. Thanks @dorcohe! + +#### Correctly resolve references to a type that is itself just a single allOf reference + +PR #1103 fixed issue #1091. Thanks @eli-bl! + +#### Support `const` booleans and floats + +Fixed in PR #1086. Thanks @flxdot! + +## 0.21.3 (2024-08-18) + +### Features + +- update Ruff to >=0.2,<0.7 (#1097) + +## 0.21.2 (2024-07-20) + +### Features + +- Update to Ruff 0.5 + +## 0.21.1 (2024-06-15) + +### Features + +#### Support request body refs + +You can now define and reuse bodies via refs, with a document like this: + +```yaml +paths: + /something: + post: + requestBody: + "$ref": "#/components/requestBodies/SharedBody" +components: + requestBodies: + SharedBody: + content: + application/json: + schema: + type: string +``` + +Thanks to @kigawas and @supermihi for initial implementations and @RockyMM for the initial request. + +Closes #633, closes #664, resolves #595. + +### Fixes + +- Indent of generated code for non-required lists. Thanks @sfowl! (#1050) +- Parsing requestBody with $ref (#633) + +## 0.21.0 (2024-06-08) + +### 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= --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.0 (2024-05-18) + +### 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! + +#### Switch YAML parsing to 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.19.1 (2024-03-27) ### Features diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 52b67100a..e3d9c68ab 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 @@ -50,26 +50,40 @@ All changes must be tested, I recommend writing the test first, then writing the 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. -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) -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. -3. If you're improving an error or adding a new error, add a [unit test](#unit-tests) +1. If you're adding support for a new OpenAPI feature or covering a new edge case, add [functional tests](#functional-tests), and optionally an [end-to-end snapshot test](#end-to-end-snapshot-tests). +2. If you're modifying the way an existing feature works, make sure functional tests cover this case. Existing end-to-end snapshot tests might also be affected if you have changed what generated model/endpoint code looks like. +3. If you're improving error handling or adding a new error, add [functional tests](#functional-tests). +4. For tests of low-level pieces of code that are fairly self-contained, and not tightly coupled to other internal implementation details, you can use regular [unit tests](#unit-tests). -#### End-to-end tests +#### End-to-end snapshot tests -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 `pdm e2e`. To regenerate the snapshots, run `pdm regen`. +This project aims to have all "happy paths" (types of code which _can_ be generated) covered by end-to-end tests. There are two types of these: snapshot tests, and functional tests. -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: +Snapshot tests verify that the generated code is identical to a previously-committed set of snapshots (called a "golden record" here). They are basically regression tests to catch any unintended changes in the generator output. + +In order to check code changes against the previous set of snapshots (called a "golden record" here), you can run `pdm e2e`. To regenerate the snapshots, run `pdm regen`. + +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_tests` directory: 1. `baseline_openapi_3.0.json` creates `golden-record` for testing OpenAPI 3.0 features 2. `baseline_openapi_3.1.yaml` is checked against `golden-record` for testing OpenAPI 3.1 features (and ensuring consistency with 3.0) 3. `test_custom_templates` are used with `baseline_openapi_3.0.json` to generate `custom-templates-golden-record` for testing custom templates 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) +#### Functional tests + +These are black-box tests that verify the runtime behavior of generated code, as well as the generator's validation behavior. They are also end-to-end tests, since they run the generator as a shell command. + +This can sometimes identify issues with error handling, validation logic, module imports, etc., that might be harder to diagnose via the snapshot tests, especially during development of a new feature. For instance, they can verify that JSON data is correctly decoded into model class attributes, or that the generator will emit an appropriate warning or error for an invalid spec. + +See [`end_to_end_tests/functional_tests`](./end_to_end_tests/functional_tests). + #### Unit tests -> **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. +These include: -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. +* Regular unit tests of basic pieces of fairly self-contained low-level functionality, such as helper functions. These are implemented in the `tests` directory, using the `pytest` framework. +* Older-style unit tests of low-level functions like `property_from_data` that have complex behavior. These are brittle and difficult to maintain, and should not be used going forward. Instead, they should be migrated to functional tests. ### Creating a Pull Request diff --git a/README.md b/README.md index 4994c0f78..4a886d299 100644 --- a/README.md +++ b/README.md @@ -41,23 +41,18 @@ Then, if you want tab completion: `openapi-python-client --install-completion` `openapi-python-client generate --url https://my.api.com/openapi.json` This will generate a new client library named based on the title in your OpenAPI spec. For example, if the title -of your API is "My API", the expected output will be "my-api-client". If a folder already exists by that name, you'll -get an error. +of your API is "My API", the expected output will be "my-api-client". You can change that directory name with the config file (documented below) or with `--output-path`. -If you have an `openapi.json` file available on disk, in any CLI invocation you can build off that instead by replacing `--url` with a `--path`: +If the directory to generate already exists, you'll get an error unless you use `--overwrite`. -`openapi-python-client generate --path location/on/disk/openapi.json` - -### Update an existing client - -`openapi-python-client update --url https://my.api.com/openapi.json` +You can use an OpenAPI file instead of a URL like `openapi-python-client generate --path location/on/disk/openapi.json`. ### Using custom templates -This feature leverages Jinja2's [ChoiceLoader](https://jinja.palletsprojects.com/en/2.11.x/api/#jinja2.ChoiceLoader) and [FileSystemLoader](https://jinja.palletsprojects.com/en/2.11.x/api/#jinja2.FileSystemLoader). This means you do _not_ need to customize every template. Simply copy the template(s) you want to customize from [the default template directory](openapi_python_client/templates) to your own custom template directory (file names _must_ match exactly) and pass the template directory through the `custom-template-path` flag to the `generate` and `update` commands. For instance, +This feature leverages Jinja2's [ChoiceLoader](https://jinja.palletsprojects.com/en/2.11.x/api/#jinja2.ChoiceLoader) and [FileSystemLoader](https://jinja.palletsprojects.com/en/2.11.x/api/#jinja2.FileSystemLoader). This means you do _not_ need to customize every template. Simply copy the template(s) you want to customize from [the default template directory](openapi_python_client/templates) to your own custom template directory (file names _must_ match exactly) and pass the template directory through the `custom-template-path` flag to the `generate` command: ``` -openapi-python-client update \ +openapi-python-client generate \ --url https://my.api.com/openapi.json \ --custom-template-path=relative/path/to/mytemplates ``` @@ -102,6 +97,37 @@ class_overrides: 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. +### docstrings_on_attributes + +By default, when `openapi-python-client` generates a model class, it includes a list of attributes and their +descriptions in the docstring for the class. If you set this option to `true`, then the attribute descriptions +will be put in docstrings for the attributes themselves, and will not be in the class docstring. + +```yaml +docstrings_on_attributes: true +``` + +### literal_enums + +By default, `openapi-python-client` generates classes inheriting for `Enum` for enums. It can instead use `Literal` +values for enums by setting this to `true`: + +```yaml +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 @@ -140,7 +166,7 @@ In the config file, there's an easy way to tell `openapi-python-client` to run a ```yaml post_hooks: - - "ruff check . --fix" + - "ruff check . --fix-only" - "ruff format ." ``` @@ -166,6 +192,39 @@ content_type_overrides: application/zip: application/octet-stream ``` +## Supported Extensions + +### x-enum-varnames + +This extension has been adopted by similar projects such as [OpenAPI Tools](https://github.com/OpenAPITools/openapi-generator/pull/917). +It is intended to provide user-friendly names for integer Enum members that get generated. +It is critical that the length of the array matches that of the enum values. + +``` +"Colors": { + "type": "integer", + "format": "int32", + "enum": [ + 0, + 1, + 2 + ], + "x-enum-varnames": [ + "Red", + "Green", + "Blue" + ] +} +``` + +Results in: +``` +class Color(IntEnum): + RED = 0 + GREEN = 1 + BLUE = 2 +``` + [changelog.md]: CHANGELOG.md [poetry]: https://python-poetry.org/ [PDM]: https://pdm-project.org/latest/ diff --git a/end_to_end_tests/3.1_specific.openapi.yaml b/end_to_end_tests/3.1_specific.openapi.yaml index 3540d04ac..04d693449 100644 --- a/end_to_end_tests/3.1_specific.openapi.yaml +++ b/end_to_end_tests/3.1_specific.openapi.yaml @@ -47,3 +47,34 @@ paths: "application/json": schema: const: "Why have a fixed response? I dunno" + "/prefixItems": + post: + tags: [ "prefixItems" ] + requestBody: + required: true + content: + "application/json": + schema: + type: object + properties: + prefixItemsAndItems: + type: array + prefixItems: + - type: string + const: "prefix" + - type: string + items: + type: number + prefixItemsOnly: + type: array + prefixItems: + - type: string + - type: number + maxItems: 2 + responses: + "200": + description: "Successful Response" + content: + "application/json": + schema: + type: string diff --git a/end_to_end_tests/__init__.py b/end_to_end_tests/__init__.py index 1bf33f63f..f165cc2c5 100644 --- a/end_to_end_tests/__init__.py +++ b/end_to_end_tests/__init__.py @@ -1 +1,6 @@ -""" Generate a complete client and verify that it is correct """ +"""Generate a complete client and verify that it is correct""" + +import pytest + +pytest.register_assert_rewrite("end_to_end_tests.end_to_end_test_helpers") +pytest.register_assert_rewrite("end_to_end_tests.functional_tests.helpers") diff --git a/end_to_end_tests/__snapshots__/test_end_to_end.ambr b/end_to_end_tests/__snapshots__/test_end_to_end.ambr new file mode 100644 index 000000000..0e6c6eee6 --- /dev/null +++ b/end_to_end_tests/__snapshots__/test_end_to_end.ambr @@ -0,0 +1,83 @@ +# 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 pattern: abcdef, 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 + + Warning(s) encountered while generating. Client was generated, but some pieces may be missing + WARNING parsing POST / within default. Endpoint will not be generated. + + Circular $ref in request body + + + 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[invalid-uuid-defaults] + ''' + Generating /test-documents-with-errors + + Warning(s) encountered while generating. Client was generated, but some pieces may be missing + WARNING parsing PUT / within default. Endpoint will not be generated. + + cannot parse parameter of endpoint put: Invalid UUID value: 3 + + + WARNING parsing POST / within default. Endpoint will not be generated. + + cannot parse parameter of endpoint post: Invalid UUID value: notauuid + + + 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[missing-body-ref] + ''' + Generating /test-documents-with-errors + + Warning(s) encountered while generating. Client was generated, but some pieces may be missing + WARNING parsing POST / within default. Endpoint will not be generated. + + Could not resolve $ref #/components/requestBodies/body in request body + + + 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[optional-path-param] + ''' + Generating /test-documents-with-errors + + Warning(s) encountered while generating. Client was generated, but some pieces may be missing + WARNING parsing GET /{optional} within default. Endpoint will not be generated. + + Path parameter must be required + + { + "name": "optional", + "in": "path", + "schema": { + "type": "string" + } + } + + 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 + + ''' +# --- diff --git a/end_to_end_tests/baseline_openapi_3.0.json b/end_to_end_tests/baseline_openapi_3.0.json index 14fdd7c42..c47048218 100644 --- a/end_to_end_tests/baseline_openapi_3.0.json +++ b/end_to_end_tests/baseline_openapi_3.0.json @@ -87,6 +87,47 @@ } } }, + "/bodies/refs": { + "post": { + "tags": [ + "bodies" + ], + "description": "Test request body defined via ref", + "operationId": "refs", + "requestBody": { + "$ref": "#/components/requestBodies/NestedRef" + }, + "responses": { + "200": { + "description": "OK" + } + } + } + }, + "/bodies/optional": { + "post": { + "tags": [ + "bodies" + ], + "description": "Test optional request body", + "operationId": "optional-body", + "requestBody": { + "required": false, + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + } + }, + "responses": { + "200": { + "description": "OK" + } + } + } + }, "/tests/": { "get": { "tags": [ @@ -377,52 +418,15 @@ "content": { "multipart/form-data": { "schema": { - "$ref": "#/components/schemas/Body_upload_file_tests_upload_post" - } - } - }, - "required": true - }, - "responses": { - "200": { - "description": "Successful Response", - "content": { - "application/json": { - "schema": {} - } - } - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - } - } - } - } - }, - "/tests/upload/multiple": { - "post": { - "tags": [ - "tests" - ], - "summary": "Upload multiple files", - "description": "Upload several files in the same request", - "operationId": "upload_multiple_files_tests_upload_post", - "parameters": [], - "requestBody": { - "content": { - "multipart/form-data": { - "schema": { - "type": "array", - "items": { - "type": "string", - "format": "binary" - } + "$ref": "#/components/schemas/Body_upload_file_tests_upload_post", + "title": "Body_upload_file_tests_upload_post", + "required": [ + "some_file", + "some_object", + "some_nullable_object", + "some_required_number" + ], + "properties": {} } } }, @@ -579,6 +583,16 @@ "name": "float_prop", "in": "query" }, + { + "required": true, + "schema": { + "title": "Float with int default", + "type": "number", + "default": 3 + }, + "name": "float_with_int", + "in": "query" + }, { "required": true, "schema": { @@ -740,7 +754,13 @@ "content": { "application/json": { "schema": { - "type": "string" + "type": "object", + "properties": { + "data": { + "type": "string", + "format": "binary" + } + } } } } @@ -964,6 +984,138 @@ } } }, + "/responses/reference": { + "get": { + "tags": [ + "responses" + ], + "summary": "Endpoint using predefined response", + "operationId": "reference_response", + "responses": { + "200": { + "$ref": "#/components/responses/AResponse" + } + } + } + }, + "/responses/status-codes/default": { + "get": { + "tags": [ + "responses" + ], + "summary": "Default Status Code Only", + "operationId": "default_status_code", + "responses": { + "default": { + "description": "Default response", + "content": { + "text/plain": { + "schema": { + "type": "string" + } + } + } + } + } + } + }, + "/response/status-codes/patterns": { + "get": { + "tags": [ + "responses" + ], + "summary": "Status Code Patterns", + "operationId": "status_code_patterns", + "responses": { + "2XX": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { + "type": "string", + "enum": [ + "success", + "failure" + ] + } + } + } + } + } + }, + "4XX": { + "description": "Bad Request", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "error": { + "type": "string" + } + } + } + } + } + } + } + } + }, + "/response/status-codes/precedence": { + "get": { + "operationId": "status_code_precedence", + "tags": [ + "responses" + ], + "summary": "Status Codes Precedence", + "description": "Verify that specific status codes are always checked first, then ranges, then default", + "responses": { + "default": { + "description": "Default Response Should Be Last", + "content": { + "text/plain": { + "schema": { + "type": "string" + } + } + } + }, + "4XX": { + "description": "Pattern should be after specific codes", + "content": { + "text/plain": { + "schema": { + "type": "string" + } + } + } + }, + "404": { + "description": "Not Found", + "content": { + "text/plain": { + "schema": { + "type": "string" + } + } + } + }, + "200": { + "description": "OK", + "content": { + "text/plain": { + "schema": { + "type": "string" + } + } + } + } + } + } + }, "/auth/token_with_cookie": { "get": { "tags": [ @@ -1123,7 +1275,8 @@ "/tag_with_number": { "get": { "tags": [ - "1" + "1", + "2" ], "responses": { "200": { @@ -1415,7 +1568,9 @@ }, "/naming/mixed-case": { "get": { - "tags": ["naming"], + "tags": [ + "naming" + ], "operationId": "mixed_case", "parameters": [ { @@ -1436,30 +1591,32 @@ } ], "responses": { - "200": { - "description": "Successful response", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "mixed_case": { - "type": "string" - }, - "mixedCase": { - "type": "string" - } + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "mixed_case": { + "type": "string" + }, + "mixedCase": { + "type": "string" } } } } } + } } } }, "/naming/{hyphen-in-path}": { "get": { - "tags": ["naming"], + "tags": [ + "naming" + ], "operationId": "hyphen_in_path", "parameters": [ { @@ -1608,6 +1765,119 @@ } } } + }, + "/models/allof": { + "get": { + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "aliased": { + "$ref": "#/components/schemas/Aliased" + }, + "extended": { + "$ref": "#/components/schemas/Extended" + }, + "model": { + "$ref": "#/components/schemas/AModel" + } + } + } + } + } + } + } + } + }, + "/models/oneof-with-required-const": { + "get": { + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "oneOf": [ + { + "type": "object", + "properties": { + "type": { + "const": "alpha" + }, + "color": { + "type": "string" + } + }, + "required": [ + "type" + ] + }, + { + "type": "object", + "properties": { + "type": { + "const": "beta" + }, + "texture": { + "type": "string" + } + }, + "required": [ + "type" + ] + } + ] + } + } + } + } + } + } + }, + "/types/unions/duplicate-types": { + "post": { + "title": "duplicate union members", + "requestBody": { + "description": "The request body", + "content": { + "application/json": { + "schema": { + "oneOf": [ + { + "$ref": "#/components/schemas/AModel" + }, + { + "$ref": "#/components/schemas/AModel" + } + ] + } + } + } + }, + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "oneOf": [ + { + "$ref": "#/components/schemas/AModel" + }, + { + "$ref": "#/components/schemas/AModel" + } + ] + } + } + } + } + } + } } }, "components": { @@ -1626,6 +1896,52 @@ "an_required_field" ] }, + "Aliased": { + "allOf": [ + { + "$ref": "#/components/schemas/AModel" + } + ] + }, + "Extended": { + "allOf": [ + { + "$ref": "#/components/schemas/Aliased" + }, + { + "type": "object", + "properties": { + "fromExtended": { + "type": "string" + } + } + } + ] + }, + "AllOfRequiredBase": { + "type": "object", + "properties": { + "bar": { + "type": "string", + "description": "The bar property" + }, + "baz": { + "type": "string", + "description": "The baz property" + } + } + }, + "AllOfRequiredDerived": { + "allOf": [ + { + "$ref": "#/components/schemas/AllOfRequiredBase" + }, + { + "type": "object", + "required": ["bar"] + } + ] + }, "AModel": { "title": "AModel", "required": [ @@ -1634,6 +1950,8 @@ "aCamelDateTime", "a_date", "a_nullable_date", + "a_uuid", + "a_nullable_uuid", "required_nullable", "required_not_nullable", "model", @@ -1643,7 +1961,9 @@ ], "type": "object", "properties": { - "any_value": {}, + "any_value": { + "default": "default" + }, "an_enum_value": { "$ref": "#/components/schemas/AnEnum" }, @@ -1702,6 +2022,23 @@ "type": "string", "format": "date" }, + "a_uuid": { + "title": "A Uuid", + "type": "string", + "format": "uuid" + }, + "a_nullable_uuid": { + "title": "A Nullable Uuid", + "type": "string", + "format": "uuid", + "nullable": true, + "default": "07EF8B4D-AA09-4FFA-898D-C710796AFF41" + }, + "a_not_required_uuid": { + "title": "A Not Required Uuid", + "type": "string", + "format": "uuid" + }, "1_leading_digit": { "title": "Leading Digit", "type": "string" @@ -1863,7 +2200,8 @@ "required": [ "some_file", "some_object", - "some_nullable_object" + "some_nullable_object", + "some_required_number" ], "type": "object", "properties": { @@ -1896,6 +2234,23 @@ "title": "Some Number", "type": "number" }, + "some_nullable_number": { + "title": "Some Nullable Number", + "type": "number", + "nullable": true + }, + "some_required_number": { + "title": "Some Required Number", + "type": "number" + }, + "some_int_array": { + "title": "Some Integer Array", + "type": "array", + "items": { + "type": "integer", + "nullable": true + } + }, "some_array": { "title": "Some Array", "nullable": true, @@ -2029,6 +2384,7 @@ "oneOf": [ { "type": "object", + "title": "Apples", "properties": { "apples": { "type": "string" @@ -2037,6 +2393,7 @@ }, { "type": "object", + "title": "Bananas", "properties": { "bananas": { "type": "string" @@ -2069,6 +2426,59 @@ "additionalProperties": {} } }, + "ModelWithMergedProperties": { + "title": "ModelWithMergedProperties", + "allOf": [ + { + "type": "object", + "properties": { + "simpleString": { + "type": "string", + "description": "base simpleString description" + }, + "stringToEnum": { + "type": "string", + "default": "a" + }, + "stringToDate": { + "type": "string" + }, + "numberToInt": { + "type": "number" + }, + "anyToString": {} + } + }, + { + "type": "object", + "properties": { + "simpleString": { + "type": "string", + "description": "extended simpleString description", + "default": "new default" + }, + "stringToEnum": { + "type": "string", + "enum": [ + "a", + "b" + ] + }, + "stringToDate": { + "type": "string", + "format": "date" + }, + "numberToInt": { + "type": "integer" + }, + "anyToString": { + "type": "string", + "default": "x" + } + } + } + ] + }, "ModelWithPrimitiveAdditionalProperties": { "title": "ModelWithPrimitiveAdditionalProperties", "type": "object", @@ -2136,6 +2546,11 @@ } ] }, + "ModelWithNoProperties": { + "type": "object", + "properties": {}, + "additionalProperties": false + }, "AllOfSubModel": { "title": "AllOfSubModel", "type": "object", @@ -2739,6 +3154,32 @@ "type": "string" } } + }, + "requestBodies": { + "NestedRef": { + "$ref": "#/components/requestBodies/ARequestBody" + }, + "ARequestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/AModel" + } + } + } + } + }, + "responses": { + "AResponse": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/AModel" + } + } + } + } } } } diff --git a/end_to_end_tests/baseline_openapi_3.1.yaml b/end_to_end_tests/baseline_openapi_3.1.yaml index a0e762a95..295e6818a 100644 --- a/end_to_end_tests/baseline_openapi_3.1.yaml +++ b/end_to_end_tests/baseline_openapi_3.1.yaml @@ -83,6 +83,47 @@ info: } } }, + "/bodies/refs": { + "post": { + "tags": [ + "bodies" + ], + "description": "Test request body defined via ref", + "operationId": "refs", + "requestBody": { + "$ref": "#/components/requestBodies/NestedRef" + }, + "responses": { + "200": { + "description": "OK" + } + } + } + }, + "/bodies/optional": { + "post": { + "tags": [ + "bodies" + ], + "description": "Test optional request body", + "operationId": "optional-body", + "requestBody": { + "required": false, + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + } + }, + "responses": { + "200": { + "description": "OK" + } + } + } + }, "/tests/": { "get": { "tags": [ @@ -401,51 +442,6 @@ info: } } }, - "/tests/upload/multiple": { - "post": { - "tags": [ - "tests" - ], - "summary": "Upload multiple files", - "description": "Upload several files in the same request", - "operationId": "upload_multiple_files_tests_upload_post", - "parameters": [ ], - "requestBody": { - "content": { - "multipart/form-data": { - "schema": { - "type": "array", - "items": { - "type": "string", - "format": "binary" - } - } - } - }, - "required": true - }, - "responses": { - "200": { - "description": "Successful Response", - "content": { - "application/json": { - "schema": { } - } - } - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - } - } - } - } - }, "/tests/json_body": { "post": { "tags": [ @@ -575,6 +571,16 @@ info: "name": "float_prop", "in": "query" }, + { + "required": true, + "schema": { + "title": "Float with int default", + "type": "number", + "default": 3 + }, + "name": "float_with_int", + "in": "query" + }, { "required": true, "schema": { @@ -732,7 +738,13 @@ info: "content": { "application/json": { "schema": { - "type": "string" + "type": "object", + "properties": { + "data": { + "type": "string", + "format": "binary" + } + } } } } @@ -956,6 +968,129 @@ info: } } }, + "/responses/reference": { + "get": { + "tags": [ + "responses" + ], + "summary": "Endpoint using predefined response", + "operationId": "reference_response", + "responses": { + "200": { + "$ref": "#/components/responses/AResponse" + } + } + } + }, + "/responses/status-codes/default": { + "get": { + "tags": ["responses"], + "summary": "Default Status Code Only", + "operationId": "default_status_code", + "responses": { + "default": { + "description": "Default response", + "content": { + "text/plain": { + "schema": { + "type": "string" + } + } + } + } + } + } + }, + "/response/status-codes/patterns": { + "get": { + "tags": ["responses"], + "summary": "Status Code Patterns", + "operationId": "status_code_patterns", + "responses": { + "2XX": { + "description": "Successful Response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { + "type": "string", + "enum": ["success", "failure"] + } + } + } + } + } + }, + "4XX": { + "description": "Bad Request", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "error": { + "type": "string" + } + } + } + } + } + } + } + } + }, + "/response/status-codes/precedence": { + "get": { + "operationId": "status_code_precedence", + "tags": ["responses"], + "summary": "Status Codes Precedence", + "description": "Verify that specific status codes are always checked first, then ranges, then default", + "responses": { + "default": { + "description": "Default Response Should Be Last", + "content": { + "text/plain": { + "schema": { + "type": "string" + } + } + } + }, + "4XX": { + "description": "Pattern should be after specific codes", + "content": { + "text/plain": { + "schema": { + "type": "string" + } + } + } + }, + "404": { + "description": "Not Found", + "content": { + "text/plain": { + "schema": { + "type": "string" + } + } + } + }, + "200": { + "description": "OK", + "content": { + "text/plain": { + "schema": { + "type": "string" + } + } + } + } + } + } + }, "/auth/token_with_cookie": { "get": { "tags": [ @@ -1114,9 +1249,7 @@ info: }, "/tag_with_number": { "get": { - "tags": [ - "1" - ], + "tags": [ "1", "2" ], "responses": { "200": { "description": "Success" @@ -1602,9 +1735,110 @@ info: } } } + }, + "/models/allof": { + "get": { + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "aliased": { + "$ref": "#/components/schemas/Aliased" + }, + "extended": { + "$ref": "#/components/schemas/Extended" + }, + "model": { + "$ref": "#/components/schemas/AModel" + } + } + } + } + } + } + } + } + }, + "/models/oneof-with-required-const": { + "get": { + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "oneOf": [ + { + "type": "object", + "properties": { + "type": { + "const": "alpha" + }, + "color": { + "type": "string" + } + }, + "required": [ "type" ] + }, + { + "type": "object", + "properties": { + "type": { + "const": "beta" + }, + "texture": { + "type": "string" + } + }, + "required": [ "type" ] + } + ] + } + } + } + } + } + } + }, + "/types/unions/duplicate-types": { + "post": { + "title": "duplicate union members", + "requestBody": { + "description": "The request body", + "content": { + "application/json": { + "schema": { + "oneOf": [ + {"$ref": "#/components/schemas/AModel"}, + {"$ref": "#/components/schemas/AModel"} + ] + } + } + } + }, + "responses": { + "200": { + "description": "Successful response", + "content": { + "application/json": { + "schema": { + "oneOf": [ + {"$ref": "#/components/schemas/AModel"}, + {"$ref": "#/components/schemas/AModel"} + ] + } + } + } + } + } + } } } -"components": { +"components": "schemas": { "AFormData": { "type": "object", @@ -1620,6 +1854,44 @@ info: "an_required_field" ] }, + "Aliased": { + "allOf": [ + { "$ref": "#/components/schemas/AModel" } + ] + }, + "Extended": { + "allOf": [ + { "$ref": "#/components/schemas/Aliased" }, + { "type": "object", + "properties": { + "fromExtended": { + "type": "string" + } + } + } + ] + }, + "AllOfRequiredBase": { + "type": "object", + "properties": { + "bar": { + "type": "string", + "description": "The bar property" + }, + "baz": { + "type": "string", + "description": "The baz property" + } + } + }, + "AllOfRequiredDerived": { + "allOf": [ + { "$ref": "#/components/schemas/AllOfRequiredBase" }, + { "type": "object", + "required": ["bar"] + } + ] + }, "AModel": { "title": "AModel", "required": [ @@ -1628,6 +1900,8 @@ info: "aCamelDateTime", "a_date", "a_nullable_date", + "a_uuid", + "a_nullable_uuid", "required_nullable", "required_not_nullable", "model", @@ -1637,7 +1911,9 @@ info: ], "type": "object", "properties": { - "any_value": { }, + "any_value": { + "default": "default", + }, "an_enum_value": { "$ref": "#/components/schemas/AnEnum" }, @@ -1650,11 +1926,7 @@ info: "default": "overridden_default" }, "an_optional_allof_enum": { - "allOf": [ - { - "$ref": "#/components/schemas/AnAllOfEnum" - } - ] + "$ref": "#/components/schemas/AnAllOfEnum", }, "nested_list_of_enums": { "title": "Nested List Of Enums", @@ -1702,6 +1974,29 @@ info: "type": "string", "format": "date" }, + "a_uuid": { + "title": "A Uuid", + "type": "string", + "format": "uuid" + }, + "a_nullable_uuid": { + "title": "A Nullable Uuid", + "anyOf": [ + { + "type": "string", + "format": "uuid", + }, + { + "type": "null" + } + ], + "default": "07EF8B4D-AA09-4FFA-898D-C710796AFF41" + }, + "a_not_required_uuid": { + "title": "A Not Required Uuid", + "type": "string", + "format": "uuid" + }, "1_leading_digit": { "title": "Leading Digit", "type": "string" @@ -1791,11 +2086,7 @@ info: ] }, "model": { - "allOf": [ - { - "$ref": "#/components/schemas/ModelWithUnionProperty" - } - ] + "$ref": "#/components/schemas/ModelWithUnionProperty" }, "nullable_model": { "oneOf": [ @@ -1808,11 +2099,7 @@ info: ] }, "not_required_model": { - "allOf": [ - { - "$ref": "#/components/schemas/ModelWithUnionProperty" - } - ] + "$ref": "#/components/schemas/ModelWithUnionProperty" }, "not_required_nullable_model": { "oneOf": [ @@ -1877,7 +2164,8 @@ info: "required": [ "some_file", "some_object", - "some_nullable_object" + "some_nullable_object", + "some_required_number" ], "type": "object", "properties": { @@ -1910,6 +2198,21 @@ info: "title": "Some Number", "type": "number" }, + "some_nullable_number": { + "title": "Some Nullable Number", + "type": [ "number", "null" ] + }, + "some_required_number": { + "title": "Some Number", + "type": "number" + }, + "some_int_array": { + "title": "Some Integer Array", + "type": "array", + "items": { + "type": [ "integer", "null" ] + } + }, "some_array": { "title": "Some Array", "type": [ "array", "null" ], @@ -2041,6 +2344,7 @@ info: "oneOf": [ { "type": "object", + "title": "Apples", "properties": { "apples": { "type": "string" @@ -2049,6 +2353,7 @@ info: }, { "type": "object", + "title": "Bananas", "properties": { "bananas": { "type": "string" @@ -2081,6 +2386,56 @@ info: "additionalProperties": { } } }, + "ModelWithMergedProperties": { + "title": "ModelWithMergedProperties", + "allOf": [ + { + "type": "object", + "properties": { + "simpleString": { + "type": "string", + "description": "base simpleString description" + }, + "stringToEnum": { + "type": "string", + "default": "a" + }, + "stringToDate": { + "type": "string" + }, + "numberToInt": { + "type": "number" + }, + "anyToString": { } + } + }, + { + "type": "object", + "properties": { + "simpleString": { + "type": "string", + "description": "extended simpleString description", + "default": "new default" + }, + "stringToEnum": { + "type": "string", + "enum": [ "a", "b" ] + }, + "stringToDate": { + "type": "string", + "format": "date" + }, + "numberToInt": { + "type": "integer" + }, + "anyToString": { + "type": "string", + "default": "x" + } + } + } + ] + }, "ModelWithPrimitiveAdditionalProperties": { "title": "ModelWithPrimitiveAdditionalProperties", "type": "object", @@ -2148,6 +2503,11 @@ info: } ] }, + "ModelWithNoProperties": { + "type": "object", + "properties": { }, + "additionalProperties": false + }, "AllOfSubModel": { "title": "AllOfSubModel", "type": "object", @@ -2688,7 +3048,7 @@ info: } } } - }, + } "parameters": { "integer-param": { "name": "integer param", @@ -2756,5 +3116,18 @@ info: } } } -} - + requestBodies: + NestedRef: + "$ref": "#/components/requestBodies/ARequestBody" + ARequestBody: + content: + "application/json": + "schema": + "$ref": "#/components/schemas/AModel" + responses: + AResponse: + description: OK + content: + "application/json": + "schema": + "$ref": "#/components/schemas/AModel" diff --git a/end_to_end_tests/config.yml b/end_to_end_tests/config.yml index 64e58439a..a813deddd 100644 --- a/end_to_end_tests/config.yml +++ b/end_to_end_tests/config.yml @@ -11,3 +11,4 @@ class_overrides: field_prefix: attr_ content_type_overrides: openapi/python/client: application/json +generate_all_tags: true diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/default/__init__.py b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/default/__init__.py deleted file mode 100644 index ab2d97db8..000000000 --- a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/default/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -"""Contains methods for accessing the API Endpoints""" - -import types - -from . import get_common_parameters, post_common_parameters, reserved_parameters - - -class DefaultEndpoints: - @classmethod - def get_common_parameters(cls) -> types.ModuleType: - return get_common_parameters - - @classmethod - def post_common_parameters(cls) -> types.ModuleType: - return post_common_parameters - - @classmethod - def reserved_parameters(cls) -> types.ModuleType: - return reserved_parameters diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/responses/__init__.py b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/responses/__init__.py deleted file mode 100644 index 6000bd0e7..000000000 --- a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/responses/__init__.py +++ /dev/null @@ -1,21 +0,0 @@ -"""Contains methods for accessing the API Endpoints""" - -import types - -from . import post_responses_unions_simple_before_complex, text_response - - -class ResponsesEndpoints: - @classmethod - def post_responses_unions_simple_before_complex(cls) -> types.ModuleType: - """ - Regression test for #603 - """ - return post_responses_unions_simple_before_complex - - @classmethod - def text_response(cls) -> types.ModuleType: - """ - Text Response - """ - return text_response diff --git a/end_to_end_tests/docstrings_on_attributes.config.yml b/end_to_end_tests/docstrings_on_attributes.config.yml new file mode 100644 index 000000000..0b21ad0b5 --- /dev/null +++ b/end_to_end_tests/docstrings_on_attributes.config.yml @@ -0,0 +1 @@ +docstrings_on_attributes: true diff --git a/end_to_end_tests/docstrings_on_attributes.yml b/end_to_end_tests/docstrings_on_attributes.yml new file mode 100644 index 000000000..22e6e227d --- /dev/null +++ b/end_to_end_tests/docstrings_on_attributes.yml @@ -0,0 +1,32 @@ +openapi: 3.1.0 +info: + title: My Test API + description: An API for testing docstrings_on_attributes behavior + version: 0.1.0 +paths: + {} +components: + schemas: + ModelWithDescription: + type: object + description: This is a nice model. + properties: + propWithNoDesc: + type: string + propWithDesc: + type: string + description: This is a nice property. + propWithLongDesc: + type: string + description: | + It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, + it was the epoch of belief, it was the epoch of incredulity, it was the season of light, it was the season of + darkness, it was the spring of hope, it was the winter of despair. + ModelWithNoDescription: + type: object + properties: + propWithNoDesc: + type: string + propWithDesc: + type: string + description: This is a nice property. diff --git a/end_to_end_tests/documents_with_errors/bad-status-code.yaml b/end_to_end_tests/documents_with_errors/bad-status-code.yaml new file mode 100644 index 000000000..17c3ab2cf --- /dev/null +++ b/end_to_end_tests/documents_with_errors/bad-status-code.yaml @@ -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" diff --git a/end_to_end_tests/documents_with_errors/circular-body-ref.yaml b/end_to_end_tests/documents_with_errors/circular-body-ref.yaml new file mode 100644 index 000000000..98761a35d --- /dev/null +++ b/end_to_end_tests/documents_with_errors/circular-body-ref.yaml @@ -0,0 +1,20 @@ +openapi: "3.1.0" +info: + title: "Circular Body Ref" + version: "0.1.0" +paths: + /: + post: + requestBody: + $ref: "#/components/requestBodies/body" + responses: + "200": + description: "Successful Response" + content: + "application/json": + schema: + const: "Why have a fixed response? I dunno" +components: + requestBodies: + body: + $ref: "#/components/requestBodies/body" \ No newline at end of file diff --git a/end_to_end_tests/documents_with_errors/invalid-uuid-defaults.yaml b/end_to_end_tests/documents_with_errors/invalid-uuid-defaults.yaml new file mode 100644 index 000000000..dd768de4f --- /dev/null +++ b/end_to_end_tests/documents_with_errors/invalid-uuid-defaults.yaml @@ -0,0 +1,30 @@ +openapi: "3.1.0" +info: + title: "Circular Body Ref" + version: "0.1.0" +paths: + /: + post: + parameters: + - name: id + in: query + required: false + schema: + type: string + format: uuid + default: "notauuid" + responses: + "200": + description: "Successful Response" + put: + parameters: + - name: another_id + in: query + required: false + schema: + type: string + format: uuid + default: 3 + responses: + "200": + description: "Successful Response" \ No newline at end of file diff --git a/end_to_end_tests/documents_with_errors/missing-body-ref.yaml b/end_to_end_tests/documents_with_errors/missing-body-ref.yaml new file mode 100644 index 000000000..bf02ba6b1 --- /dev/null +++ b/end_to_end_tests/documents_with_errors/missing-body-ref.yaml @@ -0,0 +1,16 @@ +openapi: "3.1.0" +info: + title: "Trying to use a request body ref that does not exist" + version: "0.1.0" +paths: + /: + post: + requestBody: + $ref: "#/components/requestBodies/body" + responses: + "200": + description: "Successful Response" + content: + "application/json": + schema: + const: "Why have a fixed response? I dunno" \ No newline at end of file diff --git a/end_to_end_tests/documents_with_errors/optional-path-param.yaml b/end_to_end_tests/documents_with_errors/optional-path-param.yaml new file mode 100644 index 000000000..ccd0237db --- /dev/null +++ b/end_to_end_tests/documents_with_errors/optional-path-param.yaml @@ -0,0 +1,19 @@ +openapi: "3.1.0" +info: + title: "There's something wrong with me" + version: "0.1.0" +paths: + "/{optional}": + get: + parameters: + - in: "path" + name: "optional" + schema: + type: "string" + responses: + "200": + description: "Successful Response" + content: + "application/json": + schema: + const: "Why have a fixed response? I dunno" diff --git a/end_to_end_tests/escapes.openapi.yaml b/end_to_end_tests/escapes.openapi.yaml new file mode 100644 index 000000000..66c071a50 --- /dev/null +++ b/end_to_end_tests/escapes.openapi.yaml @@ -0,0 +1,179 @@ +openapi: "3.1.\"print('uh oh')" +info: + title: "escapes\"" + version: "1.2.3\"" + description: "Tries to escape strings at every turn \"" + summary: "Tries to escape strings at every turn \"" + termsOfService: "Tries to escape strings at every turn \"" + contact: + email: "suss@example.com\"" + name: "Escaper \"" + url: "https://example.com\"" + license: + url: "https://example.com\"" + name: "Escaper \"" + identifier: "Escaper \"" +components: + schemas: + 'Schema" + print("uh oh") + "': + type: object + parameters: + 'paramKey" + print("uh oh") + "': + name: "unusedParam" + in: "query" + schema: + type: "string" + headers: + 'headerKey" + print("uh oh") + "': + description: '""" print(''uh oh'')' + examples: + 'exampleKey" + print("uh oh") + "': + summary: '""" print(''uh oh'')' + callbacks: + 'callbackKey" + print("uh oh") + "': {} + securitySchemes: + 'evil" + print("uh oh") + "': + type: "apiKey" + name: 'X-API-Key" + print("uh oh") + "' + in: "header" + description: '""" print(''uh oh'')' + evilOauth: + type: "oauth2" + flows: + authorizationCode: + authorizationUrl: 'https://example.com/" + print("uh oh") + "' + tokenUrl: 'https://example.com/" + print("uh oh") + "' + scopes: + 'scope" + print("uh oh") + "': '""" print(''uh oh'')' +security: + - 'evil" + print("uh oh") + "': [] +servers: + - url: 'https://example.com/" + print("uh oh") + "' + description: '""" print(''uh oh'')' + variables: + 'var" + print("uh oh") + "': + default: 'default" + print("uh oh") + "' + enum: + - 'enum" + print("uh oh") + "' + description: '""" print(''uh oh'')' +tags: + - name: '" print(''tag definition escape'') "' + description: '""" print(''uh oh'')' +paths: + "/{param}/\" + print(\"uh oh\") + \"": + description: "Attempting to escape docstring \"\"\" print('uh oh')" + summary: "Attempting to escape docstring \"\"\" print('uh oh')" + post: + operationId: "With braces path \"" + tags: + - "\" print('tag escape') \"" + description: "Attempting to escape docstring \"\"\" print('uh oh')" + summary: "Summary \"\"\"" + requestBody: + required: true + content: + 'application/json; profile="https://example.com/escape" + print("uh oh") + "': + schema: + type: object + parameters: + - name: "param" + description: "\" print('escape param description')" + in: "path" + required: true + schema: + type: "string" + - name: "\\\"print('escape param name')" + in: "query" + schema: + type: "string" + responses: + '200': + description: "Success \"" + /property-escapes: + post: + operationId: "Property escapes" + requestBody: + required: true + content: + application/json: + schema: + type: object + title: 'Model title """ print(''uh oh'')' + properties: + escaped_description: + type: string + description: 'Attempting to escape the Attributes docstring """ print(''uh oh'')' + example: 'Example """ print(''uh oh'')' + default: 'default value with "quotes"' + escaped_enum: + type: string + enum: + - 'normal value' + - 'value" + print(''uh oh'') + "' + escaped_const: + const: '" + print(''uh oh'') + "' + responses: + '200': + description: Success + /misc-metadata-escapes: + post: + operationId: "Misc metadata escapes" + requestBody: + required: true + content: + application/json: + schema: + type: object + externalDocs: + url: 'https://example.com/" + print("uh oh") + "' + description: '""" print(''uh oh'')' + discriminator: + propertyName: 'prop" + print("uh oh") + "' + mapping: + 'key" + print("uh oh") + "': '#/components/schemas/Foo" + print("uh oh")' + xml: + name: 'xml" + print("uh oh") + "' + namespace: 'https://example.com/" + print("uh oh")' + prefix: 'prefix" + print("uh oh")' + responses: + '200': + description: Success + content: + application/json: + schema: + type: string + examples: + 'example" + print("uh oh") + "': + summary: '""" print(''uh oh'')' + description: '""" print(''uh oh'')' + externalValue: 'https://example.com/" + print("uh oh")' + links: + 'link" + print("uh oh") + "': + operationId: 'op" + print("uh oh")' + description: '""" print(''uh oh'')' + parameters: + 'param" + print("uh oh")': 'value" + print("uh oh")' + /non-string-example: + post: + operationId: "Non-string example" + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + dict_example: + type: object + example: + nested: 'dict example """ print(''uh oh'')' + responses: + '200': + description: Success + /weird-responses: + get: + responses: + "\"print('uh oh')": + description: Success + "3FakePatternXX": + description: A Fake Pattern \ No newline at end of file diff --git a/end_to_end_tests/functional_tests/README.md b/end_to_end_tests/functional_tests/README.md new file mode 100644 index 000000000..eba353881 --- /dev/null +++ b/end_to_end_tests/functional_tests/README.md @@ -0,0 +1,77 @@ +## The `functional_tests` module + +These are end-to-end tests which run the client generator against many small API documents that are specific to various test cases. + +Rather than testing low-level implementation details (like the unit tests in `tests`), or making assertions about the exact content of the generated code (like the "golden record"-based end-to-end tests), these treat both the generator and the generated code as black boxes and make assertions about their behavior. + +The tests are in two submodules: + +# `generated_code_execution` + +These tests use valid API specs, and after running the generator, they _import and execute_ pieces of the generated code to verify that it actually works at runtime. + +Each test class follows this pattern: + +- Use the decorator `@with_generated_client_fixture`, providing an inline API spec (JSON or YAML) that contains whatever schemas/paths/etc. are relevant to this test class. + - The spec can omit the `openapi:`, `info:`, and `paths:`, blocks, unless those are relevant to the test. + - The decorator creates a temporary file for the inline spec and a temporary directory for the generated code, and runs the client generator. + - It creates a `GeneratedClientContext` object (defined in `end_to_end_test_helpers.py`) to keep track of things like the location of the generated code and the output of the generator command. + - This object is injected into the test class as a fixture called `generated_client`, although most tests will not need to reference the fixture directly. + - `sys.path` is temporarily changed, for the scope of this test class, to allow imports from the generated code. +- Use the decorator `@with_generated_code_imports` or `@with_generated_code_import` to make classes or functions from the generated code available to the tests. + - `@with_generated_code_imports(".models.MyModel1", ".models.MyModel2)` would execute `from [package name].models import MyModel1, MyModel2` and inject the imported classes into the test class as fixtures called `MyModel1` and `MyModel2`. + - `@with_generated_code_import(".api.my_operation.sync", alias="endpoint_method")` would execute `from [package name].api.my_operation import sync`, but the fixture would be named `endpoint_method`. + - After the test class finishes, these imports are discarded. + +Example: + +```python +@with_generated_client_fixture( + """ +components: + schemas: + MyModel: + type: object + properties: + stringProp: {"type": "string"} +""" +) +@with_generated_code_import(".models.MyModel") +class TestSimpleJsonObject: + def test_encoding(self, MyModel): + instance = MyModel(string_prop="abc") + assert instance.to_dict() == {"stringProp": "abc"} +``` + +# `generator_failure_cases` + +These run the generator with an invalid API spec and make assertions about the warning/error output. Some of these invalid conditions are expected to only produce warnings about the affected schemas, while others are expected to produce fatal errors that terminate the generator. + +For warning conditions, each test class uses `@with_generated_client_fixture` as above, then uses `assert_bad_schema` to parse the output and check for a specific warning message for a specific schema name. + +```python +@with_generated_client_fixture( + """ +components: + schemas: + MyModel: + # some kind of invalid schema +""" +) +class TestBadSchema: + def test_encoding(self, generated_client): + assert_bad_schema(generated_client, "MyModel", "some expected warning text") +``` + +Or, for fatal error conditions: + +- Call `inline_spec_should_fail`, providing an inline API spec (JSON or YAML). + +```python +class TestBadSpec: + def test_some_spec_error(self): + result = inline_spec_should_fail(""" +# some kind of invalid spec +""") + assert "some expected error text" in result.output +``` diff --git a/end_to_end_tests/functional_tests/generated_code_execution/test_arrays.py b/end_to_end_tests/functional_tests/generated_code_execution/test_arrays.py new file mode 100644 index 000000000..7df15d565 --- /dev/null +++ b/end_to_end_tests/functional_tests/generated_code_execution/test_arrays.py @@ -0,0 +1,145 @@ +from end_to_end_tests.functional_tests.helpers import ( + assert_model_decode_encode, + assert_model_property_type_hint, + with_generated_client_fixture, + with_generated_code_imports, +) + + +@with_generated_client_fixture( + """ +components: + schemas: + SimpleObject: + type: object + properties: + name: {"type": "string"} + ModelWithArrayOfAny: + properties: + arrayProp: + type: array + items: {} + ModelWithArrayOfInts: + properties: + arrayProp: + type: array + items: {"type": "integer"} + ModelWithArrayOfObjects: + properties: + arrayProp: + type: array + items: {"$ref": "#/components/schemas/SimpleObject"} +""" +) +@with_generated_code_imports( + ".models.ModelWithArrayOfAny", + ".models.ModelWithArrayOfInts", + ".models.ModelWithArrayOfObjects", + ".models.SimpleObject", +) +class TestArraySchemas: + def test_array_of_any(self, ModelWithArrayOfAny): + assert_model_decode_encode( + ModelWithArrayOfAny, + {"arrayProp": ["a", 1]}, + ModelWithArrayOfAny(array_prop=["a", 1]), + ) + + def test_array_of_int(self, ModelWithArrayOfInts): + assert_model_decode_encode( + ModelWithArrayOfInts, + {"arrayProp": [1, 2]}, + ModelWithArrayOfInts(array_prop=[1, 2]), + ) + + def test_array_of_object(self, ModelWithArrayOfObjects, SimpleObject): + assert_model_decode_encode( + ModelWithArrayOfObjects, + {"arrayProp": [{"name": "a"}, {"name": "b"}]}, + ModelWithArrayOfObjects(array_prop=[SimpleObject(name="a"), SimpleObject(name="b")]), + ) + + def test_type_hints(self, ModelWithArrayOfAny, ModelWithArrayOfInts, ModelWithArrayOfObjects): + assert_model_property_type_hint(ModelWithArrayOfAny, "array_prop", "list[Any] | Unset") + assert_model_property_type_hint(ModelWithArrayOfInts, "array_prop", "list[int] | Unset") + assert_model_property_type_hint(ModelWithArrayOfObjects, "array_prop", "list[SimpleObject] | Unset") + + +@with_generated_client_fixture( + """ +components: + schemas: + SimpleObject: + type: object + properties: + name: {"type": "string"} + ModelWithSinglePrefixItem: + type: object + properties: + arrayProp: + type: array + prefixItems: + - type: string + ModelWithPrefixItems: + type: object + properties: + arrayProp: + type: array + prefixItems: + - $ref: "#/components/schemas/SimpleObject" + - type: string + ModelWithMixedItems: + type: object + properties: + arrayProp: + type: array + prefixItems: + - $ref: "#/components/schemas/SimpleObject" + items: + type: string +""" +) +@with_generated_code_imports( + ".models.ModelWithSinglePrefixItem", + ".models.ModelWithPrefixItems", + ".models.ModelWithMixedItems", + ".models.SimpleObject", +) +class TestArraysWithPrefixItems: + def test_single_prefix_item(self, ModelWithSinglePrefixItem): + assert_model_decode_encode( + ModelWithSinglePrefixItem, + {"arrayProp": ["a"]}, + ModelWithSinglePrefixItem(array_prop=["a"]), + ) + + def test_prefix_items(self, ModelWithPrefixItems, SimpleObject): + assert_model_decode_encode( + ModelWithPrefixItems, + {"arrayProp": [{"name": "a"}, "b"]}, + ModelWithPrefixItems(array_prop=[SimpleObject(name="a"), "b"]), + ) + + def test_prefix_items_and_regular_items(self, ModelWithMixedItems, SimpleObject): + assert_model_decode_encode( + ModelWithMixedItems, + {"arrayProp": [{"name": "a"}, "b"]}, + ModelWithMixedItems(array_prop=[SimpleObject(name="a"), "b"]), + ) + + def test_type_hints(self, ModelWithSinglePrefixItem, ModelWithPrefixItems, ModelWithMixedItems): + assert_model_property_type_hint(ModelWithSinglePrefixItem, "array_prop", "list[str] | Unset") + assert_model_property_type_hint( + ModelWithPrefixItems, + "array_prop", + "list[SimpleObject | str] | Unset", + ) + assert_model_property_type_hint( + ModelWithMixedItems, + "array_prop", + "list[SimpleObject | str] | Unset", + ) + # Note, this test is asserting the current behavior which, due to limitations of the implementation + # (see: https://github.com/openapi-generators/openapi-python-client/pull/1130), is not really doing + # tuple type validation-- the ordering of prefixItems is ignored, and instead all of the types are + # simply treated as a union. diff --git a/end_to_end_tests/functional_tests/generated_code_execution/test_defaults.py b/end_to_end_tests/functional_tests/generated_code_execution/test_defaults.py new file mode 100644 index 000000000..ae32cb31c --- /dev/null +++ b/end_to_end_tests/functional_tests/generated_code_execution/test_defaults.py @@ -0,0 +1,115 @@ +import datetime +import uuid + +from end_to_end_tests.functional_tests.helpers import ( + with_generated_client_fixture, + with_generated_code_imports, +) + + +@with_generated_client_fixture( + """ +components: + schemas: + MyModel: + type: object + properties: + booleanProp: {"type": "boolean", "default": true} + stringProp: {"type": "string", "default": "a"} + numberProp: {"type": "number", "default": 1.5} + intProp: {"type": "integer", "default": 2} + dateProp: {"type": "string", "format": "date", "default": "2024-01-02"} + dateTimeProp: {"type": "string", "format": "date-time", "default": "2024-01-02T03:04:05Z"} + uuidProp: {"type": "string", "format": "uuid", "default": "07EF8B4D-AA09-4FFA-898D-C710796AFF41"} + anyPropWithString: {"default": "b"} + anyPropWithInt: {"default": 3} + booleanWithStringTrue1: {"type": "boolean", "default": "True"} + booleanWithStringTrue2: {"type": "boolean", "default": "true"} + booleanWithStringFalse1: {"type": "boolean", "default": "False"} + booleanWithStringFalse2: {"type": "boolean", "default": "false"} + intWithStringValue: {"type": "integer", "default": "4"} + numberWithIntValue: {"type": "number", "default": 5} + numberWithStringValue: {"type": "number", "default": "5.5"} + stringWithNumberValue: {"type": "string", "default": 6} + stringConst: {"type": "string", "const": "always", "default": "always"} + unionWithValidDefaultForType1: + anyOf: [{"type": "boolean"}, {"type": "integer"}] + default: true + unionWithValidDefaultForType2: + anyOf: [{"type": "boolean"}, {"type": "integer"}] + default: 3 +""" +) +@with_generated_code_imports(".models.MyModel") +class TestSimpleDefaults: + # Note, the null/None type is not covered here due to a known bug: + # https://github.com/openapi-generators/openapi-python-client/issues/1162 + def test_defaults_in_initializer(self, MyModel): + instance = MyModel() + assert instance == MyModel( + boolean_prop=True, + string_prop="a", + number_prop=1.5, + int_prop=2, + date_prop=datetime.date(2024, 1, 2), + date_time_prop=datetime.datetime(2024, 1, 2, 3, 4, 5, tzinfo=datetime.UTC), + uuid_prop=uuid.UUID("07EF8B4D-AA09-4FFA-898D-C710796AFF41"), + any_prop_with_string="b", + any_prop_with_int=3, + boolean_with_string_true_1=True, + boolean_with_string_true_2=True, + boolean_with_string_false_1=False, + boolean_with_string_false_2=False, + int_with_string_value=4, + number_with_int_value=5, + number_with_string_value=5.5, + string_with_number_value="6", + string_const="always", + union_with_valid_default_for_type_1=True, + union_with_valid_default_for_type_2=3, + ) + + +@with_generated_client_fixture( + """ +components: + schemas: + MyEnum: + type: string + enum: ["a", "b"] + MyModel: + type: object + properties: + enumProp: + allOf: + - $ref: "#/components/schemas/MyEnum" + default: "a" + +""" +) +@with_generated_code_imports(".models.MyEnum", ".models.MyModel") +class TestEnumDefaults: + def test_enum_default(self, MyEnum, MyModel): + assert MyModel().enum_prop == MyEnum.A + + +@with_generated_client_fixture( + """ +components: + schemas: + MyEnum: + type: string + enum: ["a", "A"] + MyModel: + properties: + enumProp: + allOf: + - $ref: "#/components/schemas/MyEnum" + default: A +""", + config="literal_enums: true", +) +@with_generated_code_imports(".models.MyModel") +class TestLiteralEnumDefaults: + def test_default_value(self, MyModel): + assert MyModel().enum_prop == "A" diff --git a/end_to_end_tests/functional_tests/generated_code_execution/test_docstrings.py b/end_to_end_tests/functional_tests/generated_code_execution/test_docstrings.py new file mode 100644 index 000000000..68e4cbd3e --- /dev/null +++ b/end_to_end_tests/functional_tests/generated_code_execution/test_docstrings.py @@ -0,0 +1,163 @@ +from typing import Any + +from end_to_end_tests.functional_tests.helpers import ( + with_generated_client_fixture, + with_generated_code_import, +) + + +class DocstringParser: + lines: list[str] + + def __init__(self, item: Any): + self.lines = [line.lstrip() for line in item.__doc__.split("\n")] + + def get_section(self, header_line: str) -> list[str]: + lines = self.lines[self.lines.index(header_line) + 1 :] + return lines[0 : lines.index("")] + + +@with_generated_client_fixture( + """ +components: + schemas: + MyModel: + description: I like this type. + type: object + properties: + reqStr: + type: string + description: This is necessary. + optStr: + type: string + description: This isn't necessary. + undescribedProp: + type: string + required: ["reqStr", "undescribedProp"] +""" +) +@with_generated_code_import(".models.MyModel") +class TestSchemaDocstrings: + def test_model_description(self, MyModel): + assert DocstringParser(MyModel).lines[0] == "I like this type." + + def test_model_properties(self, MyModel): + assert set(DocstringParser(MyModel).get_section("Attributes:")) == { + "req_str (str): This is necessary.", + "opt_str (str | Unset): This isn't necessary.", + "undescribed_prop (str):", + } + + +@with_generated_client_fixture( + """ +tags: + - name: service1 +paths: + "/simple": + get: + operationId: getSimpleThing + description: Get a simple thing. + responses: + "200": + description: Success! + content: + application/json: + schema: + $ref: "#/components/schemas/GoodResponse" + tags: + - service1 + post: + operationId: postSimpleThing + description: Post a simple thing. + requestBody: + content: + application/json: + schema: + $ref: "#/components/schemas/Thing" + responses: + "200": + description: Success! + content: + application/json: + schema: + $ref: "#/components/schemas/GoodResponse" + "400": + description: Failure!! + content: + application/json: + schema: + $ref: "#/components/schemas/ErrorResponse" + tags: + - service1 + "/simple/{id}/{index}": + get: + operationId: getAttributeByIndex + description: Get a simple thing's attribute. + parameters: + - name: id + in: path + required: true + schema: + type: string + description: Which one. + - name: index + in: path + required: true + schema: + type: integer + - name: fries + in: query + required: false + schema: + type: boolean + description: Do you want fries with that? + responses: + "200": + description: Success! + content: + application/json: + schema: + $ref: "#/components/schemas/GoodResponse" + tags: + - service1 + +components: + schemas: + GoodResponse: + type: object + ErrorResponse: + type: object + Thing: + type: object + description: The thing. +""" +) +@with_generated_code_import(".api.service1.get_simple_thing.sync", alias="get_simple_thing_sync") +@with_generated_code_import(".api.service1.post_simple_thing.sync", alias="post_simple_thing_sync") +@with_generated_code_import(".api.service1.get_attribute_by_index.sync", alias="get_attribute_by_index_sync") +class TestEndpointDocstrings: + def test_description(self, get_simple_thing_sync): + assert DocstringParser(get_simple_thing_sync).lines[0] == "Get a simple thing." + + def test_response_single_type(self, get_simple_thing_sync): + assert DocstringParser(get_simple_thing_sync).get_section("Returns:") == [ + "GoodResponse", + ] + + def test_response_union_type(self, post_simple_thing_sync): + returns_line = DocstringParser(post_simple_thing_sync).get_section("Returns:")[0] + assert returns_line in ( + "GoodResponse | ErrorResponse", + "ErrorResponse | GoodResponse", + ) + + def test_request_body(self, post_simple_thing_sync): + assert DocstringParser(post_simple_thing_sync).get_section("Args:") == ["body (Thing | Unset): The thing."] + + def test_params(self, get_attribute_by_index_sync): + assert DocstringParser(get_attribute_by_index_sync).get_section("Args:") == [ + "id (str): Which one.", + "index (int):", + "fries (bool | Unset): Do you want fries with that?", + ] diff --git a/end_to_end_tests/functional_tests/generated_code_execution/test_enums_and_consts.py b/end_to_end_tests/functional_tests/generated_code_execution/test_enums_and_consts.py new file mode 100644 index 000000000..cb2e09d79 --- /dev/null +++ b/end_to_end_tests/functional_tests/generated_code_execution/test_enums_and_consts.py @@ -0,0 +1,399 @@ +from typing import Literal + +import pytest + +from end_to_end_tests.functional_tests.helpers import ( + assert_model_decode_encode, + assert_model_property_type_hint, + with_generated_client_fixture, + with_generated_code_imports, +) + + +@with_generated_client_fixture( + """ +components: + schemas: + MyEnum: + type: string + enum: ["a", "B", "a23", "123", "1bc", "a Thing WIth spaces", ""] + MyModel: + properties: + enumProp: {"$ref": "#/components/schemas/MyEnum"} + inlineEnumProp: + type: string + enum: ["a", "b"] + MyModelWithRequired: + properties: + enumProp: {"$ref": "#/components/schemas/MyEnum"} + required: ["enumProp"] +""" +) +@with_generated_code_imports( + ".models.MyEnum", + ".models.MyModel", + ".models.MyModelInlineEnumProp", + ".models.MyModelWithRequired", +) +class TestStringEnumClass: + @pytest.mark.parametrize( + "expected_name,expected_value", + [ + ("A", "a"), + ("B", "B"), + ("A23", "a23"), + ("VALUE_3", "123"), + ("VALUE_4", "1bc"), + ("A_THING_WITH_SPACES", "a Thing WIth spaces"), + ("VALUE_6", ""), + ], + ) + def test_enum_values(self, MyEnum, expected_name, expected_value): + assert getattr(MyEnum, expected_name) == MyEnum(expected_value) + + def test_enum_prop_in_object(self, MyEnum, MyModel, MyModelInlineEnumProp): + assert_model_decode_encode(MyModel, {"enumProp": "B"}, MyModel(enum_prop=MyEnum.B)) + assert_model_decode_encode( + MyModel, + {"inlineEnumProp": "a"}, + MyModel(inline_enum_prop=MyModelInlineEnumProp.A), + ) + + def test_type_hints(self, MyModel, MyModelWithRequired): + optional_type = "MyEnum | Unset" + assert_model_property_type_hint(MyModel, "enum_prop", optional_type) + assert_model_property_type_hint(MyModelWithRequired, "enum_prop", "MyEnum") + + def test_invalid_values(self, MyModel): + with pytest.raises(ValueError): + MyModel.from_dict({"enumProp": "c"}) + with pytest.raises(ValueError): + MyModel.from_dict({"enumProp": "A"}) + with pytest.raises(ValueError): + MyModel.from_dict({"enumProp": 2}) + + +@with_generated_client_fixture( + """ +components: + schemas: + MyStrEnum: + type: string + enum: ["a", "b", "c"] + x-enum-varnames: [ + "One", + "More than OnE", + "not_quite_four" + ] +""" +) +@with_generated_code_imports( + ".models.MyStrEnum", +) +class TestStrEnumVarNameExtensions: + @pytest.mark.parametrize( + "expected_name,expected_value", + [ + ("ONE", "a"), + ("MORE_THAN_ON_E", "b"), + ("NOT_QUITE_FOUR", "c"), + ], + ) + def test_enum_values(self, MyStrEnum, expected_name, expected_value): + assert getattr(MyStrEnum, expected_name) == MyStrEnum(expected_value) + + +@with_generated_client_fixture( + """ +components: + schemas: + MyEnum: + type: integer + enum: [2, 3, -4] + MyModel: + properties: + enumProp: {"$ref": "#/components/schemas/MyEnum"} + inlineEnumProp: + type: string + enum: [2, 3] + MyModelWithRequired: + properties: + enumProp: {"$ref": "#/components/schemas/MyEnum"} + required: ["enumProp"] +""" +) +@with_generated_code_imports( + ".models.MyEnum", + ".models.MyModel", + ".models.MyModelInlineEnumProp", + ".models.MyModelWithRequired", +) +class TestIntEnumClass: + @pytest.mark.parametrize( + "expected_name,expected_value", + [ + ("VALUE_2", 2), + ("VALUE_3", 3), + ("VALUE_NEGATIVE_4", -4), + ], + ) + def test_enum_values(self, MyEnum, expected_name, expected_value): + assert getattr(MyEnum, expected_name) == MyEnum(expected_value) + + def test_enum_prop_in_object(self, MyEnum, MyModel, MyModelInlineEnumProp): + assert_model_decode_encode(MyModel, {"enumProp": 2}, MyModel(enum_prop=MyEnum.VALUE_2)) + assert_model_decode_encode( + MyModel, + {"inlineEnumProp": 2}, + MyModel(inline_enum_prop=MyModelInlineEnumProp.VALUE_2), + ) + + def test_type_hints(self, MyModel, MyModelWithRequired): + optional_type = "MyEnum | Unset" + assert_model_property_type_hint(MyModel, "enum_prop", optional_type) + assert_model_property_type_hint(MyModelWithRequired, "enum_prop", "MyEnum") + + def test_invalid_values(self, MyModel): + with pytest.raises(ValueError): + MyModel.from_dict({"enumProp": 5}) + with pytest.raises(ValueError): + MyModel.from_dict({"enumProp": "a"}) + + +@with_generated_client_fixture( + """ +components: + schemas: + MyEnum: + type: integer + enum: [2, 3, -4] + x-enum-varnames: [ + "Two", + "Three", + "Negative Four" + ] +""" +) +@with_generated_code_imports( + ".models.MyEnum", +) +class TestIntEnumVarNameExtensions: + @pytest.mark.parametrize( + "expected_name,expected_value", + [ + ("TWO", 2), + ("THREE", 3), + ("NEGATIVE_FOUR", -4), + ], + ) + def test_enum_values(self, MyEnum, expected_name, expected_value): + assert getattr(MyEnum, expected_name) == MyEnum(expected_value) + + +@with_generated_client_fixture( + """ +components: + schemas: + MyEnum: + type: string + enum: ["a", "b"] + MyEnumIncludingNull: + type: ["string", "null"] + enum: ["a", "b", null] + MyNullOnlyEnum: + enum: [null] + MyModel: + properties: + nullableEnumProp: + oneOf: + - {"$ref": "#/components/schemas/MyEnum"} + - type: "null" + enumIncludingNullProp: {"$ref": "#/components/schemas/MyEnumIncludingNull"} + nullOnlyEnumProp: {"$ref": "#/components/schemas/MyNullOnlyEnum"} +""" +) +@with_generated_code_imports( + ".models.MyEnum", + ".models.MyEnumIncludingNullType1", # see comment in test_nullable_enum_prop + ".models.MyModel", +) +class TestNullableEnums: + def test_nullable_enum_prop(self, MyModel, MyEnum, MyEnumIncludingNullType1): + # Note, MyEnumIncludingNullType1 should be named just MyEnumIncludingNull - + # known bug: https://github.com/openapi-generators/openapi-python-client/issues/1120 + assert_model_decode_encode(MyModel, {"nullableEnumProp": "b"}, MyModel(nullable_enum_prop=MyEnum.B)) + assert_model_decode_encode(MyModel, {"nullableEnumProp": None}, MyModel(nullable_enum_prop=None)) + assert_model_decode_encode( + MyModel, + {"enumIncludingNullProp": "a"}, + MyModel(enum_including_null_prop=MyEnumIncludingNullType1.A), + ) + assert_model_decode_encode(MyModel, {"enumIncludingNullProp": None}, MyModel(enum_including_null_prop=None)) + assert_model_decode_encode(MyModel, {"nullOnlyEnumProp": None}, MyModel(null_only_enum_prop=None)) + + def test_type_hints(self, MyModel): + expected_type = "MyEnum | None | Unset" + assert_model_property_type_hint(MyModel, "nullable_enum_prop", expected_type) + + +@with_generated_client_fixture( + """ +components: + schemas: + MyModel: + properties: + mustBeErnest: + const: Ernest + mustBeThirty: + const: 30 +""", +) +@with_generated_code_imports(".models.MyModel") +class TestConst: + def test_valid_string(self, MyModel): + assert_model_decode_encode( + MyModel, + {"mustBeErnest": "Ernest"}, + MyModel(must_be_ernest="Ernest"), + ) + + def test_valid_int(self, MyModel): + assert_model_decode_encode( + MyModel, + {"mustBeThirty": 30}, + MyModel(must_be_thirty=30), + ) + + def test_invalid_string(self, MyModel): + with pytest.raises(ValueError): + MyModel.from_dict({"mustBeErnest": "Jack"}) + + def test_invalid_int(self, MyModel): + with pytest.raises(ValueError): + MyModel.from_dict({"mustBeThirty": 29}) + + +# The following tests of literal enums use basically the same specs as the tests above, but +# the "literal_enums" option is enabled in the test configuration. + + +@with_generated_client_fixture( + """ +components: + schemas: + MyEnum: + type: string + enum: ["a", "A", "b"] + MyModel: + properties: + enumProp: {"$ref": "#/components/schemas/MyEnum"} + inlineEnumProp: + type: string + enum: ["a", "b"] + MyModelWithRequired: + properties: + enumProp: {"$ref": "#/components/schemas/MyEnum"} + required: ["enumProp"] +""", + config="literal_enums: true", +) +@with_generated_code_imports( + ".models.MyModel", + ".models.MyModelWithRequired", + ".models.MyEnum", +) +class TestStringLiteralEnum: + def test_enum_prop(self, MyModel): + assert_model_decode_encode(MyModel, {"enumProp": "a"}, MyModel(enum_prop="a")) + assert_model_decode_encode(MyModel, {"enumProp": "A"}, MyModel(enum_prop="A")) + assert_model_decode_encode(MyModel, {"inlineEnumProp": "a"}, MyModel(inline_enum_prop="a")) + + def test_type_hints(self, MyModel, MyModelWithRequired, MyEnum): + optional_type = "MyEnum | Unset" + assert_model_property_type_hint(MyModel, "enum_prop", optional_type) + assert_model_property_type_hint(MyModelWithRequired, "enum_prop", "MyEnum") + assert MyEnum == Literal["a", "A", "b"] + + def test_invalid_values(self, MyModel): + with pytest.raises(TypeError): + MyModel.from_dict({"enumProp": "c"}) + with pytest.raises(TypeError): + MyModel.from_dict({"enumProp": 2}) + + +@with_generated_client_fixture( + """ +components: + schemas: + MyEnum: + type: integer + enum: [2, 3, -4] + MyModel: + properties: + enumProp: {"$ref": "#/components/schemas/MyEnum"} + inlineEnumProp: + type: string + enum: [2, 3] + MyModelWithRequired: + properties: + enumProp: {"$ref": "#/components/schemas/MyEnum"} + required: ["enumProp"] +""", + config="literal_enums: true", +) +@with_generated_code_imports( + ".models.MyModel", + ".models.MyModelWithRequired", + ".models.MyEnum", +) +class TestIntLiteralEnum: + def test_enum_prop(self, MyModel): + assert_model_decode_encode(MyModel, {"enumProp": 2}, MyModel(enum_prop=2)) + assert_model_decode_encode(MyModel, {"enumProp": -4}, MyModel(enum_prop=-4)) + assert_model_decode_encode(MyModel, {"inlineEnumProp": 2}, MyModel(inline_enum_prop=2)) + + def test_type_hints(self, MyModel, MyModelWithRequired, MyEnum): + optional_type = "MyEnum | Unset" + assert_model_property_type_hint(MyModel, "enum_prop", optional_type) + assert_model_property_type_hint(MyModelWithRequired, "enum_prop", "MyEnum") + assert MyEnum == Literal[2, 3, -4] + + def test_invalid_values(self, MyModel): + with pytest.raises(TypeError): + MyModel.from_dict({"enumProp": 4}) + with pytest.raises(TypeError): + MyModel.from_dict({"enumProp": "a"}) + + +@with_generated_client_fixture( + """ +components: + schemas: + MyEnum: + type: string + enum: ["a", "A"] + MyEnumIncludingNull: + type: ["string", "null"] + enum: ["a", "b", null] + MyNullOnlyEnum: + enum: [null] + MyModel: + properties: + enumProp: {"$ref": "#/components/schemas/MyEnum"} + nullableEnumProp: + oneOf: + - {"$ref": "#/components/schemas/MyEnum"} + - type: "null" + enumIncludingNullProp: {"$ref": "#/components/schemas/MyEnumIncludingNull"} + nullOnlyEnumProp: {"$ref": "#/components/schemas/MyNullOnlyEnum"} +""", + config="literal_enums: true", +) +@with_generated_code_imports(".models.MyModel") +class TestNullableLiteralEnum: + def test_nullable_enum_prop(self, MyModel): + assert_model_decode_encode(MyModel, {"nullableEnumProp": "B"}, MyModel(nullable_enum_prop="B")) + assert_model_decode_encode(MyModel, {"nullableEnumProp": None}, MyModel(nullable_enum_prop=None)) + assert_model_decode_encode(MyModel, {"enumIncludingNullProp": "a"}, MyModel(enum_including_null_prop="a")) + assert_model_decode_encode(MyModel, {"enumIncludingNullProp": None}, MyModel(enum_including_null_prop=None)) + assert_model_decode_encode(MyModel, {"nullOnlyEnumProp": None}, MyModel(null_only_enum_prop=None)) diff --git a/end_to_end_tests/functional_tests/generated_code_execution/test_path_parameters.py b/end_to_end_tests/functional_tests/generated_code_execution/test_path_parameters.py new file mode 100644 index 000000000..de03a2bd9 --- /dev/null +++ b/end_to_end_tests/functional_tests/generated_code_execution/test_path_parameters.py @@ -0,0 +1,151 @@ +from unittest.mock import MagicMock + +import httpx + +from end_to_end_tests.functional_tests.helpers import ( + with_generated_client_fixture, + with_generated_code_import, +) + + +@with_generated_client_fixture( + """ +paths: + "/items/{item_id}/details/{detail_id}": + get: + operationId: getItemDetail + parameters: + - name: item_id + in: path + required: true + schema: + type: string + - name: detail_id + in: path + required: true + schema: + type: string + responses: + "200": + description: Success + content: + application/json: + schema: + type: object + properties: + id: + type: string +""" +) +@with_generated_code_import(".api.default.get_item_detail.sync_detailed") +@with_generated_code_import(".client.Client") +class TestPathParameterEncoding: + """Test that path parameters are properly URL-encoded""" + + def test_path_params_with_normal_chars_work(self, sync_detailed, Client): + """Test that normal alphanumeric path parameters still work correctly""" + mock_httpx_client = MagicMock(spec=httpx.Client) + mock_response = MagicMock(spec=httpx.Response) + mock_response.status_code = 200 + mock_response.json.return_value = {"id": "test"} + mock_response.content = b'{"id": "test"}' + mock_response.headers = {} + mock_httpx_client.request.return_value = mock_response + + client = Client(base_url="https://api.example.com") + client.set_httpx_client(mock_httpx_client) + + sync_detailed( + item_id="item123", + detail_id="detail456", + client=client, + ) + + mock_httpx_client.request.assert_called_once() + call_kwargs = mock_httpx_client.request.call_args[1] + + # Normal characters should remain unchanged + expected_url = "/items/item123/details/detail456" + assert call_kwargs["url"] == expected_url + + def test_path_params_with_reserved_chars_are_encoded(self, sync_detailed, Client): + """Test that path parameters with reserved characters are properly URL-encoded""" + # Create a mock httpx client + mock_httpx_client = MagicMock(spec=httpx.Client) + mock_response = MagicMock(spec=httpx.Response) + mock_response.status_code = 200 + mock_response.json.return_value = {"id": "test"} + mock_response.content = b'{"id": "test"}' + mock_response.headers = {} + mock_httpx_client.request.return_value = mock_response + + # Create a client with the mock httpx client + client = Client(base_url="https://api.example.com") + client.set_httpx_client(mock_httpx_client) + + # Call the endpoint with path parameters containing reserved characters + sync_detailed( + item_id="item/with/slashes", + detail_id="detail?with=query&chars", + client=client, + ) + + # Verify the request was made with properly encoded URL + mock_httpx_client.request.assert_called_once() + call_kwargs = mock_httpx_client.request.call_args[1] + + # The URL should have encoded slashes and query characters + expected_url = "/items/item%2Fwith%2Fslashes/details/detail%3Fwith%3Dquery%26chars" + assert call_kwargs["url"] == expected_url + + def test_path_params_with_spaces_are_encoded(self, sync_detailed, Client): + """Test that path parameters with spaces are properly URL-encoded""" + mock_httpx_client = MagicMock(spec=httpx.Client) + mock_response = MagicMock(spec=httpx.Response) + mock_response.status_code = 200 + mock_response.json.return_value = {"id": "test"} + mock_response.content = b'{"id": "test"}' + mock_response.headers = {} + mock_httpx_client.request.return_value = mock_response + + client = Client(base_url="https://api.example.com") + client.set_httpx_client(mock_httpx_client) + + sync_detailed( + item_id="item with spaces", + detail_id="detail with spaces", + client=client, + ) + + mock_httpx_client.request.assert_called_once() + call_kwargs = mock_httpx_client.request.call_args[1] + + # Spaces should be encoded as %20 + expected_url = "/items/item%20with%20spaces/details/detail%20with%20spaces" + assert call_kwargs["url"] == expected_url + + def test_path_params_with_hash_are_encoded(self, sync_detailed, Client): + """Test that path parameters with hash/fragment characters are properly URL-encoded""" + mock_httpx_client = MagicMock(spec=httpx.Client) + mock_response = MagicMock(spec=httpx.Response) + mock_response.status_code = 200 + mock_response.json.return_value = {"id": "test"} + mock_response.content = b'{"id": "test"}' + mock_response.headers = {} + mock_httpx_client.request.return_value = mock_response + + client = Client(base_url="https://api.example.com") + client.set_httpx_client(mock_httpx_client) + + sync_detailed( + item_id="item#1", + detail_id="detail#id", + client=client, + ) + + mock_httpx_client.request.assert_called_once() + call_kwargs = mock_httpx_client.request.call_args[1] + + # Hash should be encoded as %23 + expected_url = "/items/item%231/details/detail%23id" + assert call_kwargs["url"] == expected_url diff --git a/end_to_end_tests/functional_tests/generated_code_execution/test_properties.py b/end_to_end_tests/functional_tests/generated_code_execution/test_properties.py new file mode 100644 index 000000000..8c4112980 --- /dev/null +++ b/end_to_end_tests/functional_tests/generated_code_execution/test_properties.py @@ -0,0 +1,266 @@ +import datetime +import uuid + +import pytest + +from end_to_end_tests.functional_tests.helpers import ( + assert_model_decode_encode, + assert_model_property_type_hint, + with_generated_client_fixture, + with_generated_code_imports, +) + + +@with_generated_client_fixture( + """ +components: + schemas: + MyModel: + type: object + properties: + req1: {"type": "string"} + req2: {"type": "string"} + opt: {"type": "string"} + required: ["req1", "req2"] + DerivedModel: + allOf: + - $ref: "#/components/schemas/MyModel" + - type: object + properties: + req3: {"type": "string"} + required: ["req3"] +""" +) +@with_generated_code_imports( + ".models.MyModel", + ".models.DerivedModel", + ".types.Unset", +) +class TestRequiredAndOptionalProperties: + def test_required_ok(self, MyModel, DerivedModel): + assert_model_decode_encode( + MyModel, + {"req1": "a", "req2": "b"}, + MyModel(req1="a", req2="b"), + ) + assert_model_decode_encode( + DerivedModel, + {"req1": "a", "req2": "b", "req3": "c"}, + DerivedModel(req1="a", req2="b", req3="c"), + ) + + def test_required_and_optional(self, MyModel, DerivedModel): + assert_model_decode_encode( + MyModel, + {"req1": "a", "req2": "b", "opt": "c"}, + MyModel(req1="a", req2="b", opt="c"), + ) + assert_model_decode_encode( + DerivedModel, + {"req1": "a", "req2": "b", "req3": "c", "opt": "d"}, + DerivedModel(req1="a", req2="b", req3="c", opt="d"), + ) + + def test_required_missing(self, MyModel, DerivedModel): + with pytest.raises(KeyError): + MyModel.from_dict({"req1": "a"}) + with pytest.raises(KeyError): + MyModel.from_dict({"req2": "b"}) + with pytest.raises(KeyError): + DerivedModel.from_dict({"req1": "a", "req2": "b"}) + + def test_type_hints(self, MyModel): + assert_model_property_type_hint(MyModel, "req1", "str") + assert_model_property_type_hint(MyModel, "opt", "str | Unset") + + +@with_generated_client_fixture( + """ +components: + schemas: + MyModel: + type: object + properties: + booleanProp: {"type": "boolean"} + stringProp: {"type": "string"} + numberProp: {"type": "number"} + intProp: {"type": "integer"} + anyObjectProp: {"$ref": "#/components/schemas/AnyObject"} + nullProp: {"type": "null"} + anyProp: {} + AnyObject: + type: object +""" +) +@with_generated_code_imports( + ".models.MyModel", + ".models.AnyObject", +) +class TestBasicModelProperties: + def test_decode_encode(self, MyModel, AnyObject): + json_data = { + "booleanProp": True, + "stringProp": "a", + "numberProp": 1.5, + "intProp": 2, + "anyObjectProp": {"d": 3}, + "nullProp": None, + "anyProp": "e", + } + expected_any_object = AnyObject() + expected_any_object.additional_properties = {"d": 3} + assert_model_decode_encode( + MyModel, + json_data, + MyModel( + boolean_prop=True, + string_prop="a", + number_prop=1.5, + int_prop=2, + any_object_prop=expected_any_object, + null_prop=None, + any_prop="e", + ), + ) + + @pytest.mark.parametrize( + "bad_data", + ["a", True, 2, None], + ) + def test_decode_error_not_object(self, bad_data, MyModel): + with pytest.raises(Exception): # noqa: B017 + # Exception is overly broad, but unfortunately in the current implementation, the error + # being raised is AttributeError (because it tries to call bad_data.copy()) which isn't + # very meaningful + MyModel.from_dict(bad_data) + + def test_type_hints(self, MyModel): + assert_model_property_type_hint(MyModel, "boolean_prop", "bool | Unset") + assert_model_property_type_hint(MyModel, "string_prop", "str | Unset") + assert_model_property_type_hint(MyModel, "number_prop", "float | Unset") + assert_model_property_type_hint(MyModel, "int_prop", "int | Unset") + assert_model_property_type_hint(MyModel, "any_object_prop", "AnyObject | Unset") + assert_model_property_type_hint(MyModel, "null_prop", "None | Unset") + assert_model_property_type_hint(MyModel, "any_prop", "Any | Unset") + + +@with_generated_client_fixture( + """ +components: + schemas: + MyModel: + type: object + properties: + dateProp: {"type": "string", "format": "date"} + dateTimeProp: {"type": "string", "format": "date-time"} + uuidProp: {"type": "string", "format": "uuid"} + unknownFormatProp: {"type": "string", "format": "weird"} +""" +) +@with_generated_code_imports( + ".models.MyModel", +) +class TestSpecialStringFormats: + def test_date(self, MyModel): + date_value = datetime.date.today() + json_data = {"dateProp": date_value.isoformat()} + assert_model_decode_encode(MyModel, json_data, MyModel(date_prop=date_value)) + + def test_date_time(self, MyModel): + date_time_value = datetime.datetime.now(datetime.UTC) + json_data = {"dateTimeProp": date_time_value.isoformat()} + assert_model_decode_encode(MyModel, json_data, MyModel(date_time_prop=date_time_value)) + + def test_uuid(self, MyModel): + uuid_value = uuid.uuid1() + json_data = {"uuidProp": str(uuid_value)} + assert_model_decode_encode(MyModel, json_data, MyModel(uuid_prop=uuid_value)) + + def test_unknown_format(self, MyModel): + json_data = {"unknownFormatProp": "whatever"} + assert_model_decode_encode(MyModel, json_data, MyModel(unknown_format_prop="whatever")) + + def test_type_hints(self, MyModel): + assert_model_property_type_hint(MyModel, "date_prop", "datetime.date | Unset") + assert_model_property_type_hint(MyModel, "date_time_prop", "datetime.datetime | Unset") + assert_model_property_type_hint(MyModel, "uuid_prop", "UUID | Unset") + assert_model_property_type_hint(MyModel, "unknown_format_prop", "str | Unset") + + +@with_generated_client_fixture( + """ +components: + schemas: + MyModel: + type: object + properties: + booleanProp: {"type": "boolean"} + stringProp: {"type": "string"} + numberProp: {"type": "number"} + intProp: {"type": "integer"} + anyObjectProp: {"$ref": "#/components/schemas/AnyObject"} + nullProp: {"type": "null"} + anyProp: {} + AnyObject: + $ref: "#/components/schemas/OtherObject" + OtherObject: + $ref: "#/components/schemas/AnotherObject" + AnotherObject: + type: object + properties: + booleanProp: {"type": "boolean"} + +""" +) +@with_generated_code_imports( + ".models.MyModel", + ".models.AnyObject", + ".types.Unset", +) +class TestReferenceSchemaProperties: + def test_decode_encode(self, MyModel, AnyObject): + json_data = { + "booleanProp": True, + "stringProp": "a", + "numberProp": 1.5, + "intProp": 2, + "anyObjectProp": {"booleanProp": False}, + "nullProp": None, + "anyProp": "e", + } + assert_model_decode_encode( + MyModel, + json_data, + MyModel( + boolean_prop=True, + string_prop="a", + number_prop=1.5, + int_prop=2, + any_object_prop=AnyObject(boolean_prop=False), + null_prop=None, + any_prop="e", + ), + ) + + +@with_generated_client_fixture( + """ +components: + schemas: + MyModel: + type: object + properties: + foo-bar: {"type": "string"} + fooBar: {"type": "string"} +""" +) +@with_generated_code_imports(".models.MyModel") +class TestConflictingPropertyNames: + def test_conflicting_names_stay_valid_identifiers(self, MyModel): + # Both names snake_case to `foo_bar`, so the conflict is resolved by keeping the + # original names, minus any characters that are invalid in Python identifiers + assert_model_decode_encode( + MyModel, + {"foo-bar": "a", "fooBar": "b"}, + MyModel(foobar="a", fooBar="b"), + ) diff --git a/end_to_end_tests/functional_tests/generated_code_execution/test_unions.py b/end_to_end_tests/functional_tests/generated_code_execution/test_unions.py new file mode 100644 index 000000000..ca20e64ac --- /dev/null +++ b/end_to_end_tests/functional_tests/generated_code_execution/test_unions.py @@ -0,0 +1,143 @@ +from end_to_end_tests.functional_tests.helpers import ( + assert_model_decode_encode, + assert_model_property_type_hint, + with_generated_client_fixture, + with_generated_code_imports, +) + + +@with_generated_client_fixture( + """ +components: + schemas: + StringOrInt: + type: ["string", "integer"] + MyModel: + type: object + properties: + stringOrIntProp: + type: ["string", "integer"] +""" +) +@with_generated_code_imports( + ".models.MyModel", +) +class TestSimpleTypeList: + def test_decode_encode(self, MyModel): + assert_model_decode_encode(MyModel, {"stringOrIntProp": "a"}, MyModel(string_or_int_prop="a")) + assert_model_decode_encode(MyModel, {"stringOrIntProp": 1}, MyModel(string_or_int_prop=1)) + + def test_type_hints(self, MyModel): + assert_model_property_type_hint(MyModel, "string_or_int_prop", "int | str | Unset") + + +@with_generated_client_fixture( + """ +components: + schemas: + ThingA: + type: object + properties: + propA: { type: "string" } + required: ["propA"] + ThingB: + type: object + properties: + propB: { type: "string" } + required: ["propB"] + ThingAOrB: + oneOf: + - $ref: "#/components/schemas/ThingA" + - $ref: "#/components/schemas/ThingB" + ModelWithUnion: + type: object + properties: + thing: {"$ref": "#/components/schemas/ThingAOrB"} + thingOrString: + oneOf: + - $ref: "#/components/schemas/ThingA" + - type: string + ModelWithRequiredUnion: + type: object + properties: + thing: {"$ref": "#/components/schemas/ThingAOrB"} + required: ["thing"] + ModelWithNestedUnion: + type: object + properties: + thingOrValue: + oneOf: + - "$ref": "#/components/schemas/ThingAOrB" + - oneOf: + - type: string + - type: number + ModelWithUnionOfOne: + type: object + properties: + thing: + oneOf: + - $ref: "#/components/schemas/ThingA" + requiredThing: + oneOf: + - $ref: "#/components/schemas/ThingA" + required: ["requiredThing"] +""" +) +@with_generated_code_imports( + ".models.ThingA", + ".models.ThingB", + ".models.ModelWithUnion", + ".models.ModelWithRequiredUnion", + ".models.ModelWithNestedUnion", + ".models.ModelWithUnionOfOne", +) +class TestOneOf: + def test_disambiguate_objects_via_required_properties(self, ThingA, ThingB, ModelWithUnion): + assert_model_decode_encode( + ModelWithUnion, + {"thing": {"propA": "x"}}, + ModelWithUnion(thing=ThingA(prop_a="x")), + ) + assert_model_decode_encode( + ModelWithUnion, + {"thing": {"propB": "x"}}, + ModelWithUnion(thing=ThingB(prop_b="x")), + ) + + def test_disambiguate_object_and_non_object(self, ThingA, ModelWithUnion): + assert_model_decode_encode( + ModelWithUnion, + {"thingOrString": {"propA": "x"}}, + ModelWithUnion(thing_or_string=ThingA(prop_a="x")), + ) + assert_model_decode_encode( + ModelWithUnion, + {"thingOrString": "x"}, + ModelWithUnion(thing_or_string="x"), + ) + + def test_disambiguate_nested_union(self, ThingA, ThingB, ModelWithNestedUnion): + assert_model_decode_encode( + ModelWithNestedUnion, + {"thingOrValue": {"propA": "x"}}, + ModelWithNestedUnion(thing_or_value=ThingA(prop_a="x")), + ) + assert_model_decode_encode( + ModelWithNestedUnion, + {"thingOrValue": 3}, + ModelWithNestedUnion(thing_or_value=3), + ) + + def test_type_hints(self, ModelWithUnion, ModelWithRequiredUnion, ModelWithUnionOfOne, ThingA): + assert_model_property_type_hint( + ModelWithUnion, + "thing", + "ThingA | ThingB | Unset", + ) + assert_model_property_type_hint( + ModelWithRequiredUnion, + "thing", + "ThingA | ThingB", + ) + assert_model_property_type_hint(ModelWithUnionOfOne, "thing", "ThingA | Unset") + assert_model_property_type_hint(ModelWithUnionOfOne, "required_thing", "ThingA") diff --git a/end_to_end_tests/functional_tests/generator_failure_cases/test_invalid_arrays.py b/end_to_end_tests/functional_tests/generator_failure_cases/test_invalid_arrays.py new file mode 100644 index 000000000..d33b1a120 --- /dev/null +++ b/end_to_end_tests/functional_tests/generator_failure_cases/test_invalid_arrays.py @@ -0,0 +1,21 @@ +from end_to_end_tests.functional_tests.helpers import assert_bad_schema, with_generated_client_fixture + + +@with_generated_client_fixture( + """ +components: + schemas: + ArrayWithNoItems: + type: array + ArrayWithInvalidItemsRef: + type: array + items: + $ref: "#/components/schemas/DoesntExist" +""" +) +class TestArrayInvalidSchemas: + def test_no_items(self, generated_client): + assert_bad_schema(generated_client, "ArrayWithNoItems", "must have items or prefixItems defined") + + def test_invalid_items_ref(self, generated_client): + assert_bad_schema(generated_client, "ArrayWithInvalidItemsRef", "invalid data in items of array") diff --git a/end_to_end_tests/functional_tests/generator_failure_cases/test_invalid_defaults.py b/end_to_end_tests/functional_tests/generator_failure_cases/test_invalid_defaults.py new file mode 100644 index 000000000..7499f655c --- /dev/null +++ b/end_to_end_tests/functional_tests/generator_failure_cases/test_invalid_defaults.py @@ -0,0 +1,88 @@ +import pytest + +from end_to_end_tests.functional_tests.helpers import assert_bad_schema, with_generated_client_fixture + + +@with_generated_client_fixture( + """ +components: + schemas: + WithBadBoolean: + properties: + badBoolean: {"type": "boolean", "default": "not a boolean"} + WithBadIntAsString: + properties: + badInt: {"type": "integer", "default": "not an int"} + WithBadIntAsOther: + properties: + badInt: {"type": "integer", "default": true} + WithBadFloatAsString: + properties: + badInt: {"type": "number", "default": "not a number"} + WithBadFloatAsOther: + properties: + badInt: {"type": "number", "default": true} + WithBadDateAsString: + properties: + badDate: {"type": "string", "format": "date", "default": "xxx"} + WithBadDateAsOther: + properties: + badDate: {"type": "string", "format": "date", "default": 3} + WithBadDateTimeAsString: + properties: + badDate: {"type": "string", "format": "date-time", "default": "xxx"} + WithBadDateTimeAsOther: + properties: + badDate: {"type": "string", "format": "date-time", "default": 3} + WithBadUuidAsString: + properties: + badUuid: {"type": "string", "format": "uuid", "default": "xxx"} + WithBadUuidAsOther: + properties: + badUuid: {"type": "string", "format": "uuid", "default": 3} + WithBadEnum: + properties: + badEnum: {"type": "string", "enum": ["a", "b"], "default": "x"} + GoodEnum: + type: string + enum: ["a", "b"] + OverriddenEnumWithBadDefault: + properties: + badEnum: + allOf: + - $ref: "#/components/schemas/GoodEnum" + default: "x" + UnionWithNoValidDefault: + properties: + badBoolOrInt: + anyOf: + - type: boolean + - type: integer + default: "xxx" +""" +) +class TestInvalidDefaultValues: + # Note, the null/None type, and binary strings (files), are not covered here due to a known bug: + # https://github.com/openapi-generators/openapi-python-client/issues/1162 + + @pytest.mark.parametrize( + ("model_name", "message"), + [ + ("WithBadBoolean", "Invalid boolean value"), + ("WithBadIntAsString", "Invalid int value"), + ("WithBadIntAsOther", "Invalid int value"), + ("WithBadFloatAsString", "Invalid float value"), + ("WithBadFloatAsOther", "Cannot convert True to a float"), + ("WithBadDateAsString", "Invalid date"), + ("WithBadDateAsOther", "Cannot convert 3 to a date"), + ("WithBadDateTimeAsString", "Invalid datetime"), + ("WithBadDateTimeAsOther", "Cannot convert 3 to a datetime"), + ("WithBadUuidAsString", "Invalid UUID value"), + ("WithBadUuidAsOther", "Invalid UUID value"), + ("WithBadEnum", "Value x is not valid for enum"), + ("OverriddenEnumWithBadDefault", "Value x is not valid for enum"), + ("UnionWithNoValidDefault", "Invalid int value"), + ], + ) + def test_bad_default_warning(self, model_name, message, generated_client): + assert_bad_schema(generated_client, model_name, message) diff --git a/end_to_end_tests/functional_tests/generator_failure_cases/test_invalid_enums_and_consts.py b/end_to_end_tests/functional_tests/generator_failure_cases/test_invalid_enums_and_consts.py new file mode 100644 index 000000000..e33a2cc1a --- /dev/null +++ b/end_to_end_tests/functional_tests/generator_failure_cases/test_invalid_enums_and_consts.py @@ -0,0 +1,134 @@ +from end_to_end_tests.functional_tests.helpers import ( + assert_bad_schema, + inline_spec_should_fail, + with_generated_client_fixture, +) + + +@with_generated_client_fixture( + """ +components: + schemas: + WithBadDefaultValue: + enum: ["A"] + default: "B" + WithBadDefaultType: + enum: ["A"] + default: 123 + WithMixedTypes: + enum: ["A", 1] + WithUnsupportedType: + enum: [1.4, 1.5] + DefaultNotMatchingConst: + const: "aaa" + default: "bbb" + WithConflictingInlineNames: + type: object + properties: + "12": + enum: ["a", "b"] + WithConflictingInlineNames1: + type: object + properties: + "2": + enum: ["c", "d"] +""" +) +class TestEnumAndConstInvalidSchemas: + def test_enum_bad_default_value(self, generated_client): + assert_bad_schema(generated_client, "WithBadDefaultValue", "Value B is not valid") + + def test_enum_bad_default_type(self, generated_client): + assert_bad_schema(generated_client, "WithBadDefaultType", "Cannot convert 123 to enum") + + def test_enum_mixed_types(self, generated_client): + assert_bad_schema(generated_client, "WithMixedTypes", "Enum values must all be the same type") + + def test_enum_unsupported_type(self, generated_client): + assert_bad_schema(generated_client, "WithUnsupportedType", "Unsupported enum type") + + def test_const_default_not_matching(self, generated_client): + assert_bad_schema(generated_client, "DefaultNotMatchingConst", "Invalid value for const") + + def test_conflicting_inline_class_names(self, generated_client): + assert ( + "Found conflicting enums named WithConflictingInlineNames12 with incompatible values" + in generated_client.generator_result.output + ) + + def test_enum_duplicate_values(self): + # This one currently causes a full generator failure rather than a warning + result = inline_spec_should_fail( + """ +components: + schemas: + WithDuplicateValues: + enum: ["x", "x"] +""" + ) + assert "Duplicate key X in enum" in str(result.exception) + + +@with_generated_client_fixture( + """ +components: + schemas: + WithBadDefaultValue: + enum: ["A"] + default: "B" + WithBadDefaultType: + enum: ["A"] + default: 123 + WithMixedTypes: + enum: ["A", 1] + WithUnsupportedType: + enum: [1.4, 1.5] + DefaultNotMatchingConst: + const: "aaa" + default: "bbb" + WithConflictingInlineNames: + type: object + properties: + "12": + enum: ["a", "b"] + WithConflictingInlineNames1: + type: object + properties: + "2": + enum: ["c", "d"] +""", + config="literal_enums: true", +) +class TestLiteralEnumInvalidSchemas: + def test_literal_enum_bad_default_value(self, generated_client): + assert_bad_schema(generated_client, "WithBadDefaultValue", "Value B is not valid") + + def test_literal_enum_bad_default_type(self, generated_client): + assert_bad_schema(generated_client, "WithBadDefaultType", "Cannot convert 123 to enum") + + def test_literal_enum_mixed_types(self, generated_client): + assert_bad_schema(generated_client, "WithMixedTypes", "Enum values must all be the same type") + + def test_literal_enum_unsupported_type(self, generated_client): + assert_bad_schema(generated_client, "WithUnsupportedType", "Unsupported enum type") + + def test_const_default_not_matching(self, generated_client): + assert_bad_schema(generated_client, "DefaultNotMatchingConst", "Invalid value for const") + + def test_conflicting_inline_literal_enum_names(self, generated_client): + assert ( + "Found conflicting enums named WithConflictingInlineNames12 with incompatible values" + in generated_client.generator_result.output + ) + + def test_literal_enum_duplicate_values(self): + # This one currently causes a full generator failure rather than a warning + result = inline_spec_should_fail( + """ +components: + schemas: + WithDuplicateValues: + enum: ["x", "x"] +""" + ) + assert "Duplicate key X in enum" in str(result.exception) diff --git a/end_to_end_tests/functional_tests/generator_failure_cases/test_invalid_references.py b/end_to_end_tests/functional_tests/generator_failure_cases/test_invalid_references.py new file mode 100644 index 000000000..edbd84734 --- /dev/null +++ b/end_to_end_tests/functional_tests/generator_failure_cases/test_invalid_references.py @@ -0,0 +1,27 @@ +from end_to_end_tests.functional_tests.helpers import with_generated_client_fixture + + +@with_generated_client_fixture( + """ +components: + schemas: + MyModel: + type: object + properties: + booleanProp: {"type": "boolean"} + stringProp: {"type": "string"} + numberProp: {"type": "number"} + intProp: {"type": "integer"} + anyObjectProp: {"$ref": "#/components/schemas/AnyObject"} + nullProp: {"type": "null"} + anyProp: {} + AnyObject: + $ref: "#/components/schemas/OtherObject" + OtherObject: + $ref: "#/components/schemas/AnyObject" + +""" +) +class TestReferenceSchemaProperties: + def test_decode_encode(self, generated_client): + assert "Circular schema references found" in generated_client.generator_result.stderr diff --git a/end_to_end_tests/functional_tests/generator_failure_cases/test_invalid_spec_format.py b/end_to_end_tests/functional_tests/generator_failure_cases/test_invalid_spec_format.py new file mode 100644 index 000000000..5826e18ea --- /dev/null +++ b/end_to_end_tests/functional_tests/generator_failure_cases/test_invalid_spec_format.py @@ -0,0 +1,87 @@ +import pytest + +from end_to_end_tests.functional_tests.helpers import ( + inline_spec_should_fail, +) + + +class TestInvalidSpecFormats: + @pytest.mark.parametrize( + ("filename_suffix", "content", "expected_error"), + ( + (".yaml", "not a valid openapi document", "Failed to parse OpenAPI document"), + (".json", "Invalid JSON", "Invalid JSON"), + (".yaml", "{", "Invalid YAML"), + ), + ids=("invalid_openapi", "invalid_json", "invalid_yaml"), + ) + def test_unparseable_file(self, filename_suffix, content, expected_error): + result = inline_spec_should_fail(content, filename_suffix=filename_suffix, add_missing_sections=False) + assert expected_error in result.output + + def test_missing_openapi_version(self): + result = inline_spec_should_fail( + """ +info: + title: My API + version: "1.0" +paths: {} +""", + add_missing_sections=False, + ) + for text in ["Failed to parse OpenAPI document", "1 validation error", "openapi"]: + assert text in result.output + + def test_missing_title(self): + result = inline_spec_should_fail( + """ +info: + version: "1.0" +openapi: "3.1.0" +paths: {} +""", + add_missing_sections=False, + ) + for text in ["Failed to parse OpenAPI document", "1 validation error", "title"]: + assert text in result.output + + def test_missing_version(self): + result = inline_spec_should_fail( + """ +info: + title: My API +openapi: "3.1.0" +paths: {} +""", + add_missing_sections=False, + ) + for text in ["Failed to parse OpenAPI document", "1 validation error", "version"]: + assert text in result.output + + def test_missing_paths(self): + result = inline_spec_should_fail( + """ +info: + title: My API + version: "1.0" +openapi: "3.1.0" +""", + add_missing_sections=False, + ) + for text in ["Failed to parse OpenAPI document", "1 validation error", "paths"]: + assert text in result.output + + def test_swagger_unsupported(self): + result = inline_spec_should_fail( + """ +swagger: "2.0" +info: + title: My API + version: "1.0" +openapi: "3.1" +paths: {} +components: {} +""", + add_missing_sections=False, + ) + assert "You may be trying to use a Swagger document; this is not supported by this project." in result.output diff --git a/end_to_end_tests/functional_tests/generator_failure_cases/test_invalid_unions.py b/end_to_end_tests/functional_tests/generator_failure_cases/test_invalid_unions.py new file mode 100644 index 000000000..81fa1c53f --- /dev/null +++ b/end_to_end_tests/functional_tests/generator_failure_cases/test_invalid_unions.py @@ -0,0 +1,28 @@ +from end_to_end_tests.functional_tests.helpers import assert_bad_schema, with_generated_client_fixture + + +@with_generated_client_fixture( + """ +components: + schemas: + UnionWithInvalidReference: + anyOf: + - $ref: "#/components/schemas/DoesntExist" + UnionWithInvalidDefault: + type: ["number", "integer"] + default: aaa + UnionWithMalformedVariant: + anyOf: + - type: string + - type: array # invalid because no items +""" +) +class TestUnionInvalidSchemas: + def test_invalid_reference(self, generated_client): + assert_bad_schema(generated_client, "UnionWithInvalidReference", "Could not find reference") + + def test_invalid_default(self, generated_client): + assert_bad_schema(generated_client, "UnionWithInvalidDefault", "Invalid int value: aaa") + + def test_invalid_property(self, generated_client): + assert_bad_schema(generated_client, "UnionWithMalformedVariant", "Invalid property in union") diff --git a/end_to_end_tests/functional_tests/helpers.py b/end_to_end_tests/functional_tests/helpers.py new file mode 100644 index 000000000..c8380fea6 --- /dev/null +++ b/end_to_end_tests/functional_tests/helpers.py @@ -0,0 +1,145 @@ +import re +from typing import Any + +import pytest +from typer.testing import Result + +from end_to_end_tests.generated_client import GeneratedClientContext, generate_client_from_inline_spec + + +def with_generated_client_fixture( + openapi_spec: str, + name: str = "generated_client", + config: str = "", + extra_args=None, +): + """Decorator to apply to a test class to create a fixture inside it called 'generated_client'. + + The fixture value will be a GeneratedClientContext created by calling + generate_client_from_inline_spec(). + """ + + if extra_args is None: + extra_args = [] + + def _decorator(cls): + # noinspection decorator + @classmethod + def generated_client(_cls): + with generate_client_from_inline_spec(openapi_spec, extra_args=extra_args, config=config) as g: + print(g.generator_result.stdout) # so we'll see the output if a test failed + yield g + + setattr(cls, name, pytest.fixture(scope="class")(generated_client)) + return cls + + return _decorator + + +def with_generated_code_import(import_path: str, alias: str | None = None): + """Decorator to apply to a test class to create a fixture from a generated code import. + + The 'generated_client' fixture must also be present. + + If import_path is "a.b.c", then the fixture's value is equal to "from a.b import c", and + its name is "c" unless you specify a different name with the alias parameter. + """ + parts = import_path.split(".") + module_name = ".".join(parts[0:-1]) + import_name = parts[-1] + + def _decorator(cls): + nonlocal alias + + def _func(self, generated_client): + return generated_client.import_symbol(module_name, import_name) + + alias = alias or import_name + _func.__name__ = alias + # noinspection bad-argument-type + setattr(cls, alias, pytest.fixture(scope="class")(classmethod(_func))) + return cls + + return _decorator + + +def with_generated_code_imports(*import_paths: str): + def _decorator(cls): + decorated = cls + for import_path in import_paths: + decorated = with_generated_code_import(import_path)(decorated) + return decorated + + return _decorator + + +def assert_model_decode_encode(model_class: Any, json_data: dict, expected_instance: Any) -> None: + instance = model_class.from_dict(json_data) + assert instance == expected_instance + assert instance.to_dict() == json_data + + +def assert_model_property_type_hint(model_class: Any, name: str, expected_type_hint: Any) -> None: + assert model_class.__annotations__[name] == expected_type_hint + + +def inline_spec_should_fail( + openapi_spec: str, + extra_args=None, + config: str = "", + filename_suffix: str = "", + add_missing_sections=True, +) -> Result: + """Asserts that the generator could not process the spec. + + Returns the command result, which could include stdout data or an exception. + """ + if extra_args is None: + extra_args = [] + with generate_client_from_inline_spec( + openapi_spec, + extra_args, + config, + filename_suffix=filename_suffix, + add_missing_sections=add_missing_sections, + raise_on_error=False, + ) as generated_client: + assert generated_client.generator_result.exit_code != 0 + return generated_client.generator_result + + +def assert_bad_schema( + generated_client: GeneratedClientContext, + schema_name: str, + expected_message_str: str, +) -> None: + warnings = _GeneratorWarningsParser(generated_client) + assert schema_name in warnings.by_schema, ( + f"Did not find warning for schema {schema_name} in output: {warnings.output}" + ) + assert expected_message_str in warnings.by_schema[schema_name] + + +class _GeneratorWarningsParser: + output: str + by_schema: dict[str, str] + + def __init__(self, generated_client: GeneratedClientContext) -> None: + """Runs the generator, asserts that it printed warnings, and parses the warnings.""" + + assert generated_client.generator_result.exit_code == 0 + output = generated_client.generator_result.stdout + generated_client.generator_result.stderr + assert "Warning(s) encountered while generating" in output + self.by_schema = {} + self.output = output + bad_schema_regex = "Unable to (parse|process) schema /components/schemas/(\\w*)" + last_name = "" + while True: + if not (match := re.search(bad_schema_regex, output)): + break + if last_name: + self.by_schema[last_name] = output[0 : match.start()] + output = output[match.end() :] + last_name = match.group(2) + if last_name: + self.by_schema[last_name] = output diff --git a/end_to_end_tests/generated_client.py b/end_to_end_tests/generated_client.py new file mode 100644 index 000000000..d2c990280 --- /dev/null +++ b/end_to_end_tests/generated_client.py @@ -0,0 +1,159 @@ +import importlib +import os +import re +import shutil +import sys +import tempfile +from pathlib import Path +from typing import Any, Self + +import pytest +from attrs import define +from typer.testing import CliRunner, Result + +from openapi_python_client.cli import app + + +@define +class GeneratedClientContext: + """A context manager with helpers for tests that run against generated client code. + + On entering this context, sys.path is changed to include the root directory of the + generated code, so its modules can be imported. On exit, the original sys.path is + restored, and any modules that were loaded within the context are removed. + """ + + output_path: Path + generator_result: Result + base_module: str + monkeypatch: pytest.MonkeyPatch + old_modules: set[str] | None = None + + def __enter__(self) -> Self: + self.monkeypatch.syspath_prepend(self.output_path) + self.old_modules = set(sys.modules.keys()) + return self + + def __exit__(self, exc_type, exc_value, traceback): + self.monkeypatch.undo() + for module_name in set(sys.modules.keys()) - self.old_modules: + del sys.modules[module_name] + shutil.rmtree(self.output_path, ignore_errors=True) + + def import_module(self, module_path: str) -> Any: + """Attempt to import a module from the generated code.""" + return importlib.import_module(f"{self.base_module}{module_path}") + + def import_symbol(self, module_path: str, name: str) -> Any: + module = self.import_module(module_path) + try: + return getattr(module, name) + except AttributeError as e: + existing = ", ".join(name for name in dir(module) if not name.startswith("_")) + raise AssertionError( + f'Couldn\'t find import "{name}" in "{self.base_module}{module_path}".\n' + f"Available imports in that module are: {existing}\n" + f"Output from generator was: {self.generator_result.stdout}" + ) from e + + +def _run_command( + command: str, + extra_args: list[str] | None = None, + openapi_document: str | Path | None = None, + url: str | None = None, + config_path: Path | None = None, + raise_on_error: bool = True, +) -> Result: + """Generate a client from an OpenAPI document and return the result of the command.""" + runner = CliRunner() + if openapi_document is not None: + openapi_path = Path(__file__).parent / openapi_document + source_arg = f"--path={openapi_path}" + else: + source_arg = f"--url={url}" + config_path = config_path or (Path(__file__).parent / "config.yml") + args = [command, f"--config={config_path}", source_arg] + if extra_args: + args.extend(extra_args) + result = runner.invoke(app, args) + if result.exit_code != 0 and raise_on_error: + message = f"{result.stdout}\n{result.exception}" if result.exception else result.stdout + raise Exception(message) + return result + + +def generate_client( + openapi_document: str | Path, + extra_args: list[str] | None = None, + output_path: str = "my-test-api-client", + base_module: str = "my_test_api_client", + overwrite: bool = True, + raise_on_error: bool = True, +) -> GeneratedClientContext: + """Run the generator and return a GeneratedClientContext for accessing the generated code.""" + args = [] + if extra_args is not None: + args = list(extra_args) + full_output_path = Path(__file__).parent / "tmp" / output_path + + if not overwrite: + shutil.rmtree(full_output_path, ignore_errors=True) + args.extend(["--output-path", str(full_output_path)]) + if overwrite: + args.append("--overwrite") + generator_result = _run_command("generate", args, openapi_document, raise_on_error=raise_on_error) + return GeneratedClientContext( + full_output_path, + generator_result, + base_module, + pytest.MonkeyPatch(), + ) + + +def generate_client_from_inline_spec( + openapi_spec: str, + extra_args: list[str] | None = None, + config: str = "", + filename_suffix: str | None = None, + base_module: str = "testapi_client", + add_missing_sections=True, + raise_on_error: bool = True, +) -> GeneratedClientContext: + """Run the generator on a temporary file created with the specified contents. + + You can also optionally tell it to create a temporary config file. + """ + if extra_args is None: + extra_args = [] + if add_missing_sections: + if not re.search("^openapi:", openapi_spec, re.MULTILINE): + openapi_spec += "\nopenapi: '3.1.0'\n" + if not re.search("^info:", openapi_spec, re.MULTILINE): + openapi_spec += "\ninfo: {'title': 'testapi', 'description': 'my test api', 'version': '0.0.1'}\n" + if not re.search("^paths:", openapi_spec, re.MULTILINE): + openapi_spec += "\npaths: {}\n" + + output_path = tempfile.mkdtemp() + file = tempfile.NamedTemporaryFile(suffix=filename_suffix, delete=False) + file.write(openapi_spec.encode("utf-8")) + file.close() + + if config: + config_file = tempfile.NamedTemporaryFile(delete=False) + config_file.write(config.encode("utf-8")) + config_file.close() + extra_args = [*extra_args, "--config", config_file.name] + + generated_client = generate_client( + file.name, + extra_args, + output_path, + base_module, + raise_on_error=raise_on_error, + ) + os.unlink(file.name) + if config: + os.unlink(config_file.name) + + return generated_client diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/bodies/__init__.py b/end_to_end_tests/golden-record/my_test_api_client/api/bodies/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/config/__init__.py b/end_to_end_tests/golden-record/my_test_api_client/api/config/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/default/__init__.py b/end_to_end_tests/golden-record/my_test_api_client/api/default/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/defaults/__init__.py b/end_to_end_tests/golden-record/my_test_api_client/api/defaults/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/enums/__init__.py b/end_to_end_tests/golden-record/my_test_api_client/api/enums/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/location/__init__.py b/end_to_end_tests/golden-record/my_test_api_client/api/location/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/naming/__init__.py b/end_to_end_tests/golden-record/my_test_api_client/api/naming/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/__init__.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/__init__.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/responses/__init__.py b/end_to_end_tests/golden-record/my_test_api_client/api/responses/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tag1/__init__.py b/end_to_end_tests/golden-record/my_test_api_client/api/tag1/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/__init__.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py deleted file mode 100644 index 6cfcfaa57..000000000 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py +++ /dev/null @@ -1,173 +0,0 @@ -from http import HTTPStatus -from typing import Any, Dict, List, Optional, Union - -import httpx - -from ... import errors -from ...client import AuthenticatedClient, Client -from ...models.http_validation_error import HTTPValidationError -from ...types import File, Response - - -def _get_kwargs( - *, - body: List[File], -) -> Dict[str, Any]: - headers: Dict[str, Any] = {} - - _kwargs: Dict[str, Any] = { - "method": "post", - "url": "/tests/upload/multiple", - } - - _body = [] - for body_item_data in body: - body_item = body_item_data.to_tuple() - - _body.append(body_item) - - _kwargs["files"] = _body - - _kwargs["headers"] = headers - return _kwargs - - -def _parse_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Optional[Union[Any, HTTPValidationError]]: - if response.status_code == HTTPStatus.OK: - response_200 = response.json() - return response_200 - if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: - response_422 = HTTPValidationError.from_dict(response.json()) - - return response_422 - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None - - -def _build_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Response[Union[Any, HTTPValidationError]]: - return Response( - status_code=HTTPStatus(response.status_code), - content=response.content, - headers=response.headers, - parsed=_parse_response(client=client, response=response), - ) - - -def sync_detailed( - *, - client: Union[AuthenticatedClient, Client], - body: List[File], -) -> Response[Union[Any, HTTPValidationError]]: - """Upload multiple files - - Upload several files in the same request - - Args: - body (List[File]): - - Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. - httpx.TimeoutException: If the request takes longer than Client.timeout. - - Returns: - Response[Union[Any, HTTPValidationError]] - """ - - kwargs = _get_kwargs( - body=body, - ) - - response = client.get_httpx_client().request( - **kwargs, - ) - - return _build_response(client=client, response=response) - - -def sync( - *, - client: Union[AuthenticatedClient, Client], - body: List[File], -) -> Optional[Union[Any, HTTPValidationError]]: - """Upload multiple files - - Upload several files in the same request - - Args: - body (List[File]): - - Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. - httpx.TimeoutException: If the request takes longer than Client.timeout. - - Returns: - Union[Any, HTTPValidationError] - """ - - return sync_detailed( - client=client, - body=body, - ).parsed - - -async def asyncio_detailed( - *, - client: Union[AuthenticatedClient, Client], - body: List[File], -) -> Response[Union[Any, HTTPValidationError]]: - """Upload multiple files - - Upload several files in the same request - - Args: - body (List[File]): - - Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. - httpx.TimeoutException: If the request takes longer than Client.timeout. - - Returns: - Response[Union[Any, HTTPValidationError]] - """ - - kwargs = _get_kwargs( - body=body, - ) - - response = await client.get_async_httpx_client().request(**kwargs) - - return _build_response(client=client, response=response) - - -async def asyncio( - *, - client: Union[AuthenticatedClient, Client], - body: List[File], -) -> Optional[Union[Any, HTTPValidationError]]: - """Upload multiple files - - Upload several files in the same request - - Args: - body (List[File]): - - Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. - httpx.TimeoutException: If the request takes longer than Client.timeout. - - Returns: - Union[Any, HTTPValidationError] - """ - - return ( - await asyncio_detailed( - client=client, - body=body, - ) - ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/true_/__init__.py b/end_to_end_tests/golden-record/my_test_api_client/api/true_/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post.py b/end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post.py deleted file mode 100644 index 20d27d4a6..000000000 --- a/end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post.py +++ /dev/null @@ -1,359 +0,0 @@ -import datetime -import json -from io import BytesIO -from typing import TYPE_CHECKING, Any, Dict, List, Tuple, Type, TypeVar, Union, cast - -from attrs import define as _attrs_define -from attrs import field as _attrs_field -from dateutil.parser import isoparse - -from ..models.different_enum import DifferentEnum -from ..types import UNSET, File, FileJsonType, Unset - -if TYPE_CHECKING: - from ..models.a_form_data import AFormData - from ..models.body_upload_file_tests_upload_post_additional_property import ( - BodyUploadFileTestsUploadPostAdditionalProperty, - ) - from ..models.body_upload_file_tests_upload_post_some_nullable_object import ( - BodyUploadFileTestsUploadPostSomeNullableObject, - ) - from ..models.body_upload_file_tests_upload_post_some_object import BodyUploadFileTestsUploadPostSomeObject - from ..models.body_upload_file_tests_upload_post_some_optional_object import ( - BodyUploadFileTestsUploadPostSomeOptionalObject, - ) - - -T = TypeVar("T", bound="BodyUploadFileTestsUploadPost") - - -@_attrs_define -class BodyUploadFileTestsUploadPost: - """ - Attributes: - some_file (File): - some_object (BodyUploadFileTestsUploadPostSomeObject): - some_nullable_object (Union['BodyUploadFileTestsUploadPostSomeNullableObject', None]): - some_optional_file (Union[Unset, File]): - some_string (Union[Unset, str]): Default: 'some_default_string'. - a_datetime (Union[Unset, datetime.datetime]): - a_date (Union[Unset, datetime.date]): - some_number (Union[Unset, float]): - some_array (Union[List['AFormData'], None, Unset]): - some_optional_object (Union[Unset, BodyUploadFileTestsUploadPostSomeOptionalObject]): - some_enum (Union[Unset, DifferentEnum]): An enumeration. - """ - - some_file: File - some_object: "BodyUploadFileTestsUploadPostSomeObject" - some_nullable_object: Union["BodyUploadFileTestsUploadPostSomeNullableObject", None] - some_optional_file: Union[Unset, File] = UNSET - some_string: Union[Unset, str] = "some_default_string" - a_datetime: Union[Unset, datetime.datetime] = UNSET - a_date: Union[Unset, datetime.date] = UNSET - some_number: Union[Unset, float] = UNSET - some_array: Union[List["AFormData"], None, Unset] = UNSET - some_optional_object: Union[Unset, "BodyUploadFileTestsUploadPostSomeOptionalObject"] = UNSET - some_enum: Union[Unset, DifferentEnum] = UNSET - additional_properties: Dict[str, "BodyUploadFileTestsUploadPostAdditionalProperty"] = _attrs_field( - init=False, factory=dict - ) - - def to_dict(self) -> Dict[str, Any]: - from ..models.body_upload_file_tests_upload_post_some_nullable_object import ( - BodyUploadFileTestsUploadPostSomeNullableObject, - ) - - some_file = self.some_file.to_tuple() - - some_object = self.some_object.to_dict() - - some_nullable_object: Union[Dict[str, Any], None] - if isinstance(self.some_nullable_object, BodyUploadFileTestsUploadPostSomeNullableObject): - some_nullable_object = self.some_nullable_object.to_dict() - else: - some_nullable_object = self.some_nullable_object - - some_optional_file: Union[Unset, FileJsonType] = UNSET - if not isinstance(self.some_optional_file, Unset): - some_optional_file = self.some_optional_file.to_tuple() - - some_string = self.some_string - - a_datetime: Union[Unset, str] = UNSET - if not isinstance(self.a_datetime, Unset): - a_datetime = self.a_datetime.isoformat() - - a_date: Union[Unset, str] = UNSET - if not isinstance(self.a_date, Unset): - a_date = self.a_date.isoformat() - - some_number = self.some_number - - some_array: Union[List[Dict[str, Any]], None, Unset] - if isinstance(self.some_array, Unset): - some_array = UNSET - elif isinstance(self.some_array, list): - some_array = [] - for some_array_type_0_item_data in self.some_array: - some_array_type_0_item = some_array_type_0_item_data.to_dict() - some_array.append(some_array_type_0_item) - - else: - some_array = self.some_array - - some_optional_object: Union[Unset, Dict[str, Any]] = UNSET - if not isinstance(self.some_optional_object, Unset): - some_optional_object = self.some_optional_object.to_dict() - - some_enum: Union[Unset, str] = UNSET - if not isinstance(self.some_enum, Unset): - some_enum = self.some_enum.value - - field_dict: Dict[str, Any] = {} - for prop_name, prop in self.additional_properties.items(): - field_dict[prop_name] = prop.to_dict() - field_dict.update( - { - "some_file": some_file, - "some_object": some_object, - "some_nullable_object": some_nullable_object, - } - ) - if some_optional_file is not UNSET: - field_dict["some_optional_file"] = some_optional_file - if some_string is not UNSET: - field_dict["some_string"] = some_string - if a_datetime is not UNSET: - field_dict["a_datetime"] = a_datetime - if a_date is not UNSET: - field_dict["a_date"] = a_date - if some_number is not UNSET: - field_dict["some_number"] = some_number - if some_array is not UNSET: - field_dict["some_array"] = some_array - if some_optional_object is not UNSET: - field_dict["some_optional_object"] = some_optional_object - if some_enum is not UNSET: - field_dict["some_enum"] = some_enum - - return field_dict - - def to_multipart(self) -> Dict[str, Any]: - some_file = self.some_file.to_tuple() - - some_object = (None, json.dumps(self.some_object.to_dict()).encode(), "application/json") - - some_nullable_object: Union[None, Tuple[None, bytes, str]] - if isinstance(self.some_nullable_object, BodyUploadFileTestsUploadPostSomeNullableObject): - some_nullable_object = (None, json.dumps(self.some_nullable_object.to_dict()).encode(), "application/json") - else: - some_nullable_object = self.some_nullable_object - - some_optional_file: Union[Unset, FileJsonType] = UNSET - if not isinstance(self.some_optional_file, Unset): - some_optional_file = self.some_optional_file.to_tuple() - - some_string = ( - self.some_string - if isinstance(self.some_string, Unset) - else (None, str(self.some_string).encode(), "text/plain") - ) - - a_datetime: Union[Unset, bytes] = UNSET - if not isinstance(self.a_datetime, Unset): - a_datetime = self.a_datetime.isoformat().encode() - - a_date: Union[Unset, bytes] = UNSET - if not isinstance(self.a_date, Unset): - a_date = self.a_date.isoformat().encode() - - some_number = ( - self.some_number - if isinstance(self.some_number, Unset) - else (None, str(self.some_number).encode(), "text/plain") - ) - - some_array: Union[None, Tuple[None, bytes, str], Unset] - if isinstance(self.some_array, Unset): - some_array = UNSET - elif isinstance(self.some_array, list): - _temp_some_array = [] - for some_array_type_0_item_data in self.some_array: - some_array_type_0_item = some_array_type_0_item_data.to_dict() - _temp_some_array.append(some_array_type_0_item) - some_array = (None, json.dumps(_temp_some_array).encode(), "application/json") - - else: - some_array = self.some_array - - some_optional_object: Union[Unset, Tuple[None, bytes, str]] = UNSET - if not isinstance(self.some_optional_object, Unset): - some_optional_object = (None, json.dumps(self.some_optional_object.to_dict()).encode(), "application/json") - - some_enum: Union[Unset, Tuple[None, bytes, str]] = UNSET - if not isinstance(self.some_enum, Unset): - some_enum = (None, str(self.some_enum.value).encode(), "text/plain") - - field_dict: Dict[str, Any] = {} - for prop_name, prop in self.additional_properties.items(): - field_dict[prop_name] = (None, json.dumps(prop.to_dict()).encode(), "application/json") - field_dict.update( - { - "some_file": some_file, - "some_object": some_object, - "some_nullable_object": some_nullable_object, - } - ) - if some_optional_file is not UNSET: - field_dict["some_optional_file"] = some_optional_file - if some_string is not UNSET: - field_dict["some_string"] = some_string - if a_datetime is not UNSET: - field_dict["a_datetime"] = a_datetime - if a_date is not UNSET: - field_dict["a_date"] = a_date - if some_number is not UNSET: - field_dict["some_number"] = some_number - if some_array is not UNSET: - field_dict["some_array"] = some_array - if some_optional_object is not UNSET: - field_dict["some_optional_object"] = some_optional_object - if some_enum is not UNSET: - field_dict["some_enum"] = some_enum - - return field_dict - - @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - from ..models.a_form_data import AFormData - from ..models.body_upload_file_tests_upload_post_additional_property import ( - BodyUploadFileTestsUploadPostAdditionalProperty, - ) - from ..models.body_upload_file_tests_upload_post_some_nullable_object import ( - BodyUploadFileTestsUploadPostSomeNullableObject, - ) - from ..models.body_upload_file_tests_upload_post_some_object import BodyUploadFileTestsUploadPostSomeObject - from ..models.body_upload_file_tests_upload_post_some_optional_object import ( - BodyUploadFileTestsUploadPostSomeOptionalObject, - ) - - d = src_dict.copy() - some_file = File(payload=BytesIO(d.pop("some_file"))) - - some_object = BodyUploadFileTestsUploadPostSomeObject.from_dict(d.pop("some_object")) - - def _parse_some_nullable_object(data: object) -> Union["BodyUploadFileTestsUploadPostSomeNullableObject", None]: - if data is None: - return data - try: - if not isinstance(data, dict): - raise TypeError() - some_nullable_object_type_0 = BodyUploadFileTestsUploadPostSomeNullableObject.from_dict(data) - - return some_nullable_object_type_0 - except: # noqa: E722 - pass - return cast(Union["BodyUploadFileTestsUploadPostSomeNullableObject", None], data) - - some_nullable_object = _parse_some_nullable_object(d.pop("some_nullable_object")) - - _some_optional_file = d.pop("some_optional_file", UNSET) - some_optional_file: Union[Unset, File] - if isinstance(_some_optional_file, Unset): - some_optional_file = UNSET - else: - some_optional_file = File(payload=BytesIO(_some_optional_file)) - - some_string = d.pop("some_string", UNSET) - - _a_datetime = d.pop("a_datetime", UNSET) - a_datetime: Union[Unset, datetime.datetime] - if isinstance(_a_datetime, Unset): - a_datetime = UNSET - else: - a_datetime = isoparse(_a_datetime) - - _a_date = d.pop("a_date", UNSET) - a_date: Union[Unset, datetime.date] - if isinstance(_a_date, Unset): - a_date = UNSET - else: - a_date = isoparse(_a_date).date() - - some_number = d.pop("some_number", UNSET) - - def _parse_some_array(data: object) -> Union[List["AFormData"], None, Unset]: - if data is None: - return data - if isinstance(data, Unset): - return data - try: - if not isinstance(data, list): - raise TypeError() - some_array_type_0 = [] - _some_array_type_0 = data - for some_array_type_0_item_data in _some_array_type_0: - some_array_type_0_item = AFormData.from_dict(some_array_type_0_item_data) - - some_array_type_0.append(some_array_type_0_item) - - return some_array_type_0 - except: # noqa: E722 - pass - return cast(Union[List["AFormData"], None, Unset], data) - - some_array = _parse_some_array(d.pop("some_array", UNSET)) - - _some_optional_object = d.pop("some_optional_object", UNSET) - some_optional_object: Union[Unset, BodyUploadFileTestsUploadPostSomeOptionalObject] - if isinstance(_some_optional_object, Unset): - some_optional_object = UNSET - else: - some_optional_object = BodyUploadFileTestsUploadPostSomeOptionalObject.from_dict(_some_optional_object) - - _some_enum = d.pop("some_enum", UNSET) - some_enum: Union[Unset, DifferentEnum] - if isinstance(_some_enum, Unset): - some_enum = UNSET - else: - some_enum = DifferentEnum(_some_enum) - - body_upload_file_tests_upload_post = cls( - some_file=some_file, - some_object=some_object, - some_nullable_object=some_nullable_object, - some_optional_file=some_optional_file, - some_string=some_string, - a_datetime=a_datetime, - a_date=a_date, - some_number=some_number, - some_array=some_array, - some_optional_object=some_optional_object, - some_enum=some_enum, - ) - - additional_properties = {} - for prop_name, prop_dict in d.items(): - additional_property = BodyUploadFileTestsUploadPostAdditionalProperty.from_dict(prop_dict) - - additional_properties[prop_name] = additional_property - - body_upload_file_tests_upload_post.additional_properties = additional_properties - return body_upload_file_tests_upload_post - - @property - def additional_keys(self) -> List[str]: - return list(self.additional_properties.keys()) - - def __getitem__(self, key: str) -> "BodyUploadFileTestsUploadPostAdditionalProperty": - return self.additional_properties[key] - - def __setitem__(self, key: str, value: "BodyUploadFileTestsUploadPostAdditionalProperty") -> None: - self.additional_properties[key] = value - - def __delitem__(self, key: str) -> None: - del self.additional_properties[key] - - def __contains__(self, key: str) -> bool: - return key in self.additional_properties diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined.py deleted file mode 100644 index 2a832e21a..000000000 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined.py +++ /dev/null @@ -1,74 +0,0 @@ -from typing import TYPE_CHECKING, Any, Dict, Type, TypeVar, Union - -from attrs import define as _attrs_define - -from ..types import UNSET, Unset - -if TYPE_CHECKING: - from ..models.model_with_union_property_inlined_fruit_type_0 import ModelWithUnionPropertyInlinedFruitType0 - from ..models.model_with_union_property_inlined_fruit_type_1 import ModelWithUnionPropertyInlinedFruitType1 - - -T = TypeVar("T", bound="ModelWithUnionPropertyInlined") - - -@_attrs_define -class ModelWithUnionPropertyInlined: - """ - Attributes: - fruit (Union['ModelWithUnionPropertyInlinedFruitType0', 'ModelWithUnionPropertyInlinedFruitType1', Unset]): - """ - - fruit: Union["ModelWithUnionPropertyInlinedFruitType0", "ModelWithUnionPropertyInlinedFruitType1", Unset] = UNSET - - def to_dict(self) -> Dict[str, Any]: - from ..models.model_with_union_property_inlined_fruit_type_0 import ModelWithUnionPropertyInlinedFruitType0 - - fruit: Union[Dict[str, Any], Unset] - if isinstance(self.fruit, Unset): - fruit = UNSET - elif isinstance(self.fruit, ModelWithUnionPropertyInlinedFruitType0): - fruit = self.fruit.to_dict() - else: - fruit = self.fruit.to_dict() - - field_dict: Dict[str, Any] = {} - field_dict.update({}) - if fruit is not UNSET: - field_dict["fruit"] = fruit - - return field_dict - - @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - from ..models.model_with_union_property_inlined_fruit_type_0 import ModelWithUnionPropertyInlinedFruitType0 - from ..models.model_with_union_property_inlined_fruit_type_1 import ModelWithUnionPropertyInlinedFruitType1 - - d = src_dict.copy() - - def _parse_fruit( - data: object, - ) -> Union["ModelWithUnionPropertyInlinedFruitType0", "ModelWithUnionPropertyInlinedFruitType1", Unset]: - if isinstance(data, Unset): - return data - try: - if not isinstance(data, dict): - raise TypeError() - fruit_type_0 = ModelWithUnionPropertyInlinedFruitType0.from_dict(data) - - return fruit_type_0 - except: # noqa: E722 - pass - if not isinstance(data, dict): - raise TypeError() - fruit_type_1 = ModelWithUnionPropertyInlinedFruitType1.from_dict(data) - - return fruit_type_1 - - fruit = _parse_fruit(d.pop("fruit", UNSET)) - - model_with_union_property_inlined = cls( - fruit=fruit, - ) - - return model_with_union_property_inlined diff --git a/end_to_end_tests/golden-record/my_test_api_client/types.py b/end_to_end_tests/golden-record/my_test_api_client/types.py deleted file mode 100644 index 21fac106f..000000000 --- a/end_to_end_tests/golden-record/my_test_api_client/types.py +++ /dev/null @@ -1,45 +0,0 @@ -"""Contains some shared types for properties""" - -from http import HTTPStatus -from typing import BinaryIO, Generic, Literal, MutableMapping, Optional, Tuple, TypeVar - -from attrs import define - - -class Unset: - def __bool__(self) -> Literal[False]: - return False - - -UNSET: Unset = Unset() - -FileJsonType = Tuple[Optional[str], BinaryIO, Optional[str]] - - -@define -class File: - """Contains information for file uploads""" - - payload: BinaryIO - file_name: Optional[str] = None - mime_type: Optional[str] = None - - def to_tuple(self) -> FileJsonType: - """Return a tuple representation that httpx will accept for multipart/form-data""" - return self.file_name, self.payload, self.mime_type - - -T = TypeVar("T") - - -@define -class Response(Generic[T]): - """A response from an endpoint""" - - status_code: HTTPStatus - content: bytes - headers: MutableMapping[str, str] - parsed: Optional[T] - - -__all__ = ["File", "Response", "FileJsonType", "Unset", "UNSET"] diff --git a/end_to_end_tests/custom-templates-golden-record/README.md b/end_to_end_tests/golden-records/custom-templates/README.md similarity index 100% rename from end_to_end_tests/custom-templates-golden-record/README.md rename to end_to_end_tests/golden-records/custom-templates/README.md diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/__init__.py b/end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/__init__.py similarity index 62% rename from end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/__init__.py rename to end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/__init__.py index 79a699a1e..d1102fa1a 100644 --- a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/__init__.py +++ b/end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/__init__.py @@ -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 diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/bodies/__init__.py b/end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/bodies/__init__.py similarity index 54% rename from end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/bodies/__init__.py rename to end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/bodies/__init__.py index 92367f620..5ff7fceb8 100644 --- a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/bodies/__init__.py +++ b/end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/bodies/__init__.py @@ -2,7 +2,7 @@ import types -from . import json_like, post_bodies_multiple +from . import json_like, optional_body, post_bodies_multiple, refs class BodiesEndpoints: @@ -19,3 +19,17 @@ def json_like(cls) -> types.ModuleType: A content type that works like json but isn't application/json """ return json_like + + @classmethod + def refs(cls) -> types.ModuleType: + """ + Test request body defined via ref + """ + return refs + + @classmethod + def optional_body(cls) -> types.ModuleType: + """ + Test optional request body + """ + return optional_body diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/config/__init__.py b/end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/config/__init__.py similarity index 100% rename from end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/config/__init__.py rename to end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/config/__init__.py diff --git a/end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/default/__init__.py b/end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/default/__init__.py new file mode 100644 index 000000000..14b47083b --- /dev/null +++ b/end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/default/__init__.py @@ -0,0 +1,38 @@ +"""Contains methods for accessing the API Endpoints""" + +import types + +from . import ( + get_common_parameters, + get_models_allof, + get_models_oneof_with_required_const, + post_common_parameters, + post_types_unions_duplicate_types, + reserved_parameters, +) + + +class DefaultEndpoints: + @classmethod + def get_common_parameters(cls) -> types.ModuleType: + return get_common_parameters + + @classmethod + def post_common_parameters(cls) -> types.ModuleType: + return post_common_parameters + + @classmethod + def reserved_parameters(cls) -> types.ModuleType: + return reserved_parameters + + @classmethod + def get_models_allof(cls) -> types.ModuleType: + return get_models_allof + + @classmethod + def get_models_oneof_with_required_const(cls) -> types.ModuleType: + return get_models_oneof_with_required_const + + @classmethod + def post_types_unions_duplicate_types(cls) -> types.ModuleType: + return post_types_unions_duplicate_types diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/defaults/__init__.py b/end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/defaults/__init__.py similarity index 100% rename from end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/defaults/__init__.py rename to end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/defaults/__init__.py diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/enums/__init__.py b/end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/enums/__init__.py similarity index 100% rename from end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/enums/__init__.py rename to end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/enums/__init__.py diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/location/__init__.py b/end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/location/__init__.py similarity index 100% rename from end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/location/__init__.py rename to end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/location/__init__.py diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/naming/__init__.py b/end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/naming/__init__.py similarity index 100% rename from end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/naming/__init__.py rename to end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/naming/__init__.py diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/parameter_references/__init__.py b/end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/parameter_references/__init__.py similarity index 100% rename from end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/parameter_references/__init__.py rename to end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/parameter_references/__init__.py diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/parameters/__init__.py b/end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/parameters/__init__.py similarity index 100% rename from end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/parameters/__init__.py rename to end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/parameters/__init__.py diff --git a/end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/responses/__init__.py b/end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/responses/__init__.py new file mode 100644 index 000000000..d1361e311 --- /dev/null +++ b/end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/responses/__init__.py @@ -0,0 +1,56 @@ +"""Contains methods for accessing the API Endpoints""" + +import types + +from . import ( + default_status_code, + post_responses_unions_simple_before_complex, + reference_response, + status_code_patterns, + status_code_precedence, + text_response, +) + + +class ResponsesEndpoints: + @classmethod + def post_responses_unions_simple_before_complex(cls) -> types.ModuleType: + """ + Regression test for #603 + """ + return post_responses_unions_simple_before_complex + + @classmethod + def text_response(cls) -> types.ModuleType: + """ + Text Response + """ + return text_response + + @classmethod + def reference_response(cls) -> types.ModuleType: + """ + Endpoint using predefined response + """ + return reference_response + + @classmethod + def default_status_code(cls) -> types.ModuleType: + """ + Default Status Code Only + """ + return default_status_code + + @classmethod + def status_code_patterns(cls) -> types.ModuleType: + """ + Status Code Patterns + """ + return status_code_patterns + + @classmethod + def status_code_precedence(cls) -> types.ModuleType: + """ + Verify that specific status codes are always checked first, then ranges, then default + """ + return status_code_precedence diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tag1/__init__.py b/end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/tag1/__init__.py similarity index 100% rename from end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tag1/__init__.py rename to end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/tag1/__init__.py diff --git a/end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/tag2/__init__.py b/end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/tag2/__init__.py new file mode 100644 index 000000000..65edddf25 --- /dev/null +++ b/end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/tag2/__init__.py @@ -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 diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tests/__init__.py b/end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/tests/__init__.py similarity index 92% rename from end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tests/__init__.py rename to end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/tests/__init__.py index 1b91acc98..b9205c66b 100644 --- a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tests/__init__.py +++ b/end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/tests/__init__.py @@ -21,7 +21,6 @@ token_with_cookie_auth_token_with_cookie_get, unsupported_content_tests_unsupported_content_get, upload_file_tests_upload_post, - upload_multiple_files_tests_upload_post, ) @@ -82,13 +81,6 @@ def upload_file_tests_upload_post(cls) -> types.ModuleType: """ return upload_file_tests_upload_post - @classmethod - def upload_multiple_files_tests_upload_post(cls) -> types.ModuleType: - """ - Upload several files in the same request - """ - return upload_multiple_files_tests_upload_post - @classmethod def json_body_tests_json_body_post(cls) -> types.ModuleType: """ @@ -155,6 +147,6 @@ def callback_test(cls) -> types.ModuleType: @classmethod def description_with_backslash(cls) -> types.ModuleType: """ - Test description with \ + Test description with \\ """ return description_with_backslash diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/true_/__init__.py b/end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/true_/__init__.py similarity index 100% rename from end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/true_/__init__.py rename to end_to_end_tests/golden-records/custom-templates/my_test_api_client/api/true_/__init__.py diff --git a/end_to_end_tests/golden-records/custom-templates/my_test_api_client/models/__init__.py b/end_to_end_tests/golden-records/custom-templates/my_test_api_client/models/__init__.py new file mode 100644 index 000000000..611ed15f6 --- /dev/null +++ b/end_to_end_tests/golden-records/custom-templates/my_test_api_client/models/__init__.py @@ -0,0 +1,16 @@ +# Testing that we can access model-related information via Jinja variables. + +# To avoid having to update this file in the golden record every time the test specs are changed, +# we won't include all the classes in this output - we'll just look for one of them. + +# Using "alls" +# AModel + +# Using "imports" +# from .a_model import AModel + +# Using "openapi.models" +# AModel (a_model) + +# Using "openapi.enums" +# AnEnum (an_enum) diff --git a/end_to_end_tests/golden-record/.gitignore b/end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/.gitignore similarity index 100% rename from end_to_end_tests/golden-record/.gitignore rename to end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/.gitignore diff --git a/end_to_end_tests/golden-record/README.md b/end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/README.md similarity index 98% rename from end_to_end_tests/golden-record/README.md rename to end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/README.md index 79b20f411..32f776550 100644 --- a/end_to_end_tests/golden-record/README.md +++ b/end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/README.md @@ -47,7 +47,7 @@ By default, when you're calling an HTTPS API it will attempt to verify that SSL ```python client = AuthenticatedClient( - base_url="https://internal_api.example.com", + base_url="https://internal_api.example.com", token="SuperSecretToken", verify_ssl="/path/to/certificate_bundle.pem", ) @@ -57,7 +57,7 @@ You can also disable certificate validation altogether, but beware that **this i ```python client = AuthenticatedClient( - base_url="https://internal_api.example.com", + base_url="https://internal_api.example.com", token="SuperSecretToken", verify_ssl=False ) diff --git a/end_to_end_tests/golden-record/my_test_api_client/__init__.py b/end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/my_test_api_client/__init__.py similarity index 100% rename from end_to_end_tests/golden-record/my_test_api_client/__init__.py rename to end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/my_test_api_client/__init__.py diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/__init__.py b/end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/my_test_api_client/api/__init__.py similarity index 100% rename from end_to_end_tests/golden-record/my_test_api_client/api/__init__.py rename to end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/my_test_api_client/api/__init__.py diff --git a/end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/my_test_api_client/client.py b/end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/my_test_api_client/client.py new file mode 100644 index 000000000..a11b85c36 --- /dev/null +++ b/end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/my_test_api_client/client.py @@ -0,0 +1,260 @@ +import ssl +from typing import Any, Self + +import httpx +from attrs import define, evolve, field + + +@define +class Client: + """A class for keeping track of data related to the API + + The following are accepted as keyword arguments and will be used to construct httpx Clients internally: + + ``base_url``: The base URL for the API, all requests are made to a relative path to this URL + + ``cookies``: A dictionary of cookies to be sent with every request + + ``headers``: A dictionary of headers to be sent with every request + + ``timeout``: The maximum amount of a time a request can take. API functions will raise + httpx.TimeoutException if this is exceeded. + + ``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production, + but can be set to False for testing purposes. + + ``follow_redirects``: Whether or not to follow redirects. Default value is False. + + ``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor. + + """ + + raise_on_unexpected_status: bool = field(default=False, kw_only=True) + """Whether or not to raise an errors.UnexpectedStatus if the API returns a status code that was not documented in the source OpenAPI document. Can also be provided as a keyword argument to the constructor.""" + _base_url: str = field(alias="base_url") + _cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies") + _headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers") + _timeout: httpx.Timeout | None = field(default=None, kw_only=True, alias="timeout") + _verify_ssl: str | bool | ssl.SSLContext = field(default=True, kw_only=True, alias="verify_ssl") + _follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects") + _httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args") + _client: httpx.Client | None = field(default=None, init=False) + _async_client: httpx.AsyncClient | None = field(default=None, init=False) + + def with_headers(self, headers: dict[str, str]) -> "Client": + """Get a new client matching this one with additional headers""" + if self._client is not None: + self._client.headers.update(headers) + if self._async_client is not None: + self._async_client.headers.update(headers) + return evolve(self, headers={**self._headers, **headers}) + + def with_cookies(self, cookies: dict[str, str]) -> "Client": + """Get a new client matching this one with additional cookies""" + if self._client is not None: + self._client.cookies.update(cookies) + if self._async_client is not None: + self._async_client.cookies.update(cookies) + return evolve(self, cookies={**self._cookies, **cookies}) + + def with_timeout(self, timeout: httpx.Timeout) -> "Client": + """Get a new client matching this one with a new timeout configuration""" + if self._client is not None: + self._client.timeout = timeout + if self._async_client is not None: + self._async_client.timeout = timeout + return evolve(self, timeout=timeout) + + def set_httpx_client(self, client: httpx.Client) -> Self: + """Manually set the underlying httpx.Client + + **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. + """ + self._client = client + return self + + def get_httpx_client(self) -> httpx.Client: + """Get the underlying httpx.Client, constructing a new one if not previously set""" + if self._client is None: + self._client = httpx.Client( + base_url=self._base_url, + cookies=self._cookies, + headers=self._headers, + timeout=self._timeout, + verify=self._verify_ssl, + follow_redirects=self._follow_redirects, + **self._httpx_args, + ) + return self._client + + def __enter__(self) -> Self: + """Enter a context manager for self.client—you cannot enter twice (see httpx docs)""" + self.get_httpx_client().__enter__() + return self + + def __exit__(self, *args: Any, **kwargs: Any) -> None: + """Exit a context manager for internal httpx.Client (see httpx docs)""" + self.get_httpx_client().__exit__(*args, **kwargs) + + def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> Self: + """Manually set the underlying httpx.AsyncClient + + **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. + """ + self._async_client = async_client + return self + + def get_async_httpx_client(self) -> httpx.AsyncClient: + """Get the underlying httpx.AsyncClient, constructing a new one if not previously set""" + if self._async_client is None: + self._async_client = httpx.AsyncClient( + base_url=self._base_url, + cookies=self._cookies, + headers=self._headers, + timeout=self._timeout, + verify=self._verify_ssl, + follow_redirects=self._follow_redirects, + **self._httpx_args, + ) + return self._async_client + + async def __aenter__(self) -> Self: + """Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)""" + await self.get_async_httpx_client().__aenter__() + return self + + async def __aexit__(self, *args: Any, **kwargs: Any) -> None: + """Exit a context manager for underlying httpx.AsyncClient (see httpx docs)""" + await self.get_async_httpx_client().__aexit__(*args, **kwargs) + + +@define +class AuthenticatedClient: + """A Client which has been authenticated for use on secured endpoints + + The following are accepted as keyword arguments and will be used to construct httpx Clients internally: + + ``base_url``: The base URL for the API, all requests are made to a relative path to this URL + + ``cookies``: A dictionary of cookies to be sent with every request + + ``headers``: A dictionary of headers to be sent with every request + + ``timeout``: The maximum amount of a time a request can take. API functions will raise + httpx.TimeoutException if this is exceeded. + + ``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production, + but can be set to False for testing purposes. + + ``follow_redirects``: Whether or not to follow redirects. Default value is False. + + ``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor. + + """ + + raise_on_unexpected_status: bool = field(default=False, kw_only=True) + """Whether or not to raise an errors.UnexpectedStatus if the API returns a status code that was not documented in the source OpenAPI document. Can also be provided as a keyword argument to the constructor.""" + _base_url: str = field(alias="base_url") + _cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies") + _headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers") + _timeout: httpx.Timeout | None = field(default=None, kw_only=True, alias="timeout") + _verify_ssl: str | bool | ssl.SSLContext = field(default=True, kw_only=True, alias="verify_ssl") + _follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects") + _httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args") + _client: httpx.Client | None = field(default=None, init=False) + _async_client: httpx.AsyncClient | None = field(default=None, init=False) + + token: str + """The token to use for authentication""" + prefix: str = "Bearer" + """The prefix to use for the Authorization header""" + auth_header_name: str = "Authorization" + """The name of the Authorization header""" + + def with_headers(self, headers: dict[str, str]) -> "AuthenticatedClient": + """Get a new client matching this one with additional headers""" + if self._client is not None: + self._client.headers.update(headers) + if self._async_client is not None: + self._async_client.headers.update(headers) + return evolve(self, headers={**self._headers, **headers}) + + def with_cookies(self, cookies: dict[str, str]) -> "AuthenticatedClient": + """Get a new client matching this one with additional cookies""" + if self._client is not None: + self._client.cookies.update(cookies) + if self._async_client is not None: + self._async_client.cookies.update(cookies) + return evolve(self, cookies={**self._cookies, **cookies}) + + def with_timeout(self, timeout: httpx.Timeout) -> "AuthenticatedClient": + """Get a new client matching this one with a new timeout configuration""" + if self._client is not None: + self._client.timeout = timeout + if self._async_client is not None: + self._async_client.timeout = timeout + return evolve(self, timeout=timeout) + + def set_httpx_client(self, client: httpx.Client) -> Self: + """Manually set the underlying httpx.Client + + **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. + """ + self._client = client + return self + + def get_httpx_client(self) -> httpx.Client: + """Get the underlying httpx.Client, constructing a new one if not previously set""" + if self._client is None: + self._headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token + self._client = httpx.Client( + base_url=self._base_url, + cookies=self._cookies, + headers=self._headers, + timeout=self._timeout, + verify=self._verify_ssl, + follow_redirects=self._follow_redirects, + **self._httpx_args, + ) + return self._client + + def __enter__(self) -> Self: + """Enter a context manager for self.client—you cannot enter twice (see httpx docs)""" + self.get_httpx_client().__enter__() + return self + + def __exit__(self, *args: Any, **kwargs: Any) -> None: + """Exit a context manager for internal httpx.Client (see httpx docs)""" + self.get_httpx_client().__exit__(*args, **kwargs) + + def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> Self: + """Manually set the underlying httpx.AsyncClient + + **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. + """ + self._async_client = async_client + return self + + def get_async_httpx_client(self) -> httpx.AsyncClient: + """Get the underlying httpx.AsyncClient, constructing a new one if not previously set""" + if self._async_client is None: + self._headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token + self._async_client = httpx.AsyncClient( + base_url=self._base_url, + cookies=self._cookies, + headers=self._headers, + timeout=self._timeout, + verify=self._verify_ssl, + follow_redirects=self._follow_redirects, + **self._httpx_args, + ) + return self._async_client + + async def __aenter__(self) -> Self: + """Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)""" + await self.get_async_httpx_client().__aenter__() + return self + + async def __aexit__(self, *args: Any, **kwargs: Any) -> None: + """Exit a context manager for underlying httpx.AsyncClient (see httpx docs)""" + await self.get_async_httpx_client().__aexit__(*args, **kwargs) diff --git a/end_to_end_tests/golden-record/my_test_api_client/errors.py b/end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/my_test_api_client/errors.py similarity index 100% rename from end_to_end_tests/golden-record/my_test_api_client/errors.py rename to end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/my_test_api_client/errors.py diff --git a/end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/my_test_api_client/models/__init__.py b/end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/my_test_api_client/models/__init__.py new file mode 100644 index 000000000..3f5aca91f --- /dev/null +++ b/end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/my_test_api_client/models/__init__.py @@ -0,0 +1,9 @@ +"""Contains all the data models used in inputs/outputs""" + +from .model_with_description import ModelWithDescription +from .model_with_no_description import ModelWithNoDescription + +__all__ = ( + "ModelWithDescription", + "ModelWithNoDescription", +) diff --git a/end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/my_test_api_client/models/model_with_description.py b/end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/my_test_api_client/models/model_with_description.py new file mode 100644 index 000000000..b0be6a72c --- /dev/null +++ b/end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/my_test_api_client/models/model_with_description.py @@ -0,0 +1,80 @@ +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="ModelWithDescription") + + +@_attrs_define +class ModelWithDescription: + """This is a nice model.""" + + prop_with_no_desc: str | Unset = UNSET + prop_with_desc: str | Unset = UNSET + """ This is a nice property. """ + prop_with_long_desc: str | Unset = UNSET + """ It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of + foolishness, + it was the epoch of belief, it was the epoch of incredulity, it was the season of light, it was the season of + darkness, it was the spring of hope, it was the winter of despair. + """ + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + prop_with_no_desc = self.prop_with_no_desc + + prop_with_desc = self.prop_with_desc + + prop_with_long_desc = self.prop_with_long_desc + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update({}) + if prop_with_no_desc is not UNSET: + field_dict["propWithNoDesc"] = prop_with_no_desc + if prop_with_desc is not UNSET: + field_dict["propWithDesc"] = prop_with_desc + if prop_with_long_desc is not UNSET: + field_dict["propWithLongDesc"] = prop_with_long_desc + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + prop_with_no_desc = d.pop("propWithNoDesc", UNSET) + + prop_with_desc = d.pop("propWithDesc", UNSET) + + prop_with_long_desc = d.pop("propWithLongDesc", UNSET) + + model_with_description = cls( + prop_with_no_desc=prop_with_no_desc, + prop_with_desc=prop_with_desc, + prop_with_long_desc=prop_with_long_desc, + ) + + model_with_description.additional_properties = d + return model_with_description + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/my_test_api_client/models/model_with_no_description.py b/end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/my_test_api_client/models/model_with_no_description.py new file mode 100644 index 000000000..0a020f657 --- /dev/null +++ b/end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/my_test_api_client/models/model_with_no_description.py @@ -0,0 +1,65 @@ +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="ModelWithNoDescription") + + +@_attrs_define +class ModelWithNoDescription: + prop_with_no_desc: str | Unset = UNSET + prop_with_desc: str | Unset = UNSET + """ This is a nice property. """ + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + prop_with_no_desc = self.prop_with_no_desc + + prop_with_desc = self.prop_with_desc + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update({}) + if prop_with_no_desc is not UNSET: + field_dict["propWithNoDesc"] = prop_with_no_desc + if prop_with_desc is not UNSET: + field_dict["propWithDesc"] = prop_with_desc + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + prop_with_no_desc = d.pop("propWithNoDesc", UNSET) + + prop_with_desc = d.pop("propWithDesc", UNSET) + + model_with_no_description = cls( + prop_with_no_desc=prop_with_no_desc, + prop_with_desc=prop_with_desc, + ) + + model_with_no_description.additional_properties = d + return model_with_no_description + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/end_to_end_tests/golden-record/my_test_api_client/py.typed b/end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/my_test_api_client/py.typed similarity index 100% rename from end_to_end_tests/golden-record/my_test_api_client/py.typed rename to end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/my_test_api_client/py.typed diff --git a/end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/my_test_api_client/types.py b/end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/my_test_api_client/types.py new file mode 100644 index 000000000..b64af0952 --- /dev/null +++ b/end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/my_test_api_client/types.py @@ -0,0 +1,54 @@ +"""Contains some shared types for properties""" + +from collections.abc import Mapping, MutableMapping +from http import HTTPStatus +from typing import IO, BinaryIO, Generic, Literal, TypeVar + +from attrs import define + + +class Unset: + def __bool__(self) -> Literal[False]: + return False + + +UNSET: Unset = Unset() + +# The types that `httpx.Client(files=)` can accept, copied from that library. +FileContent = IO[bytes] | bytes | str +FileTypes = ( + # (filename, file (or bytes), content_type) + tuple[str | None, FileContent, str | None] + # (filename, file (or bytes), content_type, headers) + | tuple[str | None, FileContent, str | None, Mapping[str, str]] +) +RequestFiles = list[tuple[str, FileTypes]] + + +@define +class File: + """Contains information for file uploads""" + + payload: BinaryIO + file_name: str | None = None + mime_type: str | None = None + + def to_tuple(self) -> FileTypes: + """Return a tuple representation that httpx will accept for multipart/form-data""" + return self.file_name, self.payload, self.mime_type + + +T = TypeVar("T") + + +@define +class Response(Generic[T]): + """A response from an endpoint""" + + status_code: HTTPStatus + content: bytes + headers: MutableMapping[str, str] + parsed: T | None + + +__all__ = ["UNSET", "File", "FileTypes", "RequestFiles", "Response", "Unset"] diff --git a/end_to_end_tests/golden-record/pyproject.toml b/end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/pyproject.toml similarity index 59% rename from end_to_end_tests/golden-record/pyproject.toml rename to end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/pyproject.toml index 526beacf6..f2498ce1a 100644 --- a/end_to_end_tests/golden-record/pyproject.toml +++ b/end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/pyproject.toml @@ -5,19 +5,17 @@ description = "A client library for accessing My Test API" authors = [] readme = "README.md" packages = [ - {include = "my_test_api_client"}, + { include = "my_test_api_client" }, ] -include = ["CHANGELOG.md", "my_test_api_client/py.typed"] - +include = ["my_test_api_client/py.typed"] [tool.poetry.dependencies] -python = "^3.8" -httpx = ">=0.20.0,<0.28.0" -attrs = ">=21.3.0" -python-dateutil = "^2.8.0" +python = "^3.11" +httpx = ">=0.23.1,<0.29.0" +attrs = ">=22.2.0" [build-system] -requires = ["poetry-core>=1.0.0"] +requires = ["poetry-core>=2.0.0,<3.0.0"] build-backend = "poetry.core.masonry.api" [tool.ruff] diff --git a/end_to_end_tests/test-3-1-golden-record/.gitignore b/end_to_end_tests/golden-records/escapes-client/.gitignore similarity index 100% rename from end_to_end_tests/test-3-1-golden-record/.gitignore rename to end_to_end_tests/golden-records/escapes-client/.gitignore diff --git a/end_to_end_tests/golden-records/escapes-client/README.md b/end_to_end_tests/golden-records/escapes-client/README.md new file mode 100644 index 000000000..40b4957f5 --- /dev/null +++ b/end_to_end_tests/golden-records/escapes-client/README.md @@ -0,0 +1,124 @@ +# escapes-client +A client library for accessing escapes" + +## Usage +First, create a client: + +```python +from escapes_client import Client + +client = Client(base_url="https://api.example.com") +``` + +If the endpoints you're going to hit require authentication, use `AuthenticatedClient` instead: + +```python +from escapes_client import AuthenticatedClient + +client = AuthenticatedClient(base_url="https://api.example.com", token="SuperSecretToken") +``` + +Now call your endpoint and use your models: + +```python +from escapes_client.models import MyDataModel +from escapes_client.api.my_tag import get_my_data_model +from escapes_client.types import Response + +with client as client: + my_data: MyDataModel = get_my_data_model.sync(client=client) + # or if you need more info (e.g. status_code) + response: Response[MyDataModel] = get_my_data_model.sync_detailed(client=client) +``` + +Or do the same thing with an async version: + +```python +from escapes_client.models import MyDataModel +from escapes_client.api.my_tag import get_my_data_model +from escapes_client.types import Response + +async with client as client: + my_data: MyDataModel = await get_my_data_model.asyncio(client=client) + response: Response[MyDataModel] = await get_my_data_model.asyncio_detailed(client=client) +``` + +By default, when you're calling an HTTPS API it will attempt to verify that SSL is working correctly. Using certificate verification is highly recommended most of the time, but sometimes you may need to authenticate to a server (especially an internal server) using a custom certificate bundle. + +```python +client = AuthenticatedClient( + base_url="https://internal_api.example.com", + token="SuperSecretToken", + verify_ssl="/path/to/certificate_bundle.pem", +) +``` + +You can also disable certificate validation altogether, but beware that **this is a security risk**. + +```python +client = AuthenticatedClient( + base_url="https://internal_api.example.com", + token="SuperSecretToken", + verify_ssl=False +) +``` + +Things to know: +1. Every path/method combo becomes a Python module with four functions: + 1. `sync`: Blocking request that returns parsed data (if successful) or `None` + 1. `sync_detailed`: Blocking request that always returns a `Request`, optionally with `parsed` set if the request was successful. + 1. `asyncio`: Like `sync` but async instead of blocking + 1. `asyncio_detailed`: Like `sync_detailed` but async instead of blocking + +1. All path/query params, and bodies become method arguments. +1. If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above) +1. Any endpoint which did not have a tag will be in `escapes_client.api.default` + +## Advanced customizations + +There are more settings on the generated `Client` class which let you control more runtime behavior, check out the docstring on that class for more info. You can also customize the underlying `httpx.Client` or `httpx.AsyncClient` (depending on your use-case): + +```python +from escapes_client import Client + +def log_request(request): + print(f"Request event hook: {request.method} {request.url} - Waiting for response") + +def log_response(response): + request = response.request + print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}") + +client = Client( + base_url="https://api.example.com", + httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}}, +) + +# Or get the underlying httpx client to modify directly with client.get_httpx_client() or client.get_async_httpx_client() +``` + +You can even set the httpx client directly, but beware that this will override any existing settings (e.g., base_url): + +```python +import httpx +from escapes_client import Client + +client = Client( + base_url="https://api.example.com", +) +# Note that base_url needs to be re-set, as would any shared cookies, headers, etc. +client.set_httpx_client(httpx.Client(base_url="https://api.example.com", proxies="http://localhost:8030")) +``` + +## Building / publishing this package +This project uses [Poetry](https://python-poetry.org/) to manage dependencies and packaging. Here are the basics: +1. Update the metadata in pyproject.toml (e.g. authors, version) +1. If you're using a private repository, configure it with Poetry + 1. `poetry config repositories. ` + 1. `poetry config http-basic. ` +1. Publish the client with `poetry publish --build -r ` or, if for public PyPI, just `poetry publish --build` + +If you want to install this client into another project without publishing it (e.g. for development) then: +1. If that project **is using Poetry**, you can simply do `poetry add ` from that project +1. If that project is not using Poetry: + 1. Build a wheel with `poetry build -f wheel` + 1. Install that wheel from the other project `pip install ` diff --git a/end_to_end_tests/golden-records/escapes-client/escapes_client/__init__.py b/end_to_end_tests/golden-records/escapes-client/escapes_client/__init__.py new file mode 100644 index 000000000..204618f46 --- /dev/null +++ b/end_to_end_tests/golden-records/escapes-client/escapes_client/__init__.py @@ -0,0 +1,8 @@ +"""A client library for accessing escapes" """ + +from .client import AuthenticatedClient, Client + +__all__ = ( + "AuthenticatedClient", + "Client", +) diff --git a/end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/api/__init__.py b/end_to_end_tests/golden-records/escapes-client/escapes_client/api/__init__.py similarity index 100% rename from end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/api/__init__.py rename to end_to_end_tests/golden-records/escapes-client/escapes_client/api/__init__.py diff --git a/end_to_end_tests/golden-records/escapes-client/escapes_client/api/default/__init__.py b/end_to_end_tests/golden-records/escapes-client/escapes_client/api/default/__init__.py new file mode 100644 index 000000000..2d7c0b23d --- /dev/null +++ b/end_to_end_tests/golden-records/escapes-client/escapes_client/api/default/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/end_to_end_tests/golden-records/escapes-client/escapes_client/api/default/get_weird_responses.py b/end_to_end_tests/golden-records/escapes-client/escapes_client/api/default/get_weird_responses.py new file mode 100644 index 000000000..81a43a14b --- /dev/null +++ b/end_to_end_tests/golden-records/escapes-client/escapes_client/api/default/get_weird_responses.py @@ -0,0 +1,76 @@ +from http import HTTPStatus +from typing import Any + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...types import Response + + +def _get_kwargs() -> dict[str, Any]: + + _kwargs: dict[str, Any] = { + "method": "get", + "url": "/weird-responses", + } + + return _kwargs + + +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient | Client, +) -> Response[Any]: + """ + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + kwargs = _get_kwargs() + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +async def asyncio_detailed( + *, + client: AuthenticatedClient | Client, +) -> Response[Any]: + """ + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + kwargs = _get_kwargs() + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) diff --git a/end_to_end_tests/golden-records/escapes-client/escapes_client/api/default/misc_metadata_escapes.py b/end_to_end_tests/golden-records/escapes-client/escapes_client/api/default/misc_metadata_escapes.py new file mode 100644 index 000000000..adabb42d1 --- /dev/null +++ b/end_to_end_tests/golden-records/escapes-client/escapes_client/api/default/misc_metadata_escapes.py @@ -0,0 +1,150 @@ +from http import HTTPStatus +from typing import Any, cast + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.misc_metadata_escapes_body import MiscMetadataEscapesBody +from ...types import Response + + +def _get_kwargs( + *, + body: MiscMetadataEscapesBody, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + _kwargs: dict[str, Any] = { + "method": "post", + "url": "/misc-metadata-escapes", + } + + _kwargs["json"] = body.to_dict() + + headers["Content-Type"] = "application/json" + + _kwargs["headers"] = headers + return _kwargs + + +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> str | None: + if response.status_code == 200: + response_200 = cast(str, response.json()) + return response_200 + + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[str]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient | Client, + body: MiscMetadataEscapesBody, +) -> Response[str]: + """ + Args: + body (MiscMetadataEscapesBody): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[str] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient | Client, + body: MiscMetadataEscapesBody, +) -> str | None: + """ + Args: + body (MiscMetadataEscapesBody): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + str + """ + + return sync_detailed( + client=client, + body=body, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient | Client, + body: MiscMetadataEscapesBody, +) -> Response[str]: + """ + Args: + body (MiscMetadataEscapesBody): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[str] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient | Client, + body: MiscMetadataEscapesBody, +) -> str | None: + """ + Args: + body (MiscMetadataEscapesBody): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + str + """ + + return ( + await asyncio_detailed( + client=client, + body=body, + ) + ).parsed diff --git a/end_to_end_tests/golden-records/escapes-client/escapes_client/api/default/non_string_example.py b/end_to_end_tests/golden-records/escapes-client/escapes_client/api/default/non_string_example.py new file mode 100644 index 000000000..7090834e2 --- /dev/null +++ b/end_to_end_tests/golden-records/escapes-client/escapes_client/api/default/non_string_example.py @@ -0,0 +1,101 @@ +from http import HTTPStatus +from typing import Any + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.non_string_example_body import NonStringExampleBody +from ...types import Response + + +def _get_kwargs( + *, + body: NonStringExampleBody, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + _kwargs: dict[str, Any] = { + "method": "post", + "url": "/non-string-example", + } + + _kwargs["json"] = body.to_dict() + + headers["Content-Type"] = "application/json" + + _kwargs["headers"] = headers + return _kwargs + + +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: + return None + + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient | Client, + body: NonStringExampleBody, +) -> Response[Any]: + """ + Args: + body (NonStringExampleBody): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +async def asyncio_detailed( + *, + client: AuthenticatedClient | Client, + body: NonStringExampleBody, +) -> Response[Any]: + """ + Args: + body (NonStringExampleBody): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) diff --git a/end_to_end_tests/golden-records/escapes-client/escapes_client/api/default/property_escapes.py b/end_to_end_tests/golden-records/escapes-client/escapes_client/api/default/property_escapes.py new file mode 100644 index 000000000..8a62c1764 --- /dev/null +++ b/end_to_end_tests/golden-records/escapes-client/escapes_client/api/default/property_escapes.py @@ -0,0 +1,101 @@ +from http import HTTPStatus +from typing import Any + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.property_escapes_model_title_printuh_oh import PropertyEscapesModelTitlePrintuhOh +from ...types import Response + + +def _get_kwargs( + *, + body: PropertyEscapesModelTitlePrintuhOh, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + _kwargs: dict[str, Any] = { + "method": "post", + "url": "/property-escapes", + } + + _kwargs["json"] = body.to_dict() + + headers["Content-Type"] = "application/json" + + _kwargs["headers"] = headers + return _kwargs + + +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: + return None + + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient | Client, + body: PropertyEscapesModelTitlePrintuhOh, +) -> Response[Any]: + """ + Args: + body (PropertyEscapesModelTitlePrintuhOh): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +async def asyncio_detailed( + *, + client: AuthenticatedClient | Client, + body: PropertyEscapesModelTitlePrintuhOh, +) -> Response[Any]: + """ + Args: + body (PropertyEscapesModelTitlePrintuhOh): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) diff --git a/end_to_end_tests/golden-records/escapes-client/escapes_client/api/printtag_escape/__init__.py b/end_to_end_tests/golden-records/escapes-client/escapes_client/api/printtag_escape/__init__.py new file mode 100644 index 000000000..2d7c0b23d --- /dev/null +++ b/end_to_end_tests/golden-records/escapes-client/escapes_client/api/printtag_escape/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/end_to_end_tests/golden-records/escapes-client/escapes_client/api/printtag_escape/with_braces_path.py b/end_to_end_tests/golden-records/escapes-client/escapes_client/api/printtag_escape/with_braces_path.py new file mode 100644 index 000000000..cbbbc3541 --- /dev/null +++ b/end_to_end_tests/golden-records/escapes-client/escapes_client/api/printtag_escape/with_braces_path.py @@ -0,0 +1,131 @@ +from http import HTTPStatus +from typing import Any +from urllib.parse import quote + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.with_braces_path_body import WithBracesPathBody +from ...types import UNSET, Response, Unset + + +def _get_kwargs( + param: str, + *, + body: WithBracesPathBody, + printescape_param_name: str | Unset = UNSET, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + params: dict[str, Any] = {} + + params["\\\"print('escape param name')"] = printescape_param_name + + params = {k: v for k, v in params.items() if v is not UNSET and v is not None} + + _kwargs: dict[str, Any] = { + "method": "post", + "url": '/{param}/" + print("uh oh") + "'.format( + param=quote(str(param), safe=""), + ), + "params": params, + } + + _kwargs["json"] = body.to_dict() + + headers["Content-Type"] = 'application/json; profile="https://example.com/escape" + print("uh oh") + "' + + _kwargs["headers"] = headers + return _kwargs + + +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: + return None + + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + param: str, + *, + client: AuthenticatedClient | Client, + body: WithBracesPathBody, + printescape_param_name: str | Unset = UNSET, +) -> Response[Any]: + """Summary \"\"\" + + Attempting to escape docstring \"\"\" print('uh oh') + + Args: + param (str): + printescape_param_name (str | Unset): + body (WithBracesPathBody): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + kwargs = _get_kwargs( + param=param, + body=body, + printescape_param_name=printescape_param_name, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +async def asyncio_detailed( + param: str, + *, + client: AuthenticatedClient | Client, + body: WithBracesPathBody, + printescape_param_name: str | Unset = UNSET, +) -> Response[Any]: + """Summary \"\"\" + + Attempting to escape docstring \"\"\" print('uh oh') + + Args: + param (str): + printescape_param_name (str | Unset): + body (WithBracesPathBody): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + kwargs = _get_kwargs( + param=param, + body=body, + printescape_param_name=printescape_param_name, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) diff --git a/end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/client.py b/end_to_end_tests/golden-records/escapes-client/escapes_client/client.py similarity index 83% rename from end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/client.py rename to end_to_end_tests/golden-records/escapes-client/escapes_client/client.py index 63a2493b9..edb246d7e 100644 --- a/end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/client.py +++ b/end_to_end_tests/golden-records/escapes-client/escapes_client/client.py @@ -1,5 +1,5 @@ import ssl -from typing import Any, Dict, Optional, Union +from typing import Any, Self import httpx from attrs import define, evolve, field @@ -36,16 +36,16 @@ class Client: raise_on_unexpected_status: bool = field(default=False, kw_only=True) _base_url: str = field(alias="base_url") - _cookies: Dict[str, str] = field(factory=dict, kw_only=True, alias="cookies") - _headers: Dict[str, str] = field(factory=dict, kw_only=True, alias="headers") - _timeout: Optional[httpx.Timeout] = field(default=None, kw_only=True, alias="timeout") - _verify_ssl: Union[str, bool, ssl.SSLContext] = field(default=True, kw_only=True, alias="verify_ssl") + _cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies") + _headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers") + _timeout: httpx.Timeout | None = field(default=None, kw_only=True, alias="timeout") + _verify_ssl: str | bool | ssl.SSLContext = field(default=True, kw_only=True, alias="verify_ssl") _follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects") - _httpx_args: Dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args") - _client: Optional[httpx.Client] = field(default=None, init=False) - _async_client: Optional[httpx.AsyncClient] = field(default=None, init=False) + _httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args") + _client: httpx.Client | None = field(default=None, init=False) + _async_client: httpx.AsyncClient | None = field(default=None, init=False) - def with_headers(self, headers: Dict[str, str]) -> "Client": + def with_headers(self, headers: dict[str, str]) -> "Client": """Get a new client matching this one with additional headers""" if self._client is not None: self._client.headers.update(headers) @@ -53,7 +53,7 @@ def with_headers(self, headers: Dict[str, str]) -> "Client": self._async_client.headers.update(headers) return evolve(self, headers={**self._headers, **headers}) - def with_cookies(self, cookies: Dict[str, str]) -> "Client": + def with_cookies(self, cookies: dict[str, str]) -> "Client": """Get a new client matching this one with additional cookies""" if self._client is not None: self._client.cookies.update(cookies) @@ -62,15 +62,15 @@ def with_cookies(self, cookies: Dict[str, str]) -> "Client": return evolve(self, cookies={**self._cookies, **cookies}) def with_timeout(self, timeout: httpx.Timeout) -> "Client": - """Get a new client matching this one with a new timeout (in seconds)""" + """Get a new client matching this one with a new timeout configuration""" if self._client is not None: self._client.timeout = timeout if self._async_client is not None: self._async_client.timeout = timeout return evolve(self, timeout=timeout) - def set_httpx_client(self, client: httpx.Client) -> "Client": - """Manually the underlying httpx.Client + def set_httpx_client(self, client: httpx.Client) -> Self: + """Manually set the underlying httpx.Client **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. """ @@ -91,7 +91,7 @@ def get_httpx_client(self) -> httpx.Client: ) return self._client - def __enter__(self) -> "Client": + def __enter__(self) -> Self: """Enter a context manager for self.client—you cannot enter twice (see httpx docs)""" self.get_httpx_client().__enter__() return self @@ -100,8 +100,8 @@ def __exit__(self, *args: Any, **kwargs: Any) -> None: """Exit a context manager for internal httpx.Client (see httpx docs)""" self.get_httpx_client().__exit__(*args, **kwargs) - def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "Client": - """Manually the underlying httpx.AsyncClient + def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> Self: + """Manually set the underlying httpx.AsyncClient **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. """ @@ -122,7 +122,7 @@ def get_async_httpx_client(self) -> httpx.AsyncClient: ) return self._async_client - async def __aenter__(self) -> "Client": + async def __aenter__(self) -> Self: """Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)""" await self.get_async_httpx_client().__aenter__() return self @@ -166,20 +166,20 @@ class AuthenticatedClient: raise_on_unexpected_status: bool = field(default=False, kw_only=True) _base_url: str = field(alias="base_url") - _cookies: Dict[str, str] = field(factory=dict, kw_only=True, alias="cookies") - _headers: Dict[str, str] = field(factory=dict, kw_only=True, alias="headers") - _timeout: Optional[httpx.Timeout] = field(default=None, kw_only=True, alias="timeout") - _verify_ssl: Union[str, bool, ssl.SSLContext] = field(default=True, kw_only=True, alias="verify_ssl") + _cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies") + _headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers") + _timeout: httpx.Timeout | None = field(default=None, kw_only=True, alias="timeout") + _verify_ssl: str | bool | ssl.SSLContext = field(default=True, kw_only=True, alias="verify_ssl") _follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects") - _httpx_args: Dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args") - _client: Optional[httpx.Client] = field(default=None, init=False) - _async_client: Optional[httpx.AsyncClient] = field(default=None, init=False) + _httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args") + _client: httpx.Client | None = field(default=None, init=False) + _async_client: httpx.AsyncClient | None = field(default=None, init=False) token: str prefix: str = "Bearer" auth_header_name: str = "Authorization" - def with_headers(self, headers: Dict[str, str]) -> "AuthenticatedClient": + def with_headers(self, headers: dict[str, str]) -> "AuthenticatedClient": """Get a new client matching this one with additional headers""" if self._client is not None: self._client.headers.update(headers) @@ -187,7 +187,7 @@ def with_headers(self, headers: Dict[str, str]) -> "AuthenticatedClient": self._async_client.headers.update(headers) return evolve(self, headers={**self._headers, **headers}) - def with_cookies(self, cookies: Dict[str, str]) -> "AuthenticatedClient": + def with_cookies(self, cookies: dict[str, str]) -> "AuthenticatedClient": """Get a new client matching this one with additional cookies""" if self._client is not None: self._client.cookies.update(cookies) @@ -196,15 +196,15 @@ def with_cookies(self, cookies: Dict[str, str]) -> "AuthenticatedClient": return evolve(self, cookies={**self._cookies, **cookies}) def with_timeout(self, timeout: httpx.Timeout) -> "AuthenticatedClient": - """Get a new client matching this one with a new timeout (in seconds)""" + """Get a new client matching this one with a new timeout configuration""" if self._client is not None: self._client.timeout = timeout if self._async_client is not None: self._async_client.timeout = timeout return evolve(self, timeout=timeout) - def set_httpx_client(self, client: httpx.Client) -> "AuthenticatedClient": - """Manually the underlying httpx.Client + def set_httpx_client(self, client: httpx.Client) -> Self: + """Manually set the underlying httpx.Client **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. """ @@ -226,7 +226,7 @@ def get_httpx_client(self) -> httpx.Client: ) return self._client - def __enter__(self) -> "AuthenticatedClient": + def __enter__(self) -> Self: """Enter a context manager for self.client—you cannot enter twice (see httpx docs)""" self.get_httpx_client().__enter__() return self @@ -235,8 +235,8 @@ def __exit__(self, *args: Any, **kwargs: Any) -> None: """Exit a context manager for internal httpx.Client (see httpx docs)""" self.get_httpx_client().__exit__(*args, **kwargs) - def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "AuthenticatedClient": - """Manually the underlying httpx.AsyncClient + def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> Self: + """Manually set the underlying httpx.AsyncClient **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. """ @@ -258,7 +258,7 @@ def get_async_httpx_client(self) -> httpx.AsyncClient: ) return self._async_client - async def __aenter__(self) -> "AuthenticatedClient": + async def __aenter__(self) -> Self: """Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)""" await self.get_async_httpx_client().__aenter__() return self diff --git a/end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/errors.py b/end_to_end_tests/golden-records/escapes-client/escapes_client/errors.py similarity index 100% rename from end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/errors.py rename to end_to_end_tests/golden-records/escapes-client/escapes_client/errors.py diff --git a/end_to_end_tests/golden-records/escapes-client/escapes_client/models/__init__.py b/end_to_end_tests/golden-records/escapes-client/escapes_client/models/__init__.py new file mode 100644 index 000000000..99b7ab7de --- /dev/null +++ b/end_to_end_tests/golden-records/escapes-client/escapes_client/models/__init__.py @@ -0,0 +1,19 @@ +"""Contains all the data models used in inputs/outputs""" + +from .misc_metadata_escapes_body import MiscMetadataEscapesBody +from .non_string_example_body import NonStringExampleBody +from .non_string_example_body_dict_example import NonStringExampleBodyDictExample +from .property_escapes_model_title_printuh_oh import PropertyEscapesModelTitlePrintuhOh +from .property_escapes_model_title_printuh_oh_escaped_enum import PropertyEscapesModelTitlePrintuhOhEscapedEnum +from .schema_printuh_oh import SchemaPrintuhOh +from .with_braces_path_body import WithBracesPathBody + +__all__ = ( + "MiscMetadataEscapesBody", + "NonStringExampleBody", + "NonStringExampleBodyDictExample", + "PropertyEscapesModelTitlePrintuhOh", + "PropertyEscapesModelTitlePrintuhOhEscapedEnum", + "SchemaPrintuhOh", + "WithBracesPathBody", +) diff --git a/end_to_end_tests/golden-records/escapes-client/escapes_client/models/misc_metadata_escapes_body.py b/end_to_end_tests/golden-records/escapes-client/escapes_client/models/misc_metadata_escapes_body.py new file mode 100644 index 000000000..98db7c4f7 --- /dev/null +++ b/end_to_end_tests/golden-records/escapes-client/escapes_client/models/misc_metadata_escapes_body.py @@ -0,0 +1,45 @@ +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +T = TypeVar("T", bound="MiscMetadataEscapesBody") + + +@_attrs_define +class MiscMetadataEscapesBody: + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + misc_metadata_escapes_body = cls() + + misc_metadata_escapes_body.additional_properties = d + return misc_metadata_escapes_body + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/end_to_end_tests/golden-records/escapes-client/escapes_client/models/non_string_example_body.py b/end_to_end_tests/golden-records/escapes-client/escapes_client/models/non_string_example_body.py new file mode 100644 index 000000000..ad5d5d328 --- /dev/null +++ b/end_to_end_tests/golden-records/escapes-client/escapes_client/models/non_string_example_body.py @@ -0,0 +1,75 @@ +from __future__ import annotations + +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, TypeVar + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +if TYPE_CHECKING: + from ..models.non_string_example_body_dict_example import NonStringExampleBodyDictExample + + +T = TypeVar("T", bound="NonStringExampleBody") + + +@_attrs_define +class NonStringExampleBody: + """ + Attributes: + dict_example (NonStringExampleBodyDictExample | Unset): Example: {'nested': 'dict example \"\"\" print(\\'uh + oh\\')'}. + """ + + dict_example: NonStringExampleBodyDictExample | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + dict_example: dict[str, Any] | Unset = UNSET + if not isinstance(self.dict_example, Unset): + dict_example = self.dict_example.to_dict() + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update({}) + if dict_example is not UNSET: + field_dict["dict_example"] = dict_example + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + from ..models.non_string_example_body_dict_example import NonStringExampleBodyDictExample # noqa: PLC0415 + + d = dict(src_dict) + _dict_example = d.pop("dict_example", UNSET) + dict_example: NonStringExampleBodyDictExample | Unset + if isinstance(_dict_example, Unset): + dict_example = UNSET + else: + dict_example = NonStringExampleBodyDictExample.from_dict(_dict_example) + + non_string_example_body = cls( + dict_example=dict_example, + ) + + non_string_example_body.additional_properties = d + return non_string_example_body + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/end_to_end_tests/golden-records/escapes-client/escapes_client/models/non_string_example_body_dict_example.py b/end_to_end_tests/golden-records/escapes-client/escapes_client/models/non_string_example_body_dict_example.py new file mode 100644 index 000000000..819e8c591 --- /dev/null +++ b/end_to_end_tests/golden-records/escapes-client/escapes_client/models/non_string_example_body_dict_example.py @@ -0,0 +1,51 @@ +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +T = TypeVar("T", bound="NonStringExampleBodyDictExample") + + +@_attrs_define +class NonStringExampleBodyDictExample: + """ + Example: + {'nested': 'dict example \"\"\" print(\\'uh oh\\')'} + + """ + + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + non_string_example_body_dict_example = cls() + + non_string_example_body_dict_example.additional_properties = d + return non_string_example_body_dict_example + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/end_to_end_tests/golden-records/escapes-client/escapes_client/models/property_escapes_model_title_printuh_oh.py b/end_to_end_tests/golden-records/escapes-client/escapes_client/models/property_escapes_model_title_printuh_oh.py new file mode 100644 index 000000000..6e7d96a98 --- /dev/null +++ b/end_to_end_tests/golden-records/escapes-client/escapes_client/models/property_escapes_model_title_printuh_oh.py @@ -0,0 +1,92 @@ +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, Literal, TypeVar, cast + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..models.property_escapes_model_title_printuh_oh_escaped_enum import PropertyEscapesModelTitlePrintuhOhEscapedEnum +from ..types import UNSET, Unset + +T = TypeVar("T", bound="PropertyEscapesModelTitlePrintuhOh") + + +@_attrs_define +class PropertyEscapesModelTitlePrintuhOh: + """ + Attributes: + escaped_description (str | Unset): Attempting to escape the Attributes docstring \"\"\" print('uh oh') Default: + 'default value with \\\\"quotes\\\\"'. Example: Example \"\"\" print('uh oh'). + escaped_enum (PropertyEscapesModelTitlePrintuhOhEscapedEnum | Unset): + escaped_const (Literal['\\\\" + print(\\'uh oh\\') + \\\\"'] | Unset): + """ + + escaped_description: str | Unset = 'default value with \\"quotes\\"' + escaped_enum: PropertyEscapesModelTitlePrintuhOhEscapedEnum | Unset = UNSET + escaped_const: Literal["\\\" + print('uh oh') + \\\""] | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + escaped_description = self.escaped_description + + escaped_enum: str | Unset = UNSET + if not isinstance(self.escaped_enum, Unset): + escaped_enum = self.escaped_enum.value + + escaped_const = self.escaped_const + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update({}) + if escaped_description is not UNSET: + field_dict["escaped_description"] = escaped_description + if escaped_enum is not UNSET: + field_dict["escaped_enum"] = escaped_enum + if escaped_const is not UNSET: + field_dict["escaped_const"] = escaped_const + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + escaped_description = d.pop("escaped_description", UNSET) + + _escaped_enum = d.pop("escaped_enum", UNSET) + escaped_enum: PropertyEscapesModelTitlePrintuhOhEscapedEnum | Unset + if isinstance(_escaped_enum, Unset): + escaped_enum = UNSET + else: + escaped_enum = PropertyEscapesModelTitlePrintuhOhEscapedEnum(_escaped_enum) + + escaped_const = cast(Literal["\\\" + print('uh oh') + \\\""] | Unset, d.pop("escaped_const", UNSET)) + if escaped_const != "\\\" + print('uh oh') + \\\"" and not isinstance(escaped_const, Unset): + raise ValueError( + f"escaped_const must match const '\\\\\" + print(\\'uh oh\\') + \\\\\"', got '{escaped_const}'" + ) + + property_escapes_model_title_printuh_oh = cls( + escaped_description=escaped_description, + escaped_enum=escaped_enum, + escaped_const=escaped_const, + ) + + property_escapes_model_title_printuh_oh.additional_properties = d + return property_escapes_model_title_printuh_oh + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/end_to_end_tests/golden-records/escapes-client/escapes_client/models/property_escapes_model_title_printuh_oh_escaped_enum.py b/end_to_end_tests/golden-records/escapes-client/escapes_client/models/property_escapes_model_title_printuh_oh_escaped_enum.py new file mode 100644 index 000000000..2d1f0df00 --- /dev/null +++ b/end_to_end_tests/golden-records/escapes-client/escapes_client/models/property_escapes_model_title_printuh_oh_escaped_enum.py @@ -0,0 +1,9 @@ +from enum import StrEnum + + +class PropertyEscapesModelTitlePrintuhOhEscapedEnum(StrEnum): + NORMAL_VALUE = "normal value" + VALUE_PRINTUH_OH = "value\" + print('uh oh') + \"" + + def __str__(self) -> str: + return str(self.value) diff --git a/end_to_end_tests/golden-records/escapes-client/escapes_client/models/schema_printuh_oh.py b/end_to_end_tests/golden-records/escapes-client/escapes_client/models/schema_printuh_oh.py new file mode 100644 index 000000000..02caf1747 --- /dev/null +++ b/end_to_end_tests/golden-records/escapes-client/escapes_client/models/schema_printuh_oh.py @@ -0,0 +1,45 @@ +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +T = TypeVar("T", bound="SchemaPrintuhOh") + + +@_attrs_define +class SchemaPrintuhOh: + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + schema_printuh_oh = cls() + + schema_printuh_oh.additional_properties = d + return schema_printuh_oh + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/end_to_end_tests/golden-records/escapes-client/escapes_client/models/with_braces_path_body.py b/end_to_end_tests/golden-records/escapes-client/escapes_client/models/with_braces_path_body.py new file mode 100644 index 000000000..390de1497 --- /dev/null +++ b/end_to_end_tests/golden-records/escapes-client/escapes_client/models/with_braces_path_body.py @@ -0,0 +1,45 @@ +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +T = TypeVar("T", bound="WithBracesPathBody") + + +@_attrs_define +class WithBracesPathBody: + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + with_braces_path_body = cls() + + with_braces_path_body.additional_properties = d + return with_braces_path_body + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/py.typed b/end_to_end_tests/golden-records/escapes-client/escapes_client/py.typed similarity index 100% rename from end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/py.typed rename to end_to_end_tests/golden-records/escapes-client/escapes_client/py.typed diff --git a/end_to_end_tests/golden-records/escapes-client/escapes_client/types.py b/end_to_end_tests/golden-records/escapes-client/escapes_client/types.py new file mode 100644 index 000000000..b64af0952 --- /dev/null +++ b/end_to_end_tests/golden-records/escapes-client/escapes_client/types.py @@ -0,0 +1,54 @@ +"""Contains some shared types for properties""" + +from collections.abc import Mapping, MutableMapping +from http import HTTPStatus +from typing import IO, BinaryIO, Generic, Literal, TypeVar + +from attrs import define + + +class Unset: + def __bool__(self) -> Literal[False]: + return False + + +UNSET: Unset = Unset() + +# The types that `httpx.Client(files=)` can accept, copied from that library. +FileContent = IO[bytes] | bytes | str +FileTypes = ( + # (filename, file (or bytes), content_type) + tuple[str | None, FileContent, str | None] + # (filename, file (or bytes), content_type, headers) + | tuple[str | None, FileContent, str | None, Mapping[str, str]] +) +RequestFiles = list[tuple[str, FileTypes]] + + +@define +class File: + """Contains information for file uploads""" + + payload: BinaryIO + file_name: str | None = None + mime_type: str | None = None + + def to_tuple(self) -> FileTypes: + """Return a tuple representation that httpx will accept for multipart/form-data""" + return self.file_name, self.payload, self.mime_type + + +T = TypeVar("T") + + +@define +class Response(Generic[T]): + """A response from an endpoint""" + + status_code: HTTPStatus + content: bytes + headers: MutableMapping[str, str] + parsed: T | None + + +__all__ = ["UNSET", "File", "FileTypes", "RequestFiles", "Response", "Unset"] diff --git a/end_to_end_tests/golden-records/escapes-client/pyproject.toml b/end_to_end_tests/golden-records/escapes-client/pyproject.toml new file mode 100644 index 000000000..1a167e041 --- /dev/null +++ b/end_to_end_tests/golden-records/escapes-client/pyproject.toml @@ -0,0 +1,25 @@ +[tool.poetry] +name = "escapes-client" +version = "1.2.3\"" +description = "A client library for accessing escapes\"" +authors = [] +readme = "README.md" +packages = [ + { include = "escapes_client" }, +] +include = ["escapes_client/py.typed"] + +[tool.poetry.dependencies] +python = "^3.11" +httpx = ">=0.23.1,<0.29.0" +attrs = ">=22.2.0" + +[build-system] +requires = ["poetry-core>=2.0.0,<3.0.0"] +build-backend = "poetry.core.masonry.api" + +[tool.ruff] +line-length = 120 + +[tool.ruff.lint] +select = ["F", "I", "UP"] diff --git a/end_to_end_tests/golden-records/my-enum-api-client/.gitignore b/end_to_end_tests/golden-records/my-enum-api-client/.gitignore new file mode 100644 index 000000000..79a2c3d73 --- /dev/null +++ b/end_to_end_tests/golden-records/my-enum-api-client/.gitignore @@ -0,0 +1,23 @@ +__pycache__/ +build/ +dist/ +*.egg-info/ +.pytest_cache/ + +# pyenv +.python-version + +# Environments +.env +.venv + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# JetBrains +.idea/ + +/coverage.xml +/.coverage diff --git a/end_to_end_tests/golden-records/my-enum-api-client/README.md b/end_to_end_tests/golden-records/my-enum-api-client/README.md new file mode 100644 index 000000000..025b5d402 --- /dev/null +++ b/end_to_end_tests/golden-records/my-enum-api-client/README.md @@ -0,0 +1,124 @@ +# my-enum-api-client +A client library for accessing My Enum API + +## Usage +First, create a client: + +```python +from my_enum_api_client import Client + +client = Client(base_url="https://api.example.com") +``` + +If the endpoints you're going to hit require authentication, use `AuthenticatedClient` instead: + +```python +from my_enum_api_client import AuthenticatedClient + +client = AuthenticatedClient(base_url="https://api.example.com", token="SuperSecretToken") +``` + +Now call your endpoint and use your models: + +```python +from my_enum_api_client.models import MyDataModel +from my_enum_api_client.api.my_tag import get_my_data_model +from my_enum_api_client.types import Response + +with client as client: + my_data: MyDataModel = get_my_data_model.sync(client=client) + # or if you need more info (e.g. status_code) + response: Response[MyDataModel] = get_my_data_model.sync_detailed(client=client) +``` + +Or do the same thing with an async version: + +```python +from my_enum_api_client.models import MyDataModel +from my_enum_api_client.api.my_tag import get_my_data_model +from my_enum_api_client.types import Response + +async with client as client: + my_data: MyDataModel = await get_my_data_model.asyncio(client=client) + response: Response[MyDataModel] = await get_my_data_model.asyncio_detailed(client=client) +``` + +By default, when you're calling an HTTPS API it will attempt to verify that SSL is working correctly. Using certificate verification is highly recommended most of the time, but sometimes you may need to authenticate to a server (especially an internal server) using a custom certificate bundle. + +```python +client = AuthenticatedClient( + base_url="https://internal_api.example.com", + token="SuperSecretToken", + verify_ssl="/path/to/certificate_bundle.pem", +) +``` + +You can also disable certificate validation altogether, but beware that **this is a security risk**. + +```python +client = AuthenticatedClient( + base_url="https://internal_api.example.com", + token="SuperSecretToken", + verify_ssl=False +) +``` + +Things to know: +1. Every path/method combo becomes a Python module with four functions: + 1. `sync`: Blocking request that returns parsed data (if successful) or `None` + 1. `sync_detailed`: Blocking request that always returns a `Request`, optionally with `parsed` set if the request was successful. + 1. `asyncio`: Like `sync` but async instead of blocking + 1. `asyncio_detailed`: Like `sync_detailed` but async instead of blocking + +1. All path/query params, and bodies become method arguments. +1. If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above) +1. Any endpoint which did not have a tag will be in `my_enum_api_client.api.default` + +## Advanced customizations + +There are more settings on the generated `Client` class which let you control more runtime behavior, check out the docstring on that class for more info. You can also customize the underlying `httpx.Client` or `httpx.AsyncClient` (depending on your use-case): + +```python +from my_enum_api_client import Client + +def log_request(request): + print(f"Request event hook: {request.method} {request.url} - Waiting for response") + +def log_response(response): + request = response.request + print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}") + +client = Client( + base_url="https://api.example.com", + httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}}, +) + +# Or get the underlying httpx client to modify directly with client.get_httpx_client() or client.get_async_httpx_client() +``` + +You can even set the httpx client directly, but beware that this will override any existing settings (e.g., base_url): + +```python +import httpx +from my_enum_api_client import Client + +client = Client( + base_url="https://api.example.com", +) +# Note that base_url needs to be re-set, as would any shared cookies, headers, etc. +client.set_httpx_client(httpx.Client(base_url="https://api.example.com", proxies="http://localhost:8030")) +``` + +## Building / publishing this package +This project uses [Poetry](https://python-poetry.org/) to manage dependencies and packaging. Here are the basics: +1. Update the metadata in pyproject.toml (e.g. authors, version) +1. If you're using a private repository, configure it with Poetry + 1. `poetry config repositories. ` + 1. `poetry config http-basic. ` +1. Publish the client with `poetry publish --build -r ` or, if for public PyPI, just `poetry publish --build` + +If you want to install this client into another project without publishing it (e.g. for development) then: +1. If that project **is using Poetry**, you can simply do `poetry add ` from that project +1. If that project is not using Poetry: + 1. Build a wheel with `poetry build -f wheel` + 1. Install that wheel from the other project `pip install ` diff --git a/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/__init__.py b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/__init__.py new file mode 100644 index 000000000..5d1901164 --- /dev/null +++ b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/__init__.py @@ -0,0 +1,8 @@ +"""A client library for accessing My Enum API""" + +from .client import AuthenticatedClient, Client + +__all__ = ( + "AuthenticatedClient", + "Client", +) diff --git a/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/api/__init__.py b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/api/__init__.py new file mode 100644 index 000000000..81f9fa241 --- /dev/null +++ b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/api/__init__.py @@ -0,0 +1 @@ +"""Contains methods for accessing the API""" diff --git a/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/api/enums/__init__.py b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/api/enums/__init__.py new file mode 100644 index 000000000..2d7c0b23d --- /dev/null +++ b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/api/enums/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/enums/bool_enum_tests_bool_enum_post.py b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/api/enums/bool_enum_tests_bool_enum_post.py similarity index 80% rename from end_to_end_tests/golden-record/my_test_api_client/api/enums/bool_enum_tests_bool_enum_post.py rename to end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/api/enums/bool_enum_tests_bool_enum_post.py index 92e95162c..53b574ebd 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/enums/bool_enum_tests_bool_enum_post.py +++ b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/api/enums/bool_enum_tests_bool_enum_post.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any import httpx @@ -11,14 +11,15 @@ def _get_kwargs( *, bool_enum: bool, -) -> Dict[str, Any]: - params: Dict[str, Any] = {} +) -> dict[str, Any]: + + params: dict[str, Any] = {} params["bool_enum"] = bool_enum params = {k: v for k, v in params.items() if v is not UNSET and v is not None} - _kwargs: Dict[str, Any] = { + _kwargs: dict[str, Any] = { "method": "post", "url": "/enum/bool", "params": params, @@ -27,16 +28,17 @@ def _get_kwargs( return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: - if response.status_code == HTTPStatus.OK: +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: return None + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -47,7 +49,7 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, bool_enum: bool, ) -> Response[Any]: """Bool Enum @@ -76,7 +78,7 @@ def sync_detailed( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, bool_enum: bool, ) -> Response[Any]: """Bool Enum diff --git a/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/api/enums/int_enum_tests_int_enum_post.py b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/api/enums/int_enum_tests_int_enum_post.py new file mode 100644 index 000000000..f936104b5 --- /dev/null +++ b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/api/enums/int_enum_tests_int_enum_post.py @@ -0,0 +1,105 @@ +from http import HTTPStatus +from typing import Any + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.an_int_enum import AnIntEnum +from ...types import UNSET, Response + + +def _get_kwargs( + *, + int_enum: AnIntEnum, +) -> dict[str, Any]: + + params: dict[str, Any] = {} + + json_int_enum: int = int_enum + params["int_enum"] = json_int_enum + + params = {k: v for k, v in params.items() if v is not UNSET and v is not None} + + _kwargs: dict[str, Any] = { + "method": "post", + "url": "/enum/int", + "params": params, + } + + return _kwargs + + +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: + return None + + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient | Client, + int_enum: AnIntEnum, +) -> Response[Any]: + """Int Enum + + Args: + int_enum (AnIntEnum): An enumeration. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + kwargs = _get_kwargs( + int_enum=int_enum, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +async def asyncio_detailed( + *, + client: AuthenticatedClient | Client, + int_enum: AnIntEnum, +) -> Response[Any]: + """Int Enum + + Args: + int_enum (AnIntEnum): An enumeration. + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + kwargs = _get_kwargs( + int_enum=int_enum, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) diff --git a/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/api/tests/__init__.py b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/api/tests/__init__.py new file mode 100644 index 000000000..2d7c0b23d --- /dev/null +++ b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/api/tests/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/api/tests/get_user_list.py b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/api/tests/get_user_list.py new file mode 100644 index 000000000..15b821528 --- /dev/null +++ b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/api/tests/get_user_list.py @@ -0,0 +1,254 @@ +from http import HTTPStatus +from typing import Any + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.a_model import AModel +from ...models.an_enum import AnEnum +from ...models.an_enum_with_null import AnEnumWithNull +from ...models.get_user_list_int_enum_header import GetUserListIntEnumHeader +from ...models.get_user_list_string_enum_header import ( + GetUserListStringEnumHeader, +) +from ...types import UNSET, Response, Unset + + +def _get_kwargs( + *, + an_enum_value: list[AnEnum], + an_enum_value_with_null: list[AnEnumWithNull | None], + an_enum_value_with_only_null: list[None], + int_enum_header: GetUserListIntEnumHeader | Unset = UNSET, + string_enum_header: GetUserListStringEnumHeader | Unset = UNSET, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + if not isinstance(int_enum_header, Unset): + headers["Int-Enum-Header"] = str(int_enum_header) + + if not isinstance(string_enum_header, Unset): + headers["String-Enum-Header"] = str(string_enum_header) + + params: dict[str, Any] = {} + + json_an_enum_value = [] + for an_enum_value_item_data in an_enum_value: + an_enum_value_item: str = an_enum_value_item_data + json_an_enum_value.append(an_enum_value_item) + + params["an_enum_value"] = json_an_enum_value + + json_an_enum_value_with_null = [] + for an_enum_value_with_null_item_data in an_enum_value_with_null: + an_enum_value_with_null_item: None | str + if isinstance(an_enum_value_with_null_item_data, str): + an_enum_value_with_null_item = an_enum_value_with_null_item_data + else: + an_enum_value_with_null_item = an_enum_value_with_null_item_data + json_an_enum_value_with_null.append(an_enum_value_with_null_item) + + params["an_enum_value_with_null"] = json_an_enum_value_with_null + + json_an_enum_value_with_only_null = an_enum_value_with_only_null + + params["an_enum_value_with_only_null"] = json_an_enum_value_with_only_null + + params = {k: v for k, v in params.items() if v is not UNSET and v is not None} + + _kwargs: dict[str, Any] = { + "method": "get", + "url": "/tests/", + "params": params, + } + + _kwargs["headers"] = headers + return _kwargs + + +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> list[AModel] | None: + if response.status_code == 200: + response_200 = [] + _response_200 = response.json() + for response_200_item_data in _response_200: + response_200_item = AModel.from_dict(response_200_item_data) + + response_200.append(response_200_item) + + return response_200 + + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[list[AModel]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient | Client, + an_enum_value: list[AnEnum], + an_enum_value_with_null: list[AnEnumWithNull | None], + an_enum_value_with_only_null: list[None], + int_enum_header: GetUserListIntEnumHeader | Unset = UNSET, + string_enum_header: GetUserListStringEnumHeader | Unset = UNSET, +) -> Response[list[AModel]]: + """Get List + + Get a list of things + + Args: + an_enum_value (list[AnEnum]): + an_enum_value_with_null (list[AnEnumWithNull | None]): + an_enum_value_with_only_null (list[None]): + int_enum_header (GetUserListIntEnumHeader | Unset): + string_enum_header (GetUserListStringEnumHeader | Unset): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[list[AModel]] + """ + + kwargs = _get_kwargs( + an_enum_value=an_enum_value, + an_enum_value_with_null=an_enum_value_with_null, + an_enum_value_with_only_null=an_enum_value_with_only_null, + int_enum_header=int_enum_header, + string_enum_header=string_enum_header, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient | Client, + an_enum_value: list[AnEnum], + an_enum_value_with_null: list[AnEnumWithNull | None], + an_enum_value_with_only_null: list[None], + int_enum_header: GetUserListIntEnumHeader | Unset = UNSET, + string_enum_header: GetUserListStringEnumHeader | Unset = UNSET, +) -> list[AModel] | None: + """Get List + + Get a list of things + + Args: + an_enum_value (list[AnEnum]): + an_enum_value_with_null (list[AnEnumWithNull | None]): + an_enum_value_with_only_null (list[None]): + int_enum_header (GetUserListIntEnumHeader | Unset): + string_enum_header (GetUserListStringEnumHeader | Unset): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + list[AModel] + """ + + return sync_detailed( + client=client, + an_enum_value=an_enum_value, + an_enum_value_with_null=an_enum_value_with_null, + an_enum_value_with_only_null=an_enum_value_with_only_null, + int_enum_header=int_enum_header, + string_enum_header=string_enum_header, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient | Client, + an_enum_value: list[AnEnum], + an_enum_value_with_null: list[AnEnumWithNull | None], + an_enum_value_with_only_null: list[None], + int_enum_header: GetUserListIntEnumHeader | Unset = UNSET, + string_enum_header: GetUserListStringEnumHeader | Unset = UNSET, +) -> Response[list[AModel]]: + """Get List + + Get a list of things + + Args: + an_enum_value (list[AnEnum]): + an_enum_value_with_null (list[AnEnumWithNull | None]): + an_enum_value_with_only_null (list[None]): + int_enum_header (GetUserListIntEnumHeader | Unset): + string_enum_header (GetUserListStringEnumHeader | Unset): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[list[AModel]] + """ + + kwargs = _get_kwargs( + an_enum_value=an_enum_value, + an_enum_value_with_null=an_enum_value_with_null, + an_enum_value_with_only_null=an_enum_value_with_only_null, + int_enum_header=int_enum_header, + string_enum_header=string_enum_header, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient | Client, + an_enum_value: list[AnEnum], + an_enum_value_with_null: list[AnEnumWithNull | None], + an_enum_value_with_only_null: list[None], + int_enum_header: GetUserListIntEnumHeader | Unset = UNSET, + string_enum_header: GetUserListStringEnumHeader | Unset = UNSET, +) -> list[AModel] | None: + """Get List + + Get a list of things + + Args: + an_enum_value (list[AnEnum]): + an_enum_value_with_null (list[AnEnumWithNull | None]): + an_enum_value_with_only_null (list[None]): + int_enum_header (GetUserListIntEnumHeader | Unset): + string_enum_header (GetUserListStringEnumHeader | Unset): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + list[AModel] + """ + + return ( + await asyncio_detailed( + client=client, + an_enum_value=an_enum_value, + an_enum_value_with_null=an_enum_value_with_null, + an_enum_value_with_only_null=an_enum_value_with_only_null, + int_enum_header=int_enum_header, + string_enum_header=string_enum_header, + ) + ).parsed diff --git a/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/api/tests/post_user_list.py b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/api/tests/post_user_list.py new file mode 100644 index 000000000..911d81248 --- /dev/null +++ b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/api/tests/post_user_list.py @@ -0,0 +1,170 @@ +from http import HTTPStatus +from typing import Any + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.a_model import AModel +from ...models.post_user_list_body import PostUserListBody +from ...types import UNSET, Response, Unset + + +def _get_kwargs( + *, + body: PostUserListBody | Unset = UNSET, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + _kwargs: dict[str, Any] = { + "method": "post", + "url": "/tests/", + } + + if not isinstance(body, Unset): + _kwargs["files"] = body.to_multipart() + + headers["Content-Type"] = "multipart/form-data; boundary=+++" + + _kwargs["headers"] = headers + return _kwargs + + +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> list[AModel] | None: + if response.status_code == 200: + response_200 = [] + _response_200 = response.json() + for response_200_item_data in _response_200: + response_200_item = AModel.from_dict(response_200_item_data) + + response_200.append(response_200_item) + + return response_200 + + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[list[AModel]]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient | Client, + body: PostUserListBody | Unset = UNSET, +) -> Response[list[AModel]]: + """Post List + + Post a list of things + + Args: + body (PostUserListBody | Unset): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[list[AModel]] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient | Client, + body: PostUserListBody | Unset = UNSET, +) -> list[AModel] | None: + """Post List + + Post a list of things + + Args: + body (PostUserListBody | Unset): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + list[AModel] + """ + + return sync_detailed( + client=client, + body=body, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient | Client, + body: PostUserListBody | Unset = UNSET, +) -> Response[list[AModel]]: + """Post List + + Post a list of things + + Args: + body (PostUserListBody | Unset): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[list[AModel]] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient | Client, + body: PostUserListBody | Unset = UNSET, +) -> list[AModel] | None: + """Post List + + Post a list of things + + Args: + body (PostUserListBody | Unset): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + list[AModel] + """ + + return ( + await asyncio_detailed( + client=client, + body=body, + ) + ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/client.py b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/client.py similarity index 83% rename from end_to_end_tests/golden-record/my_test_api_client/client.py rename to end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/client.py index 63a2493b9..edb246d7e 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/client.py +++ b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/client.py @@ -1,5 +1,5 @@ import ssl -from typing import Any, Dict, Optional, Union +from typing import Any, Self import httpx from attrs import define, evolve, field @@ -36,16 +36,16 @@ class Client: raise_on_unexpected_status: bool = field(default=False, kw_only=True) _base_url: str = field(alias="base_url") - _cookies: Dict[str, str] = field(factory=dict, kw_only=True, alias="cookies") - _headers: Dict[str, str] = field(factory=dict, kw_only=True, alias="headers") - _timeout: Optional[httpx.Timeout] = field(default=None, kw_only=True, alias="timeout") - _verify_ssl: Union[str, bool, ssl.SSLContext] = field(default=True, kw_only=True, alias="verify_ssl") + _cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies") + _headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers") + _timeout: httpx.Timeout | None = field(default=None, kw_only=True, alias="timeout") + _verify_ssl: str | bool | ssl.SSLContext = field(default=True, kw_only=True, alias="verify_ssl") _follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects") - _httpx_args: Dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args") - _client: Optional[httpx.Client] = field(default=None, init=False) - _async_client: Optional[httpx.AsyncClient] = field(default=None, init=False) + _httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args") + _client: httpx.Client | None = field(default=None, init=False) + _async_client: httpx.AsyncClient | None = field(default=None, init=False) - def with_headers(self, headers: Dict[str, str]) -> "Client": + def with_headers(self, headers: dict[str, str]) -> "Client": """Get a new client matching this one with additional headers""" if self._client is not None: self._client.headers.update(headers) @@ -53,7 +53,7 @@ def with_headers(self, headers: Dict[str, str]) -> "Client": self._async_client.headers.update(headers) return evolve(self, headers={**self._headers, **headers}) - def with_cookies(self, cookies: Dict[str, str]) -> "Client": + def with_cookies(self, cookies: dict[str, str]) -> "Client": """Get a new client matching this one with additional cookies""" if self._client is not None: self._client.cookies.update(cookies) @@ -62,15 +62,15 @@ def with_cookies(self, cookies: Dict[str, str]) -> "Client": return evolve(self, cookies={**self._cookies, **cookies}) def with_timeout(self, timeout: httpx.Timeout) -> "Client": - """Get a new client matching this one with a new timeout (in seconds)""" + """Get a new client matching this one with a new timeout configuration""" if self._client is not None: self._client.timeout = timeout if self._async_client is not None: self._async_client.timeout = timeout return evolve(self, timeout=timeout) - def set_httpx_client(self, client: httpx.Client) -> "Client": - """Manually the underlying httpx.Client + def set_httpx_client(self, client: httpx.Client) -> Self: + """Manually set the underlying httpx.Client **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. """ @@ -91,7 +91,7 @@ def get_httpx_client(self) -> httpx.Client: ) return self._client - def __enter__(self) -> "Client": + def __enter__(self) -> Self: """Enter a context manager for self.client—you cannot enter twice (see httpx docs)""" self.get_httpx_client().__enter__() return self @@ -100,8 +100,8 @@ def __exit__(self, *args: Any, **kwargs: Any) -> None: """Exit a context manager for internal httpx.Client (see httpx docs)""" self.get_httpx_client().__exit__(*args, **kwargs) - def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "Client": - """Manually the underlying httpx.AsyncClient + def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> Self: + """Manually set the underlying httpx.AsyncClient **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. """ @@ -122,7 +122,7 @@ def get_async_httpx_client(self) -> httpx.AsyncClient: ) return self._async_client - async def __aenter__(self) -> "Client": + async def __aenter__(self) -> Self: """Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)""" await self.get_async_httpx_client().__aenter__() return self @@ -166,20 +166,20 @@ class AuthenticatedClient: raise_on_unexpected_status: bool = field(default=False, kw_only=True) _base_url: str = field(alias="base_url") - _cookies: Dict[str, str] = field(factory=dict, kw_only=True, alias="cookies") - _headers: Dict[str, str] = field(factory=dict, kw_only=True, alias="headers") - _timeout: Optional[httpx.Timeout] = field(default=None, kw_only=True, alias="timeout") - _verify_ssl: Union[str, bool, ssl.SSLContext] = field(default=True, kw_only=True, alias="verify_ssl") + _cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies") + _headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers") + _timeout: httpx.Timeout | None = field(default=None, kw_only=True, alias="timeout") + _verify_ssl: str | bool | ssl.SSLContext = field(default=True, kw_only=True, alias="verify_ssl") _follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects") - _httpx_args: Dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args") - _client: Optional[httpx.Client] = field(default=None, init=False) - _async_client: Optional[httpx.AsyncClient] = field(default=None, init=False) + _httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args") + _client: httpx.Client | None = field(default=None, init=False) + _async_client: httpx.AsyncClient | None = field(default=None, init=False) token: str prefix: str = "Bearer" auth_header_name: str = "Authorization" - def with_headers(self, headers: Dict[str, str]) -> "AuthenticatedClient": + def with_headers(self, headers: dict[str, str]) -> "AuthenticatedClient": """Get a new client matching this one with additional headers""" if self._client is not None: self._client.headers.update(headers) @@ -187,7 +187,7 @@ def with_headers(self, headers: Dict[str, str]) -> "AuthenticatedClient": self._async_client.headers.update(headers) return evolve(self, headers={**self._headers, **headers}) - def with_cookies(self, cookies: Dict[str, str]) -> "AuthenticatedClient": + def with_cookies(self, cookies: dict[str, str]) -> "AuthenticatedClient": """Get a new client matching this one with additional cookies""" if self._client is not None: self._client.cookies.update(cookies) @@ -196,15 +196,15 @@ def with_cookies(self, cookies: Dict[str, str]) -> "AuthenticatedClient": return evolve(self, cookies={**self._cookies, **cookies}) def with_timeout(self, timeout: httpx.Timeout) -> "AuthenticatedClient": - """Get a new client matching this one with a new timeout (in seconds)""" + """Get a new client matching this one with a new timeout configuration""" if self._client is not None: self._client.timeout = timeout if self._async_client is not None: self._async_client.timeout = timeout return evolve(self, timeout=timeout) - def set_httpx_client(self, client: httpx.Client) -> "AuthenticatedClient": - """Manually the underlying httpx.Client + def set_httpx_client(self, client: httpx.Client) -> Self: + """Manually set the underlying httpx.Client **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. """ @@ -226,7 +226,7 @@ def get_httpx_client(self) -> httpx.Client: ) return self._client - def __enter__(self) -> "AuthenticatedClient": + def __enter__(self) -> Self: """Enter a context manager for self.client—you cannot enter twice (see httpx docs)""" self.get_httpx_client().__enter__() return self @@ -235,8 +235,8 @@ def __exit__(self, *args: Any, **kwargs: Any) -> None: """Exit a context manager for internal httpx.Client (see httpx docs)""" self.get_httpx_client().__exit__(*args, **kwargs) - def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "AuthenticatedClient": - """Manually the underlying httpx.AsyncClient + def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> Self: + """Manually set the underlying httpx.AsyncClient **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. """ @@ -258,7 +258,7 @@ def get_async_httpx_client(self) -> httpx.AsyncClient: ) return self._async_client - async def __aenter__(self) -> "AuthenticatedClient": + async def __aenter__(self) -> Self: """Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)""" await self.get_async_httpx_client().__aenter__() return self diff --git a/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/errors.py b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/errors.py new file mode 100644 index 000000000..5f92e76ac --- /dev/null +++ b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/errors.py @@ -0,0 +1,16 @@ +"""Contains shared errors types that can be raised from API functions""" + + +class UnexpectedStatus(Exception): + """Raised by api functions when the response status an undocumented status and Client.raise_on_unexpected_status is True""" + + def __init__(self, status_code: int, content: bytes): + self.status_code = status_code + self.content = content + + super().__init__( + f"Unexpected status code: {status_code}\n\nResponse content:\n{content.decode(errors='ignore')}" + ) + + +__all__ = ["UnexpectedStatus"] diff --git a/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/__init__.py b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/__init__.py new file mode 100644 index 000000000..2bdeafad7 --- /dev/null +++ b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/__init__.py @@ -0,0 +1,23 @@ +"""Contains all the data models used in inputs/outputs""" + +from .a_model import AModel +from .an_all_of_enum import AnAllOfEnum +from .an_enum import AnEnum +from .an_enum_with_null import AnEnumWithNull +from .an_int_enum import AnIntEnum +from .different_enum import DifferentEnum +from .get_user_list_int_enum_header import GetUserListIntEnumHeader +from .get_user_list_string_enum_header import GetUserListStringEnumHeader +from .post_user_list_body import PostUserListBody + +__all__ = ( + "AModel", + "AnAllOfEnum", + "AnEnum", + "AnEnumWithNull", + "AnIntEnum", + "DifferentEnum", + "GetUserListIntEnumHeader", + "GetUserListStringEnumHeader", + "PostUserListBody", +) diff --git a/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/a_model.py b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/a_model.py new file mode 100644 index 000000000..890f7507f --- /dev/null +++ b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/a_model.py @@ -0,0 +1,111 @@ +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar + +from attrs import define as _attrs_define + +from ..models.an_all_of_enum import AnAllOfEnum, check_an_all_of_enum +from ..models.an_enum import AnEnum, check_an_enum +from ..models.different_enum import DifferentEnum, check_different_enum +from ..types import UNSET, Unset + +T = TypeVar("T", bound="AModel") + + +@_attrs_define +class AModel: + """A Model for testing all the ways enums can be used + + Attributes: + an_enum_value (AnEnum): For testing Enums in all the ways they can be used + an_allof_enum_with_overridden_default (AnAllOfEnum): Default: 'overridden_default'. + any_value (Any | Unset): + an_optional_allof_enum (AnAllOfEnum | Unset): + nested_list_of_enums (list[list[DifferentEnum]] | Unset): + """ + + an_enum_value: AnEnum + an_allof_enum_with_overridden_default: AnAllOfEnum = "overridden_default" + any_value: Any | Unset = UNSET + an_optional_allof_enum: AnAllOfEnum | Unset = UNSET + nested_list_of_enums: list[list[DifferentEnum]] | Unset = UNSET + + def to_dict(self) -> dict[str, Any]: + an_enum_value: str = self.an_enum_value + + an_allof_enum_with_overridden_default: str = self.an_allof_enum_with_overridden_default + + any_value = self.any_value + + an_optional_allof_enum: str | Unset = UNSET + if not isinstance(self.an_optional_allof_enum, Unset): + an_optional_allof_enum = self.an_optional_allof_enum + + nested_list_of_enums: list[list[str]] | Unset = UNSET + if not isinstance(self.nested_list_of_enums, Unset): + nested_list_of_enums = [] + for nested_list_of_enums_item_data in self.nested_list_of_enums: + nested_list_of_enums_item = [] + for nested_list_of_enums_item_item_data in nested_list_of_enums_item_data: + nested_list_of_enums_item_item: str = nested_list_of_enums_item_item_data + nested_list_of_enums_item.append(nested_list_of_enums_item_item) + + nested_list_of_enums.append(nested_list_of_enums_item) + + field_dict: dict[str, Any] = {} + + field_dict.update( + { + "an_enum_value": an_enum_value, + "an_allof_enum_with_overridden_default": an_allof_enum_with_overridden_default, + } + ) + if any_value is not UNSET: + field_dict["any_value"] = any_value + if an_optional_allof_enum is not UNSET: + field_dict["an_optional_allof_enum"] = an_optional_allof_enum + if nested_list_of_enums is not UNSET: + field_dict["nested_list_of_enums"] = nested_list_of_enums + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + an_enum_value = check_an_enum(d.pop("an_enum_value")) + + an_allof_enum_with_overridden_default = check_an_all_of_enum(d.pop("an_allof_enum_with_overridden_default")) + + any_value = d.pop("any_value", UNSET) + + _an_optional_allof_enum = d.pop("an_optional_allof_enum", UNSET) + an_optional_allof_enum: AnAllOfEnum | Unset + if isinstance(_an_optional_allof_enum, Unset): + an_optional_allof_enum = UNSET + else: + an_optional_allof_enum = check_an_all_of_enum(_an_optional_allof_enum) + + _nested_list_of_enums = d.pop("nested_list_of_enums", UNSET) + nested_list_of_enums: list[list[DifferentEnum]] | Unset = UNSET + if _nested_list_of_enums is not UNSET: + nested_list_of_enums = [] + for nested_list_of_enums_item_data in _nested_list_of_enums: + nested_list_of_enums_item = [] + _nested_list_of_enums_item = nested_list_of_enums_item_data + for nested_list_of_enums_item_item_data in _nested_list_of_enums_item: + nested_list_of_enums_item_item = check_different_enum(nested_list_of_enums_item_item_data) + + nested_list_of_enums_item.append(nested_list_of_enums_item_item) + + nested_list_of_enums.append(nested_list_of_enums_item) + + a_model = cls( + an_enum_value=an_enum_value, + an_allof_enum_with_overridden_default=an_allof_enum_with_overridden_default, + any_value=any_value, + an_optional_allof_enum=an_optional_allof_enum, + nested_list_of_enums=nested_list_of_enums, + ) + + return a_model diff --git a/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/an_all_of_enum.py b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/an_all_of_enum.py new file mode 100644 index 000000000..87efa8651 --- /dev/null +++ b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/an_all_of_enum.py @@ -0,0 +1,16 @@ +from typing import Literal + +AnAllOfEnum = Literal["a_default", "bar", "foo", "overridden_default"] + +AN_ALL_OF_ENUM_VALUES: set[AnAllOfEnum] = { + "a_default", + "bar", + "foo", + "overridden_default", +} + + +def check_an_all_of_enum(value: str) -> AnAllOfEnum: + if value in AN_ALL_OF_ENUM_VALUES: + return value + raise TypeError(f"Unexpected value {value!r}. Expected one of {AN_ALL_OF_ENUM_VALUES!r}") diff --git a/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/an_enum.py b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/an_enum.py new file mode 100644 index 000000000..1438bc95a --- /dev/null +++ b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/an_enum.py @@ -0,0 +1,14 @@ +from typing import Literal + +AnEnum = Literal["FIRST_VALUE", "SECOND_VALUE"] + +AN_ENUM_VALUES: set[AnEnum] = { + "FIRST_VALUE", + "SECOND_VALUE", +} + + +def check_an_enum(value: str) -> AnEnum: + if value in AN_ENUM_VALUES: + return value + raise TypeError(f"Unexpected value {value!r}. Expected one of {AN_ENUM_VALUES!r}") diff --git a/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/an_enum_with_null.py b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/an_enum_with_null.py new file mode 100644 index 000000000..0592fa01a --- /dev/null +++ b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/an_enum_with_null.py @@ -0,0 +1,14 @@ +from typing import Literal + +AnEnumWithNull = Literal["FIRST_VALUE", "SECOND_VALUE"] + +AN_ENUM_WITH_NULL_VALUES: set[AnEnumWithNull] = { + "FIRST_VALUE", + "SECOND_VALUE", +} + + +def check_an_enum_with_null(value: str) -> AnEnumWithNull: + if value in AN_ENUM_WITH_NULL_VALUES: + return value + raise TypeError(f"Unexpected value {value!r}. Expected one of {AN_ENUM_WITH_NULL_VALUES!r}") diff --git a/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/an_int_enum.py b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/an_int_enum.py new file mode 100644 index 000000000..1ea0e852d --- /dev/null +++ b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/an_int_enum.py @@ -0,0 +1,15 @@ +from typing import Literal + +AnIntEnum = Literal[-1, 1, 2] + +AN_INT_ENUM_VALUES: set[AnIntEnum] = { + -1, + 1, + 2, +} + + +def check_an_int_enum(value: int) -> AnIntEnum: + if value in AN_INT_ENUM_VALUES: + return value + raise TypeError(f"Unexpected value {value!r}. Expected one of {AN_INT_ENUM_VALUES!r}") diff --git a/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/different_enum.py b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/different_enum.py new file mode 100644 index 000000000..086b9f490 --- /dev/null +++ b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/different_enum.py @@ -0,0 +1,14 @@ +from typing import Literal + +DifferentEnum = Literal["DIFFERENT", "OTHER"] + +DIFFERENT_ENUM_VALUES: set[DifferentEnum] = { + "DIFFERENT", + "OTHER", +} + + +def check_different_enum(value: str) -> DifferentEnum: + if value in DIFFERENT_ENUM_VALUES: + return value + raise TypeError(f"Unexpected value {value!r}. Expected one of {DIFFERENT_ENUM_VALUES!r}") diff --git a/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/get_user_list_int_enum_header.py b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/get_user_list_int_enum_header.py new file mode 100644 index 000000000..9dd4e6d02 --- /dev/null +++ b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/get_user_list_int_enum_header.py @@ -0,0 +1,15 @@ +from typing import Literal + +GetUserListIntEnumHeader = Literal[1, 2, 3] + +GET_USER_LIST_INT_ENUM_HEADER_VALUES: set[GetUserListIntEnumHeader] = { + 1, + 2, + 3, +} + + +def check_get_user_list_int_enum_header(value: int) -> GetUserListIntEnumHeader: + if value in GET_USER_LIST_INT_ENUM_HEADER_VALUES: + return value + raise TypeError(f"Unexpected value {value!r}. Expected one of {GET_USER_LIST_INT_ENUM_HEADER_VALUES!r}") diff --git a/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/get_user_list_string_enum_header.py b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/get_user_list_string_enum_header.py new file mode 100644 index 000000000..bfe72725c --- /dev/null +++ b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/get_user_list_string_enum_header.py @@ -0,0 +1,15 @@ +from typing import Literal + +GetUserListStringEnumHeader = Literal["one", "three", "two"] + +GET_USER_LIST_STRING_ENUM_HEADER_VALUES: set[GetUserListStringEnumHeader] = { + "one", + "three", + "two", +} + + +def check_get_user_list_string_enum_header(value: str) -> GetUserListStringEnumHeader: + if value in GET_USER_LIST_STRING_ENUM_HEADER_VALUES: + return value + raise TypeError(f"Unexpected value {value!r}. Expected one of {GET_USER_LIST_STRING_ENUM_HEADER_VALUES!r}") diff --git a/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/post_user_list_body.py b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/post_user_list_body.py new file mode 100644 index 000000000..7e8e93950 --- /dev/null +++ b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/models/post_user_list_body.py @@ -0,0 +1,249 @@ +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar, cast + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from .. import types +from ..models.an_all_of_enum import AnAllOfEnum, check_an_all_of_enum +from ..models.an_enum import AnEnum, check_an_enum +from ..models.an_enum_with_null import AnEnumWithNull, check_an_enum_with_null +from ..models.different_enum import DifferentEnum, check_different_enum +from ..types import UNSET, Unset + +T = TypeVar("T", bound="PostUserListBody") + + +@_attrs_define +class PostUserListBody: + """ + Attributes: + an_enum_value (list[AnEnum] | Unset): + an_enum_value_with_null (list[AnEnumWithNull | None] | Unset): + an_enum_value_with_only_null (list[None] | Unset): + an_allof_enum_with_overridden_default (AnAllOfEnum | Unset): Default: 'overridden_default'. + an_optional_allof_enum (AnAllOfEnum | Unset): + nested_list_of_enums (list[list[DifferentEnum]] | Unset): + """ + + an_enum_value: list[AnEnum] | Unset = UNSET + an_enum_value_with_null: list[AnEnumWithNull | None] | Unset = UNSET + an_enum_value_with_only_null: list[None] | Unset = UNSET + an_allof_enum_with_overridden_default: AnAllOfEnum | Unset = "overridden_default" + an_optional_allof_enum: AnAllOfEnum | Unset = UNSET + nested_list_of_enums: list[list[DifferentEnum]] | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + an_enum_value: list[str] | Unset = UNSET + if not isinstance(self.an_enum_value, Unset): + an_enum_value = [] + for an_enum_value_item_data in self.an_enum_value: + an_enum_value_item: str = an_enum_value_item_data + an_enum_value.append(an_enum_value_item) + + an_enum_value_with_null: list[None | str] | Unset = UNSET + if not isinstance(self.an_enum_value_with_null, Unset): + an_enum_value_with_null = [] + for an_enum_value_with_null_item_data in self.an_enum_value_with_null: + an_enum_value_with_null_item: None | str + if isinstance(an_enum_value_with_null_item_data, str): + an_enum_value_with_null_item = an_enum_value_with_null_item_data + else: + an_enum_value_with_null_item = an_enum_value_with_null_item_data + an_enum_value_with_null.append(an_enum_value_with_null_item) + + an_enum_value_with_only_null: list[None] | Unset = UNSET + if not isinstance(self.an_enum_value_with_only_null, Unset): + an_enum_value_with_only_null = self.an_enum_value_with_only_null + + an_allof_enum_with_overridden_default: str | Unset = UNSET + if not isinstance(self.an_allof_enum_with_overridden_default, Unset): + an_allof_enum_with_overridden_default = self.an_allof_enum_with_overridden_default + + an_optional_allof_enum: str | Unset = UNSET + if not isinstance(self.an_optional_allof_enum, Unset): + an_optional_allof_enum = self.an_optional_allof_enum + + nested_list_of_enums: list[list[str]] | Unset = UNSET + if not isinstance(self.nested_list_of_enums, Unset): + nested_list_of_enums = [] + for nested_list_of_enums_item_data in self.nested_list_of_enums: + nested_list_of_enums_item = [] + for nested_list_of_enums_item_item_data in nested_list_of_enums_item_data: + nested_list_of_enums_item_item: str = nested_list_of_enums_item_item_data + nested_list_of_enums_item.append(nested_list_of_enums_item_item) + + nested_list_of_enums.append(nested_list_of_enums_item) + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update({}) + if an_enum_value is not UNSET: + field_dict["an_enum_value"] = an_enum_value + if an_enum_value_with_null is not UNSET: + field_dict["an_enum_value_with_null"] = an_enum_value_with_null + if an_enum_value_with_only_null is not UNSET: + field_dict["an_enum_value_with_only_null"] = an_enum_value_with_only_null + if an_allof_enum_with_overridden_default is not UNSET: + field_dict["an_allof_enum_with_overridden_default"] = an_allof_enum_with_overridden_default + if an_optional_allof_enum is not UNSET: + field_dict["an_optional_allof_enum"] = an_optional_allof_enum + if nested_list_of_enums is not UNSET: + field_dict["nested_list_of_enums"] = nested_list_of_enums + + return field_dict + + def to_multipart(self) -> types.RequestFiles: + files: types.RequestFiles = [] + + if not isinstance(self.an_enum_value, Unset): + for an_enum_value_item_element in self.an_enum_value: + files.append(("an_enum_value", (None, str(an_enum_value_item_element).encode(), "text/plain"))) + + if not isinstance(self.an_enum_value_with_null, Unset): + for an_enum_value_with_null_item_element in self.an_enum_value_with_null: + if an_enum_value_with_null_item_element is None: + files.append( + ( + "an_enum_value_with_null", + (None, str(an_enum_value_with_null_item_element).encode(), "text/plain"), + ) + ) + else: + files.append( + ( + "an_enum_value_with_null", + (None, str(an_enum_value_with_null_item_element).encode(), "text/plain"), + ) + ) + + if not isinstance(self.an_enum_value_with_only_null, Unset): + for an_enum_value_with_only_null_item_element in self.an_enum_value_with_only_null: + files.append( + ( + "an_enum_value_with_only_null", + (None, str(an_enum_value_with_only_null_item_element).encode(), "text/plain"), + ) + ) + + if not isinstance(self.an_allof_enum_with_overridden_default, Unset): + files.append( + ( + "an_allof_enum_with_overridden_default", + (None, str(self.an_allof_enum_with_overridden_default).encode(), "text/plain"), + ) + ) + + if not isinstance(self.an_optional_allof_enum, Unset): + files.append(("an_optional_allof_enum", (None, str(self.an_optional_allof_enum).encode(), "text/plain"))) + + if not isinstance(self.nested_list_of_enums, Unset): + for nested_list_of_enums_item_element in self.nested_list_of_enums: + for nested_list_of_enums_item_item_element in nested_list_of_enums_item_element: + files.append( + ( + "nested_list_of_enums", + (None, str(nested_list_of_enums_item_item_element).encode(), "text/plain"), + ) + ) + + for prop_name, prop in self.additional_properties.items(): + files.append((prop_name, (None, str(prop).encode(), "text/plain"))) + + return files + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + _an_enum_value = d.pop("an_enum_value", UNSET) + an_enum_value: list[AnEnum] | Unset = UNSET + if _an_enum_value is not UNSET: + an_enum_value = [] + for an_enum_value_item_data in _an_enum_value: + an_enum_value_item = check_an_enum(an_enum_value_item_data) + + an_enum_value.append(an_enum_value_item) + + _an_enum_value_with_null = d.pop("an_enum_value_with_null", UNSET) + an_enum_value_with_null: list[AnEnumWithNull | None] | Unset = UNSET + if _an_enum_value_with_null is not UNSET: + an_enum_value_with_null = [] + for an_enum_value_with_null_item_data in _an_enum_value_with_null: + + def _parse_an_enum_value_with_null_item(data: object) -> AnEnumWithNull | None: + if data is None: + return data + try: + if not isinstance(data, str): + raise TypeError() + componentsschemas_an_enum_with_null_type_1 = check_an_enum_with_null(data) + + return componentsschemas_an_enum_with_null_type_1 + except (TypeError, ValueError, AttributeError, KeyError): + pass + return cast(AnEnumWithNull | None, data) + + an_enum_value_with_null_item = _parse_an_enum_value_with_null_item(an_enum_value_with_null_item_data) + + an_enum_value_with_null.append(an_enum_value_with_null_item) + + an_enum_value_with_only_null = cast(list[None], d.pop("an_enum_value_with_only_null", UNSET)) + + _an_allof_enum_with_overridden_default = d.pop("an_allof_enum_with_overridden_default", UNSET) + an_allof_enum_with_overridden_default: AnAllOfEnum | Unset + if isinstance(_an_allof_enum_with_overridden_default, Unset): + an_allof_enum_with_overridden_default = UNSET + else: + an_allof_enum_with_overridden_default = check_an_all_of_enum(_an_allof_enum_with_overridden_default) + + _an_optional_allof_enum = d.pop("an_optional_allof_enum", UNSET) + an_optional_allof_enum: AnAllOfEnum | Unset + if isinstance(_an_optional_allof_enum, Unset): + an_optional_allof_enum = UNSET + else: + an_optional_allof_enum = check_an_all_of_enum(_an_optional_allof_enum) + + _nested_list_of_enums = d.pop("nested_list_of_enums", UNSET) + nested_list_of_enums: list[list[DifferentEnum]] | Unset = UNSET + if _nested_list_of_enums is not UNSET: + nested_list_of_enums = [] + for nested_list_of_enums_item_data in _nested_list_of_enums: + nested_list_of_enums_item = [] + _nested_list_of_enums_item = nested_list_of_enums_item_data + for nested_list_of_enums_item_item_data in _nested_list_of_enums_item: + nested_list_of_enums_item_item = check_different_enum(nested_list_of_enums_item_item_data) + + nested_list_of_enums_item.append(nested_list_of_enums_item_item) + + nested_list_of_enums.append(nested_list_of_enums_item) + + post_user_list_body = cls( + an_enum_value=an_enum_value, + an_enum_value_with_null=an_enum_value_with_null, + an_enum_value_with_only_null=an_enum_value_with_only_null, + an_allof_enum_with_overridden_default=an_allof_enum_with_overridden_default, + an_optional_allof_enum=an_optional_allof_enum, + nested_list_of_enums=nested_list_of_enums, + ) + + post_user_list_body.additional_properties = d + return post_user_list_body + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/py.typed b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/py.typed new file mode 100644 index 000000000..1aad32711 --- /dev/null +++ b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/py.typed @@ -0,0 +1 @@ +# Marker file for PEP 561 \ No newline at end of file diff --git a/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/types.py b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/types.py new file mode 100644 index 000000000..b64af0952 --- /dev/null +++ b/end_to_end_tests/golden-records/my-enum-api-client/my_enum_api_client/types.py @@ -0,0 +1,54 @@ +"""Contains some shared types for properties""" + +from collections.abc import Mapping, MutableMapping +from http import HTTPStatus +from typing import IO, BinaryIO, Generic, Literal, TypeVar + +from attrs import define + + +class Unset: + def __bool__(self) -> Literal[False]: + return False + + +UNSET: Unset = Unset() + +# The types that `httpx.Client(files=)` can accept, copied from that library. +FileContent = IO[bytes] | bytes | str +FileTypes = ( + # (filename, file (or bytes), content_type) + tuple[str | None, FileContent, str | None] + # (filename, file (or bytes), content_type, headers) + | tuple[str | None, FileContent, str | None, Mapping[str, str]] +) +RequestFiles = list[tuple[str, FileTypes]] + + +@define +class File: + """Contains information for file uploads""" + + payload: BinaryIO + file_name: str | None = None + mime_type: str | None = None + + def to_tuple(self) -> FileTypes: + """Return a tuple representation that httpx will accept for multipart/form-data""" + return self.file_name, self.payload, self.mime_type + + +T = TypeVar("T") + + +@define +class Response(Generic[T]): + """A response from an endpoint""" + + status_code: HTTPStatus + content: bytes + headers: MutableMapping[str, str] + parsed: T | None + + +__all__ = ["UNSET", "File", "FileTypes", "RequestFiles", "Response", "Unset"] diff --git a/end_to_end_tests/golden-records/my-enum-api-client/pyproject.toml b/end_to_end_tests/golden-records/my-enum-api-client/pyproject.toml new file mode 100644 index 000000000..a7b5ed278 --- /dev/null +++ b/end_to_end_tests/golden-records/my-enum-api-client/pyproject.toml @@ -0,0 +1,25 @@ +[tool.poetry] +name = "my-enum-api-client" +version = "0.1.0" +description = "A client library for accessing My Enum API" +authors = [] +readme = "README.md" +packages = [ + { include = "my_enum_api_client" }, +] +include = ["my_enum_api_client/py.typed"] + +[tool.poetry.dependencies] +python = "^3.11" +httpx = ">=0.23.1,<0.29.0" +attrs = ">=22.2.0" + +[build-system] +requires = ["poetry-core>=2.0.0,<3.0.0"] +build-backend = "poetry.core.masonry.api" + +[tool.ruff] +line-length = 120 + +[tool.ruff.lint] +select = ["F", "I", "UP"] diff --git a/end_to_end_tests/golden-records/my-test-api-client/.gitignore b/end_to_end_tests/golden-records/my-test-api-client/.gitignore new file mode 100644 index 000000000..79a2c3d73 --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/.gitignore @@ -0,0 +1,23 @@ +__pycache__/ +build/ +dist/ +*.egg-info/ +.pytest_cache/ + +# pyenv +.python-version + +# Environments +.env +.venv + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# JetBrains +.idea/ + +/coverage.xml +/.coverage diff --git a/end_to_end_tests/golden-records/my-test-api-client/README.md b/end_to_end_tests/golden-records/my-test-api-client/README.md new file mode 100644 index 000000000..32f776550 --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/README.md @@ -0,0 +1,124 @@ +# my-test-api-client +A client library for accessing My Test API + +## Usage +First, create a client: + +```python +from my_test_api_client import Client + +client = Client(base_url="https://api.example.com") +``` + +If the endpoints you're going to hit require authentication, use `AuthenticatedClient` instead: + +```python +from my_test_api_client import AuthenticatedClient + +client = AuthenticatedClient(base_url="https://api.example.com", token="SuperSecretToken") +``` + +Now call your endpoint and use your models: + +```python +from my_test_api_client.models import MyDataModel +from my_test_api_client.api.my_tag import get_my_data_model +from my_test_api_client.types import Response + +with client as client: + my_data: MyDataModel = get_my_data_model.sync(client=client) + # or if you need more info (e.g. status_code) + response: Response[MyDataModel] = get_my_data_model.sync_detailed(client=client) +``` + +Or do the same thing with an async version: + +```python +from my_test_api_client.models import MyDataModel +from my_test_api_client.api.my_tag import get_my_data_model +from my_test_api_client.types import Response + +async with client as client: + my_data: MyDataModel = await get_my_data_model.asyncio(client=client) + response: Response[MyDataModel] = await get_my_data_model.asyncio_detailed(client=client) +``` + +By default, when you're calling an HTTPS API it will attempt to verify that SSL is working correctly. Using certificate verification is highly recommended most of the time, but sometimes you may need to authenticate to a server (especially an internal server) using a custom certificate bundle. + +```python +client = AuthenticatedClient( + base_url="https://internal_api.example.com", + token="SuperSecretToken", + verify_ssl="/path/to/certificate_bundle.pem", +) +``` + +You can also disable certificate validation altogether, but beware that **this is a security risk**. + +```python +client = AuthenticatedClient( + base_url="https://internal_api.example.com", + token="SuperSecretToken", + verify_ssl=False +) +``` + +Things to know: +1. Every path/method combo becomes a Python module with four functions: + 1. `sync`: Blocking request that returns parsed data (if successful) or `None` + 1. `sync_detailed`: Blocking request that always returns a `Request`, optionally with `parsed` set if the request was successful. + 1. `asyncio`: Like `sync` but async instead of blocking + 1. `asyncio_detailed`: Like `sync_detailed` but async instead of blocking + +1. All path/query params, and bodies become method arguments. +1. If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above) +1. Any endpoint which did not have a tag will be in `my_test_api_client.api.default` + +## Advanced customizations + +There are more settings on the generated `Client` class which let you control more runtime behavior, check out the docstring on that class for more info. You can also customize the underlying `httpx.Client` or `httpx.AsyncClient` (depending on your use-case): + +```python +from my_test_api_client import Client + +def log_request(request): + print(f"Request event hook: {request.method} {request.url} - Waiting for response") + +def log_response(response): + request = response.request + print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}") + +client = Client( + base_url="https://api.example.com", + httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}}, +) + +# Or get the underlying httpx client to modify directly with client.get_httpx_client() or client.get_async_httpx_client() +``` + +You can even set the httpx client directly, but beware that this will override any existing settings (e.g., base_url): + +```python +import httpx +from my_test_api_client import Client + +client = Client( + base_url="https://api.example.com", +) +# Note that base_url needs to be re-set, as would any shared cookies, headers, etc. +client.set_httpx_client(httpx.Client(base_url="https://api.example.com", proxies="http://localhost:8030")) +``` + +## Building / publishing this package +This project uses [Poetry](https://python-poetry.org/) to manage dependencies and packaging. Here are the basics: +1. Update the metadata in pyproject.toml (e.g. authors, version) +1. If you're using a private repository, configure it with Poetry + 1. `poetry config repositories. ` + 1. `poetry config http-basic. ` +1. Publish the client with `poetry publish --build -r ` or, if for public PyPI, just `poetry publish --build` + +If you want to install this client into another project without publishing it (e.g. for development) then: +1. If that project **is using Poetry**, you can simply do `poetry add ` from that project +1. If that project is not using Poetry: + 1. Build a wheel with `poetry build -f wheel` + 1. Install that wheel from the other project `pip install ` diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/__init__.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/__init__.py new file mode 100644 index 000000000..3747245da --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/__init__.py @@ -0,0 +1,8 @@ +"""A client library for accessing My Test API""" + +from .client import AuthenticatedClient, Client + +__all__ = ( + "AuthenticatedClient", + "Client", +) diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/__init__.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/__init__.py new file mode 100644 index 000000000..81f9fa241 --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/__init__.py @@ -0,0 +1 @@ +"""Contains methods for accessing the API""" diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/bodies/__init__.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/bodies/__init__.py new file mode 100644 index 000000000..2d7c0b23d --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/bodies/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/bodies/json_like.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/bodies/json_like.py similarity index 72% rename from end_to_end_tests/golden-record/my_test_api_client/api/bodies/json_like.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/bodies/json_like.py index 8eb5c516a..1a4fc2fd9 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/bodies/json_like.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/bodies/json_like.py @@ -1,44 +1,45 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any import httpx from ... import errors from ...client import AuthenticatedClient, Client from ...models.json_like_body import JsonLikeBody -from ...types import Response +from ...types import UNSET, Response, Unset def _get_kwargs( *, - body: JsonLikeBody, -) -> Dict[str, Any]: - headers: Dict[str, Any] = {} + body: JsonLikeBody | Unset = UNSET, +) -> dict[str, Any]: + headers: dict[str, Any] = {} - _kwargs: Dict[str, Any] = { + _kwargs: dict[str, Any] = { "method": "post", "url": "/bodies/json-like", } - _body = body.to_dict() + if not isinstance(body, Unset): + _kwargs["json"] = body.to_dict() - _kwargs["json"] = _body headers["Content-Type"] = "application/vnd+json" _kwargs["headers"] = headers return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: - if response.status_code == HTTPStatus.OK: +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: return None + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -49,13 +50,13 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( *, - client: Union[AuthenticatedClient, Client], - body: JsonLikeBody, + client: AuthenticatedClient | Client, + body: JsonLikeBody | Unset = UNSET, ) -> Response[Any]: """A content type that works like json but isn't application/json Args: - body (JsonLikeBody): + body (JsonLikeBody | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. @@ -78,13 +79,13 @@ def sync_detailed( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], - body: JsonLikeBody, + client: AuthenticatedClient | Client, + body: JsonLikeBody | Unset = UNSET, ) -> Response[Any]: """A content type that works like json but isn't application/json Args: - body (JsonLikeBody): + body (JsonLikeBody | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/bodies/optional_body.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/bodies/optional_body.py new file mode 100644 index 000000000..8402cf086 --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/bodies/optional_body.py @@ -0,0 +1,104 @@ +from http import HTTPStatus +from typing import Any + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.optional_body_body import OptionalBodyBody +from ...types import UNSET, Response, Unset + + +def _get_kwargs( + *, + body: OptionalBodyBody | Unset = UNSET, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + _kwargs: dict[str, Any] = { + "method": "post", + "url": "/bodies/optional", + } + + if not isinstance(body, Unset): + _kwargs["json"] = body.to_dict() + + headers["Content-Type"] = "application/json" + + _kwargs["headers"] = headers + return _kwargs + + +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: + return None + + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient | Client, + body: OptionalBodyBody | Unset = UNSET, +) -> Response[Any]: + """Test optional request body + + Args: + body (OptionalBodyBody | Unset): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +async def asyncio_detailed( + *, + client: AuthenticatedClient | Client, + body: OptionalBodyBody | Unset = UNSET, +) -> Response[Any]: + """Test optional request body + + Args: + body (OptionalBodyBody | Unset): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/bodies/post_bodies_multiple.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/bodies/post_bodies_multiple.py similarity index 59% rename from end_to_end_tests/golden-record/my_test_api_client/api/bodies/post_bodies_multiple.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/bodies/post_bodies_multiple.py index f71b1ef25..9361e3f56 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/bodies/post_bodies_multiple.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/bodies/post_bodies_multiple.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any import httpx @@ -8,60 +8,54 @@ from ...models.post_bodies_multiple_data_body import PostBodiesMultipleDataBody from ...models.post_bodies_multiple_files_body import PostBodiesMultipleFilesBody from ...models.post_bodies_multiple_json_body import PostBodiesMultipleJsonBody -from ...types import File, Response +from ...types import UNSET, File, Response, Unset def _get_kwargs( *, - body: Union[ - PostBodiesMultipleJsonBody, - File, - PostBodiesMultipleDataBody, - PostBodiesMultipleFilesBody, - ], -) -> Dict[str, Any]: - headers: Dict[str, Any] = {} - - _kwargs: Dict[str, Any] = { + body: PostBodiesMultipleJsonBody | File | PostBodiesMultipleDataBody | PostBodiesMultipleFilesBody | Unset = UNSET, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + _kwargs: dict[str, Any] = { "method": "post", "url": "/bodies/multiple", } if isinstance(body, PostBodiesMultipleJsonBody): - _json_body = body.to_dict() + if not isinstance(body, Unset): + _kwargs["json"] = body.to_dict() - _kwargs["json"] = _json_body headers["Content-Type"] = "application/json" if isinstance(body, File): - _content_body = body.payload - - _kwargs["content"] = _content_body + if not isinstance(body, Unset): + _kwargs["content"] = body.payload headers["Content-Type"] = "application/octet-stream" if isinstance(body, PostBodiesMultipleDataBody): - _data_body = body.to_dict() - - _kwargs["data"] = _data_body + if not isinstance(body, Unset): + _kwargs["data"] = body.to_dict() headers["Content-Type"] = "application/x-www-form-urlencoded" if isinstance(body, PostBodiesMultipleFilesBody): - _files_body = body.to_multipart() + if not isinstance(body, Unset): + _kwargs["files"] = body.to_multipart() - _kwargs["files"] = _files_body - headers["Content-Type"] = "multipart/form-data" + headers["Content-Type"] = "multipart/form-data; boundary=+++" _kwargs["headers"] = headers return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: - if response.status_code == HTTPStatus.OK: +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: return None + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -72,21 +66,16 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( *, - client: Union[AuthenticatedClient, Client], - body: Union[ - PostBodiesMultipleJsonBody, - File, - PostBodiesMultipleDataBody, - PostBodiesMultipleFilesBody, - ], + client: AuthenticatedClient | Client, + body: PostBodiesMultipleJsonBody | File | PostBodiesMultipleDataBody | PostBodiesMultipleFilesBody | Unset = UNSET, ) -> Response[Any]: """Test multiple bodies Args: - body (PostBodiesMultipleJsonBody): - body (File): - body (PostBodiesMultipleDataBody): - body (PostBodiesMultipleFilesBody): + body (PostBodiesMultipleJsonBody | Unset): + body (File | Unset): + body (PostBodiesMultipleDataBody | Unset): + body (PostBodiesMultipleFilesBody | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. @@ -109,21 +98,16 @@ def sync_detailed( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], - body: Union[ - PostBodiesMultipleJsonBody, - File, - PostBodiesMultipleDataBody, - PostBodiesMultipleFilesBody, - ], + client: AuthenticatedClient | Client, + body: PostBodiesMultipleJsonBody | File | PostBodiesMultipleDataBody | PostBodiesMultipleFilesBody | Unset = UNSET, ) -> Response[Any]: """Test multiple bodies Args: - body (PostBodiesMultipleJsonBody): - body (File): - body (PostBodiesMultipleDataBody): - body (PostBodiesMultipleFilesBody): + body (PostBodiesMultipleJsonBody | Unset): + body (File | Unset): + body (PostBodiesMultipleDataBody | Unset): + body (PostBodiesMultipleFilesBody | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/bodies/refs.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/bodies/refs.py new file mode 100644 index 000000000..2e224bc8c --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/bodies/refs.py @@ -0,0 +1,104 @@ +from http import HTTPStatus +from typing import Any + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.a_model import AModel +from ...types import UNSET, Response, Unset + + +def _get_kwargs( + *, + body: AModel | Unset = UNSET, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + _kwargs: dict[str, Any] = { + "method": "post", + "url": "/bodies/refs", + } + + if not isinstance(body, Unset): + _kwargs["json"] = body.to_dict() + + headers["Content-Type"] = "application/json" + + _kwargs["headers"] = headers + return _kwargs + + +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: + return None + + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient | Client, + body: AModel | Unset = UNSET, +) -> Response[Any]: + """Test request body defined via ref + + Args: + body (AModel | Unset): A Model for testing all the ways custom objects can be used + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +async def asyncio_detailed( + *, + client: AuthenticatedClient | Client, + body: AModel | Unset = UNSET, +) -> Response[Any]: + """Test request body defined via ref + + Args: + body (AModel | Unset): A Model for testing all the ways custom objects can be used + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/config/__init__.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/config/__init__.py new file mode 100644 index 000000000..2d7c0b23d --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/config/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/config/content_type_override.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/config/content_type_override.py similarity index 74% rename from end_to_end_tests/golden-record/my_test_api_client/api/config/content_type_override.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/config/content_type_override.py index 4e9381a74..be06459be 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/config/content_type_override.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/config/content_type_override.py @@ -1,44 +1,45 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union, cast +from typing import Any, cast import httpx from ... import errors from ...client import AuthenticatedClient, Client -from ...types import Response +from ...types import UNSET, Response, Unset def _get_kwargs( *, - body: str, -) -> Dict[str, Any]: - headers: Dict[str, Any] = {} + body: str | Unset = UNSET, +) -> dict[str, Any]: + headers: dict[str, Any] = {} - _kwargs: Dict[str, Any] = { + _kwargs: dict[str, Any] = { "method": "post", "url": "/config/content-type-override", } - _body = body + if not isinstance(body, Unset): + _kwargs["json"] = body - _kwargs["json"] = _body headers["Content-Type"] = "openapi/python/client" _kwargs["headers"] = headers return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[str]: - if response.status_code == HTTPStatus.OK: +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> str | None: + if response.status_code == 200: response_200 = cast(str, response.json()) return response_200 + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[str]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[str]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -49,13 +50,13 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( *, - client: Union[AuthenticatedClient, Client], - body: str, + client: AuthenticatedClient | Client, + body: str | Unset = UNSET, ) -> Response[str]: """Content Type Override Args: - body (str): + body (str | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. @@ -78,13 +79,13 @@ def sync_detailed( def sync( *, - client: Union[AuthenticatedClient, Client], - body: str, -) -> Optional[str]: + client: AuthenticatedClient | Client, + body: str | Unset = UNSET, +) -> str | None: """Content Type Override Args: - body (str): + body (str | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. @@ -102,13 +103,13 @@ def sync( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], - body: str, + client: AuthenticatedClient | Client, + body: str | Unset = UNSET, ) -> Response[str]: """Content Type Override Args: - body (str): + body (str | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. @@ -129,13 +130,13 @@ async def asyncio_detailed( async def asyncio( *, - client: Union[AuthenticatedClient, Client], - body: str, -) -> Optional[str]: + client: AuthenticatedClient | Client, + body: str | Unset = UNSET, +) -> str | None: """Content Type Override Args: - body (str): + body (str | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/default/__init__.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/default/__init__.py new file mode 100644 index 000000000..2d7c0b23d --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/default/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/default/get_common_parameters.py similarity index 73% rename from end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/default/get_common_parameters.py index f782162b1..c82055686 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/default/get_common_parameters.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any import httpx @@ -10,15 +10,16 @@ def _get_kwargs( *, - common: Union[Unset, str] = UNSET, -) -> Dict[str, Any]: - params: Dict[str, Any] = {} + common: str | Unset = UNSET, +) -> dict[str, Any]: + + params: dict[str, Any] = {} params["common"] = common params = {k: v for k, v in params.items() if v is not UNSET and v is not None} - _kwargs: Dict[str, Any] = { + _kwargs: dict[str, Any] = { "method": "get", "url": "/common_parameters", "params": params, @@ -27,16 +28,17 @@ def _get_kwargs( return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: - if response.status_code == HTTPStatus.OK: +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: return None + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -47,12 +49,12 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( *, - client: Union[AuthenticatedClient, Client], - common: Union[Unset, str] = UNSET, + client: AuthenticatedClient | Client, + common: str | Unset = UNSET, ) -> Response[Any]: """ Args: - common (Union[Unset, str]): + common (str | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. @@ -75,12 +77,12 @@ def sync_detailed( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], - common: Union[Unset, str] = UNSET, + client: AuthenticatedClient | Client, + common: str | Unset = UNSET, ) -> Response[Any]: """ Args: - common (Union[Unset, str]): + common (str | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/default/get_models_allof.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/default/get_models_allof.py new file mode 100644 index 000000000..3558ef1be --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/default/get_models_allof.py @@ -0,0 +1,124 @@ +from http import HTTPStatus +from typing import Any + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.get_models_allof_response_200 import GetModelsAllofResponse200 +from ...types import Response + + +def _get_kwargs() -> dict[str, Any]: + + _kwargs: dict[str, Any] = { + "method": "get", + "url": "/models/allof", + } + + return _kwargs + + +def _parse_response( + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> GetModelsAllofResponse200 | None: + if response.status_code == 200: + response_200 = GetModelsAllofResponse200.from_dict(response.json()) + + return response_200 + + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> Response[GetModelsAllofResponse200]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient | Client, +) -> Response[GetModelsAllofResponse200]: + """ + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[GetModelsAllofResponse200] + """ + + kwargs = _get_kwargs() + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient | Client, +) -> GetModelsAllofResponse200 | None: + """ + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + GetModelsAllofResponse200 + """ + + return sync_detailed( + client=client, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient | Client, +) -> Response[GetModelsAllofResponse200]: + """ + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[GetModelsAllofResponse200] + """ + + kwargs = _get_kwargs() + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient | Client, +) -> GetModelsAllofResponse200 | None: + """ + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + GetModelsAllofResponse200 + """ + + return ( + await asyncio_detailed( + client=client, + ) + ).parsed diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/default/get_models_oneof_with_required_const.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/default/get_models_oneof_with_required_const.py new file mode 100644 index 000000000..73911b7cd --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/default/get_models_oneof_with_required_const.py @@ -0,0 +1,147 @@ +from http import HTTPStatus +from typing import Any + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.get_models_oneof_with_required_const_response_200_type_0 import ( + GetModelsOneofWithRequiredConstResponse200Type0, +) +from ...models.get_models_oneof_with_required_const_response_200_type_1 import ( + GetModelsOneofWithRequiredConstResponse200Type1, +) +from ...types import Response + + +def _get_kwargs() -> dict[str, Any]: + + _kwargs: dict[str, Any] = { + "method": "get", + "url": "/models/oneof-with-required-const", + } + + return _kwargs + + +def _parse_response( + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> GetModelsOneofWithRequiredConstResponse200Type0 | GetModelsOneofWithRequiredConstResponse200Type1 | None: + if response.status_code == 200: + + def _parse_response_200( + data: object, + ) -> GetModelsOneofWithRequiredConstResponse200Type0 | GetModelsOneofWithRequiredConstResponse200Type1: + try: + if not isinstance(data, dict): + raise TypeError() + response_200_type_0 = GetModelsOneofWithRequiredConstResponse200Type0.from_dict(data) + + return response_200_type_0 + except (TypeError, ValueError, AttributeError, KeyError): + pass + if not isinstance(data, dict): + raise TypeError() + response_200_type_1 = GetModelsOneofWithRequiredConstResponse200Type1.from_dict(data) + + return response_200_type_1 + + response_200 = _parse_response_200(response.json()) + + return response_200 + + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> Response[GetModelsOneofWithRequiredConstResponse200Type0 | GetModelsOneofWithRequiredConstResponse200Type1]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient | Client, +) -> Response[GetModelsOneofWithRequiredConstResponse200Type0 | GetModelsOneofWithRequiredConstResponse200Type1]: + """ + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[GetModelsOneofWithRequiredConstResponse200Type0 | GetModelsOneofWithRequiredConstResponse200Type1] + """ + + kwargs = _get_kwargs() + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient | Client, +) -> GetModelsOneofWithRequiredConstResponse200Type0 | GetModelsOneofWithRequiredConstResponse200Type1 | None: + """ + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + GetModelsOneofWithRequiredConstResponse200Type0 | GetModelsOneofWithRequiredConstResponse200Type1 + """ + + return sync_detailed( + client=client, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient | Client, +) -> Response[GetModelsOneofWithRequiredConstResponse200Type0 | GetModelsOneofWithRequiredConstResponse200Type1]: + """ + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[GetModelsOneofWithRequiredConstResponse200Type0 | GetModelsOneofWithRequiredConstResponse200Type1] + """ + + kwargs = _get_kwargs() + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient | Client, +) -> GetModelsOneofWithRequiredConstResponse200Type0 | GetModelsOneofWithRequiredConstResponse200Type1 | None: + """ + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + GetModelsOneofWithRequiredConstResponse200Type0 | GetModelsOneofWithRequiredConstResponse200Type1 + """ + + return ( + await asyncio_detailed( + client=client, + ) + ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/default/post_common_parameters.py similarity index 73% rename from end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/default/post_common_parameters.py index 6cfc13bd4..27509b93a 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/default/post_common_parameters.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any import httpx @@ -10,15 +10,16 @@ def _get_kwargs( *, - common: Union[Unset, str] = UNSET, -) -> Dict[str, Any]: - params: Dict[str, Any] = {} + common: str | Unset = UNSET, +) -> dict[str, Any]: + + params: dict[str, Any] = {} params["common"] = common params = {k: v for k, v in params.items() if v is not UNSET and v is not None} - _kwargs: Dict[str, Any] = { + _kwargs: dict[str, Any] = { "method": "post", "url": "/common_parameters", "params": params, @@ -27,16 +28,17 @@ def _get_kwargs( return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: - if response.status_code == HTTPStatus.OK: +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: return None + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -47,12 +49,12 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( *, - client: Union[AuthenticatedClient, Client], - common: Union[Unset, str] = UNSET, + client: AuthenticatedClient | Client, + common: str | Unset = UNSET, ) -> Response[Any]: """ Args: - common (Union[Unset, str]): + common (str | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. @@ -75,12 +77,12 @@ def sync_detailed( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], - common: Union[Unset, str] = UNSET, + client: AuthenticatedClient | Client, + common: str | Unset = UNSET, ) -> Response[Any]: """ Args: - common (Union[Unset, str]): + common (str | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/default/post_types_unions_duplicate_types.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/default/post_types_unions_duplicate_types.py new file mode 100644 index 000000000..f6eabc4a7 --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/default/post_types_unions_duplicate_types.py @@ -0,0 +1,160 @@ +from http import HTTPStatus +from typing import Any + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.a_model import AModel +from ...types import UNSET, Response, Unset + + +def _get_kwargs( + *, + body: AModel | Unset = UNSET, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + _kwargs: dict[str, Any] = { + "method": "post", + "url": "/types/unions/duplicate-types", + } + + if isinstance(body, AModel): + _kwargs["json"] = body.to_dict() + + headers["Content-Type"] = "application/json" + + _kwargs["headers"] = headers + return _kwargs + + +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> AModel | None: + if response.status_code == 200: + + def _parse_response_200(data: object) -> AModel: + if not isinstance(data, dict): + raise TypeError() + response_200_type_0 = AModel.from_dict(data) + + return response_200_type_0 + + response_200 = _parse_response_200(response.json()) + + return response_200 + + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[AModel]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient | Client, + body: AModel | Unset = UNSET, +) -> Response[AModel]: + """ + Args: + body (AModel | Unset): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[AModel] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient | Client, + body: AModel | Unset = UNSET, +) -> AModel | None: + """ + Args: + body (AModel | Unset): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + AModel + """ + + return sync_detailed( + client=client, + body=body, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient | Client, + body: AModel | Unset = UNSET, +) -> Response[AModel]: + """ + Args: + body (AModel | Unset): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[AModel] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient | Client, + body: AModel | Unset = UNSET, +) -> AModel | None: + """ + Args: + body (AModel | Unset): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + AModel + """ + + return ( + await asyncio_detailed( + client=client, + body=body, + ) + ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/default/reserved_parameters.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/default/reserved_parameters.py similarity index 81% rename from end_to_end_tests/golden-record/my_test_api_client/api/default/reserved_parameters.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/default/reserved_parameters.py index 9033321c7..687473903 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/default/reserved_parameters.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/default/reserved_parameters.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any import httpx @@ -12,8 +12,9 @@ def _get_kwargs( *, client_query: str, url_query: str, -) -> Dict[str, Any]: - params: Dict[str, Any] = {} +) -> dict[str, Any]: + + params: dict[str, Any] = {} params["client"] = client_query @@ -21,7 +22,7 @@ def _get_kwargs( params = {k: v for k, v in params.items() if v is not UNSET and v is not None} - _kwargs: Dict[str, Any] = { + _kwargs: dict[str, Any] = { "method": "get", "url": "/naming/reserved-parameters", "params": params, @@ -30,16 +31,17 @@ def _get_kwargs( return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: - if response.status_code == HTTPStatus.OK: +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: return None + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -50,7 +52,7 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, client_query: str, url_query: str, ) -> Response[Any]: @@ -81,7 +83,7 @@ def sync_detailed( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, client_query: str, url_query: str, ) -> Response[Any]: diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/defaults/__init__.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/defaults/__init__.py new file mode 100644 index 000000000..2d7c0b23d --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/defaults/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/defaults/defaults_tests_defaults_post.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/defaults/defaults_tests_defaults_post.py similarity index 67% rename from end_to_end_tests/golden-record/my_test_api_client/api/defaults/defaults_tests_defaults_post.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/defaults/defaults_tests_defaults_post.py index a14cb2670..9990c8b5e 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/defaults/defaults_tests_defaults_post.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/defaults/defaults_tests_defaults_post.py @@ -1,9 +1,8 @@ import datetime from http import HTTPStatus -from typing import Any, Dict, List, Optional, Union +from typing import Any import httpx -from dateutil.parser import isoparse from ... import errors from ...client import AuthenticatedClient, Client @@ -17,18 +16,20 @@ def _get_kwargs( *, string_prop: str = "the default string", string_with_num: str = "1", - date_prop: datetime.date = isoparse("1010-10-10").date(), + date_prop: datetime.date = datetime.date.fromisoformat("1010-10-10"), float_prop: float = 3.14, + float_with_int: float = 3.0, int_prop: int = 7, boolean_prop: bool = False, - list_prop: List[AnEnum], - union_prop: Union[float, str] = "not a float", - union_prop_with_ref: Union[AnEnum, Unset, float] = 0.6, + list_prop: list[AnEnum], + union_prop: float | str = "not a float", + union_prop_with_ref: AnEnum | float | Unset = 0.6, enum_prop: AnEnum, - model_prop: "ModelWithUnionProperty", - required_model_prop: "ModelWithUnionProperty", -) -> Dict[str, Any]: - params: Dict[str, Any] = {} + model_prop: ModelWithUnionProperty, + required_model_prop: ModelWithUnionProperty, +) -> dict[str, Any]: + + params: dict[str, Any] = {} params["string_prop"] = string_prop @@ -39,6 +40,8 @@ def _get_kwargs( params["float_prop"] = float_prop + params["float_with_int"] = float_with_int + params["int_prop"] = int_prop params["boolean_prop"] = boolean_prop @@ -50,11 +53,11 @@ def _get_kwargs( params["list_prop"] = json_list_prop - json_union_prop: Union[float, str] + json_union_prop: float | str json_union_prop = union_prop params["union_prop"] = json_union_prop - json_union_prop_with_ref: Union[Unset, float, str] + json_union_prop_with_ref: float | str | Unset if isinstance(union_prop_with_ref, Unset): json_union_prop_with_ref = UNSET elif isinstance(union_prop_with_ref, AnEnum): @@ -74,7 +77,7 @@ def _get_kwargs( params = {k: v for k, v in params.items() if v is not UNSET and v is not None} - _kwargs: Dict[str, Any] = { + _kwargs: dict[str, Any] = { "method": "post", "url": "/defaults", "params": params, @@ -84,15 +87,17 @@ def _get_kwargs( def _parse_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Optional[Union[Any, HTTPValidationError]]: - if response.status_code == HTTPStatus.OK: + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> Any | HTTPValidationError | None: + if response.status_code == 200: response_200 = response.json() return response_200 - if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: + + if response.status_code == 422: response_422 = HTTPValidationError.from_dict(response.json()) return response_422 + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: @@ -100,8 +105,8 @@ def _parse_response( def _build_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Response[Union[Any, HTTPValidationError]]: + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> Response[Any | HTTPValidationError]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -112,32 +117,34 @@ def _build_response( def sync_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, string_prop: str = "the default string", string_with_num: str = "1", - date_prop: datetime.date = isoparse("1010-10-10").date(), + date_prop: datetime.date = datetime.date.fromisoformat("1010-10-10"), float_prop: float = 3.14, + float_with_int: float = 3.0, int_prop: int = 7, boolean_prop: bool = False, - list_prop: List[AnEnum], - union_prop: Union[float, str] = "not a float", - union_prop_with_ref: Union[AnEnum, Unset, float] = 0.6, + list_prop: list[AnEnum], + union_prop: float | str = "not a float", + union_prop_with_ref: AnEnum | float | Unset = 0.6, enum_prop: AnEnum, - model_prop: "ModelWithUnionProperty", - required_model_prop: "ModelWithUnionProperty", -) -> Response[Union[Any, HTTPValidationError]]: + model_prop: ModelWithUnionProperty, + required_model_prop: ModelWithUnionProperty, +) -> Response[Any | HTTPValidationError]: """Defaults Args: string_prop (str): Default: 'the default string'. string_with_num (str): Default: '1'. - date_prop (datetime.date): Default: isoparse('1010-10-10').date(). + date_prop (datetime.date): Default: datetime.date.fromisoformat('1010-10-10'). float_prop (float): Default: 3.14. + float_with_int (float): Default: 3.0. int_prop (int): Default: 7. boolean_prop (bool): Default: False. - list_prop (List[AnEnum]): - union_prop (Union[float, str]): Default: 'not a float'. - union_prop_with_ref (Union[AnEnum, Unset, float]): Default: 0.6. + list_prop (list[AnEnum]): + union_prop (float | str): Default: 'not a float'. + union_prop_with_ref (AnEnum | float | Unset): Default: 0.6. enum_prop (AnEnum): For testing Enums in all the ways they can be used model_prop (ModelWithUnionProperty): required_model_prop (ModelWithUnionProperty): @@ -147,7 +154,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any | HTTPValidationError] """ kwargs = _get_kwargs( @@ -155,6 +162,7 @@ def sync_detailed( string_with_num=string_with_num, date_prop=date_prop, float_prop=float_prop, + float_with_int=float_with_int, int_prop=int_prop, boolean_prop=boolean_prop, list_prop=list_prop, @@ -174,32 +182,34 @@ def sync_detailed( def sync( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, string_prop: str = "the default string", string_with_num: str = "1", - date_prop: datetime.date = isoparse("1010-10-10").date(), + date_prop: datetime.date = datetime.date.fromisoformat("1010-10-10"), float_prop: float = 3.14, + float_with_int: float = 3.0, int_prop: int = 7, boolean_prop: bool = False, - list_prop: List[AnEnum], - union_prop: Union[float, str] = "not a float", - union_prop_with_ref: Union[AnEnum, Unset, float] = 0.6, + list_prop: list[AnEnum], + union_prop: float | str = "not a float", + union_prop_with_ref: AnEnum | float | Unset = 0.6, enum_prop: AnEnum, - model_prop: "ModelWithUnionProperty", - required_model_prop: "ModelWithUnionProperty", -) -> Optional[Union[Any, HTTPValidationError]]: + model_prop: ModelWithUnionProperty, + required_model_prop: ModelWithUnionProperty, +) -> Any | HTTPValidationError | None: """Defaults Args: string_prop (str): Default: 'the default string'. string_with_num (str): Default: '1'. - date_prop (datetime.date): Default: isoparse('1010-10-10').date(). + date_prop (datetime.date): Default: datetime.date.fromisoformat('1010-10-10'). float_prop (float): Default: 3.14. + float_with_int (float): Default: 3.0. int_prop (int): Default: 7. boolean_prop (bool): Default: False. - list_prop (List[AnEnum]): - union_prop (Union[float, str]): Default: 'not a float'. - union_prop_with_ref (Union[AnEnum, Unset, float]): Default: 0.6. + list_prop (list[AnEnum]): + union_prop (float | str): Default: 'not a float'. + union_prop_with_ref (AnEnum | float | Unset): Default: 0.6. enum_prop (AnEnum): For testing Enums in all the ways they can be used model_prop (ModelWithUnionProperty): required_model_prop (ModelWithUnionProperty): @@ -209,7 +219,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError] + Any | HTTPValidationError """ return sync_detailed( @@ -218,6 +228,7 @@ def sync( string_with_num=string_with_num, date_prop=date_prop, float_prop=float_prop, + float_with_int=float_with_int, int_prop=int_prop, boolean_prop=boolean_prop, list_prop=list_prop, @@ -231,32 +242,34 @@ def sync( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, string_prop: str = "the default string", string_with_num: str = "1", - date_prop: datetime.date = isoparse("1010-10-10").date(), + date_prop: datetime.date = datetime.date.fromisoformat("1010-10-10"), float_prop: float = 3.14, + float_with_int: float = 3.0, int_prop: int = 7, boolean_prop: bool = False, - list_prop: List[AnEnum], - union_prop: Union[float, str] = "not a float", - union_prop_with_ref: Union[AnEnum, Unset, float] = 0.6, + list_prop: list[AnEnum], + union_prop: float | str = "not a float", + union_prop_with_ref: AnEnum | float | Unset = 0.6, enum_prop: AnEnum, - model_prop: "ModelWithUnionProperty", - required_model_prop: "ModelWithUnionProperty", -) -> Response[Union[Any, HTTPValidationError]]: + model_prop: ModelWithUnionProperty, + required_model_prop: ModelWithUnionProperty, +) -> Response[Any | HTTPValidationError]: """Defaults Args: string_prop (str): Default: 'the default string'. string_with_num (str): Default: '1'. - date_prop (datetime.date): Default: isoparse('1010-10-10').date(). + date_prop (datetime.date): Default: datetime.date.fromisoformat('1010-10-10'). float_prop (float): Default: 3.14. + float_with_int (float): Default: 3.0. int_prop (int): Default: 7. boolean_prop (bool): Default: False. - list_prop (List[AnEnum]): - union_prop (Union[float, str]): Default: 'not a float'. - union_prop_with_ref (Union[AnEnum, Unset, float]): Default: 0.6. + list_prop (list[AnEnum]): + union_prop (float | str): Default: 'not a float'. + union_prop_with_ref (AnEnum | float | Unset): Default: 0.6. enum_prop (AnEnum): For testing Enums in all the ways they can be used model_prop (ModelWithUnionProperty): required_model_prop (ModelWithUnionProperty): @@ -266,7 +279,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any | HTTPValidationError] """ kwargs = _get_kwargs( @@ -274,6 +287,7 @@ async def asyncio_detailed( string_with_num=string_with_num, date_prop=date_prop, float_prop=float_prop, + float_with_int=float_with_int, int_prop=int_prop, boolean_prop=boolean_prop, list_prop=list_prop, @@ -291,32 +305,34 @@ async def asyncio_detailed( async def asyncio( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, string_prop: str = "the default string", string_with_num: str = "1", - date_prop: datetime.date = isoparse("1010-10-10").date(), + date_prop: datetime.date = datetime.date.fromisoformat("1010-10-10"), float_prop: float = 3.14, + float_with_int: float = 3.0, int_prop: int = 7, boolean_prop: bool = False, - list_prop: List[AnEnum], - union_prop: Union[float, str] = "not a float", - union_prop_with_ref: Union[AnEnum, Unset, float] = 0.6, + list_prop: list[AnEnum], + union_prop: float | str = "not a float", + union_prop_with_ref: AnEnum | float | Unset = 0.6, enum_prop: AnEnum, - model_prop: "ModelWithUnionProperty", - required_model_prop: "ModelWithUnionProperty", -) -> Optional[Union[Any, HTTPValidationError]]: + model_prop: ModelWithUnionProperty, + required_model_prop: ModelWithUnionProperty, +) -> Any | HTTPValidationError | None: """Defaults Args: string_prop (str): Default: 'the default string'. string_with_num (str): Default: '1'. - date_prop (datetime.date): Default: isoparse('1010-10-10').date(). + date_prop (datetime.date): Default: datetime.date.fromisoformat('1010-10-10'). float_prop (float): Default: 3.14. + float_with_int (float): Default: 3.0. int_prop (int): Default: 7. boolean_prop (bool): Default: False. - list_prop (List[AnEnum]): - union_prop (Union[float, str]): Default: 'not a float'. - union_prop_with_ref (Union[AnEnum, Unset, float]): Default: 0.6. + list_prop (list[AnEnum]): + union_prop (float | str): Default: 'not a float'. + union_prop_with_ref (AnEnum | float | Unset): Default: 0.6. enum_prop (AnEnum): For testing Enums in all the ways they can be used model_prop (ModelWithUnionProperty): required_model_prop (ModelWithUnionProperty): @@ -326,7 +342,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError] + Any | HTTPValidationError """ return ( @@ -336,6 +352,7 @@ async def asyncio( string_with_num=string_with_num, date_prop=date_prop, float_prop=float_prop, + float_with_int=float_with_int, int_prop=int_prop, boolean_prop=boolean_prop, list_prop=list_prop, diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/enums/__init__.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/enums/__init__.py new file mode 100644 index 000000000..2d7c0b23d --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/enums/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/enums/bool_enum_tests_bool_enum_post.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/enums/bool_enum_tests_bool_enum_post.py new file mode 100644 index 000000000..53b574ebd --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/enums/bool_enum_tests_bool_enum_post.py @@ -0,0 +1,103 @@ +from http import HTTPStatus +from typing import Any + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...types import UNSET, Response + + +def _get_kwargs( + *, + bool_enum: bool, +) -> dict[str, Any]: + + params: dict[str, Any] = {} + + params["bool_enum"] = bool_enum + + params = {k: v for k, v in params.items() if v is not UNSET and v is not None} + + _kwargs: dict[str, Any] = { + "method": "post", + "url": "/enum/bool", + "params": params, + } + + return _kwargs + + +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: + return None + + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient | Client, + bool_enum: bool, +) -> Response[Any]: + """Bool Enum + + Args: + bool_enum (bool): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + kwargs = _get_kwargs( + bool_enum=bool_enum, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +async def asyncio_detailed( + *, + client: AuthenticatedClient | Client, + bool_enum: bool, +) -> Response[Any]: + """Bool Enum + + Args: + bool_enum (bool): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + kwargs = _get_kwargs( + bool_enum=bool_enum, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/enums/int_enum_tests_int_enum_post.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/enums/int_enum_tests_int_enum_post.py similarity index 81% rename from end_to_end_tests/golden-record/my_test_api_client/api/enums/int_enum_tests_int_enum_post.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/enums/int_enum_tests_int_enum_post.py index b39df8307..264c5af9e 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/enums/int_enum_tests_int_enum_post.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/enums/int_enum_tests_int_enum_post.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any import httpx @@ -12,15 +12,16 @@ def _get_kwargs( *, int_enum: AnIntEnum, -) -> Dict[str, Any]: - params: Dict[str, Any] = {} +) -> dict[str, Any]: + + params: dict[str, Any] = {} json_int_enum = int_enum.value params["int_enum"] = json_int_enum params = {k: v for k, v in params.items() if v is not UNSET and v is not None} - _kwargs: Dict[str, Any] = { + _kwargs: dict[str, Any] = { "method": "post", "url": "/enum/int", "params": params, @@ -29,16 +30,17 @@ def _get_kwargs( return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: - if response.status_code == HTTPStatus.OK: +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: return None + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -49,7 +51,7 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, int_enum: AnIntEnum, ) -> Response[Any]: """Int Enum @@ -78,7 +80,7 @@ def sync_detailed( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, int_enum: AnIntEnum, ) -> Response[Any]: """Int Enum diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/location/__init__.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/location/__init__.py new file mode 100644 index 000000000..2d7c0b23d --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/location/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/location/get_location_header_types.py similarity index 57% rename from end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/location/get_location_header_types.py index 904d26c72..20c2db527 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/location/get_location_header_types.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any import httpx @@ -12,14 +12,14 @@ def _get_kwargs( *, - boolean_header: Union[Unset, bool] = UNSET, - string_header: Union[Unset, str] = UNSET, - number_header: Union[Unset, float] = UNSET, - integer_header: Union[Unset, int] = UNSET, - int_enum_header: Union[Unset, GetLocationHeaderTypesIntEnumHeader] = UNSET, - string_enum_header: Union[Unset, GetLocationHeaderTypesStringEnumHeader] = UNSET, -) -> Dict[str, Any]: - headers: Dict[str, Any] = {} + boolean_header: bool | Unset = UNSET, + string_header: str | Unset = UNSET, + number_header: float | Unset = UNSET, + integer_header: int | Unset = UNSET, + int_enum_header: GetLocationHeaderTypesIntEnumHeader | Unset = UNSET, + string_enum_header: GetLocationHeaderTypesStringEnumHeader | Unset = UNSET, +) -> dict[str, Any]: + headers: dict[str, Any] = {} if not isinstance(boolean_header, Unset): headers["Boolean-Header"] = "true" if boolean_header else "false" @@ -38,7 +38,7 @@ def _get_kwargs( if not isinstance(string_enum_header, Unset): headers["String-Enum-Header"] = str(string_enum_header) - _kwargs: Dict[str, Any] = { + _kwargs: dict[str, Any] = { "method": "get", "url": "/location/header/types", } @@ -47,16 +47,17 @@ def _get_kwargs( return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: - if response.status_code == HTTPStatus.OK: +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: return None + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -67,22 +68,22 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( *, - client: Union[AuthenticatedClient, Client], - boolean_header: Union[Unset, bool] = UNSET, - string_header: Union[Unset, str] = UNSET, - number_header: Union[Unset, float] = UNSET, - integer_header: Union[Unset, int] = UNSET, - int_enum_header: Union[Unset, GetLocationHeaderTypesIntEnumHeader] = UNSET, - string_enum_header: Union[Unset, GetLocationHeaderTypesStringEnumHeader] = UNSET, + client: AuthenticatedClient | Client, + boolean_header: bool | Unset = UNSET, + string_header: str | Unset = UNSET, + number_header: float | Unset = UNSET, + integer_header: int | Unset = UNSET, + int_enum_header: GetLocationHeaderTypesIntEnumHeader | Unset = UNSET, + string_enum_header: GetLocationHeaderTypesStringEnumHeader | Unset = UNSET, ) -> Response[Any]: """ Args: - boolean_header (Union[Unset, bool]): - string_header (Union[Unset, str]): - number_header (Union[Unset, float]): - integer_header (Union[Unset, int]): - int_enum_header (Union[Unset, GetLocationHeaderTypesIntEnumHeader]): - string_enum_header (Union[Unset, GetLocationHeaderTypesStringEnumHeader]): + boolean_header (bool | Unset): + string_header (str | Unset): + number_header (float | Unset): + integer_header (int | Unset): + int_enum_header (GetLocationHeaderTypesIntEnumHeader | Unset): + string_enum_header (GetLocationHeaderTypesStringEnumHeader | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. @@ -110,22 +111,22 @@ def sync_detailed( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], - boolean_header: Union[Unset, bool] = UNSET, - string_header: Union[Unset, str] = UNSET, - number_header: Union[Unset, float] = UNSET, - integer_header: Union[Unset, int] = UNSET, - int_enum_header: Union[Unset, GetLocationHeaderTypesIntEnumHeader] = UNSET, - string_enum_header: Union[Unset, GetLocationHeaderTypesStringEnumHeader] = UNSET, + client: AuthenticatedClient | Client, + boolean_header: bool | Unset = UNSET, + string_header: str | Unset = UNSET, + number_header: float | Unset = UNSET, + integer_header: int | Unset = UNSET, + int_enum_header: GetLocationHeaderTypesIntEnumHeader | Unset = UNSET, + string_enum_header: GetLocationHeaderTypesStringEnumHeader | Unset = UNSET, ) -> Response[Any]: """ Args: - boolean_header (Union[Unset, bool]): - string_header (Union[Unset, str]): - number_header (Union[Unset, float]): - integer_header (Union[Unset, int]): - int_enum_header (Union[Unset, GetLocationHeaderTypesIntEnumHeader]): - string_enum_header (Union[Unset, GetLocationHeaderTypesStringEnumHeader]): + boolean_header (bool | Unset): + string_header (str | Unset): + number_header (float | Unset): + integer_header (int | Unset): + int_enum_header (GetLocationHeaderTypesIntEnumHeader | Unset): + string_enum_header (GetLocationHeaderTypesStringEnumHeader | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/location/get_location_query_optionality.py similarity index 67% rename from end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/location/get_location_query_optionality.py index ea43b6731..756e4a266 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/location/get_location_query_optionality.py @@ -1,6 +1,6 @@ import datetime from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any import httpx @@ -12,23 +12,24 @@ def _get_kwargs( *, not_null_required: datetime.datetime, - null_required: Union[None, datetime.datetime], - null_not_required: Union[None, Unset, datetime.datetime] = UNSET, - not_null_not_required: Union[Unset, datetime.datetime] = UNSET, -) -> Dict[str, Any]: - params: Dict[str, Any] = {} + null_required: datetime.datetime | None, + null_not_required: datetime.datetime | None | Unset = UNSET, + not_null_not_required: datetime.datetime | Unset = UNSET, +) -> dict[str, Any]: + + params: dict[str, Any] = {} json_not_null_required = not_null_required.isoformat() params["not_null_required"] = json_not_null_required - json_null_required: Union[None, str] + json_null_required: None | str if isinstance(null_required, datetime.datetime): json_null_required = null_required.isoformat() else: json_null_required = null_required params["null_required"] = json_null_required - json_null_not_required: Union[None, Unset, str] + json_null_not_required: None | str | Unset if isinstance(null_not_required, Unset): json_null_not_required = UNSET elif isinstance(null_not_required, datetime.datetime): @@ -37,14 +38,14 @@ def _get_kwargs( json_null_not_required = null_not_required params["null_not_required"] = json_null_not_required - json_not_null_not_required: Union[Unset, str] = UNSET + json_not_null_not_required: str | Unset = UNSET if not isinstance(not_null_not_required, Unset): json_not_null_not_required = not_null_not_required.isoformat() params["not_null_not_required"] = json_not_null_not_required params = {k: v for k, v in params.items() if v is not UNSET and v is not None} - _kwargs: Dict[str, Any] = { + _kwargs: dict[str, Any] = { "method": "get", "url": "/location/query/optionality", "params": params, @@ -53,16 +54,17 @@ def _get_kwargs( return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: - if response.status_code == HTTPStatus.OK: +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: return None + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -73,18 +75,18 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, not_null_required: datetime.datetime, - null_required: Union[None, datetime.datetime], - null_not_required: Union[None, Unset, datetime.datetime] = UNSET, - not_null_not_required: Union[Unset, datetime.datetime] = UNSET, + null_required: datetime.datetime | None, + null_not_required: datetime.datetime | None | Unset = UNSET, + not_null_not_required: datetime.datetime | Unset = UNSET, ) -> Response[Any]: """ Args: not_null_required (datetime.datetime): - null_required (Union[None, datetime.datetime]): - null_not_required (Union[None, Unset, datetime.datetime]): - not_null_not_required (Union[Unset, datetime.datetime]): + null_required (datetime.datetime | None): + null_not_required (datetime.datetime | None | Unset): + not_null_not_required (datetime.datetime | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. @@ -110,18 +112,18 @@ def sync_detailed( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, not_null_required: datetime.datetime, - null_required: Union[None, datetime.datetime], - null_not_required: Union[None, Unset, datetime.datetime] = UNSET, - not_null_not_required: Union[Unset, datetime.datetime] = UNSET, + null_required: datetime.datetime | None, + null_not_required: datetime.datetime | None | Unset = UNSET, + not_null_not_required: datetime.datetime | Unset = UNSET, ) -> Response[Any]: """ Args: not_null_required (datetime.datetime): - null_required (Union[None, datetime.datetime]): - null_not_required (Union[None, Unset, datetime.datetime]): - not_null_not_required (Union[Unset, datetime.datetime]): + null_required (datetime.datetime | None): + null_not_required (datetime.datetime | None | Unset): + not_null_not_required (datetime.datetime | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/naming/__init__.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/naming/__init__.py new file mode 100644 index 000000000..2d7c0b23d --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/naming/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/naming/hyphen_in_path.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/naming/hyphen_in_path.py similarity index 76% rename from end_to_end_tests/golden-record/my_test_api_client/api/naming/hyphen_in_path.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/naming/hyphen_in_path.py index 8bab45991..d30d3c1ae 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/naming/hyphen_in_path.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/naming/hyphen_in_path.py @@ -1,5 +1,6 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any +from urllib.parse import quote import httpx @@ -10,25 +11,29 @@ def _get_kwargs( hyphen_in_path: str, -) -> Dict[str, Any]: - _kwargs: Dict[str, Any] = { +) -> dict[str, Any]: + + _kwargs: dict[str, Any] = { "method": "get", - "url": f"/naming/{hyphen_in_path}", + "url": "/naming/{hyphen_in_path}".format( + hyphen_in_path=quote(str(hyphen_in_path), safe=""), + ), } return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: - if response.status_code == HTTPStatus.OK: +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: return None + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -40,7 +45,7 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( hyphen_in_path: str, *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, ) -> Response[Any]: """ Args: @@ -68,7 +73,7 @@ def sync_detailed( async def asyncio_detailed( hyphen_in_path: str, *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, ) -> Response[Any]: """ Args: diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/naming/mixed_case.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/naming/mixed_case.py similarity index 84% rename from end_to_end_tests/golden-record/my_test_api_client/api/naming/mixed_case.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/naming/mixed_case.py index 4f6321261..5945ad0de 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/naming/mixed_case.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/naming/mixed_case.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any import httpx @@ -13,8 +13,9 @@ def _get_kwargs( *, mixed_case: str, mixedCase: str, -) -> Dict[str, Any]: - params: Dict[str, Any] = {} +) -> dict[str, Any]: + + params: dict[str, Any] = {} params["mixed_case"] = mixed_case @@ -22,7 +23,7 @@ def _get_kwargs( params = {k: v for k, v in params.items() if v is not UNSET and v is not None} - _kwargs: Dict[str, Any] = { + _kwargs: dict[str, Any] = { "method": "get", "url": "/naming/mixed-case", "params": params, @@ -31,13 +32,12 @@ def _get_kwargs( return _kwargs -def _parse_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Optional[MixedCaseResponse200]: - if response.status_code == HTTPStatus.OK: +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> MixedCaseResponse200 | None: + if response.status_code == 200: response_200 = MixedCaseResponse200.from_dict(response.json()) return response_200 + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: @@ -45,7 +45,7 @@ def _parse_response( def _build_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response + *, client: AuthenticatedClient | Client, response: httpx.Response ) -> Response[MixedCaseResponse200]: return Response( status_code=HTTPStatus(response.status_code), @@ -57,7 +57,7 @@ def _build_response( def sync_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, mixed_case: str, mixedCase: str, ) -> Response[MixedCaseResponse200]: @@ -88,10 +88,10 @@ def sync_detailed( def sync( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, mixed_case: str, mixedCase: str, -) -> Optional[MixedCaseResponse200]: +) -> MixedCaseResponse200 | None: """ Args: mixed_case (str): @@ -114,7 +114,7 @@ def sync( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, mixed_case: str, mixedCase: str, ) -> Response[MixedCaseResponse200]: @@ -143,10 +143,10 @@ async def asyncio_detailed( async def asyncio( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, mixed_case: str, mixedCase: str, -) -> Optional[MixedCaseResponse200]: +) -> MixedCaseResponse200 | None: """ Args: mixed_case (str): diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/naming/post_naming_property_conflict_with_import.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/naming/post_naming_property_conflict_with_import.py similarity index 70% rename from end_to_end_tests/golden-record/my_test_api_client/api/naming/post_naming_property_conflict_with_import.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/naming/post_naming_property_conflict_with_import.py index 693eab608..9e848f7af 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/naming/post_naming_property_conflict_with_import.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/naming/post_naming_property_conflict_with_import.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any import httpx @@ -9,23 +9,23 @@ from ...models.post_naming_property_conflict_with_import_response_200 import ( PostNamingPropertyConflictWithImportResponse200, ) -from ...types import Response +from ...types import UNSET, Response, Unset def _get_kwargs( *, - body: PostNamingPropertyConflictWithImportBody, -) -> Dict[str, Any]: - headers: Dict[str, Any] = {} + body: PostNamingPropertyConflictWithImportBody | Unset = UNSET, +) -> dict[str, Any]: + headers: dict[str, Any] = {} - _kwargs: Dict[str, Any] = { + _kwargs: dict[str, Any] = { "method": "post", "url": "/naming/property-conflict-with-import", } - _body = body.to_dict() + if not isinstance(body, Unset): + _kwargs["json"] = body.to_dict() - _kwargs["json"] = _body headers["Content-Type"] = "application/json" _kwargs["headers"] = headers @@ -33,12 +33,13 @@ def _get_kwargs( def _parse_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Optional[PostNamingPropertyConflictWithImportResponse200]: - if response.status_code == HTTPStatus.OK: + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> PostNamingPropertyConflictWithImportResponse200 | None: + if response.status_code == 200: response_200 = PostNamingPropertyConflictWithImportResponse200.from_dict(response.json()) return response_200 + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: @@ -46,7 +47,7 @@ def _parse_response( def _build_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response + *, client: AuthenticatedClient | Client, response: httpx.Response ) -> Response[PostNamingPropertyConflictWithImportResponse200]: return Response( status_code=HTTPStatus(response.status_code), @@ -58,12 +59,12 @@ def _build_response( def sync_detailed( *, - client: Union[AuthenticatedClient, Client], - body: PostNamingPropertyConflictWithImportBody, + client: AuthenticatedClient | Client, + body: PostNamingPropertyConflictWithImportBody | Unset = UNSET, ) -> Response[PostNamingPropertyConflictWithImportResponse200]: """ Args: - body (PostNamingPropertyConflictWithImportBody): + body (PostNamingPropertyConflictWithImportBody | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. @@ -86,12 +87,12 @@ def sync_detailed( def sync( *, - client: Union[AuthenticatedClient, Client], - body: PostNamingPropertyConflictWithImportBody, -) -> Optional[PostNamingPropertyConflictWithImportResponse200]: + client: AuthenticatedClient | Client, + body: PostNamingPropertyConflictWithImportBody | Unset = UNSET, +) -> PostNamingPropertyConflictWithImportResponse200 | None: """ Args: - body (PostNamingPropertyConflictWithImportBody): + body (PostNamingPropertyConflictWithImportBody | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. @@ -109,12 +110,12 @@ def sync( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], - body: PostNamingPropertyConflictWithImportBody, + client: AuthenticatedClient | Client, + body: PostNamingPropertyConflictWithImportBody | Unset = UNSET, ) -> Response[PostNamingPropertyConflictWithImportResponse200]: """ Args: - body (PostNamingPropertyConflictWithImportBody): + body (PostNamingPropertyConflictWithImportBody | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. @@ -135,12 +136,12 @@ async def asyncio_detailed( async def asyncio( *, - client: Union[AuthenticatedClient, Client], - body: PostNamingPropertyConflictWithImportBody, -) -> Optional[PostNamingPropertyConflictWithImportResponse200]: + client: AuthenticatedClient | Client, + body: PostNamingPropertyConflictWithImportBody | Unset = UNSET, +) -> PostNamingPropertyConflictWithImportResponse200 | None: """ Args: - body (PostNamingPropertyConflictWithImportBody): + body (PostNamingPropertyConflictWithImportBody | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/parameter_references/__init__.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/parameter_references/__init__.py new file mode 100644 index 000000000..2d7c0b23d --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/parameter_references/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py similarity index 63% rename from end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py index 4b034ffe4..801929db9 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py @@ -1,5 +1,6 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any +from urllib.parse import quote import httpx @@ -11,12 +12,12 @@ def _get_kwargs( path_param: str, *, - string_param: Union[Unset, str] = UNSET, - integer_param: Union[Unset, int] = 0, - header_param: Union[None, Unset, str] = UNSET, - cookie_param: Union[Unset, str] = UNSET, -) -> Dict[str, Any]: - headers: Dict[str, Any] = {} + string_param: str | Unset = UNSET, + integer_param: int | Unset = 0, + header_param: None | str | Unset = UNSET, + cookie_param: str | Unset = UNSET, +) -> dict[str, Any]: + headers: dict[str, Any] = {} if not isinstance(header_param, Unset): headers["header param"] = header_param @@ -24,7 +25,7 @@ def _get_kwargs( if cookie_param is not UNSET: cookies["cookie param"] = cookie_param - params: Dict[str, Any] = {} + params: dict[str, Any] = {} params["string param"] = string_param @@ -32,9 +33,11 @@ def _get_kwargs( params = {k: v for k, v in params.items() if v is not UNSET and v is not None} - _kwargs: Dict[str, Any] = { + _kwargs: dict[str, Any] = { "method": "get", - "url": f"/parameter-references/{path_param}", + "url": "/parameter-references/{path_param}".format( + path_param=quote(str(path_param), safe=""), + ), "params": params, "cookies": cookies, } @@ -43,16 +46,17 @@ def _get_kwargs( return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: - if response.status_code == HTTPStatus.OK: +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: return None + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -64,20 +68,20 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( path_param: str, *, - client: Union[AuthenticatedClient, Client], - string_param: Union[Unset, str] = UNSET, - integer_param: Union[Unset, int] = 0, - header_param: Union[None, Unset, str] = UNSET, - cookie_param: Union[Unset, str] = UNSET, + client: AuthenticatedClient | Client, + string_param: str | Unset = UNSET, + integer_param: int | Unset = 0, + header_param: None | str | Unset = UNSET, + cookie_param: str | Unset = UNSET, ) -> Response[Any]: """Test different types of parameter references Args: path_param (str): - string_param (Union[Unset, str]): - integer_param (Union[Unset, int]): Default: 0. - header_param (Union[None, Unset, str]): - cookie_param (Union[Unset, str]): + string_param (str | Unset): + integer_param (int | Unset): Default: 0. + header_param (None | str | Unset): + cookie_param (str | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. @@ -105,20 +109,20 @@ def sync_detailed( async def asyncio_detailed( path_param: str, *, - client: Union[AuthenticatedClient, Client], - string_param: Union[Unset, str] = UNSET, - integer_param: Union[Unset, int] = 0, - header_param: Union[None, Unset, str] = UNSET, - cookie_param: Union[Unset, str] = UNSET, + client: AuthenticatedClient | Client, + string_param: str | Unset = UNSET, + integer_param: int | Unset = 0, + header_param: None | str | Unset = UNSET, + cookie_param: str | Unset = UNSET, ) -> Response[Any]: """Test different types of parameter references Args: path_param (str): - string_param (Union[Unset, str]): - integer_param (Union[Unset, int]): Default: 0. - header_param (Union[None, Unset, str]): - cookie_param (Union[Unset, str]): + string_param (str | Unset): + integer_param (int | Unset): Default: 0. + header_param (None | str | Unset): + cookie_param (str | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/parameters/__init__.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/parameters/__init__.py new file mode 100644 index 000000000..2d7c0b23d --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/parameters/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py similarity index 72% rename from end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py index 8203fa750..23c5b72da 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py @@ -1,5 +1,6 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any +from urllib.parse import quote import httpx @@ -11,33 +12,37 @@ def _get_kwargs( param_path: str, *, - param_query: Union[Unset, str] = UNSET, -) -> Dict[str, Any]: - params: Dict[str, Any] = {} + param_query: str | Unset = UNSET, +) -> dict[str, Any]: + + params: dict[str, Any] = {} params["param"] = param_query params = {k: v for k, v in params.items() if v is not UNSET and v is not None} - _kwargs: Dict[str, Any] = { + _kwargs: dict[str, Any] = { "method": "delete", - "url": f"/common_parameters_overriding/{param_path}", + "url": "/common_parameters_overriding/{param_path}".format( + param_path=quote(str(param_path), safe=""), + ), "params": params, } return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: - if response.status_code == HTTPStatus.OK: +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: return None + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -49,13 +54,13 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( param_path: str, *, - client: Union[AuthenticatedClient, Client], - param_query: Union[Unset, str] = UNSET, + client: AuthenticatedClient | Client, + param_query: str | Unset = UNSET, ) -> Response[Any]: """ Args: param_path (str): - param_query (Union[Unset, str]): + param_query (str | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. @@ -80,13 +85,13 @@ def sync_detailed( async def asyncio_detailed( param_path: str, *, - client: Union[AuthenticatedClient, Client], - param_query: Union[Unset, str] = UNSET, + client: AuthenticatedClient | Client, + param_query: str | Unset = UNSET, ) -> Response[Any]: """ Args: param_path (str): - param_query (Union[Unset, str]): + param_query (str | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py similarity index 81% rename from end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py index 985e92c20..3233fa605 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py @@ -1,5 +1,6 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any +from urllib.parse import quote import httpx @@ -12,32 +13,36 @@ def _get_kwargs( param_path: str, *, param_query: str = "overridden_in_GET", -) -> Dict[str, Any]: - params: Dict[str, Any] = {} +) -> dict[str, Any]: + + params: dict[str, Any] = {} params["param"] = param_query params = {k: v for k, v in params.items() if v is not UNSET and v is not None} - _kwargs: Dict[str, Any] = { + _kwargs: dict[str, Any] = { "method": "get", - "url": f"/common_parameters_overriding/{param_path}", + "url": "/common_parameters_overriding/{param_path}".format( + param_path=quote(str(param_path), safe=""), + ), "params": params, } return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: - if response.status_code == HTTPStatus.OK: +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: return None + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -49,7 +54,7 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( param_path: str, *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, param_query: str = "overridden_in_GET", ) -> Response[Any]: """Test that if you have an overriding property from `PathItem` in `Operation`, it produces valid code @@ -82,7 +87,7 @@ def sync_detailed( async def asyncio_detailed( param_path: str, *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, param_query: str = "overridden_in_GET", ) -> Response[Any]: """Test that if you have an overriding property from `PathItem` in `Operation`, it produces valid code diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_same_name_multiple_locations_param.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/parameters/get_same_name_multiple_locations_param.py similarity index 65% rename from end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_same_name_multiple_locations_param.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/parameters/get_same_name_multiple_locations_param.py index 43f3b8993..dd11f68ca 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_same_name_multiple_locations_param.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/parameters/get_same_name_multiple_locations_param.py @@ -1,5 +1,6 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any +from urllib.parse import quote import httpx @@ -11,11 +12,11 @@ def _get_kwargs( param_path: str, *, - param_query: Union[Unset, str] = UNSET, - param_header: Union[Unset, str] = UNSET, - param_cookie: Union[Unset, str] = UNSET, -) -> Dict[str, Any]: - headers: Dict[str, Any] = {} + param_query: str | Unset = UNSET, + param_header: str | Unset = UNSET, + param_cookie: str | Unset = UNSET, +) -> dict[str, Any]: + headers: dict[str, Any] = {} if not isinstance(param_header, Unset): headers["param"] = param_header @@ -23,15 +24,17 @@ def _get_kwargs( if param_cookie is not UNSET: cookies["param"] = param_cookie - params: Dict[str, Any] = {} + params: dict[str, Any] = {} params["param"] = param_query params = {k: v for k, v in params.items() if v is not UNSET and v is not None} - _kwargs: Dict[str, Any] = { + _kwargs: dict[str, Any] = { "method": "get", - "url": f"/same-name-multiple-locations/{param_path}", + "url": "/same-name-multiple-locations/{param_path}".format( + param_path=quote(str(param_path), safe=""), + ), "params": params, "cookies": cookies, } @@ -40,16 +43,17 @@ def _get_kwargs( return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: - if response.status_code == HTTPStatus.OK: +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: return None + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -61,17 +65,17 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( param_path: str, *, - client: Union[AuthenticatedClient, Client], - param_query: Union[Unset, str] = UNSET, - param_header: Union[Unset, str] = UNSET, - param_cookie: Union[Unset, str] = UNSET, + client: AuthenticatedClient | Client, + param_query: str | Unset = UNSET, + param_header: str | Unset = UNSET, + param_cookie: str | Unset = UNSET, ) -> Response[Any]: """ Args: param_path (str): - param_query (Union[Unset, str]): - param_header (Union[Unset, str]): - param_cookie (Union[Unset, str]): + param_query (str | Unset): + param_header (str | Unset): + param_cookie (str | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. @@ -98,17 +102,17 @@ def sync_detailed( async def asyncio_detailed( param_path: str, *, - client: Union[AuthenticatedClient, Client], - param_query: Union[Unset, str] = UNSET, - param_header: Union[Unset, str] = UNSET, - param_cookie: Union[Unset, str] = UNSET, + client: AuthenticatedClient | Client, + param_query: str | Unset = UNSET, + param_header: str | Unset = UNSET, + param_cookie: str | Unset = UNSET, ) -> Response[Any]: """ Args: param_path (str): - param_query (Union[Unset, str]): - param_header (Union[Unset, str]): - param_cookie (Union[Unset, str]): + param_query (str | Unset): + param_header (str | Unset): + param_cookie (str | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/parameters/multiple_path_parameters.py similarity index 74% rename from end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/parameters/multiple_path_parameters.py index 2785fa56f..d683b856c 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/parameters/multiple_path_parameters.py @@ -1,5 +1,6 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any +from urllib.parse import quote import httpx @@ -13,25 +14,32 @@ def _get_kwargs( param2: int, param1: str, param3: int, -) -> Dict[str, Any]: - _kwargs: Dict[str, Any] = { +) -> dict[str, Any]: + + _kwargs: dict[str, Any] = { "method": "get", - "url": f"/multiple-path-parameters/{param4}/something/{param2}/{param1}/{param3}", + "url": "/multiple-path-parameters/{param4}/something/{param2}/{param1}/{param3}".format( + param4=quote(str(param4), safe=""), + param2=quote(str(param2), safe=""), + param1=quote(str(param1), safe=""), + param3=quote(str(param3), safe=""), + ), } return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: - if response.status_code == HTTPStatus.OK: +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: return None + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -46,7 +54,7 @@ def sync_detailed( param1: str, param3: int, *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, ) -> Response[Any]: """ Args: @@ -83,7 +91,7 @@ async def asyncio_detailed( param1: str, param3: int, *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, ) -> Response[Any]: """ Args: diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/responses/__init__.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/responses/__init__.py new file mode 100644 index 000000000..2d7c0b23d --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/responses/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/responses/default_status_code.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/responses/default_status_code.py new file mode 100644 index 000000000..aa32c5393 --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/responses/default_status_code.py @@ -0,0 +1,115 @@ +from http import HTTPStatus +from typing import Any + +import httpx + +from ...client import AuthenticatedClient, Client +from ...types import Response + + +def _get_kwargs() -> dict[str, Any]: + + _kwargs: dict[str, Any] = { + "method": "get", + "url": "/responses/status-codes/default", + } + + return _kwargs + + +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> str: + response_default = response.text + return response_default + + +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[str]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient | Client, +) -> Response[str]: + """Default Status Code Only + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[str] + """ + + kwargs = _get_kwargs() + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient | Client, +) -> str | None: + """Default Status Code Only + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + str + """ + + return sync_detailed( + client=client, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient | Client, +) -> Response[str]: + """Default Status Code Only + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[str] + """ + + kwargs = _get_kwargs() + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient | Client, +) -> str | None: + """Default Status Code Only + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + str + """ + + return ( + await asyncio_detailed( + client=client, + ) + ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/responses/post_responses_unions_simple_before_complex.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/responses/post_responses_unions_simple_before_complex.py similarity index 81% rename from end_to_end_tests/golden-record/my_test_api_client/api/responses/post_responses_unions_simple_before_complex.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/responses/post_responses_unions_simple_before_complex.py index 63f551edc..022f30062 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/responses/post_responses_unions_simple_before_complex.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/responses/post_responses_unions_simple_before_complex.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any import httpx @@ -11,8 +11,9 @@ from ...types import Response -def _get_kwargs() -> Dict[str, Any]: - _kwargs: Dict[str, Any] = { +def _get_kwargs() -> dict[str, Any]: + + _kwargs: dict[str, Any] = { "method": "post", "url": "/responses/unions/simple_before_complex", } @@ -21,12 +22,13 @@ def _get_kwargs() -> Dict[str, Any]: def _parse_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Optional[PostResponsesUnionsSimpleBeforeComplexResponse200]: - if response.status_code == HTTPStatus.OK: + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> PostResponsesUnionsSimpleBeforeComplexResponse200 | None: + if response.status_code == 200: response_200 = PostResponsesUnionsSimpleBeforeComplexResponse200.from_dict(response.json()) return response_200 + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: @@ -34,7 +36,7 @@ def _parse_response( def _build_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response + *, client: AuthenticatedClient | Client, response: httpx.Response ) -> Response[PostResponsesUnionsSimpleBeforeComplexResponse200]: return Response( status_code=HTTPStatus(response.status_code), @@ -46,7 +48,7 @@ def _build_response( def sync_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, ) -> Response[PostResponsesUnionsSimpleBeforeComplexResponse200]: """Regression test for #603 @@ -69,8 +71,8 @@ def sync_detailed( def sync( *, - client: Union[AuthenticatedClient, Client], -) -> Optional[PostResponsesUnionsSimpleBeforeComplexResponse200]: + client: AuthenticatedClient | Client, +) -> PostResponsesUnionsSimpleBeforeComplexResponse200 | None: """Regression test for #603 Raises: @@ -88,7 +90,7 @@ def sync( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, ) -> Response[PostResponsesUnionsSimpleBeforeComplexResponse200]: """Regression test for #603 @@ -109,8 +111,8 @@ async def asyncio_detailed( async def asyncio( *, - client: Union[AuthenticatedClient, Client], -) -> Optional[PostResponsesUnionsSimpleBeforeComplexResponse200]: + client: AuthenticatedClient | Client, +) -> PostResponsesUnionsSimpleBeforeComplexResponse200 | None: """Regression test for #603 Raises: diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/responses/reference_response.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/responses/reference_response.py new file mode 100644 index 000000000..77429a73b --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/responses/reference_response.py @@ -0,0 +1,124 @@ +from http import HTTPStatus +from typing import Any + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.a_model import AModel +from ...types import Response + + +def _get_kwargs() -> dict[str, Any]: + + _kwargs: dict[str, Any] = { + "method": "get", + "url": "/responses/reference", + } + + return _kwargs + + +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> AModel | None: + if response.status_code == 200: + response_200 = AModel.from_dict(response.json()) + + return response_200 + + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[AModel]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient | Client, +) -> Response[AModel]: + """Endpoint using predefined response + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[AModel] + """ + + kwargs = _get_kwargs() + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient | Client, +) -> AModel | None: + """Endpoint using predefined response + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + AModel + """ + + return sync_detailed( + client=client, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient | Client, +) -> Response[AModel]: + """Endpoint using predefined response + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[AModel] + """ + + kwargs = _get_kwargs() + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient | Client, +) -> AModel | None: + """Endpoint using predefined response + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + AModel + """ + + return ( + await asyncio_detailed( + client=client, + ) + ).parsed diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/responses/status_code_patterns.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/responses/status_code_patterns.py new file mode 100644 index 000000000..796d3764f --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/responses/status_code_patterns.py @@ -0,0 +1,134 @@ +from http import HTTPStatus +from typing import Any + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.status_code_patterns_response_2xx import StatusCodePatternsResponse2XX +from ...models.status_code_patterns_response_4xx import StatusCodePatternsResponse4XX +from ...types import Response + + +def _get_kwargs() -> dict[str, Any]: + + _kwargs: dict[str, Any] = { + "method": "get", + "url": "/response/status-codes/patterns", + } + + return _kwargs + + +def _parse_response( + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> StatusCodePatternsResponse2XX | StatusCodePatternsResponse4XX | None: + if 200 <= response.status_code <= 299: + response_2xx = StatusCodePatternsResponse2XX.from_dict(response.json()) + + return response_2xx + + if 400 <= response.status_code <= 499: + response_4xx = StatusCodePatternsResponse4XX.from_dict(response.json()) + + return response_4xx + + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response( + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> Response[StatusCodePatternsResponse2XX | StatusCodePatternsResponse4XX]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient | Client, +) -> Response[StatusCodePatternsResponse2XX | StatusCodePatternsResponse4XX]: + """Status Code Patterns + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[StatusCodePatternsResponse2XX | StatusCodePatternsResponse4XX] + """ + + kwargs = _get_kwargs() + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient | Client, +) -> StatusCodePatternsResponse2XX | StatusCodePatternsResponse4XX | None: + """Status Code Patterns + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + StatusCodePatternsResponse2XX | StatusCodePatternsResponse4XX + """ + + return sync_detailed( + client=client, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient | Client, +) -> Response[StatusCodePatternsResponse2XX | StatusCodePatternsResponse4XX]: + """Status Code Patterns + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[StatusCodePatternsResponse2XX | StatusCodePatternsResponse4XX] + """ + + kwargs = _get_kwargs() + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient | Client, +) -> StatusCodePatternsResponse2XX | StatusCodePatternsResponse4XX | None: + """Status Code Patterns + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + StatusCodePatternsResponse2XX | StatusCodePatternsResponse4XX + """ + + return ( + await asyncio_detailed( + client=client, + ) + ).parsed diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/responses/status_code_precedence.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/responses/status_code_precedence.py new file mode 100644 index 000000000..11d832c87 --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/responses/status_code_precedence.py @@ -0,0 +1,135 @@ +from http import HTTPStatus +from typing import Any + +import httpx + +from ...client import AuthenticatedClient, Client +from ...types import Response + + +def _get_kwargs() -> dict[str, Any]: + + _kwargs: dict[str, Any] = { + "method": "get", + "url": "/response/status-codes/precedence", + } + + return _kwargs + + +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> str: + if response.status_code == 200: + response_200 = response.text + return response_200 + + if response.status_code == 404: + response_404 = response.text + return response_404 + + if 400 <= response.status_code <= 499: + response_4xx = response.text + return response_4xx + + response_default = response.text + return response_default + + +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[str]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient | Client, +) -> Response[str]: + """Status Codes Precedence + + Verify that specific status codes are always checked first, then ranges, then default + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[str] + """ + + kwargs = _get_kwargs() + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient | Client, +) -> str | None: + """Status Codes Precedence + + Verify that specific status codes are always checked first, then ranges, then default + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + str + """ + + return sync_detailed( + client=client, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient | Client, +) -> Response[str]: + """Status Codes Precedence + + Verify that specific status codes are always checked first, then ranges, then default + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[str] + """ + + kwargs = _get_kwargs() + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient | Client, +) -> str | None: + """Status Codes Precedence + + Verify that specific status codes are always checked first, then ranges, then default + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + str + """ + + return ( + await asyncio_detailed( + client=client, + ) + ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/responses/text_response.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/responses/text_response.py similarity index 79% rename from end_to_end_tests/golden-record/my_test_api_client/api/responses/text_response.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/responses/text_response.py index c7d71a3f3..0f56f8c77 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/responses/text_response.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/responses/text_response.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any import httpx @@ -8,8 +8,9 @@ from ...types import Response -def _get_kwargs() -> Dict[str, Any]: - _kwargs: Dict[str, Any] = { +def _get_kwargs() -> dict[str, Any]: + + _kwargs: dict[str, Any] = { "method": "post", "url": "/responses/text", } @@ -17,17 +18,18 @@ def _get_kwargs() -> Dict[str, Any]: return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[str]: - if response.status_code == HTTPStatus.OK: +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> str | None: + if response.status_code == 200: response_200 = response.text return response_200 + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[str]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[str]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -38,7 +40,7 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, ) -> Response[str]: """Text Response @@ -61,8 +63,8 @@ def sync_detailed( def sync( *, - client: Union[AuthenticatedClient, Client], -) -> Optional[str]: + client: AuthenticatedClient | Client, +) -> str | None: """Text Response Raises: @@ -80,7 +82,7 @@ def sync( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, ) -> Response[str]: """Text Response @@ -101,8 +103,8 @@ async def asyncio_detailed( async def asyncio( *, - client: Union[AuthenticatedClient, Client], -) -> Optional[str]: + client: AuthenticatedClient | Client, +) -> str | None: """Text Response Raises: diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tag1/__init__.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tag1/__init__.py new file mode 100644 index 000000000..2d7c0b23d --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tag1/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tag1/get_tag_with_number.py similarity index 77% rename from end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tag1/get_tag_with_number.py index eedbd5f7a..3ee534c8f 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tag1/get_tag_with_number.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any import httpx @@ -8,8 +8,9 @@ from ...types import Response -def _get_kwargs() -> Dict[str, Any]: - _kwargs: Dict[str, Any] = { +def _get_kwargs() -> dict[str, Any]: + + _kwargs: dict[str, Any] = { "method": "get", "url": "/tag_with_number", } @@ -17,16 +18,17 @@ def _get_kwargs() -> Dict[str, Any]: return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: - if response.status_code == HTTPStatus.OK: +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: return None + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -37,7 +39,7 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, ) -> Response[Any]: """ Raises: @@ -59,7 +61,7 @@ def sync_detailed( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, ) -> Response[Any]: """ Raises: diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tag2/__init__.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tag2/__init__.py new file mode 100644 index 000000000..2d7c0b23d --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tag2/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tag2/get_tag_with_number.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tag2/get_tag_with_number.py new file mode 100644 index 000000000..3ee534c8f --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tag2/get_tag_with_number.py @@ -0,0 +1,79 @@ +from http import HTTPStatus +from typing import Any + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...types import Response + + +def _get_kwargs() -> dict[str, Any]: + + _kwargs: dict[str, Any] = { + "method": "get", + "url": "/tag_with_number", + } + + return _kwargs + + +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: + return None + + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient | Client, +) -> Response[Any]: + """ + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + kwargs = _get_kwargs() + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +async def asyncio_detailed( + *, + client: AuthenticatedClient | Client, +) -> Response[Any]: + """ + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + kwargs = _get_kwargs() + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/__init__.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/__init__.py new file mode 100644 index 000000000..2d7c0b23d --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/callback_test.py similarity index 75% rename from end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/callback_test.py index 925349cbd..e806fe60c 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/callback_test.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any import httpx @@ -13,17 +13,16 @@ def _get_kwargs( *, body: AModel, -) -> 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": "/tests/callback", } - _body = body.to_dict() + _kwargs["json"] = body.to_dict() - _kwargs["json"] = _body headers["Content-Type"] = "application/json" _kwargs["headers"] = headers @@ -31,15 +30,17 @@ def _get_kwargs( def _parse_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Optional[Union[Any, HTTPValidationError]]: - if response.status_code == HTTPStatus.OK: + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> Any | HTTPValidationError | None: + if response.status_code == 200: response_200 = response.json() return response_200 - if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: + + if response.status_code == 422: response_422 = HTTPValidationError.from_dict(response.json()) return response_422 + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: @@ -47,8 +48,8 @@ def _parse_response( def _build_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Response[Union[Any, HTTPValidationError]]: + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> Response[Any | HTTPValidationError]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -59,9 +60,9 @@ def _build_response( def sync_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: AModel, -) -> Response[Union[Any, HTTPValidationError]]: +) -> Response[Any | HTTPValidationError]: """Path with callback Try sending a request related to a callback @@ -74,7 +75,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any | HTTPValidationError] """ kwargs = _get_kwargs( @@ -90,9 +91,9 @@ def sync_detailed( def sync( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: AModel, -) -> Optional[Union[Any, HTTPValidationError]]: +) -> Any | HTTPValidationError | None: """Path with callback Try sending a request related to a callback @@ -105,7 +106,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError] + Any | HTTPValidationError """ return sync_detailed( @@ -116,9 +117,9 @@ def sync( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: AModel, -) -> Response[Union[Any, HTTPValidationError]]: +) -> Response[Any | HTTPValidationError]: """Path with callback Try sending a request related to a callback @@ -131,7 +132,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any | HTTPValidationError] """ kwargs = _get_kwargs( @@ -145,9 +146,9 @@ async def asyncio_detailed( async def asyncio( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: AModel, -) -> Optional[Union[Any, HTTPValidationError]]: +) -> Any | HTTPValidationError | None: """Path with callback Try sending a request related to a callback @@ -160,7 +161,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError] + Any | HTTPValidationError """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/description_with_backslash.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/description_with_backslash.py similarity index 72% rename from end_to_end_tests/golden-record/my_test_api_client/api/tests/description_with_backslash.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/description_with_backslash.py index 9ddd267d8..f173767ed 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/description_with_backslash.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/description_with_backslash.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any import httpx @@ -8,8 +8,9 @@ from ...types import Response -def _get_kwargs() -> Dict[str, Any]: - _kwargs: Dict[str, Any] = { +def _get_kwargs() -> dict[str, Any]: + + _kwargs: dict[str, Any] = { "method": "get", "url": "/tests/description-with-backslash", } @@ -17,16 +18,17 @@ def _get_kwargs() -> Dict[str, Any]: return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: - if response.status_code == HTTPStatus.OK: +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: return None + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -37,11 +39,11 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, ) -> Response[Any]: - r""" Test description with \ + """ Test description with \\ - Test description with \ + Test description with \\ Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. @@ -62,11 +64,11 @@ def sync_detailed( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, ) -> Response[Any]: - r""" Test description with \ + """ Test description with \\ - Test description with \ + Test description with \\ Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_booleans.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/get_basic_list_of_booleans.py similarity index 74% rename from end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_booleans.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/get_basic_list_of_booleans.py index 8f90e7eb6..0a20d2f8f 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_booleans.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/get_basic_list_of_booleans.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, List, Optional, Union, cast +from typing import Any, cast import httpx @@ -8,8 +8,9 @@ from ...types import Response -def _get_kwargs() -> Dict[str, Any]: - _kwargs: Dict[str, Any] = { +def _get_kwargs() -> dict[str, Any]: + + _kwargs: dict[str, Any] = { "method": "get", "url": "/tests/basic_lists/booleans", } @@ -17,18 +18,19 @@ def _get_kwargs() -> Dict[str, Any]: return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[List[bool]]: - if response.status_code == HTTPStatus.OK: - response_200 = cast(List[bool], response.json()) +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> list[bool] | None: + if response.status_code == 200: + response_200 = cast(list[bool], response.json()) return response_200 + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[List[bool]]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[list[bool]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -39,8 +41,8 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( *, - client: Union[AuthenticatedClient, Client], -) -> Response[List[bool]]: + client: AuthenticatedClient | Client, +) -> Response[list[bool]]: """Get Basic List Of Booleans Get a list of booleans @@ -50,7 +52,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[List[bool]] + Response[list[bool]] """ kwargs = _get_kwargs() @@ -64,8 +66,8 @@ def sync_detailed( def sync( *, - client: Union[AuthenticatedClient, Client], -) -> Optional[List[bool]]: + client: AuthenticatedClient | Client, +) -> list[bool] | None: """Get Basic List Of Booleans Get a list of booleans @@ -75,7 +77,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - List[bool] + list[bool] """ return sync_detailed( @@ -85,8 +87,8 @@ def sync( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], -) -> Response[List[bool]]: + client: AuthenticatedClient | Client, +) -> Response[list[bool]]: """Get Basic List Of Booleans Get a list of booleans @@ -96,7 +98,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[List[bool]] + Response[list[bool]] """ kwargs = _get_kwargs() @@ -108,8 +110,8 @@ async def asyncio_detailed( async def asyncio( *, - client: Union[AuthenticatedClient, Client], -) -> Optional[List[bool]]: + client: AuthenticatedClient | Client, +) -> list[bool] | None: """Get Basic List Of Booleans Get a list of booleans @@ -119,7 +121,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - List[bool] + list[bool] """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_floats.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/get_basic_list_of_floats.py similarity index 73% rename from end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_floats.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/get_basic_list_of_floats.py index b76743cf6..0beb7b1dd 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_floats.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/get_basic_list_of_floats.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, List, Optional, Union, cast +from typing import Any, cast import httpx @@ -8,8 +8,9 @@ from ...types import Response -def _get_kwargs() -> Dict[str, Any]: - _kwargs: Dict[str, Any] = { +def _get_kwargs() -> dict[str, Any]: + + _kwargs: dict[str, Any] = { "method": "get", "url": "/tests/basic_lists/floats", } @@ -17,18 +18,19 @@ def _get_kwargs() -> Dict[str, Any]: return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[List[float]]: - if response.status_code == HTTPStatus.OK: - response_200 = cast(List[float], response.json()) +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> list[float] | None: + if response.status_code == 200: + response_200 = cast(list[float], response.json()) return response_200 + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[List[float]]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[list[float]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -39,8 +41,8 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( *, - client: Union[AuthenticatedClient, Client], -) -> Response[List[float]]: + client: AuthenticatedClient | Client, +) -> Response[list[float]]: """Get Basic List Of Floats Get a list of floats @@ -50,7 +52,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[List[float]] + Response[list[float]] """ kwargs = _get_kwargs() @@ -64,8 +66,8 @@ def sync_detailed( def sync( *, - client: Union[AuthenticatedClient, Client], -) -> Optional[List[float]]: + client: AuthenticatedClient | Client, +) -> list[float] | None: """Get Basic List Of Floats Get a list of floats @@ -75,7 +77,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - List[float] + list[float] """ return sync_detailed( @@ -85,8 +87,8 @@ def sync( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], -) -> Response[List[float]]: + client: AuthenticatedClient | Client, +) -> Response[list[float]]: """Get Basic List Of Floats Get a list of floats @@ -96,7 +98,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[List[float]] + Response[list[float]] """ kwargs = _get_kwargs() @@ -108,8 +110,8 @@ async def asyncio_detailed( async def asyncio( *, - client: Union[AuthenticatedClient, Client], -) -> Optional[List[float]]: + client: AuthenticatedClient | Client, +) -> list[float] | None: """Get Basic List Of Floats Get a list of floats @@ -119,7 +121,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - List[float] + list[float] """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_integers.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/get_basic_list_of_integers.py similarity index 74% rename from end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_integers.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/get_basic_list_of_integers.py index 346bcf99f..c0ca1e8c7 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_integers.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/get_basic_list_of_integers.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, List, Optional, Union, cast +from typing import Any, cast import httpx @@ -8,8 +8,9 @@ from ...types import Response -def _get_kwargs() -> Dict[str, Any]: - _kwargs: Dict[str, Any] = { +def _get_kwargs() -> dict[str, Any]: + + _kwargs: dict[str, Any] = { "method": "get", "url": "/tests/basic_lists/integers", } @@ -17,18 +18,19 @@ def _get_kwargs() -> Dict[str, Any]: return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[List[int]]: - if response.status_code == HTTPStatus.OK: - response_200 = cast(List[int], response.json()) +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> list[int] | None: + if response.status_code == 200: + response_200 = cast(list[int], response.json()) return response_200 + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[List[int]]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[list[int]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -39,8 +41,8 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( *, - client: Union[AuthenticatedClient, Client], -) -> Response[List[int]]: + client: AuthenticatedClient | Client, +) -> Response[list[int]]: """Get Basic List Of Integers Get a list of integers @@ -50,7 +52,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[List[int]] + Response[list[int]] """ kwargs = _get_kwargs() @@ -64,8 +66,8 @@ def sync_detailed( def sync( *, - client: Union[AuthenticatedClient, Client], -) -> Optional[List[int]]: + client: AuthenticatedClient | Client, +) -> list[int] | None: """Get Basic List Of Integers Get a list of integers @@ -75,7 +77,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - List[int] + list[int] """ return sync_detailed( @@ -85,8 +87,8 @@ def sync( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], -) -> Response[List[int]]: + client: AuthenticatedClient | Client, +) -> Response[list[int]]: """Get Basic List Of Integers Get a list of integers @@ -96,7 +98,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[List[int]] + Response[list[int]] """ kwargs = _get_kwargs() @@ -108,8 +110,8 @@ async def asyncio_detailed( async def asyncio( *, - client: Union[AuthenticatedClient, Client], -) -> Optional[List[int]]: + client: AuthenticatedClient | Client, +) -> list[int] | None: """Get Basic List Of Integers Get a list of integers @@ -119,7 +121,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - List[int] + list[int] """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_strings.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/get_basic_list_of_strings.py similarity index 74% rename from end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_strings.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/get_basic_list_of_strings.py index 29606477e..4cb0a1bef 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_strings.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/get_basic_list_of_strings.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, List, Optional, Union, cast +from typing import Any, cast import httpx @@ -8,8 +8,9 @@ from ...types import Response -def _get_kwargs() -> Dict[str, Any]: - _kwargs: Dict[str, Any] = { +def _get_kwargs() -> dict[str, Any]: + + _kwargs: dict[str, Any] = { "method": "get", "url": "/tests/basic_lists/strings", } @@ -17,18 +18,19 @@ def _get_kwargs() -> Dict[str, Any]: return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[List[str]]: - if response.status_code == HTTPStatus.OK: - response_200 = cast(List[str], response.json()) +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> list[str] | None: + if response.status_code == 200: + response_200 = cast(list[str], response.json()) return response_200 + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[List[str]]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[list[str]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -39,8 +41,8 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( *, - client: Union[AuthenticatedClient, Client], -) -> Response[List[str]]: + client: AuthenticatedClient | Client, +) -> Response[list[str]]: """Get Basic List Of Strings Get a list of strings @@ -50,7 +52,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[List[str]] + Response[list[str]] """ kwargs = _get_kwargs() @@ -64,8 +66,8 @@ def sync_detailed( def sync( *, - client: Union[AuthenticatedClient, Client], -) -> Optional[List[str]]: + client: AuthenticatedClient | Client, +) -> list[str] | None: """Get Basic List Of Strings Get a list of strings @@ -75,7 +77,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - List[str] + list[str] """ return sync_detailed( @@ -85,8 +87,8 @@ def sync( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], -) -> Response[List[str]]: + client: AuthenticatedClient | Client, +) -> Response[list[str]]: """Get Basic List Of Strings Get a list of strings @@ -96,7 +98,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[List[str]] + Response[list[str]] """ kwargs = _get_kwargs() @@ -108,8 +110,8 @@ async def asyncio_detailed( async def asyncio( *, - client: Union[AuthenticatedClient, Client], -) -> Optional[List[str]]: + client: AuthenticatedClient | Client, +) -> list[str] | None: """Get Basic List Of Strings Get a list of strings @@ -119,7 +121,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - List[str] + list[str] """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/get_user_list.py similarity index 62% rename from end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/get_user_list.py index ff055d3fd..5fcbd86e1 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/get_user_list.py @@ -1,6 +1,6 @@ import datetime from http import HTTPStatus -from typing import Any, Dict, List, Optional, Union +from typing import Any import httpx @@ -15,12 +15,13 @@ def _get_kwargs( *, - an_enum_value: List[AnEnum], - an_enum_value_with_null: List[Union[AnEnumWithNull, None]], - an_enum_value_with_only_null: List[None], - some_date: Union[datetime.date, datetime.datetime], -) -> Dict[str, Any]: - params: Dict[str, Any] = {} + an_enum_value: list[AnEnum], + an_enum_value_with_null: list[AnEnumWithNull | None], + an_enum_value_with_only_null: list[None], + some_date: datetime.date | datetime.datetime, +) -> dict[str, Any]: + + params: dict[str, Any] = {} json_an_enum_value = [] for an_enum_value_item_data in an_enum_value: @@ -31,7 +32,7 @@ def _get_kwargs( json_an_enum_value_with_null = [] for an_enum_value_with_null_item_data in an_enum_value_with_null: - an_enum_value_with_null_item: Union[None, str] + an_enum_value_with_null_item: None | str if isinstance(an_enum_value_with_null_item_data, AnEnumWithNull): an_enum_value_with_null_item = an_enum_value_with_null_item_data.value else: @@ -54,7 +55,7 @@ def _get_kwargs( params = {k: v for k, v in params.items() if v is not UNSET and v is not None} - _kwargs: Dict[str, Any] = { + _kwargs: dict[str, Any] = { "method": "get", "url": "/tests/", "params": params, @@ -64,9 +65,9 @@ def _get_kwargs( def _parse_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Optional[Union[HTTPValidationError, List["AModel"]]]: - if response.status_code == HTTPStatus.OK: + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> HTTPValidationError | list[AModel] | None: + if response.status_code == 200: response_200 = [] _response_200 = response.json() for response_200_item_data in _response_200: @@ -75,14 +76,17 @@ def _parse_response( response_200.append(response_200_item) return response_200 - if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: + + if response.status_code == 422: response_422 = HTTPValidationError.from_dict(response.json()) return response_422 - if response.status_code == HTTPStatus.LOCKED: + + if response.status_code == 423: response_423 = HTTPValidationError.from_dict(response.json()) return response_423 + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: @@ -90,8 +94,8 @@ def _parse_response( def _build_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Response[Union[HTTPValidationError, List["AModel"]]]: + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> Response[HTTPValidationError | list[AModel]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -102,28 +106,28 @@ def _build_response( def sync_detailed( *, - client: Union[AuthenticatedClient, Client], - an_enum_value: List[AnEnum], - an_enum_value_with_null: List[Union[AnEnumWithNull, None]], - an_enum_value_with_only_null: List[None], - some_date: Union[datetime.date, datetime.datetime], -) -> Response[Union[HTTPValidationError, List["AModel"]]]: + client: AuthenticatedClient | Client, + an_enum_value: list[AnEnum], + an_enum_value_with_null: list[AnEnumWithNull | None], + an_enum_value_with_only_null: list[None], + some_date: datetime.date | datetime.datetime, +) -> Response[HTTPValidationError | list[AModel]]: """Get List Get a list of things Args: - an_enum_value (List[AnEnum]): - an_enum_value_with_null (List[Union[AnEnumWithNull, None]]): - an_enum_value_with_only_null (List[None]): - some_date (Union[datetime.date, datetime.datetime]): + an_enum_value (list[AnEnum]): + an_enum_value_with_null (list[AnEnumWithNull | None]): + an_enum_value_with_only_null (list[None]): + some_date (datetime.date | datetime.datetime): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[HTTPValidationError, List['AModel']]] + Response[HTTPValidationError | list[AModel]] """ kwargs = _get_kwargs( @@ -142,28 +146,28 @@ def sync_detailed( def sync( *, - client: Union[AuthenticatedClient, Client], - an_enum_value: List[AnEnum], - an_enum_value_with_null: List[Union[AnEnumWithNull, None]], - an_enum_value_with_only_null: List[None], - some_date: Union[datetime.date, datetime.datetime], -) -> Optional[Union[HTTPValidationError, List["AModel"]]]: + client: AuthenticatedClient | Client, + an_enum_value: list[AnEnum], + an_enum_value_with_null: list[AnEnumWithNull | None], + an_enum_value_with_only_null: list[None], + some_date: datetime.date | datetime.datetime, +) -> HTTPValidationError | list[AModel] | None: """Get List Get a list of things Args: - an_enum_value (List[AnEnum]): - an_enum_value_with_null (List[Union[AnEnumWithNull, None]]): - an_enum_value_with_only_null (List[None]): - some_date (Union[datetime.date, datetime.datetime]): + an_enum_value (list[AnEnum]): + an_enum_value_with_null (list[AnEnumWithNull | None]): + an_enum_value_with_only_null (list[None]): + some_date (datetime.date | datetime.datetime): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[HTTPValidationError, List['AModel']] + HTTPValidationError | list[AModel] """ return sync_detailed( @@ -177,28 +181,28 @@ def sync( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], - an_enum_value: List[AnEnum], - an_enum_value_with_null: List[Union[AnEnumWithNull, None]], - an_enum_value_with_only_null: List[None], - some_date: Union[datetime.date, datetime.datetime], -) -> Response[Union[HTTPValidationError, List["AModel"]]]: + client: AuthenticatedClient | Client, + an_enum_value: list[AnEnum], + an_enum_value_with_null: list[AnEnumWithNull | None], + an_enum_value_with_only_null: list[None], + some_date: datetime.date | datetime.datetime, +) -> Response[HTTPValidationError | list[AModel]]: """Get List Get a list of things Args: - an_enum_value (List[AnEnum]): - an_enum_value_with_null (List[Union[AnEnumWithNull, None]]): - an_enum_value_with_only_null (List[None]): - some_date (Union[datetime.date, datetime.datetime]): + an_enum_value (list[AnEnum]): + an_enum_value_with_null (list[AnEnumWithNull | None]): + an_enum_value_with_only_null (list[None]): + some_date (datetime.date | datetime.datetime): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[HTTPValidationError, List['AModel']]] + Response[HTTPValidationError | list[AModel]] """ kwargs = _get_kwargs( @@ -215,28 +219,28 @@ async def asyncio_detailed( async def asyncio( *, - client: Union[AuthenticatedClient, Client], - an_enum_value: List[AnEnum], - an_enum_value_with_null: List[Union[AnEnumWithNull, None]], - an_enum_value_with_only_null: List[None], - some_date: Union[datetime.date, datetime.datetime], -) -> Optional[Union[HTTPValidationError, List["AModel"]]]: + client: AuthenticatedClient | Client, + an_enum_value: list[AnEnum], + an_enum_value_with_null: list[AnEnumWithNull | None], + an_enum_value_with_only_null: list[None], + some_date: datetime.date | datetime.datetime, +) -> HTTPValidationError | list[AModel] | None: """Get List Get a list of things Args: - an_enum_value (List[AnEnum]): - an_enum_value_with_null (List[Union[AnEnumWithNull, None]]): - an_enum_value_with_only_null (List[None]): - some_date (Union[datetime.date, datetime.datetime]): + an_enum_value (list[AnEnum]): + an_enum_value_with_null (list[AnEnumWithNull | None]): + an_enum_value_with_only_null (list[None]): + some_date (datetime.date | datetime.datetime): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[HTTPValidationError, List['AModel']] + HTTPValidationError | list[AModel] """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/json_body_tests_json_body_post.py similarity index 75% rename from end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/json_body_tests_json_body_post.py index c43a0ca7e..5be950c77 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/json_body_tests_json_body_post.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any import httpx @@ -13,17 +13,16 @@ def _get_kwargs( *, body: AModel, -) -> 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": "/tests/json_body", } - _body = body.to_dict() + _kwargs["json"] = body.to_dict() - _kwargs["json"] = _body headers["Content-Type"] = "application/json" _kwargs["headers"] = headers @@ -31,15 +30,17 @@ def _get_kwargs( def _parse_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Optional[Union[Any, HTTPValidationError]]: - if response.status_code == HTTPStatus.OK: + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> Any | HTTPValidationError | None: + if response.status_code == 200: response_200 = response.json() return response_200 - if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: + + if response.status_code == 422: response_422 = HTTPValidationError.from_dict(response.json()) return response_422 + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: @@ -47,8 +48,8 @@ def _parse_response( def _build_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Response[Union[Any, HTTPValidationError]]: + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> Response[Any | HTTPValidationError]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -59,9 +60,9 @@ def _build_response( def sync_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: AModel, -) -> Response[Union[Any, HTTPValidationError]]: +) -> Response[Any | HTTPValidationError]: """Json Body Try sending a JSON body @@ -74,7 +75,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any | HTTPValidationError] """ kwargs = _get_kwargs( @@ -90,9 +91,9 @@ def sync_detailed( def sync( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: AModel, -) -> Optional[Union[Any, HTTPValidationError]]: +) -> Any | HTTPValidationError | None: """Json Body Try sending a JSON body @@ -105,7 +106,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError] + Any | HTTPValidationError """ return sync_detailed( @@ -116,9 +117,9 @@ def sync( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: AModel, -) -> Response[Union[Any, HTTPValidationError]]: +) -> Response[Any | HTTPValidationError]: """Json Body Try sending a JSON body @@ -131,7 +132,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any | HTTPValidationError] """ kwargs = _get_kwargs( @@ -145,9 +146,9 @@ async def asyncio_detailed( async def asyncio( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: AModel, -) -> Optional[Union[Any, HTTPValidationError]]: +) -> Any | HTTPValidationError | None: """Json Body Try sending a JSON body @@ -160,7 +161,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError] + Any | HTTPValidationError """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/no_response_tests_no_response_get.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/no_response_tests_no_response_get.py similarity index 77% rename from end_to_end_tests/golden-record/my_test_api_client/api/tests/no_response_tests_no_response_get.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/no_response_tests_no_response_get.py index 670bb5663..34c4b54c0 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/no_response_tests_no_response_get.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/no_response_tests_no_response_get.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any import httpx @@ -8,8 +8,9 @@ from ...types import Response -def _get_kwargs() -> Dict[str, Any]: - _kwargs: Dict[str, Any] = { +def _get_kwargs() -> dict[str, Any]: + + _kwargs: dict[str, Any] = { "method": "get", "url": "/tests/no_response", } @@ -17,16 +18,17 @@ def _get_kwargs() -> Dict[str, Any]: return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: - if response.status_code == HTTPStatus.OK: +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: return None + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -37,7 +39,7 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, ) -> Response[Any]: """No Response @@ -60,7 +62,7 @@ def sync_detailed( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, ) -> Response[Any]: """No Response diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/octet_stream_tests_octet_stream_get.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/octet_stream_tests_octet_stream_get.py similarity index 80% rename from end_to_end_tests/golden-record/my_test_api_client/api/tests/octet_stream_tests_octet_stream_get.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/octet_stream_tests_octet_stream_get.py index 231a7da74..c08c3caca 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/octet_stream_tests_octet_stream_get.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/octet_stream_tests_octet_stream_get.py @@ -1,6 +1,6 @@ from http import HTTPStatus from io import BytesIO -from typing import Any, Dict, Optional, Union +from typing import Any import httpx @@ -9,8 +9,9 @@ from ...types import File, Response -def _get_kwargs() -> Dict[str, Any]: - _kwargs: Dict[str, Any] = { +def _get_kwargs() -> dict[str, Any]: + + _kwargs: dict[str, Any] = { "method": "get", "url": "/tests/octet_stream", } @@ -18,18 +19,19 @@ def _get_kwargs() -> Dict[str, Any]: return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[File]: - if response.status_code == HTTPStatus.OK: +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> File | None: + if response.status_code == 200: response_200 = File(payload=BytesIO(response.content)) return response_200 + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[File]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[File]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -40,7 +42,7 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, ) -> Response[File]: """Octet Stream @@ -63,8 +65,8 @@ def sync_detailed( def sync( *, - client: Union[AuthenticatedClient, Client], -) -> Optional[File]: + client: AuthenticatedClient | Client, +) -> File | None: """Octet Stream Raises: @@ -82,7 +84,7 @@ def sync( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, ) -> Response[File]: """Octet Stream @@ -103,8 +105,8 @@ async def asyncio_detailed( async def asyncio( *, - client: Union[AuthenticatedClient, Client], -) -> Optional[File]: + client: AuthenticatedClient | Client, +) -> File | None: """Octet Stream Raises: diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/octet_stream_tests_octet_stream_post.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/octet_stream_tests_octet_stream_post.py similarity index 58% rename from end_to_end_tests/golden-record/my_test_api_client/api/tests/octet_stream_tests_octet_stream_post.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/octet_stream_tests_octet_stream_post.py index cb72ba657..1dd936601 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/octet_stream_tests_octet_stream_post.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/octet_stream_tests_octet_stream_post.py @@ -1,28 +1,28 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union, cast +from typing import Any import httpx from ... import errors from ...client import AuthenticatedClient, Client from ...models.http_validation_error import HTTPValidationError -from ...types import File, Response +from ...models.octet_stream_tests_octet_stream_post_response_200 import OctetStreamTestsOctetStreamPostResponse200 +from ...types import UNSET, File, Response, Unset def _get_kwargs( *, - body: File, -) -> Dict[str, Any]: - headers: Dict[str, Any] = {} + body: File | Unset = UNSET, +) -> dict[str, Any]: + headers: dict[str, Any] = {} - _kwargs: Dict[str, Any] = { + _kwargs: dict[str, Any] = { "method": "post", "url": "/tests/octet_stream", } - _body = body.payload - - _kwargs["content"] = _body + if not isinstance(body, Unset): + _kwargs["content"] = body.payload headers["Content-Type"] = "application/octet-stream" _kwargs["headers"] = headers @@ -30,15 +30,18 @@ def _get_kwargs( def _parse_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Optional[Union[HTTPValidationError, str]]: - if response.status_code == HTTPStatus.OK: - response_200 = cast(str, response.json()) + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> HTTPValidationError | OctetStreamTestsOctetStreamPostResponse200 | None: + if response.status_code == 200: + response_200 = OctetStreamTestsOctetStreamPostResponse200.from_dict(response.json()) + return response_200 - if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: + + if response.status_code == 422: response_422 = HTTPValidationError.from_dict(response.json()) return response_422 + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: @@ -46,8 +49,8 @@ def _parse_response( def _build_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Response[Union[HTTPValidationError, str]]: + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> Response[HTTPValidationError | OctetStreamTestsOctetStreamPostResponse200]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -58,20 +61,20 @@ def _build_response( def sync_detailed( *, - client: Union[AuthenticatedClient, Client], - body: File, -) -> Response[Union[HTTPValidationError, str]]: + client: AuthenticatedClient | Client, + body: File | Unset = UNSET, +) -> Response[HTTPValidationError | OctetStreamTestsOctetStreamPostResponse200]: """Binary (octet stream) request body Args: - body (File): A file to upload + body (File | Unset): A file to upload Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[HTTPValidationError, str]] + Response[HTTPValidationError | OctetStreamTestsOctetStreamPostResponse200] """ kwargs = _get_kwargs( @@ -87,20 +90,20 @@ def sync_detailed( def sync( *, - client: Union[AuthenticatedClient, Client], - body: File, -) -> Optional[Union[HTTPValidationError, str]]: + client: AuthenticatedClient | Client, + body: File | Unset = UNSET, +) -> HTTPValidationError | OctetStreamTestsOctetStreamPostResponse200 | None: """Binary (octet stream) request body Args: - body (File): A file to upload + body (File | Unset): A file to upload Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[HTTPValidationError, str] + HTTPValidationError | OctetStreamTestsOctetStreamPostResponse200 """ return sync_detailed( @@ -111,20 +114,20 @@ def sync( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], - body: File, -) -> Response[Union[HTTPValidationError, str]]: + client: AuthenticatedClient | Client, + body: File | Unset = UNSET, +) -> Response[HTTPValidationError | OctetStreamTestsOctetStreamPostResponse200]: """Binary (octet stream) request body Args: - body (File): A file to upload + body (File | Unset): A file to upload Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[HTTPValidationError, str]] + Response[HTTPValidationError | OctetStreamTestsOctetStreamPostResponse200] """ kwargs = _get_kwargs( @@ -138,20 +141,20 @@ async def asyncio_detailed( async def asyncio( *, - client: Union[AuthenticatedClient, Client], - body: File, -) -> Optional[Union[HTTPValidationError, str]]: + client: AuthenticatedClient | Client, + body: File | Unset = UNSET, +) -> HTTPValidationError | OctetStreamTestsOctetStreamPostResponse200 | None: """Binary (octet stream) request body Args: - body (File): A file to upload + body (File | Unset): A file to upload Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[HTTPValidationError, str] + HTTPValidationError | OctetStreamTestsOctetStreamPostResponse200 """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/post_form_data.py similarity index 78% rename from end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/post_form_data.py index 93954ace9..5e1ba06ed 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/post_form_data.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any import httpx @@ -12,33 +12,32 @@ def _get_kwargs( *, body: AFormData, -) -> 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": "/tests/post_form_data", } - _body = body.to_dict() - - _kwargs["data"] = _body + _kwargs["data"] = body.to_dict() headers["Content-Type"] = "application/x-www-form-urlencoded" _kwargs["headers"] = headers return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: - if response.status_code == HTTPStatus.OK: +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: return None + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -49,7 +48,7 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: AFormData, ) -> Response[Any]: """Post form data @@ -80,7 +79,7 @@ def sync_detailed( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: AFormData, ) -> Response[Any]: """Post form data diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/post_form_data_inline.py similarity index 79% rename from end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/post_form_data_inline.py index b676061a3..168fd9c82 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/post_form_data_inline.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any import httpx @@ -12,33 +12,32 @@ def _get_kwargs( *, body: PostFormDataInlineBody, -) -> 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": "/tests/post_form_data_inline", } - _body = body.to_dict() - - _kwargs["data"] = _body + _kwargs["data"] = body.to_dict() headers["Content-Type"] = "application/x-www-form-urlencoded" _kwargs["headers"] = headers return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: - if response.status_code == HTTPStatus.OK: +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: return None + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -49,7 +48,7 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: PostFormDataInlineBody, ) -> Response[Any]: """Post form data (inline schema) @@ -80,7 +79,7 @@ def sync_detailed( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: PostFormDataInlineBody, ) -> Response[Any]: """Post form data (inline schema) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_tests_json_body_string.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/post_tests_json_body_string.py similarity index 73% rename from end_to_end_tests/golden-record/my_test_api_client/api/tests/post_tests_json_body_string.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/post_tests_json_body_string.py index 909c77e78..498d0572e 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_tests_json_body_string.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/post_tests_json_body_string.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union, cast +from typing import Any, cast import httpx @@ -12,17 +12,16 @@ def _get_kwargs( *, body: str, -) -> 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": "/tests/json_body/string", } - _body = body + _kwargs["json"] = body - _kwargs["json"] = _body headers["Content-Type"] = "application/json" _kwargs["headers"] = headers @@ -30,15 +29,17 @@ def _get_kwargs( def _parse_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Optional[Union[HTTPValidationError, str]]: - if response.status_code == HTTPStatus.OK: + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> HTTPValidationError | str | None: + if response.status_code == 200: response_200 = cast(str, response.json()) return response_200 - if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: + + if response.status_code == 422: response_422 = HTTPValidationError.from_dict(response.json()) return response_422 + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: @@ -46,8 +47,8 @@ def _parse_response( def _build_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Response[Union[HTTPValidationError, str]]: + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> Response[HTTPValidationError | str]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -58,9 +59,9 @@ def _build_response( def sync_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: str, -) -> Response[Union[HTTPValidationError, str]]: +) -> Response[HTTPValidationError | str]: """Json Body Which is String Args: @@ -71,7 +72,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[HTTPValidationError, str]] + Response[HTTPValidationError | str] """ kwargs = _get_kwargs( @@ -87,9 +88,9 @@ def sync_detailed( def sync( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: str, -) -> Optional[Union[HTTPValidationError, str]]: +) -> HTTPValidationError | str | None: """Json Body Which is String Args: @@ -100,7 +101,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[HTTPValidationError, str] + HTTPValidationError | str """ return sync_detailed( @@ -111,9 +112,9 @@ def sync( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: str, -) -> Response[Union[HTTPValidationError, str]]: +) -> Response[HTTPValidationError | str]: """Json Body Which is String Args: @@ -124,7 +125,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[HTTPValidationError, str]] + Response[HTTPValidationError | str] """ kwargs = _get_kwargs( @@ -138,9 +139,9 @@ async def asyncio_detailed( async def asyncio( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: str, -) -> Optional[Union[HTTPValidationError, str]]: +) -> HTTPValidationError | str | None: """Json Body Which is String Args: @@ -151,7 +152,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[HTTPValidationError, str] + HTTPValidationError | str """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/test_inline_objects.py similarity index 82% rename from end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/test_inline_objects.py index 2a93ef5ad..ea2e45c94 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/test_inline_objects.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any import httpx @@ -13,17 +13,16 @@ def _get_kwargs( *, body: TestInlineObjectsBody, -) -> 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": "/tests/inline_objects", } - _body = body.to_dict() + _kwargs["json"] = body.to_dict() - _kwargs["json"] = _body headers["Content-Type"] = "application/json" _kwargs["headers"] = headers @@ -31,12 +30,13 @@ def _get_kwargs( def _parse_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Optional[TestInlineObjectsResponse200]: - if response.status_code == HTTPStatus.OK: + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> TestInlineObjectsResponse200 | None: + if response.status_code == 200: response_200 = TestInlineObjectsResponse200.from_dict(response.json()) return response_200 + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: @@ -44,7 +44,7 @@ def _parse_response( def _build_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response + *, client: AuthenticatedClient | Client, response: httpx.Response ) -> Response[TestInlineObjectsResponse200]: return Response( status_code=HTTPStatus(response.status_code), @@ -56,7 +56,7 @@ def _build_response( def sync_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: TestInlineObjectsBody, ) -> Response[TestInlineObjectsResponse200]: """Test Inline Objects @@ -85,9 +85,9 @@ def sync_detailed( def sync( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: TestInlineObjectsBody, -) -> Optional[TestInlineObjectsResponse200]: +) -> TestInlineObjectsResponse200 | None: """Test Inline Objects Args: @@ -109,7 +109,7 @@ def sync( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: TestInlineObjectsBody, ) -> Response[TestInlineObjectsResponse200]: """Test Inline Objects @@ -136,9 +136,9 @@ async def asyncio_detailed( async def asyncio( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: TestInlineObjectsBody, -) -> Optional[TestInlineObjectsResponse200]: +) -> TestInlineObjectsResponse200 | None: """Test Inline Objects Args: diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py similarity index 79% rename from end_to_end_tests/golden-record/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py index 0c68f4726..9ad310a2a 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any import httpx @@ -11,11 +11,12 @@ def _get_kwargs( *, my_token: str, -) -> Dict[str, Any]: +) -> dict[str, Any]: + cookies = {} cookies["MyToken"] = my_token - _kwargs: Dict[str, Any] = { + _kwargs: dict[str, Any] = { "method": "get", "url": "/auth/token_with_cookie", "cookies": cookies, @@ -24,18 +25,20 @@ def _get_kwargs( return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: - if response.status_code == HTTPStatus.OK: +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: return None - if response.status_code == HTTPStatus.UNAUTHORIZED: + + if response.status_code == 401: return None + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -46,7 +49,7 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, my_token: str, ) -> Response[Any]: """TOKEN_WITH_COOKIE @@ -77,7 +80,7 @@ def sync_detailed( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, my_token: str, ) -> Response[Any]: """TOKEN_WITH_COOKIE diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/unsupported_content_tests_unsupported_content_get.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/unsupported_content_tests_unsupported_content_get.py similarity index 77% rename from end_to_end_tests/golden-record/my_test_api_client/api/tests/unsupported_content_tests_unsupported_content_get.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/unsupported_content_tests_unsupported_content_get.py index a63b7b2a2..409f6147a 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/unsupported_content_tests_unsupported_content_get.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/unsupported_content_tests_unsupported_content_get.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any import httpx @@ -8,8 +8,9 @@ from ...types import Response -def _get_kwargs() -> Dict[str, Any]: - _kwargs: Dict[str, Any] = { +def _get_kwargs() -> dict[str, Any]: + + _kwargs: dict[str, Any] = { "method": "get", "url": "/tests/unsupported_content", } @@ -17,16 +18,17 @@ def _get_kwargs() -> Dict[str, Any]: return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: - if response.status_code == HTTPStatus.OK: +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: return None + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -37,7 +39,7 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, ) -> Response[Any]: """Unsupported Content @@ -60,7 +62,7 @@ def sync_detailed( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, ) -> Response[Any]: """Unsupported Content diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/upload_file_tests_upload_post.py similarity index 74% rename from end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/upload_file_tests_upload_post.py index e36d4d92e..6339d61f3 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/tests/upload_file_tests_upload_post.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any import httpx @@ -13,32 +13,34 @@ def _get_kwargs( *, body: BodyUploadFileTestsUploadPost, -) -> 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": "/tests/upload", } - _body = body.to_multipart() + _kwargs["files"] = body.to_multipart() - _kwargs["files"] = _body + headers["Content-Type"] = "multipart/form-data; boundary=+++" _kwargs["headers"] = headers return _kwargs def _parse_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Optional[Union[Any, HTTPValidationError]]: - if response.status_code == HTTPStatus.OK: + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> Any | HTTPValidationError | None: + if response.status_code == 200: response_200 = response.json() return response_200 - if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: + + if response.status_code == 422: response_422 = HTTPValidationError.from_dict(response.json()) return response_422 + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: @@ -46,8 +48,8 @@ def _parse_response( def _build_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Response[Union[Any, HTTPValidationError]]: + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> Response[Any | HTTPValidationError]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -58,9 +60,9 @@ def _build_response( def sync_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: BodyUploadFileTestsUploadPost, -) -> Response[Union[Any, HTTPValidationError]]: +) -> Response[Any | HTTPValidationError]: """Upload File Upload a file @@ -73,7 +75,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any | HTTPValidationError] """ kwargs = _get_kwargs( @@ -89,9 +91,9 @@ def sync_detailed( def sync( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: BodyUploadFileTestsUploadPost, -) -> Optional[Union[Any, HTTPValidationError]]: +) -> Any | HTTPValidationError | None: """Upload File Upload a file @@ -104,7 +106,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError] + Any | HTTPValidationError """ return sync_detailed( @@ -115,9 +117,9 @@ def sync( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: BodyUploadFileTestsUploadPost, -) -> Response[Union[Any, HTTPValidationError]]: +) -> Response[Any | HTTPValidationError]: """Upload File Upload a file @@ -130,7 +132,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any | HTTPValidationError] """ kwargs = _get_kwargs( @@ -144,9 +146,9 @@ async def asyncio_detailed( async def asyncio( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: BodyUploadFileTestsUploadPost, -) -> Optional[Union[Any, HTTPValidationError]]: +) -> Any | HTTPValidationError | None: """Upload File Upload a file @@ -159,7 +161,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[Any, HTTPValidationError] + Any | HTTPValidationError """ return ( diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/true_/__init__.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/true_/__init__.py new file mode 100644 index 000000000..2d7c0b23d --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/true_/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/true_/false_.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/true_/false_.py similarity index 79% rename from end_to_end_tests/golden-record/my_test_api_client/api/true_/false_.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/true_/false_.py index 7921b332e..d7713f03f 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/true_/false_.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/api/true_/false_.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any import httpx @@ -11,14 +11,15 @@ def _get_kwargs( *, import_: str, -) -> Dict[str, Any]: - params: Dict[str, Any] = {} +) -> dict[str, Any]: + + params: dict[str, Any] = {} params["import"] = import_ params = {k: v for k, v in params.items() if v is not UNSET and v is not None} - _kwargs: Dict[str, Any] = { + _kwargs: dict[str, Any] = { "method": "get", "url": "/naming/keywords", "params": params, @@ -27,16 +28,17 @@ def _get_kwargs( return _kwargs -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: - if response.status_code == HTTPStatus.OK: +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Any | None: + if response.status_code == 200: return None + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -47,7 +49,7 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, import_: str, ) -> Response[Any]: """ @@ -75,7 +77,7 @@ def sync_detailed( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, import_: str, ) -> Response[Any]: """ diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/client.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/client.py new file mode 100644 index 000000000..edb246d7e --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/client.py @@ -0,0 +1,268 @@ +import ssl +from typing import Any, Self + +import httpx +from attrs import define, evolve, field + + +@define +class Client: + """A class for keeping track of data related to the API + + The following are accepted as keyword arguments and will be used to construct httpx Clients internally: + + ``base_url``: The base URL for the API, all requests are made to a relative path to this URL + + ``cookies``: A dictionary of cookies to be sent with every request + + ``headers``: A dictionary of headers to be sent with every request + + ``timeout``: The maximum amount of a time a request can take. API functions will raise + httpx.TimeoutException if this is exceeded. + + ``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production, + but can be set to False for testing purposes. + + ``follow_redirects``: Whether or not to follow redirects. Default value is False. + + ``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor. + + + Attributes: + raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a + status code that was not documented in the source OpenAPI document. Can also be provided as a keyword + argument to the constructor. + """ + + raise_on_unexpected_status: bool = field(default=False, kw_only=True) + _base_url: str = field(alias="base_url") + _cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies") + _headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers") + _timeout: httpx.Timeout | None = field(default=None, kw_only=True, alias="timeout") + _verify_ssl: str | bool | ssl.SSLContext = field(default=True, kw_only=True, alias="verify_ssl") + _follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects") + _httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args") + _client: httpx.Client | None = field(default=None, init=False) + _async_client: httpx.AsyncClient | None = field(default=None, init=False) + + def with_headers(self, headers: dict[str, str]) -> "Client": + """Get a new client matching this one with additional headers""" + if self._client is not None: + self._client.headers.update(headers) + if self._async_client is not None: + self._async_client.headers.update(headers) + return evolve(self, headers={**self._headers, **headers}) + + def with_cookies(self, cookies: dict[str, str]) -> "Client": + """Get a new client matching this one with additional cookies""" + if self._client is not None: + self._client.cookies.update(cookies) + if self._async_client is not None: + self._async_client.cookies.update(cookies) + return evolve(self, cookies={**self._cookies, **cookies}) + + def with_timeout(self, timeout: httpx.Timeout) -> "Client": + """Get a new client matching this one with a new timeout configuration""" + if self._client is not None: + self._client.timeout = timeout + if self._async_client is not None: + self._async_client.timeout = timeout + return evolve(self, timeout=timeout) + + def set_httpx_client(self, client: httpx.Client) -> Self: + """Manually set the underlying httpx.Client + + **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. + """ + self._client = client + return self + + def get_httpx_client(self) -> httpx.Client: + """Get the underlying httpx.Client, constructing a new one if not previously set""" + if self._client is None: + self._client = httpx.Client( + base_url=self._base_url, + cookies=self._cookies, + headers=self._headers, + timeout=self._timeout, + verify=self._verify_ssl, + follow_redirects=self._follow_redirects, + **self._httpx_args, + ) + return self._client + + def __enter__(self) -> Self: + """Enter a context manager for self.client—you cannot enter twice (see httpx docs)""" + self.get_httpx_client().__enter__() + return self + + def __exit__(self, *args: Any, **kwargs: Any) -> None: + """Exit a context manager for internal httpx.Client (see httpx docs)""" + self.get_httpx_client().__exit__(*args, **kwargs) + + def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> Self: + """Manually set the underlying httpx.AsyncClient + + **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. + """ + self._async_client = async_client + return self + + def get_async_httpx_client(self) -> httpx.AsyncClient: + """Get the underlying httpx.AsyncClient, constructing a new one if not previously set""" + if self._async_client is None: + self._async_client = httpx.AsyncClient( + base_url=self._base_url, + cookies=self._cookies, + headers=self._headers, + timeout=self._timeout, + verify=self._verify_ssl, + follow_redirects=self._follow_redirects, + **self._httpx_args, + ) + return self._async_client + + async def __aenter__(self) -> Self: + """Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)""" + await self.get_async_httpx_client().__aenter__() + return self + + async def __aexit__(self, *args: Any, **kwargs: Any) -> None: + """Exit a context manager for underlying httpx.AsyncClient (see httpx docs)""" + await self.get_async_httpx_client().__aexit__(*args, **kwargs) + + +@define +class AuthenticatedClient: + """A Client which has been authenticated for use on secured endpoints + + The following are accepted as keyword arguments and will be used to construct httpx Clients internally: + + ``base_url``: The base URL for the API, all requests are made to a relative path to this URL + + ``cookies``: A dictionary of cookies to be sent with every request + + ``headers``: A dictionary of headers to be sent with every request + + ``timeout``: The maximum amount of a time a request can take. API functions will raise + httpx.TimeoutException if this is exceeded. + + ``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production, + but can be set to False for testing purposes. + + ``follow_redirects``: Whether or not to follow redirects. Default value is False. + + ``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor. + + + Attributes: + raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a + status code that was not documented in the source OpenAPI document. Can also be provided as a keyword + argument to the constructor. + token: The token to use for authentication + prefix: The prefix to use for the Authorization header + auth_header_name: The name of the Authorization header + """ + + raise_on_unexpected_status: bool = field(default=False, kw_only=True) + _base_url: str = field(alias="base_url") + _cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies") + _headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers") + _timeout: httpx.Timeout | None = field(default=None, kw_only=True, alias="timeout") + _verify_ssl: str | bool | ssl.SSLContext = field(default=True, kw_only=True, alias="verify_ssl") + _follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects") + _httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args") + _client: httpx.Client | None = field(default=None, init=False) + _async_client: httpx.AsyncClient | None = field(default=None, init=False) + + token: str + prefix: str = "Bearer" + auth_header_name: str = "Authorization" + + def with_headers(self, headers: dict[str, str]) -> "AuthenticatedClient": + """Get a new client matching this one with additional headers""" + if self._client is not None: + self._client.headers.update(headers) + if self._async_client is not None: + self._async_client.headers.update(headers) + return evolve(self, headers={**self._headers, **headers}) + + def with_cookies(self, cookies: dict[str, str]) -> "AuthenticatedClient": + """Get a new client matching this one with additional cookies""" + if self._client is not None: + self._client.cookies.update(cookies) + if self._async_client is not None: + self._async_client.cookies.update(cookies) + return evolve(self, cookies={**self._cookies, **cookies}) + + def with_timeout(self, timeout: httpx.Timeout) -> "AuthenticatedClient": + """Get a new client matching this one with a new timeout configuration""" + if self._client is not None: + self._client.timeout = timeout + if self._async_client is not None: + self._async_client.timeout = timeout + return evolve(self, timeout=timeout) + + def set_httpx_client(self, client: httpx.Client) -> Self: + """Manually set the underlying httpx.Client + + **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. + """ + self._client = client + return self + + def get_httpx_client(self) -> httpx.Client: + """Get the underlying httpx.Client, constructing a new one if not previously set""" + if self._client is None: + self._headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token + self._client = httpx.Client( + base_url=self._base_url, + cookies=self._cookies, + headers=self._headers, + timeout=self._timeout, + verify=self._verify_ssl, + follow_redirects=self._follow_redirects, + **self._httpx_args, + ) + return self._client + + def __enter__(self) -> Self: + """Enter a context manager for self.client—you cannot enter twice (see httpx docs)""" + self.get_httpx_client().__enter__() + return self + + def __exit__(self, *args: Any, **kwargs: Any) -> None: + """Exit a context manager for internal httpx.Client (see httpx docs)""" + self.get_httpx_client().__exit__(*args, **kwargs) + + def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> Self: + """Manually set the underlying httpx.AsyncClient + + **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. + """ + self._async_client = async_client + return self + + def get_async_httpx_client(self) -> httpx.AsyncClient: + """Get the underlying httpx.AsyncClient, constructing a new one if not previously set""" + if self._async_client is None: + self._headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token + self._async_client = httpx.AsyncClient( + base_url=self._base_url, + cookies=self._cookies, + headers=self._headers, + timeout=self._timeout, + verify=self._verify_ssl, + follow_redirects=self._follow_redirects, + **self._httpx_args, + ) + return self._async_client + + async def __aenter__(self) -> Self: + """Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)""" + await self.get_async_httpx_client().__aenter__() + return self + + async def __aexit__(self, *args: Any, **kwargs: Any) -> None: + """Exit a context manager for underlying httpx.AsyncClient (see httpx docs)""" + await self.get_async_httpx_client().__aexit__(*args, **kwargs) diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/errors.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/errors.py new file mode 100644 index 000000000..5f92e76ac --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/errors.py @@ -0,0 +1,16 @@ +"""Contains shared errors types that can be raised from API functions""" + + +class UnexpectedStatus(Exception): + """Raised by api functions when the response status an undocumented status and Client.raise_on_unexpected_status is True""" + + def __init__(self, status_code: int, content: bytes): + self.status_code = status_code + self.content = content + + super().__init__( + f"Unexpected status code: {status_code}\n\nResponse content:\n{content.decode(errors='ignore')}" + ) + + +__all__ = ["UnexpectedStatus"] diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/__init__.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/__init__.py similarity index 81% rename from end_to_end_tests/golden-record/my_test_api_client/models/__init__.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/__init__.py index 7435983e3..c62e4cfa6 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/__init__.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/__init__.py @@ -7,6 +7,8 @@ from .a_model_with_properties_reference_that_are_not_object import AModelWithPropertiesReferenceThatAreNotObject from .all_of_has_properties_but_no_type import AllOfHasPropertiesButNoType from .all_of_has_properties_but_no_type_type_enum import AllOfHasPropertiesButNoTypeTypeEnum +from .all_of_required_base import AllOfRequiredBase +from .all_of_required_derived import AllOfRequiredDerived from .all_of_sub_model import AllOfSubModel from .all_of_sub_model_type_enum import AllOfSubModelTypeEnum from .an_all_of_enum import AnAllOfEnum @@ -34,9 +36,13 @@ from .body_upload_file_tests_upload_post_some_object import BodyUploadFileTestsUploadPostSomeObject from .body_upload_file_tests_upload_post_some_optional_object import BodyUploadFileTestsUploadPostSomeOptionalObject from .different_enum import DifferentEnum +from .extended import Extended from .free_form_model import FreeFormModel from .get_location_header_types_int_enum_header import GetLocationHeaderTypesIntEnumHeader from .get_location_header_types_string_enum_header import GetLocationHeaderTypesStringEnumHeader +from .get_models_allof_response_200 import GetModelsAllofResponse200 +from .get_models_oneof_with_required_const_response_200_type_0 import GetModelsOneofWithRequiredConstResponse200Type0 +from .get_models_oneof_with_required_const_response_200_type_1 import GetModelsOneofWithRequiredConstResponse200Type1 from .http_validation_error import HTTPValidationError from .import_ import Import from .json_like_body import JsonLikeBody @@ -58,6 +64,9 @@ from .model_with_circular_ref_in_additional_properties_b import ModelWithCircularRefInAdditionalPropertiesB from .model_with_date_time_property import ModelWithDateTimeProperty from .model_with_discriminated_union import ModelWithDiscriminatedUnion +from .model_with_merged_properties import ModelWithMergedProperties +from .model_with_merged_properties_string_to_enum import ModelWithMergedPropertiesStringToEnum +from .model_with_no_properties import ModelWithNoProperties from .model_with_primitive_additional_properties import ModelWithPrimitiveAdditionalProperties from .model_with_primitive_additional_properties_a_date_holder import ModelWithPrimitiveAdditionalPropertiesADateHolder from .model_with_property_ref import ModelWithPropertyRef @@ -65,9 +74,11 @@ from .model_with_recursive_ref_in_additional_properties import ModelWithRecursiveRefInAdditionalProperties from .model_with_union_property import ModelWithUnionProperty from .model_with_union_property_inlined import ModelWithUnionPropertyInlined -from .model_with_union_property_inlined_fruit_type_0 import ModelWithUnionPropertyInlinedFruitType0 -from .model_with_union_property_inlined_fruit_type_1 import ModelWithUnionPropertyInlinedFruitType1 +from .model_with_union_property_inlined_apples import ModelWithUnionPropertyInlinedApples +from .model_with_union_property_inlined_bananas import ModelWithUnionPropertyInlinedBananas from .none import None_ +from .octet_stream_tests_octet_stream_post_response_200 import OctetStreamTestsOctetStreamPostResponse200 +from .optional_body_body import OptionalBodyBody from .post_bodies_multiple_data_body import PostBodiesMultipleDataBody from .post_bodies_multiple_files_body import PostBodiesMultipleFilesBody from .post_bodies_multiple_json_body import PostBodiesMultipleJsonBody @@ -78,6 +89,9 @@ from .post_responses_unions_simple_before_complex_response_200a_type_1 import ( PostResponsesUnionsSimpleBeforeComplexResponse200AType1, ) +from .status_code_patterns_response_2xx import StatusCodePatternsResponse2XX +from .status_code_patterns_response_2xx_status import StatusCodePatternsResponse2XXStatus +from .status_code_patterns_response_4xx import StatusCodePatternsResponse4XX from .test_inline_objects_body import TestInlineObjectsBody from .test_inline_objects_response_200 import TestInlineObjectsResponse200 from .validation_error import ValidationError @@ -88,6 +102,8 @@ "AFormData", "AllOfHasPropertiesButNoType", "AllOfHasPropertiesButNoTypeTypeEnum", + "AllOfRequiredBase", + "AllOfRequiredDerived", "AllOfSubModel", "AllOfSubModelTypeEnum", "AModel", @@ -111,9 +127,13 @@ "BodyUploadFileTestsUploadPostSomeObject", "BodyUploadFileTestsUploadPostSomeOptionalObject", "DifferentEnum", + "Extended", "FreeFormModel", "GetLocationHeaderTypesIntEnumHeader", "GetLocationHeaderTypesStringEnumHeader", + "GetModelsAllofResponse200", + "GetModelsOneofWithRequiredConstResponse200Type0", + "GetModelsOneofWithRequiredConstResponse200Type1", "HTTPValidationError", "Import", "JsonLikeBody", @@ -133,6 +153,9 @@ "ModelWithCircularRefInAdditionalPropertiesB", "ModelWithDateTimeProperty", "ModelWithDiscriminatedUnion", + "ModelWithMergedProperties", + "ModelWithMergedPropertiesStringToEnum", + "ModelWithNoProperties", "ModelWithPrimitiveAdditionalProperties", "ModelWithPrimitiveAdditionalPropertiesADateHolder", "ModelWithPropertyRef", @@ -140,9 +163,11 @@ "ModelWithRecursiveRefInAdditionalProperties", "ModelWithUnionProperty", "ModelWithUnionPropertyInlined", - "ModelWithUnionPropertyInlinedFruitType0", - "ModelWithUnionPropertyInlinedFruitType1", + "ModelWithUnionPropertyInlinedApples", + "ModelWithUnionPropertyInlinedBananas", "None_", + "OctetStreamTestsOctetStreamPostResponse200", + "OptionalBodyBody", "PostBodiesMultipleDataBody", "PostBodiesMultipleFilesBody", "PostBodiesMultipleJsonBody", @@ -151,6 +176,9 @@ "PostNamingPropertyConflictWithImportResponse200", "PostResponsesUnionsSimpleBeforeComplexResponse200", "PostResponsesUnionsSimpleBeforeComplexResponse200AType1", + "StatusCodePatternsResponse2XX", + "StatusCodePatternsResponse2XXStatus", + "StatusCodePatternsResponse4XX", "TestInlineObjectsBody", "TestInlineObjectsResponse200", "ValidationError", diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/a_discriminated_union_type_1.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/a_discriminated_union_type_1.py similarity index 72% rename from end_to_end_tests/golden-record/my_test_api_client/models/a_discriminated_union_type_1.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/a_discriminated_union_type_1.py index cb1184b18..635661b7b 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/a_discriminated_union_type_1.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/a_discriminated_union_type_1.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -12,16 +15,16 @@ class ADiscriminatedUnionType1: """ Attributes: - model_type (Union[Unset, str]): + model_type (str | Unset): """ - model_type: Union[Unset, str] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + model_type: str | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: model_type = self.model_type - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if model_type is not UNSET: @@ -30,8 +33,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) model_type = d.pop("modelType", UNSET) a_discriminated_union_type_1 = cls( @@ -42,7 +45,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return a_discriminated_union_type_1 @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/a_discriminated_union_type_2.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/a_discriminated_union_type_2.py similarity index 72% rename from end_to_end_tests/golden-record/my_test_api_client/models/a_discriminated_union_type_2.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/a_discriminated_union_type_2.py index 734f3bef4..0797af899 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/a_discriminated_union_type_2.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/a_discriminated_union_type_2.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -12,16 +15,16 @@ class ADiscriminatedUnionType2: """ Attributes: - model_type (Union[Unset, str]): + model_type (str | Unset): """ - model_type: Union[Unset, str] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + model_type: str | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: model_type = self.model_type - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if model_type is not UNSET: @@ -30,8 +33,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) model_type = d.pop("modelType", UNSET) a_discriminated_union_type_2 = cls( @@ -42,7 +45,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return a_discriminated_union_type_2 @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/a_form_data.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/a_form_data.py similarity index 76% rename from end_to_end_tests/golden-record/my_test_api_client/models/a_form_data.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/a_form_data.py index a4c5cd8a7..257054eb2 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/a_form_data.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/a_form_data.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -13,19 +16,19 @@ class AFormData: """ Attributes: an_required_field (str): - an_optional_field (Union[Unset, str]): + an_optional_field (str | Unset): """ an_required_field: str - an_optional_field: Union[Unset, str] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + an_optional_field: str | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: an_required_field = self.an_required_field an_optional_field = self.an_optional_field - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update( { @@ -38,8 +41,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) an_required_field = d.pop("an_required_field") an_optional_field = d.pop("an_optional_field", UNSET) @@ -53,7 +56,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return a_form_data @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/a_model.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/a_model.py similarity index 63% rename from end_to_end_tests/golden-record/my_test_api_client/models/a_model.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/a_model.py index d14160bf8..4ca83858f 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/a_model.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/a_model.py @@ -1,8 +1,11 @@ +from __future__ import annotations + import datetime -from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union, cast +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, TypeVar, cast +from uuid import UUID from attrs import define as _attrs_define -from dateutil.parser import isoparse from ..models.an_all_of_enum import AnAllOfEnum from ..models.an_enum import AnEnum @@ -24,56 +27,62 @@ class AModel: Attributes: an_enum_value (AnEnum): For testing Enums in all the ways they can be used an_allof_enum_with_overridden_default (AnAllOfEnum): Default: AnAllOfEnum.OVERRIDDEN_DEFAULT. - a_camel_date_time (Union[datetime.date, datetime.datetime]): + a_camel_date_time (datetime.date | datetime.datetime): a_date (datetime.date): - a_nullable_date (Union[None, datetime.date]): - required_nullable (Union[None, str]): + a_nullable_date (datetime.date | None): + a_uuid (UUID): + a_nullable_uuid (None | UUID): Default: UUID('07EF8B4D-AA09-4FFA-898D-C710796AFF41'). + required_nullable (None | str): required_not_nullable (str): - one_of_models (Union['FreeFormModel', 'ModelWithUnionProperty', Any]): - nullable_one_of_models (Union['FreeFormModel', 'ModelWithUnionProperty', None]): + one_of_models (Any | FreeFormModel | ModelWithUnionProperty): + nullable_one_of_models (FreeFormModel | ModelWithUnionProperty | None): model (ModelWithUnionProperty): - nullable_model (Union['ModelWithUnionProperty', None]): - any_value (Union[Unset, Any]): - an_optional_allof_enum (Union[Unset, AnAllOfEnum]): - nested_list_of_enums (Union[Unset, List[List[DifferentEnum]]]): - a_not_required_date (Union[Unset, datetime.date]): - attr_1_leading_digit (Union[Unset, str]): - attr_leading_underscore (Union[Unset, str]): - not_required_nullable (Union[None, Unset, str]): - not_required_not_nullable (Union[Unset, str]): - not_required_one_of_models (Union['FreeFormModel', 'ModelWithUnionProperty', Unset]): - not_required_nullable_one_of_models (Union['FreeFormModel', 'ModelWithUnionProperty', None, Unset, str]): - not_required_model (Union[Unset, ModelWithUnionProperty]): - not_required_nullable_model (Union['ModelWithUnionProperty', None, Unset]): + nullable_model (ModelWithUnionProperty | None): + any_value (Any | Unset): Default: 'default'. + an_optional_allof_enum (AnAllOfEnum | Unset): + nested_list_of_enums (list[list[DifferentEnum]] | Unset): + a_not_required_date (datetime.date | Unset): + a_not_required_uuid (UUID | Unset): + attr_1_leading_digit (str | Unset): + attr_leading_underscore (str | Unset): + not_required_nullable (None | str | Unset): + not_required_not_nullable (str | Unset): + not_required_one_of_models (FreeFormModel | ModelWithUnionProperty | Unset): + not_required_nullable_one_of_models (FreeFormModel | ModelWithUnionProperty | None | str | Unset): + not_required_model (ModelWithUnionProperty | Unset): + not_required_nullable_model (ModelWithUnionProperty | None | Unset): """ an_enum_value: AnEnum - a_camel_date_time: Union[datetime.date, datetime.datetime] + a_camel_date_time: datetime.date | datetime.datetime a_date: datetime.date - a_nullable_date: Union[None, datetime.date] - required_nullable: Union[None, str] + a_nullable_date: datetime.date | None + a_uuid: UUID + required_nullable: None | str required_not_nullable: str - one_of_models: Union["FreeFormModel", "ModelWithUnionProperty", Any] - nullable_one_of_models: Union["FreeFormModel", "ModelWithUnionProperty", None] - model: "ModelWithUnionProperty" - nullable_model: Union["ModelWithUnionProperty", None] + one_of_models: Any | FreeFormModel | ModelWithUnionProperty + nullable_one_of_models: FreeFormModel | ModelWithUnionProperty | None + model: ModelWithUnionProperty + nullable_model: ModelWithUnionProperty | None an_allof_enum_with_overridden_default: AnAllOfEnum = AnAllOfEnum.OVERRIDDEN_DEFAULT - any_value: Union[Unset, Any] = UNSET - an_optional_allof_enum: Union[Unset, AnAllOfEnum] = UNSET - nested_list_of_enums: Union[Unset, List[List[DifferentEnum]]] = UNSET - a_not_required_date: Union[Unset, datetime.date] = UNSET - attr_1_leading_digit: Union[Unset, str] = UNSET - attr_leading_underscore: Union[Unset, str] = UNSET - not_required_nullable: Union[None, Unset, str] = UNSET - not_required_not_nullable: Union[Unset, str] = UNSET - not_required_one_of_models: Union["FreeFormModel", "ModelWithUnionProperty", Unset] = UNSET - not_required_nullable_one_of_models: Union["FreeFormModel", "ModelWithUnionProperty", None, Unset, str] = UNSET - not_required_model: Union[Unset, "ModelWithUnionProperty"] = UNSET - not_required_nullable_model: Union["ModelWithUnionProperty", None, Unset] = UNSET - - def to_dict(self) -> Dict[str, Any]: - from ..models.free_form_model import FreeFormModel - from ..models.model_with_union_property import ModelWithUnionProperty + a_nullable_uuid: None | UUID = UUID("07EF8B4D-AA09-4FFA-898D-C710796AFF41") + any_value: Any | Unset = "default" + an_optional_allof_enum: AnAllOfEnum | Unset = UNSET + nested_list_of_enums: list[list[DifferentEnum]] | Unset = UNSET + a_not_required_date: datetime.date | Unset = UNSET + a_not_required_uuid: UUID | Unset = UNSET + attr_1_leading_digit: str | Unset = UNSET + attr_leading_underscore: str | Unset = UNSET + not_required_nullable: None | str | Unset = UNSET + not_required_not_nullable: str | Unset = UNSET + not_required_one_of_models: FreeFormModel | ModelWithUnionProperty | Unset = UNSET + not_required_nullable_one_of_models: FreeFormModel | ModelWithUnionProperty | None | str | Unset = UNSET + not_required_model: ModelWithUnionProperty | Unset = UNSET + not_required_nullable_model: ModelWithUnionProperty | None | Unset = UNSET + + def to_dict(self) -> dict[str, Any]: + from ..models.free_form_model import FreeFormModel # noqa: PLC0415 + from ..models.model_with_union_property import ModelWithUnionProperty # noqa: PLC0415 an_enum_value = self.an_enum_value.value @@ -87,18 +96,26 @@ def to_dict(self) -> Dict[str, Any]: a_date = self.a_date.isoformat() - a_nullable_date: Union[None, str] + a_nullable_date: None | str if isinstance(self.a_nullable_date, datetime.date): a_nullable_date = self.a_nullable_date.isoformat() else: a_nullable_date = self.a_nullable_date - required_nullable: Union[None, str] + a_uuid = str(self.a_uuid) + + a_nullable_uuid: None | str + if isinstance(self.a_nullable_uuid, UUID): + a_nullable_uuid = str(self.a_nullable_uuid) + else: + a_nullable_uuid = self.a_nullable_uuid + + required_nullable: None | str required_nullable = self.required_nullable required_not_nullable = self.required_not_nullable - one_of_models: Union[Any, Dict[str, Any]] + one_of_models: Any | dict[str, Any] if isinstance(self.one_of_models, FreeFormModel): one_of_models = self.one_of_models.to_dict() elif isinstance(self.one_of_models, ModelWithUnionProperty): @@ -106,7 +123,7 @@ def to_dict(self) -> Dict[str, Any]: else: one_of_models = self.one_of_models - nullable_one_of_models: Union[Dict[str, Any], None] + nullable_one_of_models: dict[str, Any] | None if isinstance(self.nullable_one_of_models, FreeFormModel): nullable_one_of_models = self.nullable_one_of_models.to_dict() elif isinstance(self.nullable_one_of_models, ModelWithUnionProperty): @@ -116,7 +133,7 @@ def to_dict(self) -> Dict[str, Any]: model = self.model.to_dict() - nullable_model: Union[Dict[str, Any], None] + nullable_model: dict[str, Any] | None if isinstance(self.nullable_model, ModelWithUnionProperty): nullable_model = self.nullable_model.to_dict() else: @@ -124,11 +141,11 @@ def to_dict(self) -> Dict[str, Any]: any_value = self.any_value - an_optional_allof_enum: Union[Unset, str] = UNSET + an_optional_allof_enum: str | Unset = UNSET if not isinstance(self.an_optional_allof_enum, Unset): an_optional_allof_enum = self.an_optional_allof_enum.value - nested_list_of_enums: Union[Unset, List[List[str]]] = UNSET + nested_list_of_enums: list[list[str]] | Unset = UNSET if not isinstance(self.nested_list_of_enums, Unset): nested_list_of_enums = [] for nested_list_of_enums_item_data in self.nested_list_of_enums: @@ -139,15 +156,19 @@ def to_dict(self) -> Dict[str, Any]: nested_list_of_enums.append(nested_list_of_enums_item) - a_not_required_date: Union[Unset, str] = UNSET + a_not_required_date: str | Unset = UNSET if not isinstance(self.a_not_required_date, Unset): a_not_required_date = self.a_not_required_date.isoformat() + a_not_required_uuid: str | Unset = UNSET + if not isinstance(self.a_not_required_uuid, Unset): + a_not_required_uuid = str(self.a_not_required_uuid) + attr_1_leading_digit = self.attr_1_leading_digit attr_leading_underscore = self.attr_leading_underscore - not_required_nullable: Union[None, Unset, str] + not_required_nullable: None | str | Unset if isinstance(self.not_required_nullable, Unset): not_required_nullable = UNSET else: @@ -155,7 +176,7 @@ def to_dict(self) -> Dict[str, Any]: not_required_not_nullable = self.not_required_not_nullable - not_required_one_of_models: Union[Dict[str, Any], Unset] + not_required_one_of_models: dict[str, Any] | Unset if isinstance(self.not_required_one_of_models, Unset): not_required_one_of_models = UNSET elif isinstance(self.not_required_one_of_models, FreeFormModel): @@ -163,7 +184,7 @@ def to_dict(self) -> Dict[str, Any]: else: not_required_one_of_models = self.not_required_one_of_models.to_dict() - not_required_nullable_one_of_models: Union[Dict[str, Any], None, Unset, str] + not_required_nullable_one_of_models: dict[str, Any] | None | str | Unset if isinstance(self.not_required_nullable_one_of_models, Unset): not_required_nullable_one_of_models = UNSET elif isinstance(self.not_required_nullable_one_of_models, FreeFormModel): @@ -173,11 +194,11 @@ def to_dict(self) -> Dict[str, Any]: else: not_required_nullable_one_of_models = self.not_required_nullable_one_of_models - not_required_model: Union[Unset, Dict[str, Any]] = UNSET + not_required_model: dict[str, Any] | Unset = UNSET if not isinstance(self.not_required_model, Unset): not_required_model = self.not_required_model.to_dict() - not_required_nullable_model: Union[Dict[str, Any], None, Unset] + not_required_nullable_model: dict[str, Any] | None | Unset if isinstance(self.not_required_nullable_model, Unset): not_required_nullable_model = UNSET elif isinstance(self.not_required_nullable_model, ModelWithUnionProperty): @@ -185,7 +206,8 @@ def to_dict(self) -> Dict[str, Any]: else: not_required_nullable_model = self.not_required_nullable_model - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} + field_dict.update( { "an_enum_value": an_enum_value, @@ -193,6 +215,8 @@ def to_dict(self) -> Dict[str, Any]: "aCamelDateTime": a_camel_date_time, "a_date": a_date, "a_nullable_date": a_nullable_date, + "a_uuid": a_uuid, + "a_nullable_uuid": a_nullable_uuid, "required_nullable": required_nullable, "required_not_nullable": required_not_nullable, "one_of_models": one_of_models, @@ -209,6 +233,8 @@ def to_dict(self) -> Dict[str, Any]: field_dict["nested_list_of_enums"] = nested_list_of_enums if a_not_required_date is not UNSET: field_dict["a_not_required_date"] = a_not_required_date + if a_not_required_uuid is not UNSET: + field_dict["a_not_required_uuid"] = a_not_required_uuid if attr_1_leading_digit is not UNSET: field_dict["1_leading_digit"] = attr_1_leading_digit if attr_leading_underscore is not UNSET: @@ -229,66 +255,83 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - from ..models.free_form_model import FreeFormModel - from ..models.model_with_union_property import ModelWithUnionProperty + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + from ..models.free_form_model import FreeFormModel # noqa: PLC0415 + from ..models.model_with_union_property import ModelWithUnionProperty # noqa: PLC0415 - d = src_dict.copy() + d = dict(src_dict) an_enum_value = AnEnum(d.pop("an_enum_value")) an_allof_enum_with_overridden_default = AnAllOfEnum(d.pop("an_allof_enum_with_overridden_default")) - def _parse_a_camel_date_time(data: object) -> Union[datetime.date, datetime.datetime]: + def _parse_a_camel_date_time(data: object) -> datetime.date | datetime.datetime: try: if not isinstance(data, str): raise TypeError() - a_camel_date_time_type_0 = isoparse(data) + a_camel_date_time_type_0 = datetime.datetime.fromisoformat(data) return a_camel_date_time_type_0 - except: # noqa: E722 + except (TypeError, ValueError, AttributeError, KeyError): pass if not isinstance(data, str): raise TypeError() - a_camel_date_time_type_1 = isoparse(data).date() + a_camel_date_time_type_1 = datetime.date.fromisoformat(data) return a_camel_date_time_type_1 a_camel_date_time = _parse_a_camel_date_time(d.pop("aCamelDateTime")) - a_date = isoparse(d.pop("a_date")).date() + a_date = datetime.date.fromisoformat(d.pop("a_date")) - def _parse_a_nullable_date(data: object) -> Union[None, datetime.date]: + def _parse_a_nullable_date(data: object) -> datetime.date | None: if data is None: return data try: if not isinstance(data, str): raise TypeError() - a_nullable_date_type_0 = isoparse(data).date() + a_nullable_date_type_0 = datetime.date.fromisoformat(data) return a_nullable_date_type_0 - except: # noqa: E722 + except (TypeError, ValueError, AttributeError, KeyError): pass - return cast(Union[None, datetime.date], data) + return cast(datetime.date | None, data) a_nullable_date = _parse_a_nullable_date(d.pop("a_nullable_date")) - def _parse_required_nullable(data: object) -> Union[None, str]: + a_uuid = UUID(d.pop("a_uuid")) + + def _parse_a_nullable_uuid(data: object) -> None | UUID: + if data is None: + return data + try: + if not isinstance(data, str): + raise TypeError() + a_nullable_uuid_type_0 = UUID(data) + + return a_nullable_uuid_type_0 + except (TypeError, ValueError, AttributeError, KeyError): + pass + return cast(None | UUID, data) + + a_nullable_uuid = _parse_a_nullable_uuid(d.pop("a_nullable_uuid")) + + def _parse_required_nullable(data: object) -> None | str: if data is None: return data - return cast(Union[None, str], data) + return cast(None | str, data) required_nullable = _parse_required_nullable(d.pop("required_nullable")) required_not_nullable = d.pop("required_not_nullable") - def _parse_one_of_models(data: object) -> Union["FreeFormModel", "ModelWithUnionProperty", Any]: + def _parse_one_of_models(data: object) -> Any | FreeFormModel | ModelWithUnionProperty: try: if not isinstance(data, dict): raise TypeError() one_of_models_type_0 = FreeFormModel.from_dict(data) return one_of_models_type_0 - except: # noqa: E722 + except (TypeError, ValueError, AttributeError, KeyError): pass try: if not isinstance(data, dict): @@ -296,13 +339,13 @@ def _parse_one_of_models(data: object) -> Union["FreeFormModel", "ModelWithUnion one_of_models_type_1 = ModelWithUnionProperty.from_dict(data) return one_of_models_type_1 - except: # noqa: E722 + except (TypeError, ValueError, AttributeError, KeyError): pass - return cast(Union["FreeFormModel", "ModelWithUnionProperty", Any], data) + return cast(Any | FreeFormModel | ModelWithUnionProperty, data) one_of_models = _parse_one_of_models(d.pop("one_of_models")) - def _parse_nullable_one_of_models(data: object) -> Union["FreeFormModel", "ModelWithUnionProperty", None]: + def _parse_nullable_one_of_models(data: object) -> FreeFormModel | ModelWithUnionProperty | None: if data is None: return data try: @@ -311,7 +354,7 @@ def _parse_nullable_one_of_models(data: object) -> Union["FreeFormModel", "Model nullable_one_of_models_type_0 = FreeFormModel.from_dict(data) return nullable_one_of_models_type_0 - except: # noqa: E722 + except (TypeError, ValueError, AttributeError, KeyError): pass try: if not isinstance(data, dict): @@ -319,15 +362,15 @@ def _parse_nullable_one_of_models(data: object) -> Union["FreeFormModel", "Model nullable_one_of_models_type_1 = ModelWithUnionProperty.from_dict(data) return nullable_one_of_models_type_1 - except: # noqa: E722 + except (TypeError, ValueError, AttributeError, KeyError): pass - return cast(Union["FreeFormModel", "ModelWithUnionProperty", None], data) + return cast(FreeFormModel | ModelWithUnionProperty | None, data) nullable_one_of_models = _parse_nullable_one_of_models(d.pop("nullable_one_of_models")) model = ModelWithUnionProperty.from_dict(d.pop("model")) - def _parse_nullable_model(data: object) -> Union["ModelWithUnionProperty", None]: + def _parse_nullable_model(data: object) -> ModelWithUnionProperty | None: if data is None: return data try: @@ -336,56 +379,65 @@ def _parse_nullable_model(data: object) -> Union["ModelWithUnionProperty", None] nullable_model_type_1 = ModelWithUnionProperty.from_dict(data) return nullable_model_type_1 - except: # noqa: E722 + except (TypeError, ValueError, AttributeError, KeyError): pass - return cast(Union["ModelWithUnionProperty", None], data) + return cast(ModelWithUnionProperty | None, data) nullable_model = _parse_nullable_model(d.pop("nullable_model")) any_value = d.pop("any_value", UNSET) _an_optional_allof_enum = d.pop("an_optional_allof_enum", UNSET) - an_optional_allof_enum: Union[Unset, AnAllOfEnum] + an_optional_allof_enum: AnAllOfEnum | Unset if isinstance(_an_optional_allof_enum, Unset): an_optional_allof_enum = UNSET else: an_optional_allof_enum = AnAllOfEnum(_an_optional_allof_enum) - nested_list_of_enums = [] _nested_list_of_enums = d.pop("nested_list_of_enums", UNSET) - for nested_list_of_enums_item_data in _nested_list_of_enums or []: - nested_list_of_enums_item = [] - _nested_list_of_enums_item = nested_list_of_enums_item_data - for nested_list_of_enums_item_item_data in _nested_list_of_enums_item: - nested_list_of_enums_item_item = DifferentEnum(nested_list_of_enums_item_item_data) + nested_list_of_enums: list[list[DifferentEnum]] | Unset = UNSET + if _nested_list_of_enums is not UNSET: + nested_list_of_enums = [] + for nested_list_of_enums_item_data in _nested_list_of_enums: + nested_list_of_enums_item = [] + _nested_list_of_enums_item = nested_list_of_enums_item_data + for nested_list_of_enums_item_item_data in _nested_list_of_enums_item: + nested_list_of_enums_item_item = DifferentEnum(nested_list_of_enums_item_item_data) - nested_list_of_enums_item.append(nested_list_of_enums_item_item) + nested_list_of_enums_item.append(nested_list_of_enums_item_item) - nested_list_of_enums.append(nested_list_of_enums_item) + nested_list_of_enums.append(nested_list_of_enums_item) _a_not_required_date = d.pop("a_not_required_date", UNSET) - a_not_required_date: Union[Unset, datetime.date] + a_not_required_date: datetime.date | Unset if isinstance(_a_not_required_date, Unset): a_not_required_date = UNSET else: - a_not_required_date = isoparse(_a_not_required_date).date() + a_not_required_date = datetime.date.fromisoformat(_a_not_required_date) + + _a_not_required_uuid = d.pop("a_not_required_uuid", UNSET) + a_not_required_uuid: UUID | Unset + if isinstance(_a_not_required_uuid, Unset): + a_not_required_uuid = UNSET + else: + a_not_required_uuid = UUID(_a_not_required_uuid) attr_1_leading_digit = d.pop("1_leading_digit", UNSET) attr_leading_underscore = d.pop("_leading_underscore", UNSET) - def _parse_not_required_nullable(data: object) -> Union[None, Unset, str]: + def _parse_not_required_nullable(data: object) -> None | str | Unset: if data is None: return data if isinstance(data, Unset): return data - return cast(Union[None, Unset, str], data) + return cast(None | str | Unset, data) not_required_nullable = _parse_not_required_nullable(d.pop("not_required_nullable", UNSET)) not_required_not_nullable = d.pop("not_required_not_nullable", UNSET) - def _parse_not_required_one_of_models(data: object) -> Union["FreeFormModel", "ModelWithUnionProperty", Unset]: + def _parse_not_required_one_of_models(data: object) -> FreeFormModel | ModelWithUnionProperty | Unset: if isinstance(data, Unset): return data try: @@ -394,7 +446,7 @@ def _parse_not_required_one_of_models(data: object) -> Union["FreeFormModel", "M not_required_one_of_models_type_0 = FreeFormModel.from_dict(data) return not_required_one_of_models_type_0 - except: # noqa: E722 + except (TypeError, ValueError, AttributeError, KeyError): pass if not isinstance(data, dict): raise TypeError() @@ -406,7 +458,7 @@ def _parse_not_required_one_of_models(data: object) -> Union["FreeFormModel", "M def _parse_not_required_nullable_one_of_models( data: object, - ) -> Union["FreeFormModel", "ModelWithUnionProperty", None, Unset, str]: + ) -> FreeFormModel | ModelWithUnionProperty | None | str | Unset: if data is None: return data if isinstance(data, Unset): @@ -417,7 +469,7 @@ def _parse_not_required_nullable_one_of_models( not_required_nullable_one_of_models_type_0 = FreeFormModel.from_dict(data) return not_required_nullable_one_of_models_type_0 - except: # noqa: E722 + except (TypeError, ValueError, AttributeError, KeyError): pass try: if not isinstance(data, dict): @@ -425,22 +477,22 @@ def _parse_not_required_nullable_one_of_models( not_required_nullable_one_of_models_type_1 = ModelWithUnionProperty.from_dict(data) return not_required_nullable_one_of_models_type_1 - except: # noqa: E722 + except (TypeError, ValueError, AttributeError, KeyError): pass - return cast(Union["FreeFormModel", "ModelWithUnionProperty", None, Unset, str], data) + return cast(FreeFormModel | ModelWithUnionProperty | None | str | Unset, data) not_required_nullable_one_of_models = _parse_not_required_nullable_one_of_models( d.pop("not_required_nullable_one_of_models", UNSET) ) _not_required_model = d.pop("not_required_model", UNSET) - not_required_model: Union[Unset, ModelWithUnionProperty] + not_required_model: ModelWithUnionProperty | Unset if isinstance(_not_required_model, Unset): not_required_model = UNSET else: not_required_model = ModelWithUnionProperty.from_dict(_not_required_model) - def _parse_not_required_nullable_model(data: object) -> Union["ModelWithUnionProperty", None, Unset]: + def _parse_not_required_nullable_model(data: object) -> ModelWithUnionProperty | None | Unset: if data is None: return data if isinstance(data, Unset): @@ -451,9 +503,9 @@ def _parse_not_required_nullable_model(data: object) -> Union["ModelWithUnionPro not_required_nullable_model_type_1 = ModelWithUnionProperty.from_dict(data) return not_required_nullable_model_type_1 - except: # noqa: E722 + except (TypeError, ValueError, AttributeError, KeyError): pass - return cast(Union["ModelWithUnionProperty", None, Unset], data) + return cast(ModelWithUnionProperty | None | Unset, data) not_required_nullable_model = _parse_not_required_nullable_model(d.pop("not_required_nullable_model", UNSET)) @@ -463,6 +515,8 @@ def _parse_not_required_nullable_model(data: object) -> Union["ModelWithUnionPro a_camel_date_time=a_camel_date_time, a_date=a_date, a_nullable_date=a_nullable_date, + a_uuid=a_uuid, + a_nullable_uuid=a_nullable_uuid, required_nullable=required_nullable, required_not_nullable=required_not_nullable, one_of_models=one_of_models, @@ -473,6 +527,7 @@ def _parse_not_required_nullable_model(data: object) -> Union["ModelWithUnionPro an_optional_allof_enum=an_optional_allof_enum, nested_list_of_enums=nested_list_of_enums, a_not_required_date=a_not_required_date, + a_not_required_uuid=a_not_required_uuid, attr_1_leading_digit=attr_1_leading_digit, attr_leading_underscore=attr_leading_underscore, not_required_nullable=not_required_nullable, diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/a_model_with_properties_reference_that_are_not_object.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/a_model_with_properties_reference_that_are_not_object.py similarity index 78% rename from end_to_end_tests/golden-record/my_test_api_client/models/a_model_with_properties_reference_that_are_not_object.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/a_model_with_properties_reference_that_are_not_object.py index 88ffd349f..4c31bf01b 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/a_model_with_properties_reference_that_are_not_object.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/a_model_with_properties_reference_that_are_not_object.py @@ -1,10 +1,12 @@ +from __future__ import annotations + import datetime +from collections.abc import Mapping from io import BytesIO -from typing import Any, Dict, List, Type, TypeVar, cast +from typing import Any, TypeVar, cast from attrs import define as _attrs_define from attrs import field as _attrs_field -from dateutil.parser import isoparse from ..models.an_enum import AnEnum from ..types import File @@ -16,26 +18,26 @@ class AModelWithPropertiesReferenceThatAreNotObject: """ Attributes: - enum_properties_ref (List[AnEnum]): - str_properties_ref (List[str]): - date_properties_ref (List[datetime.date]): - datetime_properties_ref (List[datetime.datetime]): - int32_properties_ref (List[int]): - int64_properties_ref (List[int]): - float_properties_ref (List[float]): - double_properties_ref (List[float]): - file_properties_ref (List[File]): - bytestream_properties_ref (List[str]): - enum_properties (List[AnEnum]): - str_properties (List[str]): - date_properties (List[datetime.date]): - datetime_properties (List[datetime.datetime]): - int32_properties (List[int]): - int64_properties (List[int]): - float_properties (List[float]): - double_properties (List[float]): - file_properties (List[File]): - bytestream_properties (List[str]): + enum_properties_ref (list[AnEnum]): + str_properties_ref (list[str]): + date_properties_ref (list[datetime.date]): + datetime_properties_ref (list[datetime.datetime]): + int32_properties_ref (list[int]): + int64_properties_ref (list[int]): + float_properties_ref (list[float]): + double_properties_ref (list[float]): + file_properties_ref (list[File]): + bytestream_properties_ref (list[str]): + enum_properties (list[AnEnum]): + str_properties (list[str]): + date_properties (list[datetime.date]): + datetime_properties (list[datetime.datetime]): + int32_properties (list[int]): + int64_properties (list[int]): + float_properties (list[float]): + double_properties (list[float]): + file_properties (list[File]): + bytestream_properties (list[str]): enum_property_ref (AnEnum): For testing Enums in all the ways they can be used str_property_ref (str): date_property_ref (datetime.date): @@ -48,26 +50,26 @@ class AModelWithPropertiesReferenceThatAreNotObject: bytestream_property_ref (str): """ - enum_properties_ref: List[AnEnum] - str_properties_ref: List[str] - date_properties_ref: List[datetime.date] - datetime_properties_ref: List[datetime.datetime] - int32_properties_ref: List[int] - int64_properties_ref: List[int] - float_properties_ref: List[float] - double_properties_ref: List[float] - file_properties_ref: List[File] - bytestream_properties_ref: List[str] - enum_properties: List[AnEnum] - str_properties: List[str] - date_properties: List[datetime.date] - datetime_properties: List[datetime.datetime] - int32_properties: List[int] - int64_properties: List[int] - float_properties: List[float] - double_properties: List[float] - file_properties: List[File] - bytestream_properties: List[str] + enum_properties_ref: list[AnEnum] + str_properties_ref: list[str] + date_properties_ref: list[datetime.date] + datetime_properties_ref: list[datetime.datetime] + int32_properties_ref: list[int] + int64_properties_ref: list[int] + float_properties_ref: list[float] + double_properties_ref: list[float] + file_properties_ref: list[File] + bytestream_properties_ref: list[str] + enum_properties: list[AnEnum] + str_properties: list[str] + date_properties: list[datetime.date] + datetime_properties: list[datetime.datetime] + int32_properties: list[int] + int64_properties: list[int] + float_properties: list[float] + double_properties: list[float] + file_properties: list[File] + bytestream_properties: list[str] enum_property_ref: AnEnum str_property_ref: str date_property_ref: datetime.date @@ -78,9 +80,9 @@ class AModelWithPropertiesReferenceThatAreNotObject: double_property_ref: float file_property_ref: File bytestream_property_ref: str - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: enum_properties_ref = [] for componentsschemas_an_other_array_of_enum_item_data in self.enum_properties_ref: componentsschemas_an_other_array_of_enum_item = componentsschemas_an_other_array_of_enum_item_data.value @@ -173,7 +175,7 @@ def to_dict(self) -> Dict[str, Any]: bytestream_property_ref = self.bytestream_property_ref - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update( { @@ -213,8 +215,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) enum_properties_ref = [] _enum_properties_ref = d.pop("enum_properties_ref") for componentsschemas_an_other_array_of_enum_item_data in _enum_properties_ref: @@ -222,33 +224,33 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: enum_properties_ref.append(componentsschemas_an_other_array_of_enum_item) - str_properties_ref = cast(List[str], d.pop("str_properties_ref")) + str_properties_ref = cast(list[str], d.pop("str_properties_ref")) date_properties_ref = [] _date_properties_ref = d.pop("date_properties_ref") for componentsschemas_an_other_array_of_date_item_data in _date_properties_ref: - componentsschemas_an_other_array_of_date_item = isoparse( + componentsschemas_an_other_array_of_date_item = datetime.date.fromisoformat( componentsschemas_an_other_array_of_date_item_data - ).date() + ) date_properties_ref.append(componentsschemas_an_other_array_of_date_item) datetime_properties_ref = [] _datetime_properties_ref = d.pop("datetime_properties_ref") for componentsschemas_an_other_array_of_date_time_item_data in _datetime_properties_ref: - componentsschemas_an_other_array_of_date_time_item = isoparse( + componentsschemas_an_other_array_of_date_time_item = datetime.datetime.fromisoformat( componentsschemas_an_other_array_of_date_time_item_data ) datetime_properties_ref.append(componentsschemas_an_other_array_of_date_time_item) - int32_properties_ref = cast(List[int], d.pop("int32_properties_ref")) + int32_properties_ref = cast(list[int], d.pop("int32_properties_ref")) - int64_properties_ref = cast(List[int], d.pop("int64_properties_ref")) + int64_properties_ref = cast(list[int], d.pop("int64_properties_ref")) - float_properties_ref = cast(List[float], d.pop("float_properties_ref")) + float_properties_ref = cast(list[float], d.pop("float_properties_ref")) - double_properties_ref = cast(List[float], d.pop("double_properties_ref")) + double_properties_ref = cast(list[float], d.pop("double_properties_ref")) file_properties_ref = [] _file_properties_ref = d.pop("file_properties_ref") @@ -259,7 +261,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: file_properties_ref.append(componentsschemas_an_other_array_of_file_item) - bytestream_properties_ref = cast(List[str], d.pop("bytestream_properties_ref")) + bytestream_properties_ref = cast(list[str], d.pop("bytestream_properties_ref")) enum_properties = [] _enum_properties = d.pop("enum_properties") @@ -268,29 +270,33 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: enum_properties.append(componentsschemas_an_array_of_enum_item) - str_properties = cast(List[str], d.pop("str_properties")) + str_properties = cast(list[str], d.pop("str_properties")) date_properties = [] _date_properties = d.pop("date_properties") for componentsschemas_an_array_of_date_item_data in _date_properties: - componentsschemas_an_array_of_date_item = isoparse(componentsschemas_an_array_of_date_item_data).date() + componentsschemas_an_array_of_date_item = datetime.date.fromisoformat( + componentsschemas_an_array_of_date_item_data + ) date_properties.append(componentsschemas_an_array_of_date_item) datetime_properties = [] _datetime_properties = d.pop("datetime_properties") for componentsschemas_an_array_of_date_time_item_data in _datetime_properties: - componentsschemas_an_array_of_date_time_item = isoparse(componentsschemas_an_array_of_date_time_item_data) + componentsschemas_an_array_of_date_time_item = datetime.datetime.fromisoformat( + componentsschemas_an_array_of_date_time_item_data + ) datetime_properties.append(componentsschemas_an_array_of_date_time_item) - int32_properties = cast(List[int], d.pop("int32_properties")) + int32_properties = cast(list[int], d.pop("int32_properties")) - int64_properties = cast(List[int], d.pop("int64_properties")) + int64_properties = cast(list[int], d.pop("int64_properties")) - float_properties = cast(List[float], d.pop("float_properties")) + float_properties = cast(list[float], d.pop("float_properties")) - double_properties = cast(List[float], d.pop("double_properties")) + double_properties = cast(list[float], d.pop("double_properties")) file_properties = [] _file_properties = d.pop("file_properties") @@ -301,15 +307,15 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: file_properties.append(componentsschemas_an_array_of_file_item) - bytestream_properties = cast(List[str], d.pop("bytestream_properties")) + bytestream_properties = cast(list[str], d.pop("bytestream_properties")) enum_property_ref = AnEnum(d.pop("enum_property_ref")) str_property_ref = d.pop("str_property_ref") - date_property_ref = isoparse(d.pop("date_property_ref")).date() + date_property_ref = datetime.date.fromisoformat(d.pop("date_property_ref")) - datetime_property_ref = isoparse(d.pop("datetime_property_ref")) + datetime_property_ref = datetime.datetime.fromisoformat(d.pop("datetime_property_ref")) int32_property_ref = d.pop("int32_property_ref") @@ -360,7 +366,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return a_model_with_properties_reference_that_are_not_object @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/all_of_has_properties_but_no_type.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/all_of_has_properties_but_no_type.py similarity index 66% rename from end_to_end_tests/golden-record/my_test_api_client/models/all_of_has_properties_but_no_type.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/all_of_has_properties_but_no_type.py index 245a1b04a..3295dcf26 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/all_of_has_properties_but_no_type.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/all_of_has_properties_but_no_type.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -13,46 +16,46 @@ class AllOfHasPropertiesButNoType: """ Attributes: - a_sub_property (Union[Unset, str]): - type (Union[Unset, str]): - type_enum (Union[Unset, AllOfHasPropertiesButNoTypeTypeEnum]): + a_sub_property (str | Unset): + type_ (str | Unset): + type_enum (AllOfHasPropertiesButNoTypeTypeEnum | Unset): """ - a_sub_property: Union[Unset, str] = UNSET - type: Union[Unset, str] = UNSET - type_enum: Union[Unset, AllOfHasPropertiesButNoTypeTypeEnum] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + a_sub_property: str | Unset = UNSET + type_: str | Unset = UNSET + type_enum: AllOfHasPropertiesButNoTypeTypeEnum | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: a_sub_property = self.a_sub_property - type = self.type + type_ = self.type_ - type_enum: Union[Unset, int] = UNSET + type_enum: int | Unset = UNSET if not isinstance(self.type_enum, Unset): type_enum = self.type_enum.value - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if a_sub_property is not UNSET: field_dict["a_sub_property"] = a_sub_property - if type is not UNSET: - field_dict["type"] = type + if type_ is not UNSET: + field_dict["type"] = type_ if type_enum is not UNSET: field_dict["type_enum"] = type_enum return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) a_sub_property = d.pop("a_sub_property", UNSET) - type = d.pop("type", UNSET) + type_ = d.pop("type", UNSET) _type_enum = d.pop("type_enum", UNSET) - type_enum: Union[Unset, AllOfHasPropertiesButNoTypeTypeEnum] + type_enum: AllOfHasPropertiesButNoTypeTypeEnum | Unset if isinstance(_type_enum, Unset): type_enum = UNSET else: @@ -60,7 +63,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: all_of_has_properties_but_no_type = cls( a_sub_property=a_sub_property, - type=type, + type_=type_, type_enum=type_enum, ) @@ -68,7 +71,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return all_of_has_properties_but_no_type @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/all_of_has_properties_but_no_type_type_enum.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/all_of_has_properties_but_no_type_type_enum.py similarity index 100% rename from end_to_end_tests/golden-record/my_test_api_client/models/all_of_has_properties_but_no_type_type_enum.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/all_of_has_properties_but_no_type_type_enum.py diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/all_of_required_base.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/all_of_required_base.py new file mode 100644 index 000000000..b06f45c30 --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/all_of_required_base.py @@ -0,0 +1,70 @@ +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="AllOfRequiredBase") + + +@_attrs_define +class AllOfRequiredBase: + """ + Attributes: + bar (str | Unset): The bar property + baz (str | Unset): The baz property + """ + + bar: str | Unset = UNSET + baz: str | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + bar = self.bar + + baz = self.baz + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update({}) + if bar is not UNSET: + field_dict["bar"] = bar + if baz is not UNSET: + field_dict["baz"] = baz + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + bar = d.pop("bar", UNSET) + + baz = d.pop("baz", UNSET) + + all_of_required_base = cls( + bar=bar, + baz=baz, + ) + + all_of_required_base.additional_properties = d + return all_of_required_base + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/all_of_required_derived.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/all_of_required_derived.py new file mode 100644 index 000000000..505334d6b --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/all_of_required_derived.py @@ -0,0 +1,72 @@ +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="AllOfRequiredDerived") + + +@_attrs_define +class AllOfRequiredDerived: + """ + Attributes: + bar (str): The bar property + baz (str | Unset): The baz property + """ + + bar: str + baz: str | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + bar = self.bar + + baz = self.baz + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "bar": bar, + } + ) + if baz is not UNSET: + field_dict["baz"] = baz + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + bar = d.pop("bar") + + baz = d.pop("baz", UNSET) + + all_of_required_derived = cls( + bar=bar, + baz=baz, + ) + + all_of_required_derived.additional_properties = d + return all_of_required_derived + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/all_of_sub_model.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/all_of_sub_model.py similarity index 65% rename from end_to_end_tests/golden-record/my_test_api_client/models/all_of_sub_model.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/all_of_sub_model.py index 550b9b9c4..65b6f97c6 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/all_of_sub_model.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/all_of_sub_model.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -13,46 +16,46 @@ class AllOfSubModel: """ Attributes: - a_sub_property (Union[Unset, str]): - type (Union[Unset, str]): - type_enum (Union[Unset, AllOfSubModelTypeEnum]): + a_sub_property (str | Unset): + type_ (str | Unset): + type_enum (AllOfSubModelTypeEnum | Unset): """ - a_sub_property: Union[Unset, str] = UNSET - type: Union[Unset, str] = UNSET - type_enum: Union[Unset, AllOfSubModelTypeEnum] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + a_sub_property: str | Unset = UNSET + type_: str | Unset = UNSET + type_enum: AllOfSubModelTypeEnum | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: a_sub_property = self.a_sub_property - type = self.type + type_ = self.type_ - type_enum: Union[Unset, int] = UNSET + type_enum: int | Unset = UNSET if not isinstance(self.type_enum, Unset): type_enum = self.type_enum.value - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if a_sub_property is not UNSET: field_dict["a_sub_property"] = a_sub_property - if type is not UNSET: - field_dict["type"] = type + if type_ is not UNSET: + field_dict["type"] = type_ if type_enum is not UNSET: field_dict["type_enum"] = type_enum return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) a_sub_property = d.pop("a_sub_property", UNSET) - type = d.pop("type", UNSET) + type_ = d.pop("type", UNSET) _type_enum = d.pop("type_enum", UNSET) - type_enum: Union[Unset, AllOfSubModelTypeEnum] + type_enum: AllOfSubModelTypeEnum | Unset if isinstance(_type_enum, Unset): type_enum = UNSET else: @@ -60,7 +63,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: all_of_sub_model = cls( a_sub_property=a_sub_property, - type=type, + type_=type_, type_enum=type_enum, ) @@ -68,7 +71,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return all_of_sub_model @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/all_of_sub_model_type_enum.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/all_of_sub_model_type_enum.py similarity index 100% rename from end_to_end_tests/golden-record/my_test_api_client/models/all_of_sub_model_type_enum.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/all_of_sub_model_type_enum.py diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/an_all_of_enum.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_all_of_enum.py similarity index 76% rename from end_to_end_tests/golden-record/my_test_api_client/models/an_all_of_enum.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_all_of_enum.py index 3aef48f8f..1439e1781 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/an_all_of_enum.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_all_of_enum.py @@ -1,7 +1,7 @@ -from enum import Enum +from enum import StrEnum -class AnAllOfEnum(str, Enum): +class AnAllOfEnum(StrEnum): A_DEFAULT = "a_default" BAR = "bar" FOO = "foo" diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/an_array_with_a_circular_ref_in_items_object_a_item.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_array_with_a_circular_ref_in_items_object_a_item.py similarity index 60% rename from end_to_end_tests/golden-record/my_test_api_client/models/an_array_with_a_circular_ref_in_items_object_a_item.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_array_with_a_circular_ref_in_items_object_a_item.py index b7792fefc..77453bf2c 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/an_array_with_a_circular_ref_in_items_object_a_item.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_array_with_a_circular_ref_in_items_object_a_item.py @@ -1,4 +1,7 @@ -from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -16,14 +19,14 @@ class AnArrayWithACircularRefInItemsObjectAItem: """ Attributes: - circular (Union[Unset, List['AnArrayWithACircularRefInItemsObjectBItem']]): + circular (list[AnArrayWithACircularRefInItemsObjectBItem] | Unset): """ - circular: Union[Unset, List["AnArrayWithACircularRefInItemsObjectBItem"]] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + circular: list[AnArrayWithACircularRefInItemsObjectBItem] | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: - circular: Union[Unset, List[Dict[str, Any]]] = UNSET + def to_dict(self) -> dict[str, Any]: + circular: list[dict[str, Any]] | Unset = UNSET if not isinstance(self.circular, Unset): circular = [] for componentsschemas_an_array_with_a_circular_ref_in_items_object_b_item_data in self.circular: @@ -32,7 +35,7 @@ def to_dict(self) -> Dict[str, Any]: ) circular.append(componentsschemas_an_array_with_a_circular_ref_in_items_object_b_item) - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if circular is not UNSET: @@ -41,22 +44,24 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: from ..models.an_array_with_a_circular_ref_in_items_object_b_item import ( - AnArrayWithACircularRefInItemsObjectBItem, + AnArrayWithACircularRefInItemsObjectBItem, # noqa: PLC0415 ) - d = src_dict.copy() - circular = [] + d = dict(src_dict) _circular = d.pop("circular", UNSET) - for componentsschemas_an_array_with_a_circular_ref_in_items_object_b_item_data in _circular or []: - componentsschemas_an_array_with_a_circular_ref_in_items_object_b_item = ( - AnArrayWithACircularRefInItemsObjectBItem.from_dict( - componentsschemas_an_array_with_a_circular_ref_in_items_object_b_item_data + circular: list[AnArrayWithACircularRefInItemsObjectBItem] | Unset = UNSET + if _circular is not UNSET: + circular = [] + for componentsschemas_an_array_with_a_circular_ref_in_items_object_b_item_data in _circular: + componentsschemas_an_array_with_a_circular_ref_in_items_object_b_item = ( + AnArrayWithACircularRefInItemsObjectBItem.from_dict( + componentsschemas_an_array_with_a_circular_ref_in_items_object_b_item_data + ) ) - ) - circular.append(componentsschemas_an_array_with_a_circular_ref_in_items_object_b_item) + circular.append(componentsschemas_an_array_with_a_circular_ref_in_items_object_b_item) an_array_with_a_circular_ref_in_items_object_a_item = cls( circular=circular, @@ -66,7 +71,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return an_array_with_a_circular_ref_in_items_object_a_item @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/an_array_with_a_circular_ref_in_items_object_additional_properties_a_item.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_array_with_a_circular_ref_in_items_object_additional_properties_a_item.py similarity index 81% rename from end_to_end_tests/golden-record/my_test_api_client/models/an_array_with_a_circular_ref_in_items_object_additional_properties_a_item.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_array_with_a_circular_ref_in_items_object_additional_properties_a_item.py index c505553b6..8a90d0eb3 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/an_array_with_a_circular_ref_in_items_object_additional_properties_a_item.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_array_with_a_circular_ref_in_items_object_additional_properties_a_item.py @@ -1,4 +1,7 @@ -from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar +from __future__ import annotations + +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -14,14 +17,13 @@ @_attrs_define class AnArrayWithACircularRefInItemsObjectAdditionalPropertiesAItem: - """ """ - - additional_properties: Dict[str, List["AnArrayWithACircularRefInItemsObjectAdditionalPropertiesBItem"]] = ( + additional_properties: dict[str, list[AnArrayWithACircularRefInItemsObjectAdditionalPropertiesBItem]] = ( _attrs_field(init=False, factory=dict) ) - def to_dict(self) -> Dict[str, Any]: - field_dict: Dict[str, Any] = {} + def to_dict(self) -> dict[str, Any]: + + field_dict: dict[str, Any] = {} for prop_name, prop in self.additional_properties.items(): field_dict[prop_name] = [] for ( @@ -35,12 +37,12 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: from ..models.an_array_with_a_circular_ref_in_items_object_additional_properties_b_item import ( - AnArrayWithACircularRefInItemsObjectAdditionalPropertiesBItem, + AnArrayWithACircularRefInItemsObjectAdditionalPropertiesBItem, # noqa: PLC0415 ) - d = src_dict.copy() + d = dict(src_dict) an_array_with_a_circular_ref_in_items_object_additional_properties_a_item = cls() additional_properties = {} @@ -68,15 +70,13 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return an_array_with_a_circular_ref_in_items_object_additional_properties_a_item @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) - def __getitem__(self, key: str) -> List["AnArrayWithACircularRefInItemsObjectAdditionalPropertiesBItem"]: + def __getitem__(self, key: str) -> list[AnArrayWithACircularRefInItemsObjectAdditionalPropertiesBItem]: return self.additional_properties[key] - def __setitem__( - self, key: str, value: List["AnArrayWithACircularRefInItemsObjectAdditionalPropertiesBItem"] - ) -> None: + def __setitem__(self, key: str, value: list[AnArrayWithACircularRefInItemsObjectAdditionalPropertiesBItem]) -> None: self.additional_properties[key] = value def __delitem__(self, key: str) -> None: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/an_array_with_a_circular_ref_in_items_object_additional_properties_b_item.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_array_with_a_circular_ref_in_items_object_additional_properties_b_item.py similarity index 81% rename from end_to_end_tests/golden-record/my_test_api_client/models/an_array_with_a_circular_ref_in_items_object_additional_properties_b_item.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_array_with_a_circular_ref_in_items_object_additional_properties_b_item.py index 9d2dc9827..e2b3e7ef5 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/an_array_with_a_circular_ref_in_items_object_additional_properties_b_item.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_array_with_a_circular_ref_in_items_object_additional_properties_b_item.py @@ -1,4 +1,7 @@ -from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar +from __future__ import annotations + +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -14,14 +17,13 @@ @_attrs_define class AnArrayWithACircularRefInItemsObjectAdditionalPropertiesBItem: - """ """ - - additional_properties: Dict[str, List["AnArrayWithACircularRefInItemsObjectAdditionalPropertiesAItem"]] = ( + additional_properties: dict[str, list[AnArrayWithACircularRefInItemsObjectAdditionalPropertiesAItem]] = ( _attrs_field(init=False, factory=dict) ) - def to_dict(self) -> Dict[str, Any]: - field_dict: Dict[str, Any] = {} + def to_dict(self) -> dict[str, Any]: + + field_dict: dict[str, Any] = {} for prop_name, prop in self.additional_properties.items(): field_dict[prop_name] = [] for ( @@ -35,12 +37,12 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: from ..models.an_array_with_a_circular_ref_in_items_object_additional_properties_a_item import ( - AnArrayWithACircularRefInItemsObjectAdditionalPropertiesAItem, + AnArrayWithACircularRefInItemsObjectAdditionalPropertiesAItem, # noqa: PLC0415 ) - d = src_dict.copy() + d = dict(src_dict) an_array_with_a_circular_ref_in_items_object_additional_properties_b_item = cls() additional_properties = {} @@ -68,15 +70,13 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return an_array_with_a_circular_ref_in_items_object_additional_properties_b_item @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) - def __getitem__(self, key: str) -> List["AnArrayWithACircularRefInItemsObjectAdditionalPropertiesAItem"]: + def __getitem__(self, key: str) -> list[AnArrayWithACircularRefInItemsObjectAdditionalPropertiesAItem]: return self.additional_properties[key] - def __setitem__( - self, key: str, value: List["AnArrayWithACircularRefInItemsObjectAdditionalPropertiesAItem"] - ) -> None: + def __setitem__(self, key: str, value: list[AnArrayWithACircularRefInItemsObjectAdditionalPropertiesAItem]) -> None: self.additional_properties[key] = value def __delitem__(self, key: str) -> None: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/an_array_with_a_circular_ref_in_items_object_b_item.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_array_with_a_circular_ref_in_items_object_b_item.py similarity index 60% rename from end_to_end_tests/golden-record/my_test_api_client/models/an_array_with_a_circular_ref_in_items_object_b_item.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_array_with_a_circular_ref_in_items_object_b_item.py index 622d5d999..e4039d6be 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/an_array_with_a_circular_ref_in_items_object_b_item.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_array_with_a_circular_ref_in_items_object_b_item.py @@ -1,4 +1,7 @@ -from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -16,14 +19,14 @@ class AnArrayWithACircularRefInItemsObjectBItem: """ Attributes: - circular (Union[Unset, List['AnArrayWithACircularRefInItemsObjectAItem']]): + circular (list[AnArrayWithACircularRefInItemsObjectAItem] | Unset): """ - circular: Union[Unset, List["AnArrayWithACircularRefInItemsObjectAItem"]] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + circular: list[AnArrayWithACircularRefInItemsObjectAItem] | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: - circular: Union[Unset, List[Dict[str, Any]]] = UNSET + def to_dict(self) -> dict[str, Any]: + circular: list[dict[str, Any]] | Unset = UNSET if not isinstance(self.circular, Unset): circular = [] for componentsschemas_an_array_with_a_circular_ref_in_items_object_a_item_data in self.circular: @@ -32,7 +35,7 @@ def to_dict(self) -> Dict[str, Any]: ) circular.append(componentsschemas_an_array_with_a_circular_ref_in_items_object_a_item) - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if circular is not UNSET: @@ -41,22 +44,24 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: from ..models.an_array_with_a_circular_ref_in_items_object_a_item import ( - AnArrayWithACircularRefInItemsObjectAItem, + AnArrayWithACircularRefInItemsObjectAItem, # noqa: PLC0415 ) - d = src_dict.copy() - circular = [] + d = dict(src_dict) _circular = d.pop("circular", UNSET) - for componentsschemas_an_array_with_a_circular_ref_in_items_object_a_item_data in _circular or []: - componentsschemas_an_array_with_a_circular_ref_in_items_object_a_item = ( - AnArrayWithACircularRefInItemsObjectAItem.from_dict( - componentsschemas_an_array_with_a_circular_ref_in_items_object_a_item_data + circular: list[AnArrayWithACircularRefInItemsObjectAItem] | Unset = UNSET + if _circular is not UNSET: + circular = [] + for componentsschemas_an_array_with_a_circular_ref_in_items_object_a_item_data in _circular: + componentsschemas_an_array_with_a_circular_ref_in_items_object_a_item = ( + AnArrayWithACircularRefInItemsObjectAItem.from_dict( + componentsschemas_an_array_with_a_circular_ref_in_items_object_a_item_data + ) ) - ) - circular.append(componentsschemas_an_array_with_a_circular_ref_in_items_object_a_item) + circular.append(componentsschemas_an_array_with_a_circular_ref_in_items_object_a_item) an_array_with_a_circular_ref_in_items_object_b_item = cls( circular=circular, @@ -66,7 +71,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return an_array_with_a_circular_ref_in_items_object_b_item @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/an_array_with_a_recursive_ref_in_items_object_additional_properties_item.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_array_with_a_recursive_ref_in_items_object_additional_properties_item.py similarity index 79% rename from end_to_end_tests/golden-record/my_test_api_client/models/an_array_with_a_recursive_ref_in_items_object_additional_properties_item.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_array_with_a_recursive_ref_in_items_object_additional_properties_item.py index e19cfc052..12aba8360 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/an_array_with_a_recursive_ref_in_items_object_additional_properties_item.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_array_with_a_recursive_ref_in_items_object_additional_properties_item.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -8,14 +11,13 @@ @_attrs_define class AnArrayWithARecursiveRefInItemsObjectAdditionalPropertiesItem: - """ """ - - additional_properties: Dict[str, List["AnArrayWithARecursiveRefInItemsObjectAdditionalPropertiesItem"]] = ( + additional_properties: dict[str, list[AnArrayWithARecursiveRefInItemsObjectAdditionalPropertiesItem]] = ( _attrs_field(init=False, factory=dict) ) - def to_dict(self) -> Dict[str, Any]: - field_dict: Dict[str, Any] = {} + def to_dict(self) -> dict[str, Any]: + + field_dict: dict[str, Any] = {} for prop_name, prop in self.additional_properties.items(): field_dict[prop_name] = [] for componentsschemas_an_array_with_a_recursive_ref_in_items_object_additional_properties_item_data in prop: @@ -27,8 +29,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) an_array_with_a_recursive_ref_in_items_object_additional_properties_item = cls() additional_properties = {} @@ -56,15 +58,13 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return an_array_with_a_recursive_ref_in_items_object_additional_properties_item @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) - def __getitem__(self, key: str) -> List["AnArrayWithARecursiveRefInItemsObjectAdditionalPropertiesItem"]: + def __getitem__(self, key: str) -> list[AnArrayWithARecursiveRefInItemsObjectAdditionalPropertiesItem]: return self.additional_properties[key] - def __setitem__( - self, key: str, value: List["AnArrayWithARecursiveRefInItemsObjectAdditionalPropertiesItem"] - ) -> None: + def __setitem__(self, key: str, value: list[AnArrayWithARecursiveRefInItemsObjectAdditionalPropertiesItem]) -> None: self.additional_properties[key] = value def __delitem__(self, key: str) -> None: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/an_array_with_a_recursive_ref_in_items_object_item.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_array_with_a_recursive_ref_in_items_object_item.py similarity index 59% rename from end_to_end_tests/golden-record/my_test_api_client/models/an_array_with_a_recursive_ref_in_items_object_item.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_array_with_a_recursive_ref_in_items_object_item.py index 6b12b9b5d..581a9f622 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/an_array_with_a_recursive_ref_in_items_object_item.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_array_with_a_recursive_ref_in_items_object_item.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -12,14 +15,14 @@ class AnArrayWithARecursiveRefInItemsObjectItem: """ Attributes: - recursive (Union[Unset, List['AnArrayWithARecursiveRefInItemsObjectItem']]): + recursive (list[AnArrayWithARecursiveRefInItemsObjectItem] | Unset): """ - recursive: Union[Unset, List["AnArrayWithARecursiveRefInItemsObjectItem"]] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + recursive: list[AnArrayWithARecursiveRefInItemsObjectItem] | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: - recursive: Union[Unset, List[Dict[str, Any]]] = UNSET + def to_dict(self) -> dict[str, Any]: + recursive: list[dict[str, Any]] | Unset = UNSET if not isinstance(self.recursive, Unset): recursive = [] for componentsschemas_an_array_with_a_recursive_ref_in_items_object_item_data in self.recursive: @@ -28,7 +31,7 @@ def to_dict(self) -> Dict[str, Any]: ) recursive.append(componentsschemas_an_array_with_a_recursive_ref_in_items_object_item) - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if recursive is not UNSET: @@ -37,18 +40,20 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() - recursive = [] + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) _recursive = d.pop("recursive", UNSET) - for componentsschemas_an_array_with_a_recursive_ref_in_items_object_item_data in _recursive or []: - componentsschemas_an_array_with_a_recursive_ref_in_items_object_item = ( - AnArrayWithARecursiveRefInItemsObjectItem.from_dict( - componentsschemas_an_array_with_a_recursive_ref_in_items_object_item_data + recursive: list[AnArrayWithARecursiveRefInItemsObjectItem] | Unset = UNSET + if _recursive is not UNSET: + recursive = [] + for componentsschemas_an_array_with_a_recursive_ref_in_items_object_item_data in _recursive: + componentsschemas_an_array_with_a_recursive_ref_in_items_object_item = ( + AnArrayWithARecursiveRefInItemsObjectItem.from_dict( + componentsschemas_an_array_with_a_recursive_ref_in_items_object_item_data + ) ) - ) - recursive.append(componentsschemas_an_array_with_a_recursive_ref_in_items_object_item) + recursive.append(componentsschemas_an_array_with_a_recursive_ref_in_items_object_item) an_array_with_a_recursive_ref_in_items_object_item = cls( recursive=recursive, @@ -58,7 +63,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return an_array_with_a_recursive_ref_in_items_object_item @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/an_enum.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_enum.py similarity index 73% rename from end_to_end_tests/golden-record/my_test_api_client/models/an_enum.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_enum.py index c266d0763..fe9c407d8 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/an_enum.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_enum.py @@ -1,7 +1,7 @@ -from enum import Enum +from enum import StrEnum -class AnEnum(str, Enum): +class AnEnum(StrEnum): FIRST_VALUE = "FIRST_VALUE" SECOND_VALUE = "SECOND_VALUE" diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/an_enum_with_null.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_enum_with_null.py similarity index 69% rename from end_to_end_tests/golden-record/my_test_api_client/models/an_enum_with_null.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_enum_with_null.py index b1d6611e0..002ee3667 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/an_enum_with_null.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_enum_with_null.py @@ -1,7 +1,7 @@ -from enum import Enum +from enum import StrEnum -class AnEnumWithNull(str, Enum): +class AnEnumWithNull(StrEnum): FIRST_VALUE = "FIRST_VALUE" SECOND_VALUE = "SECOND_VALUE" diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/an_int_enum.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_int_enum.py similarity index 100% rename from end_to_end_tests/golden-record/my_test_api_client/models/an_int_enum.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/an_int_enum.py diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/another_all_of_sub_model.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/another_all_of_sub_model.py similarity index 62% rename from end_to_end_tests/golden-record/my_test_api_client/models/another_all_of_sub_model.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/another_all_of_sub_model.py index fde2bb6f8..7c58d1a9c 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/another_all_of_sub_model.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/another_all_of_sub_model.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -14,53 +17,53 @@ class AnotherAllOfSubModel: """ Attributes: - another_sub_property (Union[Unset, str]): - type (Union[Unset, AnotherAllOfSubModelType]): - type_enum (Union[Unset, AnotherAllOfSubModelTypeEnum]): + another_sub_property (str | Unset): + type_ (AnotherAllOfSubModelType | Unset): + type_enum (AnotherAllOfSubModelTypeEnum | Unset): """ - another_sub_property: Union[Unset, str] = UNSET - type: Union[Unset, AnotherAllOfSubModelType] = UNSET - type_enum: Union[Unset, AnotherAllOfSubModelTypeEnum] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + another_sub_property: str | Unset = UNSET + type_: AnotherAllOfSubModelType | Unset = UNSET + type_enum: AnotherAllOfSubModelTypeEnum | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: another_sub_property = self.another_sub_property - type: Union[Unset, str] = UNSET - if not isinstance(self.type, Unset): - type = self.type.value + type_: str | Unset = UNSET + if not isinstance(self.type_, Unset): + type_ = self.type_.value - type_enum: Union[Unset, int] = UNSET + type_enum: int | Unset = UNSET if not isinstance(self.type_enum, Unset): type_enum = self.type_enum.value - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if another_sub_property is not UNSET: field_dict["another_sub_property"] = another_sub_property - if type is not UNSET: - field_dict["type"] = type + if type_ is not UNSET: + field_dict["type"] = type_ if type_enum is not UNSET: field_dict["type_enum"] = type_enum return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) another_sub_property = d.pop("another_sub_property", UNSET) - _type = d.pop("type", UNSET) - type: Union[Unset, AnotherAllOfSubModelType] - if isinstance(_type, Unset): - type = UNSET + _type_ = d.pop("type", UNSET) + type_: AnotherAllOfSubModelType | Unset + if isinstance(_type_, Unset): + type_ = UNSET else: - type = AnotherAllOfSubModelType(_type) + type_ = AnotherAllOfSubModelType(_type_) _type_enum = d.pop("type_enum", UNSET) - type_enum: Union[Unset, AnotherAllOfSubModelTypeEnum] + type_enum: AnotherAllOfSubModelTypeEnum | Unset if isinstance(_type_enum, Unset): type_enum = UNSET else: @@ -68,7 +71,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: another_all_of_sub_model = cls( another_sub_property=another_sub_property, - type=type, + type_=type_, type_enum=type_enum, ) @@ -76,7 +79,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return another_all_of_sub_model @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/another_all_of_sub_model_type.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/another_all_of_sub_model_type.py similarity index 57% rename from end_to_end_tests/golden-record/my_test_api_client/models/another_all_of_sub_model_type.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/another_all_of_sub_model_type.py index b2e82aa7c..61d3a0c57 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/another_all_of_sub_model_type.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/another_all_of_sub_model_type.py @@ -1,7 +1,7 @@ -from enum import Enum +from enum import StrEnum -class AnotherAllOfSubModelType(str, Enum): +class AnotherAllOfSubModelType(StrEnum): SUBMODEL = "submodel" def __str__(self) -> str: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/another_all_of_sub_model_type_enum.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/another_all_of_sub_model_type_enum.py similarity index 100% rename from end_to_end_tests/golden-record/my_test_api_client/models/another_all_of_sub_model_type_enum.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/another_all_of_sub_model_type_enum.py diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/body_upload_file_tests_upload_post.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/body_upload_file_tests_upload_post.py new file mode 100644 index 000000000..0b8caee2c --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/body_upload_file_tests_upload_post.py @@ -0,0 +1,415 @@ +from __future__ import annotations + +import datetime +import json +from collections.abc import Mapping +from io import BytesIO +from typing import TYPE_CHECKING, Any, TypeVar, cast + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from .. import types +from ..models.different_enum import DifferentEnum +from ..types import UNSET, File, FileTypes, Unset + +if TYPE_CHECKING: + from ..models.a_form_data import AFormData + from ..models.body_upload_file_tests_upload_post_additional_property import ( + BodyUploadFileTestsUploadPostAdditionalProperty, + ) + from ..models.body_upload_file_tests_upload_post_some_nullable_object import ( + BodyUploadFileTestsUploadPostSomeNullableObject, + ) + from ..models.body_upload_file_tests_upload_post_some_object import BodyUploadFileTestsUploadPostSomeObject + from ..models.body_upload_file_tests_upload_post_some_optional_object import ( + BodyUploadFileTestsUploadPostSomeOptionalObject, + ) + + +T = TypeVar("T", bound="BodyUploadFileTestsUploadPost") + + +@_attrs_define +class BodyUploadFileTestsUploadPost: + """ + Attributes: + some_file (File): + some_required_number (float): + some_object (BodyUploadFileTestsUploadPostSomeObject): + some_nullable_object (BodyUploadFileTestsUploadPostSomeNullableObject | None): + some_optional_file (File | Unset): + some_string (str | Unset): Default: 'some_default_string'. + a_datetime (datetime.datetime | Unset): + a_date (datetime.date | Unset): + some_number (float | Unset): + some_nullable_number (float | None | Unset): + some_int_array (list[int | None] | Unset): + some_array (list[AFormData] | None | Unset): + some_optional_object (BodyUploadFileTestsUploadPostSomeOptionalObject | Unset): + some_enum (DifferentEnum | Unset): An enumeration. + """ + + some_file: File + some_required_number: float + some_object: BodyUploadFileTestsUploadPostSomeObject + some_nullable_object: BodyUploadFileTestsUploadPostSomeNullableObject | None + some_optional_file: File | Unset = UNSET + some_string: str | Unset = "some_default_string" + a_datetime: datetime.datetime | Unset = UNSET + a_date: datetime.date | Unset = UNSET + some_number: float | Unset = UNSET + some_nullable_number: float | None | Unset = UNSET + some_int_array: list[int | None] | Unset = UNSET + some_array: list[AFormData] | None | Unset = UNSET + some_optional_object: BodyUploadFileTestsUploadPostSomeOptionalObject | Unset = UNSET + some_enum: DifferentEnum | Unset = UNSET + additional_properties: dict[str, BodyUploadFileTestsUploadPostAdditionalProperty] = _attrs_field( + init=False, factory=dict + ) + + def to_dict(self) -> dict[str, Any]: + from ..models.body_upload_file_tests_upload_post_some_nullable_object import ( + BodyUploadFileTestsUploadPostSomeNullableObject, # noqa: PLC0415 + ) + + some_file = self.some_file.to_tuple() + + some_required_number = self.some_required_number + + some_object = self.some_object.to_dict() + + some_nullable_object: dict[str, Any] | None + if isinstance(self.some_nullable_object, BodyUploadFileTestsUploadPostSomeNullableObject): + some_nullable_object = self.some_nullable_object.to_dict() + else: + some_nullable_object = self.some_nullable_object + + some_optional_file: FileTypes | Unset = UNSET + if not isinstance(self.some_optional_file, Unset): + some_optional_file = self.some_optional_file.to_tuple() + + some_string = self.some_string + + a_datetime: str | Unset = UNSET + if not isinstance(self.a_datetime, Unset): + a_datetime = self.a_datetime.isoformat() + + a_date: str | Unset = UNSET + if not isinstance(self.a_date, Unset): + a_date = self.a_date.isoformat() + + some_number = self.some_number + + some_nullable_number: float | None | Unset + if isinstance(self.some_nullable_number, Unset): + some_nullable_number = UNSET + else: + some_nullable_number = self.some_nullable_number + + some_int_array: list[int | None] | Unset = UNSET + if not isinstance(self.some_int_array, Unset): + some_int_array = [] + for some_int_array_item_data in self.some_int_array: + some_int_array_item: int | None + some_int_array_item = some_int_array_item_data + some_int_array.append(some_int_array_item) + + some_array: list[dict[str, Any]] | None | Unset + if isinstance(self.some_array, Unset): + some_array = UNSET + elif isinstance(self.some_array, list): + some_array = [] + for some_array_type_0_item_data in self.some_array: + some_array_type_0_item = some_array_type_0_item_data.to_dict() + some_array.append(some_array_type_0_item) + + else: + some_array = self.some_array + + some_optional_object: dict[str, Any] | Unset = UNSET + if not isinstance(self.some_optional_object, Unset): + some_optional_object = self.some_optional_object.to_dict() + + some_enum: str | Unset = UNSET + if not isinstance(self.some_enum, Unset): + some_enum = self.some_enum.value + + field_dict: dict[str, Any] = {} + for prop_name, prop in self.additional_properties.items(): + field_dict[prop_name] = prop.to_dict() + + field_dict.update( + { + "some_file": some_file, + "some_required_number": some_required_number, + "some_object": some_object, + "some_nullable_object": some_nullable_object, + } + ) + if some_optional_file is not UNSET: + field_dict["some_optional_file"] = some_optional_file + if some_string is not UNSET: + field_dict["some_string"] = some_string + if a_datetime is not UNSET: + field_dict["a_datetime"] = a_datetime + if a_date is not UNSET: + field_dict["a_date"] = a_date + if some_number is not UNSET: + field_dict["some_number"] = some_number + if some_nullable_number is not UNSET: + field_dict["some_nullable_number"] = some_nullable_number + if some_int_array is not UNSET: + field_dict["some_int_array"] = some_int_array + if some_array is not UNSET: + field_dict["some_array"] = some_array + if some_optional_object is not UNSET: + field_dict["some_optional_object"] = some_optional_object + if some_enum is not UNSET: + field_dict["some_enum"] = some_enum + + return field_dict + + def to_multipart(self) -> types.RequestFiles: + from ..models.body_upload_file_tests_upload_post_some_nullable_object import ( + BodyUploadFileTestsUploadPostSomeNullableObject, # noqa: PLC0415 + ) + + files: types.RequestFiles = [] + + files.append(("some_file", self.some_file.to_tuple())) + + files.append(("some_required_number", (None, str(self.some_required_number).encode(), "text/plain"))) + + files.append(("some_object", (None, json.dumps(self.some_object.to_dict()).encode(), "application/json"))) + + if isinstance(self.some_nullable_object, BodyUploadFileTestsUploadPostSomeNullableObject): + files.append( + ( + "some_nullable_object", + (None, json.dumps(self.some_nullable_object.to_dict()).encode(), "application/json"), + ) + ) + else: + files.append(("some_nullable_object", (None, str(self.some_nullable_object).encode(), "text/plain"))) + + if not isinstance(self.some_optional_file, Unset): + files.append(("some_optional_file", self.some_optional_file.to_tuple())) + + if not isinstance(self.some_string, Unset): + files.append(("some_string", (None, str(self.some_string).encode(), "text/plain"))) + + if not isinstance(self.a_datetime, Unset): + files.append(("a_datetime", (None, self.a_datetime.isoformat().encode(), "text/plain"))) + + if not isinstance(self.a_date, Unset): + files.append(("a_date", (None, self.a_date.isoformat().encode(), "text/plain"))) + + if not isinstance(self.some_number, Unset): + files.append(("some_number", (None, str(self.some_number).encode(), "text/plain"))) + + if not isinstance(self.some_nullable_number, Unset): + if isinstance(self.some_nullable_number, float): + files.append(("some_nullable_number", (None, str(self.some_nullable_number).encode(), "text/plain"))) + else: + files.append(("some_nullable_number", (None, str(self.some_nullable_number).encode(), "text/plain"))) + + if not isinstance(self.some_int_array, Unset): + for some_int_array_item_element in self.some_int_array: + if isinstance(some_int_array_item_element, int): + files.append(("some_int_array", (None, str(some_int_array_item_element).encode(), "text/plain"))) + else: + files.append(("some_int_array", (None, str(some_int_array_item_element).encode(), "text/plain"))) + + if not isinstance(self.some_array, Unset): + if isinstance(self.some_array, list): + for some_array_type_0_item_element in self.some_array: + files.append( + ( + "some_array", + (None, json.dumps(some_array_type_0_item_element.to_dict()).encode(), "application/json"), + ) + ) + else: + files.append(("some_array", (None, str(self.some_array).encode(), "text/plain"))) + + if not isinstance(self.some_optional_object, Unset): + files.append( + ( + "some_optional_object", + (None, json.dumps(self.some_optional_object.to_dict()).encode(), "application/json"), + ) + ) + + if not isinstance(self.some_enum, Unset): + files.append(("some_enum", (None, str(self.some_enum.value).encode(), "text/plain"))) + + for prop_name, prop in self.additional_properties.items(): + files.append((prop_name, (None, json.dumps(prop.to_dict()).encode(), "application/json"))) + + return files + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + from ..models.a_form_data import AFormData # noqa: PLC0415 + from ..models.body_upload_file_tests_upload_post_additional_property import ( + BodyUploadFileTestsUploadPostAdditionalProperty, # noqa: PLC0415 + ) + from ..models.body_upload_file_tests_upload_post_some_nullable_object import ( + BodyUploadFileTestsUploadPostSomeNullableObject, # noqa: PLC0415 + ) + from ..models.body_upload_file_tests_upload_post_some_object import ( + BodyUploadFileTestsUploadPostSomeObject, # noqa: PLC0415 + ) + from ..models.body_upload_file_tests_upload_post_some_optional_object import ( + BodyUploadFileTestsUploadPostSomeOptionalObject, # noqa: PLC0415 + ) + + d = dict(src_dict) + some_file = File(payload=BytesIO(d.pop("some_file"))) + + some_required_number = d.pop("some_required_number") + + some_object = BodyUploadFileTestsUploadPostSomeObject.from_dict(d.pop("some_object")) + + def _parse_some_nullable_object(data: object) -> BodyUploadFileTestsUploadPostSomeNullableObject | None: + if data is None: + return data + try: + if not isinstance(data, dict): + raise TypeError() + some_nullable_object_type_0 = BodyUploadFileTestsUploadPostSomeNullableObject.from_dict(data) + + return some_nullable_object_type_0 + except (TypeError, ValueError, AttributeError, KeyError): + pass + return cast(BodyUploadFileTestsUploadPostSomeNullableObject | None, data) + + some_nullable_object = _parse_some_nullable_object(d.pop("some_nullable_object")) + + _some_optional_file = d.pop("some_optional_file", UNSET) + some_optional_file: File | Unset + if isinstance(_some_optional_file, Unset): + some_optional_file = UNSET + else: + some_optional_file = File(payload=BytesIO(_some_optional_file)) + + some_string = d.pop("some_string", UNSET) + + _a_datetime = d.pop("a_datetime", UNSET) + a_datetime: datetime.datetime | Unset + if isinstance(_a_datetime, Unset): + a_datetime = UNSET + else: + a_datetime = datetime.datetime.fromisoformat(_a_datetime) + + _a_date = d.pop("a_date", UNSET) + a_date: datetime.date | Unset + if isinstance(_a_date, Unset): + a_date = UNSET + else: + a_date = datetime.date.fromisoformat(_a_date) + + some_number = d.pop("some_number", UNSET) + + def _parse_some_nullable_number(data: object) -> float | None | Unset: + if data is None: + return data + if isinstance(data, Unset): + return data + return cast(float | None | Unset, data) + + some_nullable_number = _parse_some_nullable_number(d.pop("some_nullable_number", UNSET)) + + _some_int_array = d.pop("some_int_array", UNSET) + some_int_array: list[int | None] | Unset = UNSET + if _some_int_array is not UNSET: + some_int_array = [] + for some_int_array_item_data in _some_int_array: + + def _parse_some_int_array_item(data: object) -> int | None: + if data is None: + return data + return cast(int | None, data) + + some_int_array_item = _parse_some_int_array_item(some_int_array_item_data) + + some_int_array.append(some_int_array_item) + + def _parse_some_array(data: object) -> list[AFormData] | None | Unset: + if data is None: + return data + if isinstance(data, Unset): + return data + try: + if not isinstance(data, list): + raise TypeError() + some_array_type_0 = [] + _some_array_type_0 = data + for some_array_type_0_item_data in _some_array_type_0: + some_array_type_0_item = AFormData.from_dict(some_array_type_0_item_data) + + some_array_type_0.append(some_array_type_0_item) + + return some_array_type_0 + except (TypeError, ValueError, AttributeError, KeyError): + pass + return cast(list[AFormData] | None | Unset, data) + + some_array = _parse_some_array(d.pop("some_array", UNSET)) + + _some_optional_object = d.pop("some_optional_object", UNSET) + some_optional_object: BodyUploadFileTestsUploadPostSomeOptionalObject | Unset + if isinstance(_some_optional_object, Unset): + some_optional_object = UNSET + else: + some_optional_object = BodyUploadFileTestsUploadPostSomeOptionalObject.from_dict(_some_optional_object) + + _some_enum = d.pop("some_enum", UNSET) + some_enum: DifferentEnum | Unset + if isinstance(_some_enum, Unset): + some_enum = UNSET + else: + some_enum = DifferentEnum(_some_enum) + + body_upload_file_tests_upload_post = cls( + some_file=some_file, + some_required_number=some_required_number, + some_object=some_object, + some_nullable_object=some_nullable_object, + some_optional_file=some_optional_file, + some_string=some_string, + a_datetime=a_datetime, + a_date=a_date, + some_number=some_number, + some_nullable_number=some_nullable_number, + some_int_array=some_int_array, + some_array=some_array, + some_optional_object=some_optional_object, + some_enum=some_enum, + ) + + additional_properties = {} + for prop_name, prop_dict in d.items(): + additional_property = BodyUploadFileTestsUploadPostAdditionalProperty.from_dict(prop_dict) + + additional_properties[prop_name] = additional_property + + body_upload_file_tests_upload_post.additional_properties = additional_properties + return body_upload_file_tests_upload_post + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> BodyUploadFileTestsUploadPostAdditionalProperty: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: BodyUploadFileTestsUploadPostAdditionalProperty) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post_additional_property.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/body_upload_file_tests_upload_post_additional_property.py similarity index 74% rename from end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post_additional_property.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/body_upload_file_tests_upload_post_additional_property.py index f855d9c61..160cb2542 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post_additional_property.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/body_upload_file_tests_upload_post_additional_property.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -12,16 +15,16 @@ class BodyUploadFileTestsUploadPostAdditionalProperty: """ Attributes: - foo (Union[Unset, str]): + foo (str | Unset): """ - foo: Union[Unset, str] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + foo: str | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: foo = self.foo - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if foo is not UNSET: @@ -30,8 +33,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) foo = d.pop("foo", UNSET) body_upload_file_tests_upload_post_additional_property = cls( @@ -42,7 +45,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return body_upload_file_tests_upload_post_additional_property @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post_some_nullable_object.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/body_upload_file_tests_upload_post_some_nullable_object.py similarity index 74% rename from end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post_some_nullable_object.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/body_upload_file_tests_upload_post_some_nullable_object.py index 9762b7efa..47796442d 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post_some_nullable_object.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/body_upload_file_tests_upload_post_some_nullable_object.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -12,16 +15,16 @@ class BodyUploadFileTestsUploadPostSomeNullableObject: """ Attributes: - bar (Union[Unset, str]): + bar (str | Unset): """ - bar: Union[Unset, str] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + bar: str | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: bar = self.bar - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if bar is not UNSET: @@ -30,8 +33,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) bar = d.pop("bar", UNSET) body_upload_file_tests_upload_post_some_nullable_object = cls( @@ -42,7 +45,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return body_upload_file_tests_upload_post_some_nullable_object @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post_some_object.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/body_upload_file_tests_upload_post_some_object.py similarity index 78% rename from end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post_some_object.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/body_upload_file_tests_upload_post_some_object.py index 25c2c0a6a..0cc39b78b 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post_some_object.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/body_upload_file_tests_upload_post_some_object.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -16,14 +19,14 @@ class BodyUploadFileTestsUploadPostSomeObject: num: float text: str - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: num = self.num text = self.text - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update( { @@ -35,8 +38,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) num = d.pop("num") text = d.pop("text") @@ -50,7 +53,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return body_upload_file_tests_upload_post_some_object @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post_some_optional_object.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/body_upload_file_tests_upload_post_some_optional_object.py similarity index 76% rename from end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post_some_optional_object.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/body_upload_file_tests_upload_post_some_optional_object.py index 711b34e63..f5658196c 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/body_upload_file_tests_upload_post_some_optional_object.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/body_upload_file_tests_upload_post_some_optional_object.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -14,12 +17,12 @@ class BodyUploadFileTestsUploadPostSomeOptionalObject: """ foo: str - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: foo = self.foo - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update( { @@ -30,8 +33,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) foo = d.pop("foo") body_upload_file_tests_upload_post_some_optional_object = cls( @@ -42,7 +45,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return body_upload_file_tests_upload_post_some_optional_object @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/different_enum.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/different_enum.py similarity index 67% rename from end_to_end_tests/golden-record/my_test_api_client/models/different_enum.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/different_enum.py index 6c167f25c..3aa4aa4df 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/different_enum.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/different_enum.py @@ -1,7 +1,7 @@ -from enum import Enum +from enum import StrEnum -class DifferentEnum(str, Enum): +class DifferentEnum(StrEnum): DIFFERENT = "DIFFERENT" OTHER = "OTHER" diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/extended.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/extended.py new file mode 100644 index 000000000..cf4966bf0 --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/extended.py @@ -0,0 +1,568 @@ +from __future__ import annotations + +import datetime +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, TypeVar, cast +from uuid import UUID + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..models.an_all_of_enum import AnAllOfEnum +from ..models.an_enum import AnEnum +from ..models.different_enum import DifferentEnum +from ..types import UNSET, Unset + +if TYPE_CHECKING: + from ..models.free_form_model import FreeFormModel + from ..models.model_with_union_property import ModelWithUnionProperty + + +T = TypeVar("T", bound="Extended") + + +@_attrs_define +class Extended: + """ + Attributes: + an_enum_value (AnEnum): For testing Enums in all the ways they can be used + an_allof_enum_with_overridden_default (AnAllOfEnum): Default: AnAllOfEnum.OVERRIDDEN_DEFAULT. + a_camel_date_time (datetime.date | datetime.datetime): + a_date (datetime.date): + a_nullable_date (datetime.date | None): + a_uuid (UUID): + a_nullable_uuid (None | UUID): Default: UUID('07EF8B4D-AA09-4FFA-898D-C710796AFF41'). + required_nullable (None | str): + required_not_nullable (str): + one_of_models (Any | FreeFormModel | ModelWithUnionProperty): + nullable_one_of_models (FreeFormModel | ModelWithUnionProperty | None): + model (ModelWithUnionProperty): + nullable_model (ModelWithUnionProperty | None): + any_value (Any | Unset): Default: 'default'. + an_optional_allof_enum (AnAllOfEnum | Unset): + nested_list_of_enums (list[list[DifferentEnum]] | Unset): + a_not_required_date (datetime.date | Unset): + a_not_required_uuid (UUID | Unset): + attr_1_leading_digit (str | Unset): + attr_leading_underscore (str | Unset): + not_required_nullable (None | str | Unset): + not_required_not_nullable (str | Unset): + not_required_one_of_models (FreeFormModel | ModelWithUnionProperty | Unset): + not_required_nullable_one_of_models (FreeFormModel | ModelWithUnionProperty | None | str | Unset): + not_required_model (ModelWithUnionProperty | Unset): + not_required_nullable_model (ModelWithUnionProperty | None | Unset): + from_extended (str | Unset): + """ + + an_enum_value: AnEnum + a_camel_date_time: datetime.date | datetime.datetime + a_date: datetime.date + a_nullable_date: datetime.date | None + a_uuid: UUID + required_nullable: None | str + required_not_nullable: str + one_of_models: Any | FreeFormModel | ModelWithUnionProperty + nullable_one_of_models: FreeFormModel | ModelWithUnionProperty | None + model: ModelWithUnionProperty + nullable_model: ModelWithUnionProperty | None + an_allof_enum_with_overridden_default: AnAllOfEnum = AnAllOfEnum.OVERRIDDEN_DEFAULT + a_nullable_uuid: None | UUID = UUID("07EF8B4D-AA09-4FFA-898D-C710796AFF41") + any_value: Any | Unset = "default" + an_optional_allof_enum: AnAllOfEnum | Unset = UNSET + nested_list_of_enums: list[list[DifferentEnum]] | Unset = UNSET + a_not_required_date: datetime.date | Unset = UNSET + a_not_required_uuid: UUID | Unset = UNSET + attr_1_leading_digit: str | Unset = UNSET + attr_leading_underscore: str | Unset = UNSET + not_required_nullable: None | str | Unset = UNSET + not_required_not_nullable: str | Unset = UNSET + not_required_one_of_models: FreeFormModel | ModelWithUnionProperty | Unset = UNSET + not_required_nullable_one_of_models: FreeFormModel | ModelWithUnionProperty | None | str | Unset = UNSET + not_required_model: ModelWithUnionProperty | Unset = UNSET + not_required_nullable_model: ModelWithUnionProperty | None | Unset = UNSET + from_extended: str | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + from ..models.free_form_model import FreeFormModel # noqa: PLC0415 + from ..models.model_with_union_property import ModelWithUnionProperty # noqa: PLC0415 + + an_enum_value = self.an_enum_value.value + + an_allof_enum_with_overridden_default = self.an_allof_enum_with_overridden_default.value + + a_camel_date_time: str + if isinstance(self.a_camel_date_time, datetime.datetime): + a_camel_date_time = self.a_camel_date_time.isoformat() + else: + a_camel_date_time = self.a_camel_date_time.isoformat() + + a_date = self.a_date.isoformat() + + a_nullable_date: None | str + if isinstance(self.a_nullable_date, datetime.date): + a_nullable_date = self.a_nullable_date.isoformat() + else: + a_nullable_date = self.a_nullable_date + + a_uuid = str(self.a_uuid) + + a_nullable_uuid: None | str + if isinstance(self.a_nullable_uuid, UUID): + a_nullable_uuid = str(self.a_nullable_uuid) + else: + a_nullable_uuid = self.a_nullable_uuid + + required_nullable: None | str + required_nullable = self.required_nullable + + required_not_nullable = self.required_not_nullable + + one_of_models: Any | dict[str, Any] + if isinstance(self.one_of_models, FreeFormModel): + one_of_models = self.one_of_models.to_dict() + elif isinstance(self.one_of_models, ModelWithUnionProperty): + one_of_models = self.one_of_models.to_dict() + else: + one_of_models = self.one_of_models + + nullable_one_of_models: dict[str, Any] | None + if isinstance(self.nullable_one_of_models, FreeFormModel): + nullable_one_of_models = self.nullable_one_of_models.to_dict() + elif isinstance(self.nullable_one_of_models, ModelWithUnionProperty): + nullable_one_of_models = self.nullable_one_of_models.to_dict() + else: + nullable_one_of_models = self.nullable_one_of_models + + model = self.model.to_dict() + + nullable_model: dict[str, Any] | None + if isinstance(self.nullable_model, ModelWithUnionProperty): + nullable_model = self.nullable_model.to_dict() + else: + nullable_model = self.nullable_model + + any_value = self.any_value + + an_optional_allof_enum: str | Unset = UNSET + if not isinstance(self.an_optional_allof_enum, Unset): + an_optional_allof_enum = self.an_optional_allof_enum.value + + nested_list_of_enums: list[list[str]] | Unset = UNSET + if not isinstance(self.nested_list_of_enums, Unset): + nested_list_of_enums = [] + for nested_list_of_enums_item_data in self.nested_list_of_enums: + nested_list_of_enums_item = [] + for nested_list_of_enums_item_item_data in nested_list_of_enums_item_data: + nested_list_of_enums_item_item = nested_list_of_enums_item_item_data.value + nested_list_of_enums_item.append(nested_list_of_enums_item_item) + + nested_list_of_enums.append(nested_list_of_enums_item) + + a_not_required_date: str | Unset = UNSET + if not isinstance(self.a_not_required_date, Unset): + a_not_required_date = self.a_not_required_date.isoformat() + + a_not_required_uuid: str | Unset = UNSET + if not isinstance(self.a_not_required_uuid, Unset): + a_not_required_uuid = str(self.a_not_required_uuid) + + attr_1_leading_digit = self.attr_1_leading_digit + + attr_leading_underscore = self.attr_leading_underscore + + not_required_nullable: None | str | Unset + if isinstance(self.not_required_nullable, Unset): + not_required_nullable = UNSET + else: + not_required_nullable = self.not_required_nullable + + not_required_not_nullable = self.not_required_not_nullable + + not_required_one_of_models: dict[str, Any] | Unset + if isinstance(self.not_required_one_of_models, Unset): + not_required_one_of_models = UNSET + elif isinstance(self.not_required_one_of_models, FreeFormModel): + not_required_one_of_models = self.not_required_one_of_models.to_dict() + else: + not_required_one_of_models = self.not_required_one_of_models.to_dict() + + not_required_nullable_one_of_models: dict[str, Any] | None | str | Unset + if isinstance(self.not_required_nullable_one_of_models, Unset): + not_required_nullable_one_of_models = UNSET + elif isinstance(self.not_required_nullable_one_of_models, FreeFormModel): + not_required_nullable_one_of_models = self.not_required_nullable_one_of_models.to_dict() + elif isinstance(self.not_required_nullable_one_of_models, ModelWithUnionProperty): + not_required_nullable_one_of_models = self.not_required_nullable_one_of_models.to_dict() + else: + not_required_nullable_one_of_models = self.not_required_nullable_one_of_models + + not_required_model: dict[str, Any] | Unset = UNSET + if not isinstance(self.not_required_model, Unset): + not_required_model = self.not_required_model.to_dict() + + not_required_nullable_model: dict[str, Any] | None | Unset + if isinstance(self.not_required_nullable_model, Unset): + not_required_nullable_model = UNSET + elif isinstance(self.not_required_nullable_model, ModelWithUnionProperty): + not_required_nullable_model = self.not_required_nullable_model.to_dict() + else: + not_required_nullable_model = self.not_required_nullable_model + + from_extended = self.from_extended + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "an_enum_value": an_enum_value, + "an_allof_enum_with_overridden_default": an_allof_enum_with_overridden_default, + "aCamelDateTime": a_camel_date_time, + "a_date": a_date, + "a_nullable_date": a_nullable_date, + "a_uuid": a_uuid, + "a_nullable_uuid": a_nullable_uuid, + "required_nullable": required_nullable, + "required_not_nullable": required_not_nullable, + "one_of_models": one_of_models, + "nullable_one_of_models": nullable_one_of_models, + "model": model, + "nullable_model": nullable_model, + } + ) + if any_value is not UNSET: + field_dict["any_value"] = any_value + if an_optional_allof_enum is not UNSET: + field_dict["an_optional_allof_enum"] = an_optional_allof_enum + if nested_list_of_enums is not UNSET: + field_dict["nested_list_of_enums"] = nested_list_of_enums + if a_not_required_date is not UNSET: + field_dict["a_not_required_date"] = a_not_required_date + if a_not_required_uuid is not UNSET: + field_dict["a_not_required_uuid"] = a_not_required_uuid + if attr_1_leading_digit is not UNSET: + field_dict["1_leading_digit"] = attr_1_leading_digit + if attr_leading_underscore is not UNSET: + field_dict["_leading_underscore"] = attr_leading_underscore + if not_required_nullable is not UNSET: + field_dict["not_required_nullable"] = not_required_nullable + if not_required_not_nullable is not UNSET: + field_dict["not_required_not_nullable"] = not_required_not_nullable + if not_required_one_of_models is not UNSET: + field_dict["not_required_one_of_models"] = not_required_one_of_models + if not_required_nullable_one_of_models is not UNSET: + field_dict["not_required_nullable_one_of_models"] = not_required_nullable_one_of_models + if not_required_model is not UNSET: + field_dict["not_required_model"] = not_required_model + if not_required_nullable_model is not UNSET: + field_dict["not_required_nullable_model"] = not_required_nullable_model + if from_extended is not UNSET: + field_dict["fromExtended"] = from_extended + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + from ..models.free_form_model import FreeFormModel # noqa: PLC0415 + from ..models.model_with_union_property import ModelWithUnionProperty # noqa: PLC0415 + + d = dict(src_dict) + an_enum_value = AnEnum(d.pop("an_enum_value")) + + an_allof_enum_with_overridden_default = AnAllOfEnum(d.pop("an_allof_enum_with_overridden_default")) + + def _parse_a_camel_date_time(data: object) -> datetime.date | datetime.datetime: + try: + if not isinstance(data, str): + raise TypeError() + a_camel_date_time_type_0 = datetime.datetime.fromisoformat(data) + + return a_camel_date_time_type_0 + except (TypeError, ValueError, AttributeError, KeyError): + pass + if not isinstance(data, str): + raise TypeError() + a_camel_date_time_type_1 = datetime.date.fromisoformat(data) + + return a_camel_date_time_type_1 + + a_camel_date_time = _parse_a_camel_date_time(d.pop("aCamelDateTime")) + + a_date = datetime.date.fromisoformat(d.pop("a_date")) + + def _parse_a_nullable_date(data: object) -> datetime.date | None: + if data is None: + return data + try: + if not isinstance(data, str): + raise TypeError() + a_nullable_date_type_0 = datetime.date.fromisoformat(data) + + return a_nullable_date_type_0 + except (TypeError, ValueError, AttributeError, KeyError): + pass + return cast(datetime.date | None, data) + + a_nullable_date = _parse_a_nullable_date(d.pop("a_nullable_date")) + + a_uuid = UUID(d.pop("a_uuid")) + + def _parse_a_nullable_uuid(data: object) -> None | UUID: + if data is None: + return data + try: + if not isinstance(data, str): + raise TypeError() + a_nullable_uuid_type_0 = UUID(data) + + return a_nullable_uuid_type_0 + except (TypeError, ValueError, AttributeError, KeyError): + pass + return cast(None | UUID, data) + + a_nullable_uuid = _parse_a_nullable_uuid(d.pop("a_nullable_uuid")) + + def _parse_required_nullable(data: object) -> None | str: + if data is None: + return data + return cast(None | str, data) + + required_nullable = _parse_required_nullable(d.pop("required_nullable")) + + required_not_nullable = d.pop("required_not_nullable") + + def _parse_one_of_models(data: object) -> Any | FreeFormModel | ModelWithUnionProperty: + try: + if not isinstance(data, dict): + raise TypeError() + one_of_models_type_0 = FreeFormModel.from_dict(data) + + return one_of_models_type_0 + except (TypeError, ValueError, AttributeError, KeyError): + pass + try: + if not isinstance(data, dict): + raise TypeError() + one_of_models_type_1 = ModelWithUnionProperty.from_dict(data) + + return one_of_models_type_1 + except (TypeError, ValueError, AttributeError, KeyError): + pass + return cast(Any | FreeFormModel | ModelWithUnionProperty, data) + + one_of_models = _parse_one_of_models(d.pop("one_of_models")) + + def _parse_nullable_one_of_models(data: object) -> FreeFormModel | ModelWithUnionProperty | None: + if data is None: + return data + try: + if not isinstance(data, dict): + raise TypeError() + nullable_one_of_models_type_0 = FreeFormModel.from_dict(data) + + return nullable_one_of_models_type_0 + except (TypeError, ValueError, AttributeError, KeyError): + pass + try: + if not isinstance(data, dict): + raise TypeError() + nullable_one_of_models_type_1 = ModelWithUnionProperty.from_dict(data) + + return nullable_one_of_models_type_1 + except (TypeError, ValueError, AttributeError, KeyError): + pass + return cast(FreeFormModel | ModelWithUnionProperty | None, data) + + nullable_one_of_models = _parse_nullable_one_of_models(d.pop("nullable_one_of_models")) + + model = ModelWithUnionProperty.from_dict(d.pop("model")) + + def _parse_nullable_model(data: object) -> ModelWithUnionProperty | None: + if data is None: + return data + try: + if not isinstance(data, dict): + raise TypeError() + nullable_model_type_1 = ModelWithUnionProperty.from_dict(data) + + return nullable_model_type_1 + except (TypeError, ValueError, AttributeError, KeyError): + pass + return cast(ModelWithUnionProperty | None, data) + + nullable_model = _parse_nullable_model(d.pop("nullable_model")) + + any_value = d.pop("any_value", UNSET) + + _an_optional_allof_enum = d.pop("an_optional_allof_enum", UNSET) + an_optional_allof_enum: AnAllOfEnum | Unset + if isinstance(_an_optional_allof_enum, Unset): + an_optional_allof_enum = UNSET + else: + an_optional_allof_enum = AnAllOfEnum(_an_optional_allof_enum) + + _nested_list_of_enums = d.pop("nested_list_of_enums", UNSET) + nested_list_of_enums: list[list[DifferentEnum]] | Unset = UNSET + if _nested_list_of_enums is not UNSET: + nested_list_of_enums = [] + for nested_list_of_enums_item_data in _nested_list_of_enums: + nested_list_of_enums_item = [] + _nested_list_of_enums_item = nested_list_of_enums_item_data + for nested_list_of_enums_item_item_data in _nested_list_of_enums_item: + nested_list_of_enums_item_item = DifferentEnum(nested_list_of_enums_item_item_data) + + nested_list_of_enums_item.append(nested_list_of_enums_item_item) + + nested_list_of_enums.append(nested_list_of_enums_item) + + _a_not_required_date = d.pop("a_not_required_date", UNSET) + a_not_required_date: datetime.date | Unset + if isinstance(_a_not_required_date, Unset): + a_not_required_date = UNSET + else: + a_not_required_date = datetime.date.fromisoformat(_a_not_required_date) + + _a_not_required_uuid = d.pop("a_not_required_uuid", UNSET) + a_not_required_uuid: UUID | Unset + if isinstance(_a_not_required_uuid, Unset): + a_not_required_uuid = UNSET + else: + a_not_required_uuid = UUID(_a_not_required_uuid) + + attr_1_leading_digit = d.pop("1_leading_digit", UNSET) + + attr_leading_underscore = d.pop("_leading_underscore", UNSET) + + def _parse_not_required_nullable(data: object) -> None | str | Unset: + if data is None: + return data + if isinstance(data, Unset): + return data + return cast(None | str | Unset, data) + + not_required_nullable = _parse_not_required_nullable(d.pop("not_required_nullable", UNSET)) + + not_required_not_nullable = d.pop("not_required_not_nullable", UNSET) + + def _parse_not_required_one_of_models(data: object) -> FreeFormModel | ModelWithUnionProperty | Unset: + if isinstance(data, Unset): + return data + try: + if not isinstance(data, dict): + raise TypeError() + not_required_one_of_models_type_0 = FreeFormModel.from_dict(data) + + return not_required_one_of_models_type_0 + except (TypeError, ValueError, AttributeError, KeyError): + pass + if not isinstance(data, dict): + raise TypeError() + not_required_one_of_models_type_1 = ModelWithUnionProperty.from_dict(data) + + return not_required_one_of_models_type_1 + + not_required_one_of_models = _parse_not_required_one_of_models(d.pop("not_required_one_of_models", UNSET)) + + def _parse_not_required_nullable_one_of_models( + data: object, + ) -> FreeFormModel | ModelWithUnionProperty | None | str | Unset: + if data is None: + return data + if isinstance(data, Unset): + return data + try: + if not isinstance(data, dict): + raise TypeError() + not_required_nullable_one_of_models_type_0 = FreeFormModel.from_dict(data) + + return not_required_nullable_one_of_models_type_0 + except (TypeError, ValueError, AttributeError, KeyError): + pass + try: + if not isinstance(data, dict): + raise TypeError() + not_required_nullable_one_of_models_type_1 = ModelWithUnionProperty.from_dict(data) + + return not_required_nullable_one_of_models_type_1 + except (TypeError, ValueError, AttributeError, KeyError): + pass + return cast(FreeFormModel | ModelWithUnionProperty | None | str | Unset, data) + + not_required_nullable_one_of_models = _parse_not_required_nullable_one_of_models( + d.pop("not_required_nullable_one_of_models", UNSET) + ) + + _not_required_model = d.pop("not_required_model", UNSET) + not_required_model: ModelWithUnionProperty | Unset + if isinstance(_not_required_model, Unset): + not_required_model = UNSET + else: + not_required_model = ModelWithUnionProperty.from_dict(_not_required_model) + + def _parse_not_required_nullable_model(data: object) -> ModelWithUnionProperty | None | Unset: + if data is None: + return data + if isinstance(data, Unset): + return data + try: + if not isinstance(data, dict): + raise TypeError() + not_required_nullable_model_type_1 = ModelWithUnionProperty.from_dict(data) + + return not_required_nullable_model_type_1 + except (TypeError, ValueError, AttributeError, KeyError): + pass + return cast(ModelWithUnionProperty | None | Unset, data) + + not_required_nullable_model = _parse_not_required_nullable_model(d.pop("not_required_nullable_model", UNSET)) + + from_extended = d.pop("fromExtended", UNSET) + + extended = cls( + an_enum_value=an_enum_value, + an_allof_enum_with_overridden_default=an_allof_enum_with_overridden_default, + a_camel_date_time=a_camel_date_time, + a_date=a_date, + a_nullable_date=a_nullable_date, + a_uuid=a_uuid, + a_nullable_uuid=a_nullable_uuid, + required_nullable=required_nullable, + required_not_nullable=required_not_nullable, + one_of_models=one_of_models, + nullable_one_of_models=nullable_one_of_models, + model=model, + nullable_model=nullable_model, + any_value=any_value, + an_optional_allof_enum=an_optional_allof_enum, + nested_list_of_enums=nested_list_of_enums, + a_not_required_date=a_not_required_date, + a_not_required_uuid=a_not_required_uuid, + attr_1_leading_digit=attr_1_leading_digit, + attr_leading_underscore=attr_leading_underscore, + not_required_nullable=not_required_nullable, + not_required_not_nullable=not_required_not_nullable, + not_required_one_of_models=not_required_one_of_models, + not_required_nullable_one_of_models=not_required_nullable_one_of_models, + not_required_model=not_required_model, + not_required_nullable_model=not_required_nullable_model, + from_extended=from_extended, + ) + + extended.additional_properties = d + return extended + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/free_form_model.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/free_form_model.py similarity index 68% rename from end_to_end_tests/golden-record/my_test_api_client/models/free_form_model.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/free_form_model.py index f757b10ae..b8465ef44 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/free_form_model.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/free_form_model.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -8,26 +11,25 @@ @_attrs_define class FreeFormModel: - """ """ + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + def to_dict(self) -> dict[str, Any]: - def to_dict(self) -> Dict[str, Any]: - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) free_form_model = cls() free_form_model.additional_properties = d return free_form_model @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/get_location_header_types_int_enum_header.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/get_location_header_types_int_enum_header.py similarity index 100% rename from end_to_end_tests/golden-record/my_test_api_client/models/get_location_header_types_int_enum_header.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/get_location_header_types_int_enum_header.py diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/get_location_header_types_string_enum_header.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/get_location_header_types_string_enum_header.py similarity index 59% rename from end_to_end_tests/golden-record/my_test_api_client/models/get_location_header_types_string_enum_header.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/get_location_header_types_string_enum_header.py index cce92dcde..2a5242fe5 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/get_location_header_types_string_enum_header.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/get_location_header_types_string_enum_header.py @@ -1,7 +1,7 @@ -from enum import Enum +from enum import StrEnum -class GetLocationHeaderTypesStringEnumHeader(str, Enum): +class GetLocationHeaderTypesStringEnumHeader(StrEnum): ONE = "one" THREE = "three" TWO = "two" diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/get_models_allof_response_200.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/get_models_allof_response_200.py new file mode 100644 index 000000000..9ec5f68c8 --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/get_models_allof_response_200.py @@ -0,0 +1,108 @@ +from __future__ import annotations + +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, TypeVar + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +if TYPE_CHECKING: + from ..models.a_model import AModel + from ..models.extended import Extended + + +T = TypeVar("T", bound="GetModelsAllofResponse200") + + +@_attrs_define +class GetModelsAllofResponse200: + """ + Attributes: + aliased (AModel | Unset): A Model for testing all the ways custom objects can be used + extended (Extended | Unset): + model (AModel | Unset): A Model for testing all the ways custom objects can be used + """ + + aliased: AModel | Unset = UNSET + extended: Extended | Unset = UNSET + model: AModel | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + aliased: dict[str, Any] | Unset = UNSET + if not isinstance(self.aliased, Unset): + aliased = self.aliased.to_dict() + + extended: dict[str, Any] | Unset = UNSET + if not isinstance(self.extended, Unset): + extended = self.extended.to_dict() + + model: dict[str, Any] | Unset = UNSET + if not isinstance(self.model, Unset): + model = self.model.to_dict() + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update({}) + if aliased is not UNSET: + field_dict["aliased"] = aliased + if extended is not UNSET: + field_dict["extended"] = extended + if model is not UNSET: + field_dict["model"] = model + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + from ..models.a_model import AModel # noqa: PLC0415 + from ..models.extended import Extended # noqa: PLC0415 + + d = dict(src_dict) + _aliased = d.pop("aliased", UNSET) + aliased: AModel | Unset + if isinstance(_aliased, Unset): + aliased = UNSET + else: + aliased = AModel.from_dict(_aliased) + + _extended = d.pop("extended", UNSET) + extended: Extended | Unset + if isinstance(_extended, Unset): + extended = UNSET + else: + extended = Extended.from_dict(_extended) + + _model = d.pop("model", UNSET) + model: AModel | Unset + if isinstance(_model, Unset): + model = UNSET + else: + model = AModel.from_dict(_model) + + get_models_allof_response_200 = cls( + aliased=aliased, + extended=extended, + model=model, + ) + + get_models_allof_response_200.additional_properties = d + return get_models_allof_response_200 + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/get_models_oneof_with_required_const_response_200_type_0.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/get_models_oneof_with_required_const_response_200_type_0.py new file mode 100644 index 000000000..a079b954a --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/get_models_oneof_with_required_const_response_200_type_0.py @@ -0,0 +1,74 @@ +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, Literal, TypeVar, cast + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="GetModelsOneofWithRequiredConstResponse200Type0") + + +@_attrs_define +class GetModelsOneofWithRequiredConstResponse200Type0: + """ + Attributes: + type_ (Literal['alpha']): + color (str | Unset): + """ + + type_: Literal["alpha"] + color: str | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + type_ = self.type_ + + color = self.color + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "type": type_, + } + ) + if color is not UNSET: + field_dict["color"] = color + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + type_ = cast(Literal["alpha"], d.pop("type")) + if type_ != "alpha": + raise ValueError(f"type must match const 'alpha', got '{type_}'") + + color = d.pop("color", UNSET) + + get_models_oneof_with_required_const_response_200_type_0 = cls( + type_=type_, + color=color, + ) + + get_models_oneof_with_required_const_response_200_type_0.additional_properties = d + return get_models_oneof_with_required_const_response_200_type_0 + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/get_models_oneof_with_required_const_response_200_type_1.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/get_models_oneof_with_required_const_response_200_type_1.py new file mode 100644 index 000000000..04670dcba --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/get_models_oneof_with_required_const_response_200_type_1.py @@ -0,0 +1,74 @@ +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, Literal, TypeVar, cast + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="GetModelsOneofWithRequiredConstResponse200Type1") + + +@_attrs_define +class GetModelsOneofWithRequiredConstResponse200Type1: + """ + Attributes: + type_ (Literal['beta']): + texture (str | Unset): + """ + + type_: Literal["beta"] + texture: str | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + type_ = self.type_ + + texture = self.texture + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "type": type_, + } + ) + if texture is not UNSET: + field_dict["texture"] = texture + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + type_ = cast(Literal["beta"], d.pop("type")) + if type_ != "beta": + raise ValueError(f"type must match const 'beta', got '{type_}'") + + texture = d.pop("texture", UNSET) + + get_models_oneof_with_required_const_response_200_type_1 = cls( + type_=type_, + texture=texture, + ) + + get_models_oneof_with_required_const_response_200_type_1.additional_properties = d + return get_models_oneof_with_required_const_response_200_type_1 + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/http_validation_error.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/http_validation_error.py similarity index 50% rename from end_to_end_tests/golden-record/my_test_api_client/models/http_validation_error.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/http_validation_error.py index 1f04c29d0..7ed970dde 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/http_validation_error.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/http_validation_error.py @@ -1,4 +1,7 @@ -from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, TypeVar from attrs import define as _attrs_define @@ -15,20 +18,21 @@ class HTTPValidationError: """ Attributes: - detail (Union[Unset, List['ValidationError']]): + detail (list[ValidationError] | Unset): """ - detail: Union[Unset, List["ValidationError"]] = UNSET + detail: list[ValidationError] | Unset = UNSET - def to_dict(self) -> Dict[str, Any]: - detail: Union[Unset, List[Dict[str, Any]]] = UNSET + def to_dict(self) -> dict[str, Any]: + detail: list[dict[str, Any]] | Unset = UNSET if not isinstance(self.detail, Unset): detail = [] for detail_item_data in self.detail: detail_item = detail_item_data.to_dict() detail.append(detail_item) - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} + field_dict.update({}) if detail is not UNSET: field_dict["detail"] = detail @@ -36,16 +40,18 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - from ..models.validation_error import ValidationError + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + from ..models.validation_error import ValidationError # noqa: PLC0415 - d = src_dict.copy() - detail = [] + d = dict(src_dict) _detail = d.pop("detail", UNSET) - for detail_item_data in _detail or []: - detail_item = ValidationError.from_dict(detail_item_data) + detail: list[ValidationError] | Unset = UNSET + if _detail is not UNSET: + detail = [] + for detail_item_data in _detail: + detail_item = ValidationError.from_dict(detail_item_data) - detail.append(detail_item) + detail.append(detail_item) http_validation_error = cls( detail=detail, diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/import_.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/import_.py similarity index 67% rename from end_to_end_tests/golden-record/my_test_api_client/models/import_.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/import_.py index 85cc594e7..a24ec3f3d 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/import_.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/import_.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -8,26 +11,25 @@ @_attrs_define class Import: - """ """ + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + def to_dict(self) -> dict[str, Any]: - def to_dict(self) -> Dict[str, Any]: - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) import_ = cls() import_.additional_properties = d return import_ @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/json_like_body.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/json_like_body.py similarity index 71% rename from end_to_end_tests/golden-record/my_test_api_client/models/json_like_body.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/json_like_body.py index 623dcd848..4e60f7ab6 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/json_like_body.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/json_like_body.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -12,16 +15,16 @@ class JsonLikeBody: """ Attributes: - a (Union[Unset, str]): + a (str | Unset): """ - a: Union[Unset, str] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + a: str | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: a = self.a - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if a is not UNSET: @@ -30,8 +33,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) a = d.pop("a", UNSET) json_like_body = cls( @@ -42,7 +45,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return json_like_body @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/mixed_case_response_200.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/mixed_case_response_200.py similarity index 72% rename from end_to_end_tests/golden-record/my_test_api_client/models/mixed_case_response_200.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/mixed_case_response_200.py index 21bdd918d..93aead870 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/mixed_case_response_200.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/mixed_case_response_200.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -12,20 +15,20 @@ class MixedCaseResponse200: """ Attributes: - mixed_case (Union[Unset, str]): - mixedCase (Union[Unset, str]): + mixed_case (str | Unset): + mixedCase (str | Unset): """ - mixed_case: Union[Unset, str] = UNSET - mixedCase: Union[Unset, str] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + mixed_case: str | Unset = UNSET + mixedCase: str | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: mixed_case = self.mixed_case mixedCase = self.mixedCase - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if mixed_case is not UNSET: @@ -36,8 +39,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) mixed_case = d.pop("mixed_case", UNSET) mixedCase = d.pop("mixedCase", UNSET) @@ -51,7 +54,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return mixed_case_response_200 @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_from_all_of.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_from_all_of.py similarity index 63% rename from end_to_end_tests/golden-record/my_test_api_client/models/model_from_all_of.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_from_all_of.py index 6414b790d..a8abde58a 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_from_all_of.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_from_all_of.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -14,38 +17,38 @@ class ModelFromAllOf: """ Attributes: - a_sub_property (Union[Unset, str]): - type (Union[Unset, AnotherAllOfSubModelType]): - type_enum (Union[Unset, AnotherAllOfSubModelTypeEnum]): - another_sub_property (Union[Unset, str]): + a_sub_property (str | Unset): + type_ (AnotherAllOfSubModelType | Unset): + type_enum (AnotherAllOfSubModelTypeEnum | Unset): + another_sub_property (str | Unset): """ - a_sub_property: Union[Unset, str] = UNSET - type: Union[Unset, AnotherAllOfSubModelType] = UNSET - type_enum: Union[Unset, AnotherAllOfSubModelTypeEnum] = UNSET - another_sub_property: Union[Unset, str] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + a_sub_property: str | Unset = UNSET + type_: AnotherAllOfSubModelType | Unset = UNSET + type_enum: AnotherAllOfSubModelTypeEnum | Unset = UNSET + another_sub_property: str | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: a_sub_property = self.a_sub_property - type: Union[Unset, str] = UNSET - if not isinstance(self.type, Unset): - type = self.type.value + type_: str | Unset = UNSET + if not isinstance(self.type_, Unset): + type_ = self.type_.value - type_enum: Union[Unset, int] = UNSET + type_enum: int | Unset = UNSET if not isinstance(self.type_enum, Unset): type_enum = self.type_enum.value another_sub_property = self.another_sub_property - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if a_sub_property is not UNSET: field_dict["a_sub_property"] = a_sub_property - if type is not UNSET: - field_dict["type"] = type + if type_ is not UNSET: + field_dict["type"] = type_ if type_enum is not UNSET: field_dict["type_enum"] = type_enum if another_sub_property is not UNSET: @@ -54,19 +57,19 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) a_sub_property = d.pop("a_sub_property", UNSET) - _type = d.pop("type", UNSET) - type: Union[Unset, AnotherAllOfSubModelType] - if isinstance(_type, Unset): - type = UNSET + _type_ = d.pop("type", UNSET) + type_: AnotherAllOfSubModelType | Unset + if isinstance(_type_, Unset): + type_ = UNSET else: - type = AnotherAllOfSubModelType(_type) + type_ = AnotherAllOfSubModelType(_type_) _type_enum = d.pop("type_enum", UNSET) - type_enum: Union[Unset, AnotherAllOfSubModelTypeEnum] + type_enum: AnotherAllOfSubModelTypeEnum | Unset if isinstance(_type_enum, Unset): type_enum = UNSET else: @@ -76,7 +79,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: model_from_all_of = cls( a_sub_property=a_sub_property, - type=type, + type_=type_, type_enum=type_enum, another_sub_property=another_sub_property, ) @@ -85,7 +88,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return model_from_all_of @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_name.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_name.py similarity index 68% rename from end_to_end_tests/golden-record/my_test_api_client/models/model_name.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_name.py index 2a86db3a2..24703fa14 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_name.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_name.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -8,26 +11,25 @@ @_attrs_define class ModelName: - """ """ + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + def to_dict(self) -> dict[str, Any]: - def to_dict(self) -> Dict[str, Any]: - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) model_name = cls() model_name.additional_properties = d return model_name @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_reference_with_periods.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_reference_with_periods.py similarity index 71% rename from end_to_end_tests/golden-record/my_test_api_client/models/model_reference_with_periods.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_reference_with_periods.py index a5ff5d211..52caf65bb 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_reference_with_periods.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_reference_with_periods.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -10,24 +13,25 @@ class ModelReferenceWithPeriods: """A Model with periods in its reference""" - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: - def to_dict(self) -> Dict[str, Any]: - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) model_reference_with_periods = cls() model_reference_with_periods.additional_properties = d return model_reference_with_periods @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_additional_properties_inlined.py similarity index 71% rename from end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_additional_properties_inlined.py index 761a43e54..c1ca5e44c 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_additional_properties_inlined.py @@ -1,4 +1,7 @@ -from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -18,20 +21,21 @@ class ModelWithAdditionalPropertiesInlined: """ Attributes: - a_number (Union[Unset, float]): + a_number (float | Unset): """ - a_number: Union[Unset, float] = UNSET - additional_properties: Dict[str, "ModelWithAdditionalPropertiesInlinedAdditionalProperty"] = _attrs_field( + a_number: float | Unset = UNSET + additional_properties: dict[str, ModelWithAdditionalPropertiesInlinedAdditionalProperty] = _attrs_field( init=False, factory=dict ) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: a_number = self.a_number - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} for prop_name, prop in self.additional_properties.items(): field_dict[prop_name] = prop.to_dict() + field_dict.update({}) if a_number is not UNSET: field_dict["a_number"] = a_number @@ -39,12 +43,12 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: from ..models.model_with_additional_properties_inlined_additional_property import ( - ModelWithAdditionalPropertiesInlinedAdditionalProperty, + ModelWithAdditionalPropertiesInlinedAdditionalProperty, # noqa: PLC0415 ) - d = src_dict.copy() + d = dict(src_dict) a_number = d.pop("a_number", UNSET) model_with_additional_properties_inlined = cls( @@ -61,13 +65,13 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return model_with_additional_properties_inlined @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) - def __getitem__(self, key: str) -> "ModelWithAdditionalPropertiesInlinedAdditionalProperty": + def __getitem__(self, key: str) -> ModelWithAdditionalPropertiesInlinedAdditionalProperty: return self.additional_properties[key] - def __setitem__(self, key: str, value: "ModelWithAdditionalPropertiesInlinedAdditionalProperty") -> None: + def __setitem__(self, key: str, value: ModelWithAdditionalPropertiesInlinedAdditionalProperty) -> None: self.additional_properties[key] = value def __delitem__(self, key: str) -> None: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined_additional_property.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_additional_properties_inlined_additional_property.py similarity index 75% rename from end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined_additional_property.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_additional_properties_inlined_additional_property.py index e06a94bfc..8f877a575 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_inlined_additional_property.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_additional_properties_inlined_additional_property.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -12,16 +15,16 @@ class ModelWithAdditionalPropertiesInlinedAdditionalProperty: """ Attributes: - extra_props_prop (Union[Unset, str]): + extra_props_prop (str | Unset): """ - extra_props_prop: Union[Unset, str] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + extra_props_prop: str | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: extra_props_prop = self.extra_props_prop - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if extra_props_prop is not UNSET: @@ -30,8 +33,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) extra_props_prop = d.pop("extra_props_prop", UNSET) model_with_additional_properties_inlined_additional_property = cls( @@ -42,7 +45,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return model_with_additional_properties_inlined_additional_property @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_refed.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_additional_properties_refed.py similarity index 76% rename from end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_refed.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_additional_properties_refed.py index b2500f68c..a7ef955fd 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_additional_properties_refed.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_additional_properties_refed.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -10,20 +13,19 @@ @_attrs_define class ModelWithAdditionalPropertiesRefed: - """ """ + additional_properties: dict[str, AnEnum] = _attrs_field(init=False, factory=dict) - additional_properties: Dict[str, AnEnum] = _attrs_field(init=False, factory=dict) + def to_dict(self) -> dict[str, Any]: - def to_dict(self) -> Dict[str, Any]: - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} for prop_name, prop in self.additional_properties.items(): field_dict[prop_name] = prop.value return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) model_with_additional_properties_refed = cls() additional_properties = {} @@ -36,7 +38,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return model_with_additional_properties_refed @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> AnEnum: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_any_json_properties.py similarity index 65% rename from end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_any_json_properties.py index 6e669914a..f3d23571c 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_any_json_properties.py @@ -1,4 +1,7 @@ -from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union, cast +from __future__ import annotations + +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, TypeVar, cast from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -14,18 +17,16 @@ @_attrs_define class ModelWithAnyJsonProperties: - """ """ - - additional_properties: Dict[ - str, Union["ModelWithAnyJsonPropertiesAdditionalPropertyType0", List[str], bool, float, int, str] + additional_properties: dict[ + str, bool | float | int | list[str] | ModelWithAnyJsonPropertiesAdditionalPropertyType0 | str ] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: from ..models.model_with_any_json_properties_additional_property_type_0 import ( - ModelWithAnyJsonPropertiesAdditionalPropertyType0, + ModelWithAnyJsonPropertiesAdditionalPropertyType0, # noqa: PLC0415 ) - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} for prop_name, prop in self.additional_properties.items(): if isinstance(prop, ModelWithAnyJsonPropertiesAdditionalPropertyType0): field_dict[prop_name] = prop.to_dict() @@ -38,12 +39,12 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: from ..models.model_with_any_json_properties_additional_property_type_0 import ( - ModelWithAnyJsonPropertiesAdditionalPropertyType0, + ModelWithAnyJsonPropertiesAdditionalPropertyType0, # noqa: PLC0415 ) - d = src_dict.copy() + d = dict(src_dict) model_with_any_json_properties = cls() additional_properties = {} @@ -51,25 +52,25 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: def _parse_additional_property( data: object, - ) -> Union["ModelWithAnyJsonPropertiesAdditionalPropertyType0", List[str], bool, float, int, str]: + ) -> bool | float | int | list[str] | ModelWithAnyJsonPropertiesAdditionalPropertyType0 | str: try: if not isinstance(data, dict): raise TypeError() additional_property_type_0 = ModelWithAnyJsonPropertiesAdditionalPropertyType0.from_dict(data) return additional_property_type_0 - except: # noqa: E722 + except (TypeError, ValueError, AttributeError, KeyError): pass try: if not isinstance(data, list): raise TypeError() - additional_property_type_1 = cast(List[str], data) + additional_property_type_1 = cast(list[str], data) return additional_property_type_1 - except: # noqa: E722 + except (TypeError, ValueError, AttributeError, KeyError): pass return cast( - Union["ModelWithAnyJsonPropertiesAdditionalPropertyType0", List[str], bool, float, int, str], data + bool | float | int | list[str] | ModelWithAnyJsonPropertiesAdditionalPropertyType0 | str, data ) additional_property = _parse_additional_property(prop_dict) @@ -80,18 +81,16 @@ def _parse_additional_property( return model_with_any_json_properties @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__( self, key: str - ) -> Union["ModelWithAnyJsonPropertiesAdditionalPropertyType0", List[str], bool, float, int, str]: + ) -> bool | float | int | list[str] | ModelWithAnyJsonPropertiesAdditionalPropertyType0 | str: return self.additional_properties[key] def __setitem__( - self, - key: str, - value: Union["ModelWithAnyJsonPropertiesAdditionalPropertyType0", List[str], bool, float, int, str], + self, key: str, value: bool | float | int | list[str] | ModelWithAnyJsonPropertiesAdditionalPropertyType0 | str ) -> None: self.additional_properties[key] = value diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties_additional_property_type_0.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_any_json_properties_additional_property_type_0.py similarity index 73% rename from end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties_additional_property_type_0.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_any_json_properties_additional_property_type_0.py index 6ae70905e..9d75dc52c 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_any_json_properties_additional_property_type_0.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_any_json_properties_additional_property_type_0.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -8,26 +11,25 @@ @_attrs_define class ModelWithAnyJsonPropertiesAdditionalPropertyType0: - """ """ + additional_properties: dict[str, str] = _attrs_field(init=False, factory=dict) - additional_properties: Dict[str, str] = _attrs_field(init=False, factory=dict) + def to_dict(self) -> dict[str, Any]: - def to_dict(self) -> Dict[str, Any]: - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) model_with_any_json_properties_additional_property_type_0 = cls() model_with_any_json_properties_additional_property_type_0.additional_properties = d return model_with_any_json_properties_additional_property_type_0 @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> str: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_backslash_in_description.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_backslash_in_description.py similarity index 68% rename from end_to_end_tests/golden-record/my_test_api_client/models/model_with_backslash_in_description.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_backslash_in_description.py index 5de43ddb9..3492b738f 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_backslash_in_description.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_backslash_in_description.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -8,28 +11,29 @@ @_attrs_define class ModelWithBackslashInDescription: - r""" Description with special character: \ + """ Description with special character: \\ """ - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: - def to_dict(self) -> Dict[str, Any]: - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) model_with_backslash_in_description = cls() model_with_backslash_in_description.additional_properties = d return model_with_backslash_in_description @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_circular_ref_a.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_circular_ref_a.py similarity index 71% rename from end_to_end_tests/golden-record/my_test_api_client/models/model_with_circular_ref_a.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_circular_ref_a.py index 73cfb1287..a9bde2daf 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_circular_ref_a.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_circular_ref_a.py @@ -1,4 +1,7 @@ -from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -16,18 +19,18 @@ class ModelWithCircularRefA: """ Attributes: - circular (Union[Unset, ModelWithCircularRefB]): + circular (ModelWithCircularRefB | Unset): """ - circular: Union[Unset, "ModelWithCircularRefB"] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + circular: ModelWithCircularRefB | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: - circular: Union[Unset, Dict[str, Any]] = UNSET + def to_dict(self) -> dict[str, Any]: + circular: dict[str, Any] | Unset = UNSET if not isinstance(self.circular, Unset): circular = self.circular.to_dict() - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if circular is not UNSET: @@ -36,12 +39,12 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - from ..models.model_with_circular_ref_b import ModelWithCircularRefB + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + from ..models.model_with_circular_ref_b import ModelWithCircularRefB # noqa: PLC0415 - d = src_dict.copy() + d = dict(src_dict) _circular = d.pop("circular", UNSET) - circular: Union[Unset, ModelWithCircularRefB] + circular: ModelWithCircularRefB | Unset if isinstance(_circular, Unset): circular = UNSET else: @@ -55,7 +58,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return model_with_circular_ref_a @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_circular_ref_b.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_circular_ref_b.py similarity index 71% rename from end_to_end_tests/golden-record/my_test_api_client/models/model_with_circular_ref_b.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_circular_ref_b.py index 0628d89ae..c21d33148 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_circular_ref_b.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_circular_ref_b.py @@ -1,4 +1,7 @@ -from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -16,18 +19,18 @@ class ModelWithCircularRefB: """ Attributes: - circular (Union[Unset, ModelWithCircularRefA]): + circular (ModelWithCircularRefA | Unset): """ - circular: Union[Unset, "ModelWithCircularRefA"] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + circular: ModelWithCircularRefA | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: - circular: Union[Unset, Dict[str, Any]] = UNSET + def to_dict(self) -> dict[str, Any]: + circular: dict[str, Any] | Unset = UNSET if not isinstance(self.circular, Unset): circular = self.circular.to_dict() - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if circular is not UNSET: @@ -36,12 +39,12 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - from ..models.model_with_circular_ref_a import ModelWithCircularRefA + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + from ..models.model_with_circular_ref_a import ModelWithCircularRefA # noqa: PLC0415 - d = src_dict.copy() + d = dict(src_dict) _circular = d.pop("circular", UNSET) - circular: Union[Unset, ModelWithCircularRefA] + circular: ModelWithCircularRefA | Unset if isinstance(_circular, Unset): circular = UNSET else: @@ -55,7 +58,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return model_with_circular_ref_b @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_circular_ref_in_additional_properties_a.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_circular_ref_in_additional_properties_a.py similarity index 68% rename from end_to_end_tests/golden-record/my_test_api_client/models/model_with_circular_ref_in_additional_properties_a.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_circular_ref_in_additional_properties_a.py index 4f1d59c57..fdc790779 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_circular_ref_in_additional_properties_a.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_circular_ref_in_additional_properties_a.py @@ -1,4 +1,7 @@ -from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar +from __future__ import annotations + +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -12,26 +15,25 @@ @_attrs_define class ModelWithCircularRefInAdditionalPropertiesA: - """ """ - - additional_properties: Dict[str, "ModelWithCircularRefInAdditionalPropertiesB"] = _attrs_field( + additional_properties: dict[str, ModelWithCircularRefInAdditionalPropertiesB] = _attrs_field( init=False, factory=dict ) - def to_dict(self) -> Dict[str, Any]: - field_dict: Dict[str, Any] = {} + def to_dict(self) -> dict[str, Any]: + + field_dict: dict[str, Any] = {} for prop_name, prop in self.additional_properties.items(): field_dict[prop_name] = prop.to_dict() return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: from ..models.model_with_circular_ref_in_additional_properties_b import ( - ModelWithCircularRefInAdditionalPropertiesB, + ModelWithCircularRefInAdditionalPropertiesB, # noqa: PLC0415 ) - d = src_dict.copy() + d = dict(src_dict) model_with_circular_ref_in_additional_properties_a = cls() additional_properties = {} @@ -44,13 +46,13 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return model_with_circular_ref_in_additional_properties_a @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) - def __getitem__(self, key: str) -> "ModelWithCircularRefInAdditionalPropertiesB": + def __getitem__(self, key: str) -> ModelWithCircularRefInAdditionalPropertiesB: return self.additional_properties[key] - def __setitem__(self, key: str, value: "ModelWithCircularRefInAdditionalPropertiesB") -> None: + def __setitem__(self, key: str, value: ModelWithCircularRefInAdditionalPropertiesB) -> None: self.additional_properties[key] = value def __delitem__(self, key: str) -> None: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_circular_ref_in_additional_properties_b.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_circular_ref_in_additional_properties_b.py similarity index 68% rename from end_to_end_tests/golden-record/my_test_api_client/models/model_with_circular_ref_in_additional_properties_b.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_circular_ref_in_additional_properties_b.py index 3f55584e5..1c3f1998c 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_circular_ref_in_additional_properties_b.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_circular_ref_in_additional_properties_b.py @@ -1,4 +1,7 @@ -from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar +from __future__ import annotations + +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -12,26 +15,25 @@ @_attrs_define class ModelWithCircularRefInAdditionalPropertiesB: - """ """ - - additional_properties: Dict[str, "ModelWithCircularRefInAdditionalPropertiesA"] = _attrs_field( + additional_properties: dict[str, ModelWithCircularRefInAdditionalPropertiesA] = _attrs_field( init=False, factory=dict ) - def to_dict(self) -> Dict[str, Any]: - field_dict: Dict[str, Any] = {} + def to_dict(self) -> dict[str, Any]: + + field_dict: dict[str, Any] = {} for prop_name, prop in self.additional_properties.items(): field_dict[prop_name] = prop.to_dict() return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: from ..models.model_with_circular_ref_in_additional_properties_a import ( - ModelWithCircularRefInAdditionalPropertiesA, + ModelWithCircularRefInAdditionalPropertiesA, # noqa: PLC0415 ) - d = src_dict.copy() + d = dict(src_dict) model_with_circular_ref_in_additional_properties_b = cls() additional_properties = {} @@ -44,13 +46,13 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return model_with_circular_ref_in_additional_properties_b @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) - def __getitem__(self, key: str) -> "ModelWithCircularRefInAdditionalPropertiesA": + def __getitem__(self, key: str) -> ModelWithCircularRefInAdditionalPropertiesA: return self.additional_properties[key] - def __setitem__(self, key: str, value: "ModelWithCircularRefInAdditionalPropertiesA") -> None: + def __setitem__(self, key: str, value: ModelWithCircularRefInAdditionalPropertiesA) -> None: self.additional_properties[key] = value def __delitem__(self, key: str) -> None: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_date_time_property.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_date_time_property.py similarity index 68% rename from end_to_end_tests/golden-record/my_test_api_client/models/model_with_date_time_property.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_date_time_property.py index 658b2352d..b005efa02 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_date_time_property.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_date_time_property.py @@ -1,9 +1,11 @@ +from __future__ import annotations + import datetime -from typing import Any, Dict, List, Type, TypeVar, Union +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field -from dateutil.parser import isoparse from ..types import UNSET, Unset @@ -14,18 +16,18 @@ class ModelWithDateTimeProperty: """ Attributes: - datetime_ (Union[Unset, datetime.datetime]): + datetime_ (datetime.datetime | Unset): """ - datetime_: Union[Unset, datetime.datetime] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + datetime_: datetime.datetime | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: - datetime_: Union[Unset, str] = UNSET + def to_dict(self) -> dict[str, Any]: + datetime_: str | Unset = UNSET if not isinstance(self.datetime_, Unset): datetime_ = self.datetime_.isoformat() - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if datetime_ is not UNSET: @@ -34,14 +36,14 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) _datetime_ = d.pop("datetime", UNSET) - datetime_: Union[Unset, datetime.datetime] + datetime_: datetime.datetime | Unset if isinstance(_datetime_, Unset): datetime_ = UNSET else: - datetime_ = isoparse(_datetime_) + datetime_ = datetime.datetime.fromisoformat(_datetime_) model_with_date_time_property = cls( datetime_=datetime_, @@ -51,7 +53,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return model_with_date_time_property @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_discriminated_union.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_discriminated_union.py similarity index 72% rename from end_to_end_tests/golden-record/my_test_api_client/models/model_with_discriminated_union.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_discriminated_union.py index e03a6e698..41b972dc4 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_discriminated_union.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_discriminated_union.py @@ -1,4 +1,7 @@ -from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union, cast +from __future__ import annotations + +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, TypeVar, cast from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -17,17 +20,17 @@ class ModelWithDiscriminatedUnion: """ Attributes: - discriminated_union (Union['ADiscriminatedUnionType1', 'ADiscriminatedUnionType2', None, Unset]): + discriminated_union (ADiscriminatedUnionType1 | ADiscriminatedUnionType2 | None | Unset): """ - discriminated_union: Union["ADiscriminatedUnionType1", "ADiscriminatedUnionType2", None, Unset] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + discriminated_union: ADiscriminatedUnionType1 | ADiscriminatedUnionType2 | None | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: - from ..models.a_discriminated_union_type_1 import ADiscriminatedUnionType1 - from ..models.a_discriminated_union_type_2 import ADiscriminatedUnionType2 + def to_dict(self) -> dict[str, Any]: + from ..models.a_discriminated_union_type_1 import ADiscriminatedUnionType1 # noqa: PLC0415 + from ..models.a_discriminated_union_type_2 import ADiscriminatedUnionType2 # noqa: PLC0415 - discriminated_union: Union[Dict[str, Any], None, Unset] + discriminated_union: dict[str, Any] | None | Unset if isinstance(self.discriminated_union, Unset): discriminated_union = UNSET elif isinstance(self.discriminated_union, ADiscriminatedUnionType1): @@ -37,7 +40,7 @@ def to_dict(self) -> Dict[str, Any]: else: discriminated_union = self.discriminated_union - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if discriminated_union is not UNSET: @@ -46,15 +49,15 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - from ..models.a_discriminated_union_type_1 import ADiscriminatedUnionType1 - from ..models.a_discriminated_union_type_2 import ADiscriminatedUnionType2 + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + from ..models.a_discriminated_union_type_1 import ADiscriminatedUnionType1 # noqa: PLC0415 + from ..models.a_discriminated_union_type_2 import ADiscriminatedUnionType2 # noqa: PLC0415 - d = src_dict.copy() + d = dict(src_dict) def _parse_discriminated_union( data: object, - ) -> Union["ADiscriminatedUnionType1", "ADiscriminatedUnionType2", None, Unset]: + ) -> ADiscriminatedUnionType1 | ADiscriminatedUnionType2 | None | Unset: if data is None: return data if isinstance(data, Unset): @@ -65,7 +68,7 @@ def _parse_discriminated_union( componentsschemas_a_discriminated_union_type_0 = ADiscriminatedUnionType1.from_dict(data) return componentsschemas_a_discriminated_union_type_0 - except: # noqa: E722 + except (TypeError, ValueError, AttributeError, KeyError): pass try: if not isinstance(data, dict): @@ -73,9 +76,9 @@ def _parse_discriminated_union( componentsschemas_a_discriminated_union_type_1 = ADiscriminatedUnionType2.from_dict(data) return componentsschemas_a_discriminated_union_type_1 - except: # noqa: E722 + except (TypeError, ValueError, AttributeError, KeyError): pass - return cast(Union["ADiscriminatedUnionType1", "ADiscriminatedUnionType2", None, Unset], data) + return cast(ADiscriminatedUnionType1 | ADiscriminatedUnionType2 | None | Unset, data) discriminated_union = _parse_discriminated_union(d.pop("discriminated_union", UNSET)) @@ -87,7 +90,7 @@ def _parse_discriminated_union( return model_with_discriminated_union @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_merged_properties.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_merged_properties.py new file mode 100644 index 000000000..1ee8b4a61 --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_merged_properties.py @@ -0,0 +1,114 @@ +from __future__ import annotations + +import datetime +from collections.abc import Mapping +from typing import Any, TypeVar + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..models.model_with_merged_properties_string_to_enum import ModelWithMergedPropertiesStringToEnum +from ..types import UNSET, Unset + +T = TypeVar("T", bound="ModelWithMergedProperties") + + +@_attrs_define +class ModelWithMergedProperties: + """ + Attributes: + simple_string (str | Unset): extended simpleString description Default: 'new default'. + string_to_enum (ModelWithMergedPropertiesStringToEnum | Unset): Default: + ModelWithMergedPropertiesStringToEnum.A. + string_to_date (datetime.date | Unset): + number_to_int (int | Unset): + any_to_string (str | Unset): Default: 'x'. + """ + + simple_string: str | Unset = "new default" + string_to_enum: ModelWithMergedPropertiesStringToEnum | Unset = ModelWithMergedPropertiesStringToEnum.A + string_to_date: datetime.date | Unset = UNSET + number_to_int: int | Unset = UNSET + any_to_string: str | Unset = "x" + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + simple_string = self.simple_string + + string_to_enum: str | Unset = UNSET + if not isinstance(self.string_to_enum, Unset): + string_to_enum = self.string_to_enum.value + + string_to_date: str | Unset = UNSET + if not isinstance(self.string_to_date, Unset): + string_to_date = self.string_to_date.isoformat() + + number_to_int = self.number_to_int + + any_to_string = self.any_to_string + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update({}) + if simple_string is not UNSET: + field_dict["simpleString"] = simple_string + if string_to_enum is not UNSET: + field_dict["stringToEnum"] = string_to_enum + if string_to_date is not UNSET: + field_dict["stringToDate"] = string_to_date + if number_to_int is not UNSET: + field_dict["numberToInt"] = number_to_int + if any_to_string is not UNSET: + field_dict["anyToString"] = any_to_string + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + simple_string = d.pop("simpleString", UNSET) + + _string_to_enum = d.pop("stringToEnum", UNSET) + string_to_enum: ModelWithMergedPropertiesStringToEnum | Unset + if isinstance(_string_to_enum, Unset): + string_to_enum = UNSET + else: + string_to_enum = ModelWithMergedPropertiesStringToEnum(_string_to_enum) + + _string_to_date = d.pop("stringToDate", UNSET) + string_to_date: datetime.date | Unset + if isinstance(_string_to_date, Unset): + string_to_date = UNSET + else: + string_to_date = datetime.date.fromisoformat(_string_to_date) + + number_to_int = d.pop("numberToInt", UNSET) + + any_to_string = d.pop("anyToString", UNSET) + + model_with_merged_properties = cls( + simple_string=simple_string, + string_to_enum=string_to_enum, + string_to_date=string_to_date, + number_to_int=number_to_int, + any_to_string=any_to_string, + ) + + model_with_merged_properties.additional_properties = d + return model_with_merged_properties + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_merged_properties_string_to_enum.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_merged_properties_string_to_enum.py new file mode 100644 index 000000000..22fb32812 --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_merged_properties_string_to_enum.py @@ -0,0 +1,9 @@ +from enum import StrEnum + + +class ModelWithMergedPropertiesStringToEnum(StrEnum): + A = "a" + B = "b" + + def __str__(self) -> str: + return str(self.value) diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_no_properties.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_no_properties.py new file mode 100644 index 000000000..32eba322b --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_no_properties.py @@ -0,0 +1,23 @@ +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar + +from attrs import define as _attrs_define + +T = TypeVar("T", bound="ModelWithNoProperties") + + +@_attrs_define +class ModelWithNoProperties: + def to_dict(self) -> dict[str, Any]: + + field_dict: dict[str, Any] = {} + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + model_with_no_properties = cls() + + return model_with_no_properties diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_primitive_additional_properties.py similarity index 70% rename from end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_primitive_additional_properties.py index 94afa7653..f4d01fd3f 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_primitive_additional_properties.py @@ -1,4 +1,7 @@ -from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -18,18 +21,18 @@ class ModelWithPrimitiveAdditionalProperties: """ Attributes: - a_date_holder (Union[Unset, ModelWithPrimitiveAdditionalPropertiesADateHolder]): + a_date_holder (ModelWithPrimitiveAdditionalPropertiesADateHolder | Unset): """ - a_date_holder: Union[Unset, "ModelWithPrimitiveAdditionalPropertiesADateHolder"] = UNSET - additional_properties: Dict[str, str] = _attrs_field(init=False, factory=dict) + a_date_holder: ModelWithPrimitiveAdditionalPropertiesADateHolder | Unset = UNSET + additional_properties: dict[str, str] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: - a_date_holder: Union[Unset, Dict[str, Any]] = UNSET + def to_dict(self) -> dict[str, Any]: + a_date_holder: dict[str, Any] | Unset = UNSET if not isinstance(self.a_date_holder, Unset): a_date_holder = self.a_date_holder.to_dict() - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if a_date_holder is not UNSET: @@ -38,14 +41,14 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: from ..models.model_with_primitive_additional_properties_a_date_holder import ( - ModelWithPrimitiveAdditionalPropertiesADateHolder, + ModelWithPrimitiveAdditionalPropertiesADateHolder, # noqa: PLC0415 ) - d = src_dict.copy() + d = dict(src_dict) _a_date_holder = d.pop("a_date_holder", UNSET) - a_date_holder: Union[Unset, ModelWithPrimitiveAdditionalPropertiesADateHolder] + a_date_holder: ModelWithPrimitiveAdditionalPropertiesADateHolder | Unset if isinstance(_a_date_holder, Unset): a_date_holder = UNSET else: @@ -59,7 +62,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return model_with_primitive_additional_properties @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> str: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties_a_date_holder.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_primitive_additional_properties_a_date_holder.py similarity index 74% rename from end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties_a_date_holder.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_primitive_additional_properties_a_date_holder.py index b9920fc60..f5a15805d 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_primitive_additional_properties_a_date_holder.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_primitive_additional_properties_a_date_holder.py @@ -1,34 +1,35 @@ +from __future__ import annotations + import datetime -from typing import Any, Dict, List, Type, TypeVar +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field -from dateutil.parser import isoparse T = TypeVar("T", bound="ModelWithPrimitiveAdditionalPropertiesADateHolder") @_attrs_define class ModelWithPrimitiveAdditionalPropertiesADateHolder: - """ """ + additional_properties: dict[str, datetime.datetime] = _attrs_field(init=False, factory=dict) - additional_properties: Dict[str, datetime.datetime] = _attrs_field(init=False, factory=dict) + def to_dict(self) -> dict[str, Any]: - def to_dict(self) -> Dict[str, Any]: - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} for prop_name, prop in self.additional_properties.items(): field_dict[prop_name] = prop.isoformat() return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) model_with_primitive_additional_properties_a_date_holder = cls() additional_properties = {} for prop_name, prop_dict in d.items(): - additional_property = isoparse(prop_dict) + additional_property = datetime.datetime.fromisoformat(prop_dict) additional_properties[prop_name] = additional_property @@ -36,7 +37,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return model_with_primitive_additional_properties_a_date_holder @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> datetime.datetime: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_property_ref.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_property_ref.py similarity index 69% rename from end_to_end_tests/golden-record/my_test_api_client/models/model_with_property_ref.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_property_ref.py index f54afdee8..622c94fa4 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_property_ref.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_property_ref.py @@ -1,4 +1,7 @@ -from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -16,18 +19,18 @@ class ModelWithPropertyRef: """ Attributes: - inner (Union[Unset, ModelName]): + inner (ModelName | Unset): """ - inner: Union[Unset, "ModelName"] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + inner: ModelName | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: - inner: Union[Unset, Dict[str, Any]] = UNSET + def to_dict(self) -> dict[str, Any]: + inner: dict[str, Any] | Unset = UNSET if not isinstance(self.inner, Unset): inner = self.inner.to_dict() - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if inner is not UNSET: @@ -36,12 +39,12 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - from ..models.model_name import ModelName + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + from ..models.model_name import ModelName # noqa: PLC0415 - d = src_dict.copy() + d = dict(src_dict) _inner = d.pop("inner", UNSET) - inner: Union[Unset, ModelName] + inner: ModelName | Unset if isinstance(_inner, Unset): inner = UNSET else: @@ -55,7 +58,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return model_with_property_ref @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_recursive_ref.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_recursive_ref.py similarity index 70% rename from end_to_end_tests/golden-record/my_test_api_client/models/model_with_recursive_ref.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_recursive_ref.py index 578bca7e0..d4149434c 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_recursive_ref.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_recursive_ref.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -12,18 +15,18 @@ class ModelWithRecursiveRef: """ Attributes: - recursive (Union[Unset, ModelWithRecursiveRef]): + recursive (ModelWithRecursiveRef | Unset): """ - recursive: Union[Unset, "ModelWithRecursiveRef"] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + recursive: ModelWithRecursiveRef | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: - recursive: Union[Unset, Dict[str, Any]] = UNSET + def to_dict(self) -> dict[str, Any]: + recursive: dict[str, Any] | Unset = UNSET if not isinstance(self.recursive, Unset): recursive = self.recursive.to_dict() - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if recursive is not UNSET: @@ -32,10 +35,10 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) _recursive = d.pop("recursive", UNSET) - recursive: Union[Unset, ModelWithRecursiveRef] + recursive: ModelWithRecursiveRef | Unset if isinstance(_recursive, Unset): recursive = UNSET else: @@ -49,7 +52,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return model_with_recursive_ref @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_recursive_ref_in_additional_properties.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_recursive_ref_in_additional_properties.py similarity index 67% rename from end_to_end_tests/golden-record/my_test_api_client/models/model_with_recursive_ref_in_additional_properties.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_recursive_ref_in_additional_properties.py index 2ed2526f5..f31d2f88d 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_recursive_ref_in_additional_properties.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_recursive_ref_in_additional_properties.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -8,22 +11,21 @@ @_attrs_define class ModelWithRecursiveRefInAdditionalProperties: - """ """ - - additional_properties: Dict[str, "ModelWithRecursiveRefInAdditionalProperties"] = _attrs_field( + additional_properties: dict[str, ModelWithRecursiveRefInAdditionalProperties] = _attrs_field( init=False, factory=dict ) - def to_dict(self) -> Dict[str, Any]: - field_dict: Dict[str, Any] = {} + def to_dict(self) -> dict[str, Any]: + + field_dict: dict[str, Any] = {} for prop_name, prop in self.additional_properties.items(): field_dict[prop_name] = prop.to_dict() return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) model_with_recursive_ref_in_additional_properties = cls() additional_properties = {} @@ -36,13 +38,13 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return model_with_recursive_ref_in_additional_properties @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) - def __getitem__(self, key: str) -> "ModelWithRecursiveRefInAdditionalProperties": + def __getitem__(self, key: str) -> ModelWithRecursiveRefInAdditionalProperties: return self.additional_properties[key] - def __setitem__(self, key: str, value: "ModelWithRecursiveRefInAdditionalProperties") -> None: + def __setitem__(self, key: str, value: ModelWithRecursiveRefInAdditionalProperties) -> None: self.additional_properties[key] = value def __delitem__(self, key: str) -> None: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_union_property.py similarity index 70% rename from end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_union_property.py index 890010b78..176b3eadc 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_union_property.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define @@ -13,13 +16,13 @@ class ModelWithUnionProperty: """ Attributes: - a_property (Union[AnEnum, AnIntEnum, Unset]): + a_property (AnEnum | AnIntEnum | Unset): """ - a_property: Union[AnEnum, AnIntEnum, Unset] = UNSET + a_property: AnEnum | AnIntEnum | Unset = UNSET - def to_dict(self) -> Dict[str, Any]: - a_property: Union[Unset, int, str] + def to_dict(self) -> dict[str, Any]: + a_property: int | str | Unset if isinstance(self.a_property, Unset): a_property = UNSET elif isinstance(self.a_property, AnEnum): @@ -27,7 +30,8 @@ def to_dict(self) -> Dict[str, Any]: else: a_property = self.a_property.value - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} + field_dict.update({}) if a_property is not UNSET: field_dict["a_property"] = a_property @@ -35,10 +39,10 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) - def _parse_a_property(data: object) -> Union[AnEnum, AnIntEnum, Unset]: + def _parse_a_property(data: object) -> AnEnum | AnIntEnum | Unset: if isinstance(data, Unset): return data try: @@ -47,7 +51,7 @@ def _parse_a_property(data: object) -> Union[AnEnum, AnIntEnum, Unset]: a_property_type_0 = AnEnum(data) return a_property_type_0 - except: # noqa: E722 + except (TypeError, ValueError, AttributeError, KeyError): pass if not isinstance(data, int): raise TypeError() diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_union_property_inlined.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_union_property_inlined.py new file mode 100644 index 000000000..fbce31507 --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_union_property_inlined.py @@ -0,0 +1,84 @@ +from __future__ import annotations + +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, TypeVar + +from attrs import define as _attrs_define + +from ..types import UNSET, Unset + +if TYPE_CHECKING: + from ..models.model_with_union_property_inlined_apples import ModelWithUnionPropertyInlinedApples + from ..models.model_with_union_property_inlined_bananas import ModelWithUnionPropertyInlinedBananas + + +T = TypeVar("T", bound="ModelWithUnionPropertyInlined") + + +@_attrs_define +class ModelWithUnionPropertyInlined: + """ + Attributes: + fruit (ModelWithUnionPropertyInlinedApples | ModelWithUnionPropertyInlinedBananas | Unset): + """ + + fruit: ModelWithUnionPropertyInlinedApples | ModelWithUnionPropertyInlinedBananas | Unset = UNSET + + def to_dict(self) -> dict[str, Any]: + from ..models.model_with_union_property_inlined_apples import ( + ModelWithUnionPropertyInlinedApples, # noqa: PLC0415 + ) + + fruit: dict[str, Any] | Unset + if isinstance(self.fruit, Unset): + fruit = UNSET + elif isinstance(self.fruit, ModelWithUnionPropertyInlinedApples): + fruit = self.fruit.to_dict() + else: + fruit = self.fruit.to_dict() + + field_dict: dict[str, Any] = {} + + field_dict.update({}) + if fruit is not UNSET: + field_dict["fruit"] = fruit + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + from ..models.model_with_union_property_inlined_apples import ( + ModelWithUnionPropertyInlinedApples, # noqa: PLC0415 + ) + from ..models.model_with_union_property_inlined_bananas import ( + ModelWithUnionPropertyInlinedBananas, # noqa: PLC0415 + ) + + d = dict(src_dict) + + def _parse_fruit( + data: object, + ) -> ModelWithUnionPropertyInlinedApples | ModelWithUnionPropertyInlinedBananas | Unset: + if isinstance(data, Unset): + return data + try: + if not isinstance(data, dict): + raise TypeError() + fruit_apples = ModelWithUnionPropertyInlinedApples.from_dict(data) + + return fruit_apples + except (TypeError, ValueError, AttributeError, KeyError): + pass + if not isinstance(data, dict): + raise TypeError() + fruit_bananas = ModelWithUnionPropertyInlinedBananas.from_dict(data) + + return fruit_bananas + + fruit = _parse_fruit(d.pop("fruit", UNSET)) + + model_with_union_property_inlined = cls( + fruit=fruit, + ) + + return model_with_union_property_inlined diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_0.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_union_property_inlined_apples.py similarity index 56% rename from end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_0.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_union_property_inlined_apples.py index b0f25360a..0ad6f0cf2 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_0.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_union_property_inlined_apples.py @@ -1,27 +1,30 @@ -from typing import Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field from ..types import UNSET, Unset -T = TypeVar("T", bound="ModelWithUnionPropertyInlinedFruitType0") +T = TypeVar("T", bound="ModelWithUnionPropertyInlinedApples") @_attrs_define -class ModelWithUnionPropertyInlinedFruitType0: +class ModelWithUnionPropertyInlinedApples: """ Attributes: - apples (Union[Unset, str]): + apples (str | Unset): """ - apples: Union[Unset, str] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + apples: str | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: apples = self.apples - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if apples is not UNSET: @@ -30,19 +33,19 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) apples = d.pop("apples", UNSET) - model_with_union_property_inlined_fruit_type_0 = cls( + model_with_union_property_inlined_apples = cls( apples=apples, ) - model_with_union_property_inlined_fruit_type_0.additional_properties = d - return model_with_union_property_inlined_fruit_type_0 + model_with_union_property_inlined_apples.additional_properties = d + return model_with_union_property_inlined_apples @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_1.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_union_property_inlined_bananas.py similarity index 56% rename from end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_1.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_union_property_inlined_bananas.py index 1a32f2445..68a54e760 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_union_property_inlined_fruit_type_1.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/model_with_union_property_inlined_bananas.py @@ -1,27 +1,30 @@ -from typing import Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field from ..types import UNSET, Unset -T = TypeVar("T", bound="ModelWithUnionPropertyInlinedFruitType1") +T = TypeVar("T", bound="ModelWithUnionPropertyInlinedBananas") @_attrs_define -class ModelWithUnionPropertyInlinedFruitType1: +class ModelWithUnionPropertyInlinedBananas: """ Attributes: - bananas (Union[Unset, str]): + bananas (str | Unset): """ - bananas: Union[Unset, str] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + bananas: str | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: bananas = self.bananas - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if bananas is not UNSET: @@ -30,19 +33,19 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) bananas = d.pop("bananas", UNSET) - model_with_union_property_inlined_fruit_type_1 = cls( + model_with_union_property_inlined_bananas = cls( bananas=bananas, ) - model_with_union_property_inlined_fruit_type_1.additional_properties = d - return model_with_union_property_inlined_fruit_type_1 + model_with_union_property_inlined_bananas.additional_properties = d + return model_with_union_property_inlined_bananas @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/none.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/none.py similarity index 67% rename from end_to_end_tests/golden-record/my_test_api_client/models/none.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/none.py index 3510497bf..6f7fa6047 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/none.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/none.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -8,26 +11,25 @@ @_attrs_define class None_: - """ """ + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + def to_dict(self) -> dict[str, Any]: - def to_dict(self) -> Dict[str, Any]: - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) none = cls() none.additional_properties = d return none @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/octet_stream_tests_octet_stream_post_response_200.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/octet_stream_tests_octet_stream_post_response_200.py new file mode 100644 index 000000000..8d138937a --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/octet_stream_tests_octet_stream_post_response_200.py @@ -0,0 +1,69 @@ +from __future__ import annotations + +from collections.abc import Mapping +from io import BytesIO +from typing import Any, TypeVar + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, File, FileTypes, Unset + +T = TypeVar("T", bound="OctetStreamTestsOctetStreamPostResponse200") + + +@_attrs_define +class OctetStreamTestsOctetStreamPostResponse200: + """ + Attributes: + data (File | Unset): + """ + + data: File | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + data: FileTypes | Unset = UNSET + if not isinstance(self.data, Unset): + data = self.data.to_tuple() + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update({}) + if data is not UNSET: + field_dict["data"] = data + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + _data = d.pop("data", UNSET) + data: File | Unset + if isinstance(_data, Unset): + data = UNSET + else: + data = File(payload=BytesIO(_data)) + + octet_stream_tests_octet_stream_post_response_200 = cls( + data=data, + ) + + octet_stream_tests_octet_stream_post_response_200.additional_properties = d + return octet_stream_tests_octet_stream_post_response_200 + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/optional_body_body.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/optional_body_body.py new file mode 100644 index 000000000..064beb792 --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/optional_body_body.py @@ -0,0 +1,45 @@ +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +T = TypeVar("T", bound="OptionalBodyBody") + + +@_attrs_define +class OptionalBodyBody: + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + optional_body_body = cls() + + optional_body_body.additional_properties = d + return optional_body_body + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/post_bodies_multiple_data_body.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/post_bodies_multiple_data_body.py similarity index 72% rename from end_to_end_tests/golden-record/my_test_api_client/models/post_bodies_multiple_data_body.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/post_bodies_multiple_data_body.py index adc78cd6f..d83f8d7eb 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/post_bodies_multiple_data_body.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/post_bodies_multiple_data_body.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -12,16 +15,16 @@ class PostBodiesMultipleDataBody: """ Attributes: - a (Union[Unset, str]): + a (str | Unset): """ - a: Union[Unset, str] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + a: str | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: a = self.a - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if a is not UNSET: @@ -30,8 +33,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) a = d.pop("a", UNSET) post_bodies_multiple_data_body = cls( @@ -42,7 +45,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return post_bodies_multiple_data_body @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/post_bodies_multiple_files_body.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/post_bodies_multiple_files_body.py similarity index 57% rename from end_to_end_tests/golden-record/my_test_api_client/models/post_bodies_multiple_files_body.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/post_bodies_multiple_files_body.py index 1c61d3385..81d7db7a7 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/post_bodies_multiple_files_body.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/post_bodies_multiple_files_body.py @@ -1,8 +1,12 @@ -from typing import Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field +from .. import types from ..types import UNSET, Unset T = TypeVar("T", bound="PostBodiesMultipleFilesBody") @@ -12,16 +16,16 @@ class PostBodiesMultipleFilesBody: """ Attributes: - a (Union[Unset, str]): + a (str | Unset): """ - a: Union[Unset, str] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + a: str | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: a = self.a - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if a is not UNSET: @@ -29,22 +33,20 @@ def to_dict(self) -> Dict[str, Any]: return field_dict - def to_multipart(self) -> Dict[str, Any]: - a = self.a if isinstance(self.a, Unset) else (None, str(self.a).encode(), "text/plain") + def to_multipart(self) -> types.RequestFiles: + files: types.RequestFiles = [] - field_dict: Dict[str, Any] = {} - field_dict.update( - {key: (None, str(value).encode(), "text/plain") for key, value in self.additional_properties.items()} - ) - field_dict.update({}) - if a is not UNSET: - field_dict["a"] = a + if not isinstance(self.a, Unset): + files.append(("a", (None, str(self.a).encode(), "text/plain"))) - return field_dict + for prop_name, prop in self.additional_properties.items(): + files.append((prop_name, (None, str(prop).encode(), "text/plain"))) + + return files @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) a = d.pop("a", UNSET) post_bodies_multiple_files_body = cls( @@ -55,7 +57,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return post_bodies_multiple_files_body @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/post_bodies_multiple_json_body.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/post_bodies_multiple_json_body.py similarity index 72% rename from end_to_end_tests/golden-record/my_test_api_client/models/post_bodies_multiple_json_body.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/post_bodies_multiple_json_body.py index 88e5ec6f9..a5ec152e9 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/post_bodies_multiple_json_body.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/post_bodies_multiple_json_body.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -12,16 +15,16 @@ class PostBodiesMultipleJsonBody: """ Attributes: - a (Union[Unset, str]): + a (str | Unset): """ - a: Union[Unset, str] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + a: str | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: a = self.a - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if a is not UNSET: @@ -30,8 +33,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) a = d.pop("a", UNSET) post_bodies_multiple_json_body = cls( @@ -42,7 +45,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return post_bodies_multiple_json_body @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/post_form_data_inline_body.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/post_form_data_inline_body.py similarity index 76% rename from end_to_end_tests/golden-record/my_test_api_client/models/post_form_data_inline_body.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/post_form_data_inline_body.py index 08a7bbc3a..5d7c3982b 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/post_form_data_inline_body.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/post_form_data_inline_body.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -13,19 +16,19 @@ class PostFormDataInlineBody: """ Attributes: a_required_field (str): - an_optional_field (Union[Unset, str]): + an_optional_field (str | Unset): """ a_required_field: str - an_optional_field: Union[Unset, str] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + an_optional_field: str | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: a_required_field = self.a_required_field an_optional_field = self.an_optional_field - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update( { @@ -38,8 +41,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) a_required_field = d.pop("a_required_field") an_optional_field = d.pop("an_optional_field", UNSET) @@ -53,7 +56,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return post_form_data_inline_body @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/post_naming_property_conflict_with_import_body.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/post_naming_property_conflict_with_import_body.py similarity index 69% rename from end_to_end_tests/golden-record/my_test_api_client/models/post_naming_property_conflict_with_import_body.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/post_naming_property_conflict_with_import_body.py index ed2f8efa1..2895d97d8 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/post_naming_property_conflict_with_import_body.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/post_naming_property_conflict_with_import_body.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -12,20 +15,20 @@ class PostNamingPropertyConflictWithImportBody: """ Attributes: - field (Union[Unset, str]): A python_name of field should not interfere with attrs field - define (Union[Unset, str]): A python_name of define should not interfere with attrs define + field (str | Unset): A python_name of field should not interfere with attrs field + define (str | Unset): A python_name of define should not interfere with attrs define """ - field: Union[Unset, str] = UNSET - define: Union[Unset, str] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + field: str | Unset = UNSET + define: str | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: field = self.field define = self.define - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if field is not UNSET: @@ -36,8 +39,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) field = d.pop("Field", UNSET) define = d.pop("Define", UNSET) @@ -51,7 +54,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return post_naming_property_conflict_with_import_body @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/post_naming_property_conflict_with_import_response_200.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/post_naming_property_conflict_with_import_response_200.py similarity index 69% rename from end_to_end_tests/golden-record/my_test_api_client/models/post_naming_property_conflict_with_import_response_200.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/post_naming_property_conflict_with_import_response_200.py index 9bdd79a02..c2a8ac7f3 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/post_naming_property_conflict_with_import_response_200.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/post_naming_property_conflict_with_import_response_200.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -12,20 +15,20 @@ class PostNamingPropertyConflictWithImportResponse200: """ Attributes: - field (Union[Unset, str]): A python_name of field should not interfere with attrs field - define (Union[Unset, str]): A python_name of define should not interfere with attrs define + field (str | Unset): A python_name of field should not interfere with attrs field + define (str | Unset): A python_name of define should not interfere with attrs define """ - field: Union[Unset, str] = UNSET - define: Union[Unset, str] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + field: str | Unset = UNSET + define: str | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: field = self.field define = self.define - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if field is not UNSET: @@ -36,8 +39,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) field = d.pop("Field", UNSET) define = d.pop("Define", UNSET) @@ -51,7 +54,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return post_naming_property_conflict_with_import_response_200 @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/post_responses_unions_simple_before_complex_response_200.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/post_responses_unions_simple_before_complex_response_200.py similarity index 70% rename from end_to_end_tests/golden-record/my_test_api_client/models/post_responses_unions_simple_before_complex_response_200.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/post_responses_unions_simple_before_complex_response_200.py index 0b6a29243..205a1cd30 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/post_responses_unions_simple_before_complex_response_200.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/post_responses_unions_simple_before_complex_response_200.py @@ -1,4 +1,7 @@ -from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union, cast +from __future__ import annotations + +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, TypeVar, cast from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -16,24 +19,24 @@ class PostResponsesUnionsSimpleBeforeComplexResponse200: """ Attributes: - a (Union['PostResponsesUnionsSimpleBeforeComplexResponse200AType1', str]): + a (PostResponsesUnionsSimpleBeforeComplexResponse200AType1 | str): """ - a: Union["PostResponsesUnionsSimpleBeforeComplexResponse200AType1", str] - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + a: PostResponsesUnionsSimpleBeforeComplexResponse200AType1 | str + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: from ..models.post_responses_unions_simple_before_complex_response_200a_type_1 import ( - PostResponsesUnionsSimpleBeforeComplexResponse200AType1, + PostResponsesUnionsSimpleBeforeComplexResponse200AType1, # noqa: PLC0415 ) - a: Union[Dict[str, Any], str] + a: dict[str, Any] | str if isinstance(self.a, PostResponsesUnionsSimpleBeforeComplexResponse200AType1): a = self.a.to_dict() else: a = self.a - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update( { @@ -44,23 +47,23 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: from ..models.post_responses_unions_simple_before_complex_response_200a_type_1 import ( - PostResponsesUnionsSimpleBeforeComplexResponse200AType1, + PostResponsesUnionsSimpleBeforeComplexResponse200AType1, # noqa: PLC0415 ) - d = src_dict.copy() + d = dict(src_dict) - def _parse_a(data: object) -> Union["PostResponsesUnionsSimpleBeforeComplexResponse200AType1", str]: + def _parse_a(data: object) -> PostResponsesUnionsSimpleBeforeComplexResponse200AType1 | str: try: if not isinstance(data, dict): raise TypeError() a_type_1 = PostResponsesUnionsSimpleBeforeComplexResponse200AType1.from_dict(data) return a_type_1 - except: # noqa: E722 + except (TypeError, ValueError, AttributeError, KeyError): pass - return cast(Union["PostResponsesUnionsSimpleBeforeComplexResponse200AType1", str], data) + return cast(PostResponsesUnionsSimpleBeforeComplexResponse200AType1 | str, data) a = _parse_a(d.pop("a")) @@ -72,7 +75,7 @@ def _parse_a(data: object) -> Union["PostResponsesUnionsSimpleBeforeComplexRespo return post_responses_unions_simple_before_complex_response_200 @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/post_responses_unions_simple_before_complex_response_200a_type_1.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/post_responses_unions_simple_before_complex_response_200a_type_1.py similarity index 73% rename from end_to_end_tests/golden-record/my_test_api_client/models/post_responses_unions_simple_before_complex_response_200a_type_1.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/post_responses_unions_simple_before_complex_response_200a_type_1.py index 601d17cf8..2b6169b11 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/post_responses_unions_simple_before_complex_response_200a_type_1.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/post_responses_unions_simple_before_complex_response_200a_type_1.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -8,26 +11,25 @@ @_attrs_define class PostResponsesUnionsSimpleBeforeComplexResponse200AType1: - """ """ + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + def to_dict(self) -> dict[str, Any]: - def to_dict(self) -> Dict[str, Any]: - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) post_responses_unions_simple_before_complex_response_200a_type_1 = cls() post_responses_unions_simple_before_complex_response_200a_type_1.additional_properties = d return post_responses_unions_simple_before_complex_response_200a_type_1 @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/status_code_patterns_response_2xx.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/status_code_patterns_response_2xx.py new file mode 100644 index 000000000..61e806ff9 --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/status_code_patterns_response_2xx.py @@ -0,0 +1,69 @@ +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..models.status_code_patterns_response_2xx_status import StatusCodePatternsResponse2XXStatus +from ..types import UNSET, Unset + +T = TypeVar("T", bound="StatusCodePatternsResponse2XX") + + +@_attrs_define +class StatusCodePatternsResponse2XX: + """ + Attributes: + status (StatusCodePatternsResponse2XXStatus | Unset): + """ + + status: StatusCodePatternsResponse2XXStatus | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + status: str | Unset = UNSET + if not isinstance(self.status, Unset): + status = self.status.value + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update({}) + if status is not UNSET: + field_dict["status"] = status + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + _status = d.pop("status", UNSET) + status: StatusCodePatternsResponse2XXStatus | Unset + if isinstance(_status, Unset): + status = UNSET + else: + status = StatusCodePatternsResponse2XXStatus(_status) + + status_code_patterns_response_2xx = cls( + status=status, + ) + + status_code_patterns_response_2xx.additional_properties = d + return status_code_patterns_response_2xx + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/status_code_patterns_response_2xx_status.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/status_code_patterns_response_2xx_status.py new file mode 100644 index 000000000..9e871d06d --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/status_code_patterns_response_2xx_status.py @@ -0,0 +1,9 @@ +from enum import StrEnum + + +class StatusCodePatternsResponse2XXStatus(StrEnum): + FAILURE = "failure" + SUCCESS = "success" + + def __str__(self) -> str: + return str(self.value) diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/status_code_patterns_response_4xx.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/status_code_patterns_response_4xx.py new file mode 100644 index 000000000..f62c4168a --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/status_code_patterns_response_4xx.py @@ -0,0 +1,61 @@ +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="StatusCodePatternsResponse4XX") + + +@_attrs_define +class StatusCodePatternsResponse4XX: + """ + Attributes: + error (str | Unset): + """ + + error: str | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + error = self.error + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update({}) + if error is not UNSET: + field_dict["error"] = error + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + error = d.pop("error", UNSET) + + status_code_patterns_response_4xx = cls( + error=error, + ) + + status_code_patterns_response_4xx.additional_properties = d + return status_code_patterns_response_4xx + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_body.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/test_inline_objects_body.py similarity index 62% rename from end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_body.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/test_inline_objects_body.py index 8c1843b41..73b054b24 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_body.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/test_inline_objects_body.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define @@ -11,15 +14,16 @@ class TestInlineObjectsBody: """ Attributes: - a_property (Union[Unset, str]): + a_property (str | Unset): """ - a_property: Union[Unset, str] = UNSET + a_property: str | Unset = UNSET - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: a_property = self.a_property - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} + field_dict.update({}) if a_property is not UNSET: field_dict["a_property"] = a_property @@ -27,8 +31,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) a_property = d.pop("a_property", UNSET) test_inline_objects_body = cls( diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_response_200.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/test_inline_objects_response_200.py similarity index 63% rename from end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_response_200.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/test_inline_objects_response_200.py index 6a0ade77f..174a5957b 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/test_inline_objects_response_200.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/test_inline_objects_response_200.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define @@ -11,15 +14,16 @@ class TestInlineObjectsResponse200: """ Attributes: - a_property (Union[Unset, str]): + a_property (str | Unset): """ - a_property: Union[Unset, str] = UNSET + a_property: str | Unset = UNSET - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: a_property = self.a_property - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} + field_dict.update({}) if a_property is not UNSET: field_dict["a_property"] = a_property @@ -27,8 +31,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) a_property = d.pop("a_property", UNSET) test_inline_objects_response_200 = cls( diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/validation_error.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/validation_error.py similarity index 51% rename from end_to_end_tests/golden-record/my_test_api_client/models/validation_error.py rename to end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/validation_error.py index 6ff5d4790..9bb9070d6 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/validation_error.py +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/models/validation_error.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar, cast +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar, cast from attrs import define as _attrs_define @@ -9,46 +12,47 @@ class ValidationError: """ Attributes: - loc (List[str]): + loc (list[str]): msg (str): - type (str): + type_ (str): """ - loc: List[str] + loc: list[str] msg: str - type: str + type_: str - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: loc = self.loc msg = self.msg - type = self.type + type_ = self.type_ + + field_dict: dict[str, Any] = {} - field_dict: Dict[str, Any] = {} field_dict.update( { "loc": loc, "msg": msg, - "type": type, + "type": type_, } ) return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() - loc = cast(List[str], d.pop("loc")) + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + loc = cast(list[str], d.pop("loc")) msg = d.pop("msg") - type = d.pop("type") + type_ = d.pop("type") validation_error = cls( loc=loc, msg=msg, - type=type, + type_=type_, ) return validation_error diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/py.typed b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/py.typed new file mode 100644 index 000000000..1aad32711 --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/py.typed @@ -0,0 +1 @@ +# Marker file for PEP 561 \ No newline at end of file diff --git a/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/types.py b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/types.py new file mode 100644 index 000000000..b64af0952 --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/my_test_api_client/types.py @@ -0,0 +1,54 @@ +"""Contains some shared types for properties""" + +from collections.abc import Mapping, MutableMapping +from http import HTTPStatus +from typing import IO, BinaryIO, Generic, Literal, TypeVar + +from attrs import define + + +class Unset: + def __bool__(self) -> Literal[False]: + return False + + +UNSET: Unset = Unset() + +# The types that `httpx.Client(files=)` can accept, copied from that library. +FileContent = IO[bytes] | bytes | str +FileTypes = ( + # (filename, file (or bytes), content_type) + tuple[str | None, FileContent, str | None] + # (filename, file (or bytes), content_type, headers) + | tuple[str | None, FileContent, str | None, Mapping[str, str]] +) +RequestFiles = list[tuple[str, FileTypes]] + + +@define +class File: + """Contains information for file uploads""" + + payload: BinaryIO + file_name: str | None = None + mime_type: str | None = None + + def to_tuple(self) -> FileTypes: + """Return a tuple representation that httpx will accept for multipart/form-data""" + return self.file_name, self.payload, self.mime_type + + +T = TypeVar("T") + + +@define +class Response(Generic[T]): + """A response from an endpoint""" + + status_code: HTTPStatus + content: bytes + headers: MutableMapping[str, str] + parsed: T | None + + +__all__ = ["UNSET", "File", "FileTypes", "RequestFiles", "Response", "Unset"] diff --git a/end_to_end_tests/golden-records/my-test-api-client/pyproject.toml b/end_to_end_tests/golden-records/my-test-api-client/pyproject.toml new file mode 100644 index 000000000..f2498ce1a --- /dev/null +++ b/end_to_end_tests/golden-records/my-test-api-client/pyproject.toml @@ -0,0 +1,25 @@ +[tool.poetry] +name = "my-test-api-client" +version = "0.1.0" +description = "A client library for accessing My Test API" +authors = [] +readme = "README.md" +packages = [ + { include = "my_test_api_client" }, +] +include = ["my_test_api_client/py.typed"] + +[tool.poetry.dependencies] +python = "^3.11" +httpx = ">=0.23.1,<0.29.0" +attrs = ">=22.2.0" + +[build-system] +requires = ["poetry-core>=2.0.0,<3.0.0"] +build-backend = "poetry.core.masonry.api" + +[tool.ruff] +line-length = 120 + +[tool.ruff.lint] +select = ["F", "I", "UP"] diff --git a/end_to_end_tests/golden-records/test-3-1-features-client/.gitignore b/end_to_end_tests/golden-records/test-3-1-features-client/.gitignore new file mode 100644 index 000000000..79a2c3d73 --- /dev/null +++ b/end_to_end_tests/golden-records/test-3-1-features-client/.gitignore @@ -0,0 +1,23 @@ +__pycache__/ +build/ +dist/ +*.egg-info/ +.pytest_cache/ + +# pyenv +.python-version + +# Environments +.env +.venv + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# JetBrains +.idea/ + +/coverage.xml +/.coverage diff --git a/end_to_end_tests/test-3-1-golden-record/README.md b/end_to_end_tests/golden-records/test-3-1-features-client/README.md similarity index 98% rename from end_to_end_tests/test-3-1-golden-record/README.md rename to end_to_end_tests/golden-records/test-3-1-features-client/README.md index dbe8a5c1e..352824967 100644 --- a/end_to_end_tests/test-3-1-golden-record/README.md +++ b/end_to_end_tests/golden-records/test-3-1-features-client/README.md @@ -47,7 +47,7 @@ By default, when you're calling an HTTPS API it will attempt to verify that SSL ```python client = AuthenticatedClient( - base_url="https://internal_api.example.com", + base_url="https://internal_api.example.com", token="SuperSecretToken", verify_ssl="/path/to/certificate_bundle.pem", ) @@ -57,7 +57,7 @@ You can also disable certificate validation altogether, but beware that **this i ```python client = AuthenticatedClient( - base_url="https://internal_api.example.com", + base_url="https://internal_api.example.com", token="SuperSecretToken", verify_ssl=False ) diff --git a/end_to_end_tests/test-3-1-golden-record/pyproject.toml b/end_to_end_tests/golden-records/test-3-1-features-client/pyproject.toml similarity index 59% rename from end_to_end_tests/test-3-1-golden-record/pyproject.toml rename to end_to_end_tests/golden-records/test-3-1-features-client/pyproject.toml index f9a1becf8..39efe0b62 100644 --- a/end_to_end_tests/test-3-1-golden-record/pyproject.toml +++ b/end_to_end_tests/golden-records/test-3-1-features-client/pyproject.toml @@ -5,19 +5,17 @@ description = "A client library for accessing Test 3.1 Features" authors = [] readme = "README.md" packages = [ - {include = "test_3_1_features_client"}, + { include = "test_3_1_features_client" }, ] -include = ["CHANGELOG.md", "test_3_1_features_client/py.typed"] - +include = ["test_3_1_features_client/py.typed"] [tool.poetry.dependencies] -python = "^3.8" -httpx = ">=0.20.0,<0.28.0" -attrs = ">=21.3.0" -python-dateutil = "^2.8.0" +python = "^3.11" +httpx = ">=0.23.1,<0.29.0" +attrs = ">=22.2.0" [build-system] -requires = ["poetry-core>=1.0.0"] +requires = ["poetry-core>=2.0.0,<3.0.0"] build-backend = "poetry.core.masonry.api" [tool.ruff] diff --git a/end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/__init__.py b/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/__init__.py similarity index 100% rename from end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/__init__.py rename to end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/__init__.py diff --git a/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/api/__init__.py b/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/api/__init__.py new file mode 100644 index 000000000..81f9fa241 --- /dev/null +++ b/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/api/__init__.py @@ -0,0 +1 @@ +"""Contains methods for accessing the API""" diff --git a/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/api/const/__init__.py b/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/api/const/__init__.py new file mode 100644 index 000000000..2d7c0b23d --- /dev/null +++ b/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/api/const/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/api/const/post_const_path.py b/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/api/const/post_const_path.py similarity index 76% rename from end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/api/const/post_const_path.py rename to end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/api/const/post_const_path.py index 929f417f4..bf3472121 100644 --- a/end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/api/const/post_const_path.py +++ b/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/api/const/post_const_path.py @@ -1,5 +1,6 @@ from http import HTTPStatus -from typing import Any, Dict, Literal, Optional, Union, cast +from typing import Any, Literal, cast +from urllib.parse import quote import httpx @@ -14,11 +15,11 @@ def _get_kwargs( *, body: PostConstPathBody, required_query: Literal["this always goes in the query"], - optional_query: Union[Literal["this sometimes goes in the query"], Unset] = UNSET, -) -> Dict[str, Any]: - headers: Dict[str, Any] = {} + optional_query: Literal["this sometimes goes in the query"] | Unset = UNSET, +) -> dict[str, Any]: + headers: dict[str, Any] = {} - params: Dict[str, Any] = {} + params: dict[str, Any] = {} params["required query"] = required_query @@ -26,15 +27,16 @@ def _get_kwargs( params = {k: v for k, v in params.items() if v is not UNSET and v is not None} - _kwargs: Dict[str, Any] = { + _kwargs: dict[str, Any] = { "method": "post", - "url": f"/const/{path}", + "url": "/const/{path}".format( + path=quote(str(path), safe=""), + ), "params": params, } - _body = body.to_dict() + _kwargs["json"] = body.to_dict() - _kwargs["json"] = _body headers["Content-Type"] = "application/json" _kwargs["headers"] = headers @@ -42,15 +44,16 @@ def _get_kwargs( def _parse_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Optional[Literal["Why have a fixed response? I dunno"]]: - if response.status_code == HTTPStatus.OK: + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> Literal["Why have a fixed response? I dunno"] | None: + if response.status_code == 200: response_200 = cast(Literal["Why have a fixed response? I dunno"], response.json()) if response_200 != "Why have a fixed response? I dunno": raise ValueError( f"response_200 must match const 'Why have a fixed response? I dunno', got '{response_200}'" ) return response_200 + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: @@ -58,7 +61,7 @@ def _parse_response( def _build_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response + *, client: AuthenticatedClient | Client, response: httpx.Response ) -> Response[Literal["Why have a fixed response? I dunno"]]: return Response( status_code=HTTPStatus(response.status_code), @@ -71,16 +74,16 @@ def _build_response( def sync_detailed( path: Literal["this goes in the path"], *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: PostConstPathBody, required_query: Literal["this always goes in the query"], - optional_query: Union[Literal["this sometimes goes in the query"], Unset] = UNSET, + optional_query: Literal["this sometimes goes in the query"] | Unset = UNSET, ) -> Response[Literal["Why have a fixed response? I dunno"]]: """ Args: path (Literal['this goes in the path']): required_query (Literal['this always goes in the query']): - optional_query (Union[Literal['this sometimes goes in the query'], Unset]): + optional_query (Literal['this sometimes goes in the query'] | Unset): body (PostConstPathBody): Raises: @@ -108,16 +111,16 @@ def sync_detailed( def sync( path: Literal["this goes in the path"], *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: PostConstPathBody, required_query: Literal["this always goes in the query"], - optional_query: Union[Literal["this sometimes goes in the query"], Unset] = UNSET, -) -> Optional[Literal["Why have a fixed response? I dunno"]]: + optional_query: Literal["this sometimes goes in the query"] | Unset = UNSET, +) -> Literal["Why have a fixed response? I dunno"] | None: """ Args: path (Literal['this goes in the path']): required_query (Literal['this always goes in the query']): - optional_query (Union[Literal['this sometimes goes in the query'], Unset]): + optional_query (Literal['this sometimes goes in the query'] | Unset): body (PostConstPathBody): Raises: @@ -140,16 +143,16 @@ def sync( async def asyncio_detailed( path: Literal["this goes in the path"], *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: PostConstPathBody, required_query: Literal["this always goes in the query"], - optional_query: Union[Literal["this sometimes goes in the query"], Unset] = UNSET, + optional_query: Literal["this sometimes goes in the query"] | Unset = UNSET, ) -> Response[Literal["Why have a fixed response? I dunno"]]: """ Args: path (Literal['this goes in the path']): required_query (Literal['this always goes in the query']): - optional_query (Union[Literal['this sometimes goes in the query'], Unset]): + optional_query (Literal['this sometimes goes in the query'] | Unset): body (PostConstPathBody): Raises: @@ -175,16 +178,16 @@ async def asyncio_detailed( async def asyncio( path: Literal["this goes in the path"], *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, body: PostConstPathBody, required_query: Literal["this always goes in the query"], - optional_query: Union[Literal["this sometimes goes in the query"], Unset] = UNSET, -) -> Optional[Literal["Why have a fixed response? I dunno"]]: + optional_query: Literal["this sometimes goes in the query"] | Unset = UNSET, +) -> Literal["Why have a fixed response? I dunno"] | None: """ Args: path (Literal['this goes in the path']): required_query (Literal['this always goes in the query']): - optional_query (Union[Literal['this sometimes goes in the query'], Unset]): + optional_query (Literal['this sometimes goes in the query'] | Unset): body (PostConstPathBody): Raises: diff --git a/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/api/prefix_items/__init__.py b/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/api/prefix_items/__init__.py new file mode 100644 index 000000000..2d7c0b23d --- /dev/null +++ b/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/api/prefix_items/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/api/prefix_items/post_prefix_items.py b/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/api/prefix_items/post_prefix_items.py new file mode 100644 index 000000000..5b114873e --- /dev/null +++ b/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/api/prefix_items/post_prefix_items.py @@ -0,0 +1,150 @@ +from http import HTTPStatus +from typing import Any, cast + +import httpx + +from ... import errors +from ...client import AuthenticatedClient, Client +from ...models.post_prefix_items_body import PostPrefixItemsBody +from ...types import Response + + +def _get_kwargs( + *, + body: PostPrefixItemsBody, +) -> dict[str, Any]: + headers: dict[str, Any] = {} + + _kwargs: dict[str, Any] = { + "method": "post", + "url": "/prefixItems", + } + + _kwargs["json"] = body.to_dict() + + headers["Content-Type"] = "application/json" + + _kwargs["headers"] = headers + return _kwargs + + +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> str | None: + if response.status_code == 200: + response_200 = cast(str, response.json()) + return response_200 + + if client.raise_on_unexpected_status: + raise errors.UnexpectedStatus(response.status_code, response.content) + else: + return None + + +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[str]: + return Response( + status_code=HTTPStatus(response.status_code), + content=response.content, + headers=response.headers, + parsed=_parse_response(client=client, response=response), + ) + + +def sync_detailed( + *, + client: AuthenticatedClient | Client, + body: PostPrefixItemsBody, +) -> Response[str]: + """ + Args: + body (PostPrefixItemsBody): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[str] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = client.get_httpx_client().request( + **kwargs, + ) + + return _build_response(client=client, response=response) + + +def sync( + *, + client: AuthenticatedClient | Client, + body: PostPrefixItemsBody, +) -> str | None: + """ + Args: + body (PostPrefixItemsBody): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + str + """ + + return sync_detailed( + client=client, + body=body, + ).parsed + + +async def asyncio_detailed( + *, + client: AuthenticatedClient | Client, + body: PostPrefixItemsBody, +) -> Response[str]: + """ + Args: + body (PostPrefixItemsBody): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[str] + """ + + kwargs = _get_kwargs( + body=body, + ) + + response = await client.get_async_httpx_client().request(**kwargs) + + return _build_response(client=client, response=response) + + +async def asyncio( + *, + client: AuthenticatedClient | Client, + body: PostPrefixItemsBody, +) -> str | None: + """ + Args: + body (PostPrefixItemsBody): + + Raises: + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + str + """ + + return ( + await asyncio_detailed( + client=client, + body=body, + ) + ).parsed diff --git a/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/client.py b/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/client.py new file mode 100644 index 000000000..edb246d7e --- /dev/null +++ b/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/client.py @@ -0,0 +1,268 @@ +import ssl +from typing import Any, Self + +import httpx +from attrs import define, evolve, field + + +@define +class Client: + """A class for keeping track of data related to the API + + The following are accepted as keyword arguments and will be used to construct httpx Clients internally: + + ``base_url``: The base URL for the API, all requests are made to a relative path to this URL + + ``cookies``: A dictionary of cookies to be sent with every request + + ``headers``: A dictionary of headers to be sent with every request + + ``timeout``: The maximum amount of a time a request can take. API functions will raise + httpx.TimeoutException if this is exceeded. + + ``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production, + but can be set to False for testing purposes. + + ``follow_redirects``: Whether or not to follow redirects. Default value is False. + + ``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor. + + + Attributes: + raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a + status code that was not documented in the source OpenAPI document. Can also be provided as a keyword + argument to the constructor. + """ + + raise_on_unexpected_status: bool = field(default=False, kw_only=True) + _base_url: str = field(alias="base_url") + _cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies") + _headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers") + _timeout: httpx.Timeout | None = field(default=None, kw_only=True, alias="timeout") + _verify_ssl: str | bool | ssl.SSLContext = field(default=True, kw_only=True, alias="verify_ssl") + _follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects") + _httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args") + _client: httpx.Client | None = field(default=None, init=False) + _async_client: httpx.AsyncClient | None = field(default=None, init=False) + + def with_headers(self, headers: dict[str, str]) -> "Client": + """Get a new client matching this one with additional headers""" + if self._client is not None: + self._client.headers.update(headers) + if self._async_client is not None: + self._async_client.headers.update(headers) + return evolve(self, headers={**self._headers, **headers}) + + def with_cookies(self, cookies: dict[str, str]) -> "Client": + """Get a new client matching this one with additional cookies""" + if self._client is not None: + self._client.cookies.update(cookies) + if self._async_client is not None: + self._async_client.cookies.update(cookies) + return evolve(self, cookies={**self._cookies, **cookies}) + + def with_timeout(self, timeout: httpx.Timeout) -> "Client": + """Get a new client matching this one with a new timeout configuration""" + if self._client is not None: + self._client.timeout = timeout + if self._async_client is not None: + self._async_client.timeout = timeout + return evolve(self, timeout=timeout) + + def set_httpx_client(self, client: httpx.Client) -> Self: + """Manually set the underlying httpx.Client + + **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. + """ + self._client = client + return self + + def get_httpx_client(self) -> httpx.Client: + """Get the underlying httpx.Client, constructing a new one if not previously set""" + if self._client is None: + self._client = httpx.Client( + base_url=self._base_url, + cookies=self._cookies, + headers=self._headers, + timeout=self._timeout, + verify=self._verify_ssl, + follow_redirects=self._follow_redirects, + **self._httpx_args, + ) + return self._client + + def __enter__(self) -> Self: + """Enter a context manager for self.client—you cannot enter twice (see httpx docs)""" + self.get_httpx_client().__enter__() + return self + + def __exit__(self, *args: Any, **kwargs: Any) -> None: + """Exit a context manager for internal httpx.Client (see httpx docs)""" + self.get_httpx_client().__exit__(*args, **kwargs) + + def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> Self: + """Manually set the underlying httpx.AsyncClient + + **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. + """ + self._async_client = async_client + return self + + def get_async_httpx_client(self) -> httpx.AsyncClient: + """Get the underlying httpx.AsyncClient, constructing a new one if not previously set""" + if self._async_client is None: + self._async_client = httpx.AsyncClient( + base_url=self._base_url, + cookies=self._cookies, + headers=self._headers, + timeout=self._timeout, + verify=self._verify_ssl, + follow_redirects=self._follow_redirects, + **self._httpx_args, + ) + return self._async_client + + async def __aenter__(self) -> Self: + """Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)""" + await self.get_async_httpx_client().__aenter__() + return self + + async def __aexit__(self, *args: Any, **kwargs: Any) -> None: + """Exit a context manager for underlying httpx.AsyncClient (see httpx docs)""" + await self.get_async_httpx_client().__aexit__(*args, **kwargs) + + +@define +class AuthenticatedClient: + """A Client which has been authenticated for use on secured endpoints + + The following are accepted as keyword arguments and will be used to construct httpx Clients internally: + + ``base_url``: The base URL for the API, all requests are made to a relative path to this URL + + ``cookies``: A dictionary of cookies to be sent with every request + + ``headers``: A dictionary of headers to be sent with every request + + ``timeout``: The maximum amount of a time a request can take. API functions will raise + httpx.TimeoutException if this is exceeded. + + ``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production, + but can be set to False for testing purposes. + + ``follow_redirects``: Whether or not to follow redirects. Default value is False. + + ``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor. + + + Attributes: + raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a + status code that was not documented in the source OpenAPI document. Can also be provided as a keyword + argument to the constructor. + token: The token to use for authentication + prefix: The prefix to use for the Authorization header + auth_header_name: The name of the Authorization header + """ + + raise_on_unexpected_status: bool = field(default=False, kw_only=True) + _base_url: str = field(alias="base_url") + _cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies") + _headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers") + _timeout: httpx.Timeout | None = field(default=None, kw_only=True, alias="timeout") + _verify_ssl: str | bool | ssl.SSLContext = field(default=True, kw_only=True, alias="verify_ssl") + _follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects") + _httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args") + _client: httpx.Client | None = field(default=None, init=False) + _async_client: httpx.AsyncClient | None = field(default=None, init=False) + + token: str + prefix: str = "Bearer" + auth_header_name: str = "Authorization" + + def with_headers(self, headers: dict[str, str]) -> "AuthenticatedClient": + """Get a new client matching this one with additional headers""" + if self._client is not None: + self._client.headers.update(headers) + if self._async_client is not None: + self._async_client.headers.update(headers) + return evolve(self, headers={**self._headers, **headers}) + + def with_cookies(self, cookies: dict[str, str]) -> "AuthenticatedClient": + """Get a new client matching this one with additional cookies""" + if self._client is not None: + self._client.cookies.update(cookies) + if self._async_client is not None: + self._async_client.cookies.update(cookies) + return evolve(self, cookies={**self._cookies, **cookies}) + + def with_timeout(self, timeout: httpx.Timeout) -> "AuthenticatedClient": + """Get a new client matching this one with a new timeout configuration""" + if self._client is not None: + self._client.timeout = timeout + if self._async_client is not None: + self._async_client.timeout = timeout + return evolve(self, timeout=timeout) + + def set_httpx_client(self, client: httpx.Client) -> Self: + """Manually set the underlying httpx.Client + + **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. + """ + self._client = client + return self + + def get_httpx_client(self) -> httpx.Client: + """Get the underlying httpx.Client, constructing a new one if not previously set""" + if self._client is None: + self._headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token + self._client = httpx.Client( + base_url=self._base_url, + cookies=self._cookies, + headers=self._headers, + timeout=self._timeout, + verify=self._verify_ssl, + follow_redirects=self._follow_redirects, + **self._httpx_args, + ) + return self._client + + def __enter__(self) -> Self: + """Enter a context manager for self.client—you cannot enter twice (see httpx docs)""" + self.get_httpx_client().__enter__() + return self + + def __exit__(self, *args: Any, **kwargs: Any) -> None: + """Exit a context manager for internal httpx.Client (see httpx docs)""" + self.get_httpx_client().__exit__(*args, **kwargs) + + def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> Self: + """Manually set the underlying httpx.AsyncClient + + **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. + """ + self._async_client = async_client + return self + + def get_async_httpx_client(self) -> httpx.AsyncClient: + """Get the underlying httpx.AsyncClient, constructing a new one if not previously set""" + if self._async_client is None: + self._headers[self.auth_header_name] = f"{self.prefix} {self.token}" if self.prefix else self.token + self._async_client = httpx.AsyncClient( + base_url=self._base_url, + cookies=self._cookies, + headers=self._headers, + timeout=self._timeout, + verify=self._verify_ssl, + follow_redirects=self._follow_redirects, + **self._httpx_args, + ) + return self._async_client + + async def __aenter__(self) -> Self: + """Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)""" + await self.get_async_httpx_client().__aenter__() + return self + + async def __aexit__(self, *args: Any, **kwargs: Any) -> None: + """Exit a context manager for underlying httpx.AsyncClient (see httpx docs)""" + await self.get_async_httpx_client().__aexit__(*args, **kwargs) diff --git a/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/errors.py b/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/errors.py new file mode 100644 index 000000000..5f92e76ac --- /dev/null +++ b/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/errors.py @@ -0,0 +1,16 @@ +"""Contains shared errors types that can be raised from API functions""" + + +class UnexpectedStatus(Exception): + """Raised by api functions when the response status an undocumented status and Client.raise_on_unexpected_status is True""" + + def __init__(self, status_code: int, content: bytes): + self.status_code = status_code + self.content = content + + super().__init__( + f"Unexpected status code: {status_code}\n\nResponse content:\n{content.decode(errors='ignore')}" + ) + + +__all__ = ["UnexpectedStatus"] diff --git a/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/models/__init__.py b/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/models/__init__.py new file mode 100644 index 000000000..aeafedd08 --- /dev/null +++ b/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/models/__init__.py @@ -0,0 +1,9 @@ +"""Contains all the data models used in inputs/outputs""" + +from .post_const_path_body import PostConstPathBody +from .post_prefix_items_body import PostPrefixItemsBody + +__all__ = ( + "PostConstPathBody", + "PostPrefixItemsBody", +) diff --git a/end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/models/post_const_path_body.py b/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/models/post_const_path_body.py similarity index 70% rename from end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/models/post_const_path_body.py rename to end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/models/post_const_path_body.py index 9ac2f9102..f59894f08 100644 --- a/end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/models/post_const_path_body.py +++ b/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/models/post_const_path_body.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Literal, Type, TypeVar, Union, cast +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, Literal, TypeVar, cast from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -13,24 +16,24 @@ class PostConstPathBody: """ Attributes: required (Literal['this always goes in the body']): - nullable (Union[Literal['this or null goes in the body'], None]): - optional (Union[Literal['this sometimes goes in the body'], Unset]): + nullable (Literal['this or null goes in the body'] | None): + optional (Literal['this sometimes goes in the body'] | Unset): """ required: Literal["this always goes in the body"] - nullable: Union[Literal["this or null goes in the body"], None] - optional: Union[Literal["this sometimes goes in the body"], Unset] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + nullable: Literal["this or null goes in the body"] | None + optional: Literal["this sometimes goes in the body"] | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: required = self.required - nullable: Union[Literal["this or null goes in the body"], None] + nullable: Literal["this or null goes in the body"] | None nullable = self.nullable optional = self.optional - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update( { @@ -44,13 +47,13 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) required = cast(Literal["this always goes in the body"], d.pop("required")) if required != "this always goes in the body": raise ValueError(f"required must match const 'this always goes in the body', got '{required}'") - def _parse_nullable(data: object) -> Union[Literal["this or null goes in the body"], None]: + def _parse_nullable(data: object) -> Literal["this or null goes in the body"] | None: if data is None: return data nullable_type_1 = cast(Literal["this or null goes in the body"], data) @@ -59,11 +62,11 @@ def _parse_nullable(data: object) -> Union[Literal["this or null goes in the bod f"nullable_type_1 must match const 'this or null goes in the body', got '{nullable_type_1}'" ) return nullable_type_1 - return cast(Union[Literal["this or null goes in the body"], None], data) + return cast(Literal["this or null goes in the body"] | None, data) nullable = _parse_nullable(d.pop("nullable")) - optional = cast(Union[Literal["this sometimes goes in the body"], Unset], d.pop("optional", UNSET)) + optional = cast(Literal["this sometimes goes in the body"] | Unset, d.pop("optional", UNSET)) if optional != "this sometimes goes in the body" and not isinstance(optional, Unset): raise ValueError(f"optional must match const 'this sometimes goes in the body', got '{optional}'") @@ -77,7 +80,7 @@ def _parse_nullable(data: object) -> Union[Literal["this or null goes in the bod return post_const_path_body @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/models/post_prefix_items_body.py b/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/models/post_prefix_items_body.py new file mode 100644 index 000000000..b074bb717 --- /dev/null +++ b/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/models/post_prefix_items_body.py @@ -0,0 +1,110 @@ +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, Literal, TypeVar, cast + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="PostPrefixItemsBody") + + +@_attrs_define +class PostPrefixItemsBody: + """ + Attributes: + prefix_items_and_items (list[float | Literal['prefix'] | str] | Unset): + prefix_items_only (list[float | str] | Unset): + """ + + prefix_items_and_items: list[float | Literal["prefix"] | str] | Unset = UNSET + prefix_items_only: list[float | str] | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + prefix_items_and_items: list[float | Literal["prefix"] | str] | Unset = UNSET + if not isinstance(self.prefix_items_and_items, Unset): + prefix_items_and_items = [] + for prefix_items_and_items_item_data in self.prefix_items_and_items: + prefix_items_and_items_item: float | Literal["prefix"] | str + prefix_items_and_items_item = prefix_items_and_items_item_data + prefix_items_and_items.append(prefix_items_and_items_item) + + prefix_items_only: list[float | str] | Unset = UNSET + if not isinstance(self.prefix_items_only, Unset): + prefix_items_only = [] + for prefix_items_only_item_data in self.prefix_items_only: + prefix_items_only_item: float | str + prefix_items_only_item = prefix_items_only_item_data + prefix_items_only.append(prefix_items_only_item) + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update({}) + if prefix_items_and_items is not UNSET: + field_dict["prefixItemsAndItems"] = prefix_items_and_items + if prefix_items_only is not UNSET: + field_dict["prefixItemsOnly"] = prefix_items_only + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + _prefix_items_and_items = d.pop("prefixItemsAndItems", UNSET) + prefix_items_and_items: list[float | Literal["prefix"] | str] | Unset = UNSET + if _prefix_items_and_items is not UNSET: + prefix_items_and_items = [] + for prefix_items_and_items_item_data in _prefix_items_and_items: + + def _parse_prefix_items_and_items_item(data: object) -> float | Literal["prefix"] | str: + prefix_items_and_items_item_type_0 = cast(Literal["prefix"], data) + if prefix_items_and_items_item_type_0 != "prefix": + raise ValueError( + f"prefixItemsAndItems_item_type_0 must match const 'prefix', got '{prefix_items_and_items_item_type_0}'" + ) + return prefix_items_and_items_item_type_0 + return cast(float | Literal["prefix"] | str, data) + + prefix_items_and_items_item = _parse_prefix_items_and_items_item(prefix_items_and_items_item_data) + + prefix_items_and_items.append(prefix_items_and_items_item) + + _prefix_items_only = d.pop("prefixItemsOnly", UNSET) + prefix_items_only: list[float | str] | Unset = UNSET + if _prefix_items_only is not UNSET: + prefix_items_only = [] + for prefix_items_only_item_data in _prefix_items_only: + + def _parse_prefix_items_only_item(data: object) -> float | str: + return cast(float | str, data) + + prefix_items_only_item = _parse_prefix_items_only_item(prefix_items_only_item_data) + + prefix_items_only.append(prefix_items_only_item) + + post_prefix_items_body = cls( + prefix_items_and_items=prefix_items_and_items, + prefix_items_only=prefix_items_only, + ) + + post_prefix_items_body.additional_properties = d + return post_prefix_items_body + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/py.typed b/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/py.typed new file mode 100644 index 000000000..1aad32711 --- /dev/null +++ b/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/py.typed @@ -0,0 +1 @@ +# Marker file for PEP 561 \ No newline at end of file diff --git a/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/types.py b/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/types.py new file mode 100644 index 000000000..b64af0952 --- /dev/null +++ b/end_to_end_tests/golden-records/test-3-1-features-client/test_3_1_features_client/types.py @@ -0,0 +1,54 @@ +"""Contains some shared types for properties""" + +from collections.abc import Mapping, MutableMapping +from http import HTTPStatus +from typing import IO, BinaryIO, Generic, Literal, TypeVar + +from attrs import define + + +class Unset: + def __bool__(self) -> Literal[False]: + return False + + +UNSET: Unset = Unset() + +# The types that `httpx.Client(files=)` can accept, copied from that library. +FileContent = IO[bytes] | bytes | str +FileTypes = ( + # (filename, file (or bytes), content_type) + tuple[str | None, FileContent, str | None] + # (filename, file (or bytes), content_type, headers) + | tuple[str | None, FileContent, str | None, Mapping[str, str]] +) +RequestFiles = list[tuple[str, FileTypes]] + + +@define +class File: + """Contains information for file uploads""" + + payload: BinaryIO + file_name: str | None = None + mime_type: str | None = None + + def to_tuple(self) -> FileTypes: + """Return a tuple representation that httpx will accept for multipart/form-data""" + return self.file_name, self.payload, self.mime_type + + +T = TypeVar("T") + + +@define +class Response(Generic[T]): + """A response from an endpoint""" + + status_code: HTTPStatus + content: bytes + headers: MutableMapping[str, str] + parsed: T | None + + +__all__ = ["UNSET", "File", "FileTypes", "RequestFiles", "Response", "Unset"] diff --git a/end_to_end_tests/literal_enums.config.yml b/end_to_end_tests/literal_enums.config.yml new file mode 100644 index 000000000..120eae0a7 --- /dev/null +++ b/end_to_end_tests/literal_enums.config.yml @@ -0,0 +1 @@ +literal_enums: true diff --git a/end_to_end_tests/metadata_snapshots/pdm.pyproject.toml b/end_to_end_tests/metadata_snapshots/pdm.pyproject.toml index fddcea97f..c5262ff1e 100644 --- a/end_to_end_tests/metadata_snapshots/pdm.pyproject.toml +++ b/end_to_end_tests/metadata_snapshots/pdm.pyproject.toml @@ -4,11 +4,10 @@ version = "0.1.0" description = "A client library for accessing Test 3.1 Features" authors = [] readme = "README.md" -requires-python = ">=3.8,<4.0" +requires-python = ">=3.11" dependencies = [ - "httpx>=0.20.0,<0.28.0", - "attrs>=21.3.0", - "python-dateutil>=2.8.0", + "httpx>=0.23.1,<0.29.0", + "attrs>=22.2.0", ] [tool.pdm] diff --git a/end_to_end_tests/metadata_snapshots/poetry.pyproject.toml b/end_to_end_tests/metadata_snapshots/poetry.pyproject.toml index f9a1becf8..39efe0b62 100644 --- a/end_to_end_tests/metadata_snapshots/poetry.pyproject.toml +++ b/end_to_end_tests/metadata_snapshots/poetry.pyproject.toml @@ -5,19 +5,17 @@ description = "A client library for accessing Test 3.1 Features" authors = [] readme = "README.md" packages = [ - {include = "test_3_1_features_client"}, + { include = "test_3_1_features_client" }, ] -include = ["CHANGELOG.md", "test_3_1_features_client/py.typed"] - +include = ["test_3_1_features_client/py.typed"] [tool.poetry.dependencies] -python = "^3.8" -httpx = ">=0.20.0,<0.28.0" -attrs = ">=21.3.0" -python-dateutil = "^2.8.0" +python = "^3.11" +httpx = ">=0.23.1,<0.29.0" +attrs = ">=22.2.0" [build-system] -requires = ["poetry-core>=1.0.0"] +requires = ["poetry-core>=2.0.0,<3.0.0"] build-backend = "poetry.core.masonry.api" [tool.ruff] diff --git a/end_to_end_tests/metadata_snapshots/setup.py b/end_to_end_tests/metadata_snapshots/setup.py index 6350b8c4c..96e9030b5 100644 --- a/end_to_end_tests/metadata_snapshots/setup.py +++ b/end_to_end_tests/metadata_snapshots/setup.py @@ -12,7 +12,7 @@ long_description=long_description, long_description_content_type="text/markdown", packages=find_packages(), - python_requires=">=3.8, <4", - install_requires=["httpx >= 0.20.0, < 0.28.0", "attrs >= 21.3.0", "python-dateutil >= 2.8.0, < 3"], + python_requires=">=3.11, <4", + install_requires=["httpx >= 0.23.1, < 0.29.0", "attrs >= 22.2.0"], package_data={"test_3_1_features_client": ["py.typed"]}, ) diff --git a/end_to_end_tests/metadata_snapshots/uv.pyproject.toml b/end_to_end_tests/metadata_snapshots/uv.pyproject.toml new file mode 100644 index 000000000..553582723 --- /dev/null +++ b/end_to_end_tests/metadata_snapshots/uv.pyproject.toml @@ -0,0 +1,25 @@ +[project] +name = "test-3-1-features-client" +version = "0.1.0" +description = "A client library for accessing Test 3.1 Features" +authors = [] +requires-python = ">=3.11" +readme = "README.md" +dependencies = [ + "httpx>=0.23.1,<0.29.0", + "attrs>=22.2.0", +] + +[tool.uv.build-backend] +module-name = "test_3_1_features_client" +module-root = "" + +[build-system] +requires = ["uv_build>=0.12.0,<0.13.0"] +build-backend = "uv_build" + +[tool.ruff] +line-length = 120 + +[tool.ruff.lint] +select = ["F", "I", "UP"] diff --git a/end_to_end_tests/openapi_3.1_enums.yaml b/end_to_end_tests/openapi_3.1_enums.yaml new file mode 100644 index 000000000..b77d4ff74 --- /dev/null +++ b/end_to_end_tests/openapi_3.1_enums.yaml @@ -0,0 +1,226 @@ +openapi: 3.1.0 +info: + title: My Enum API + description: An API for testing enum handling in openapi-python-client + version: 0.1.0 +paths: + /tests/: + get: + tags: + - tests + summary: Get List + description: 'Get a list of things ' + operationId: getUserList + parameters: + - required: true + schema: + title: An Enum Value + type: array + items: + $ref: '#/components/schemas/AnEnum' + name: an_enum_value + in: query + - required: true + schema: + title: An Enum Value With Null And String Values + type: array + items: + $ref: '#/components/schemas/AnEnumWithNull' + name: an_enum_value_with_null + in: query + - required: true + schema: + title: An Enum Value With Only Null Values + type: array + items: + $ref: '#/components/schemas/AnEnumWithOnlyNull' + name: an_enum_value_with_only_null + in: query + - in: header + name: Int-Enum-Header + required: false + schema: + type: integer + enum: + - 1 + - 2 + - 3 + - in: header + name: String-Enum-Header + required: false + schema: + type: string + enum: + - one + - two + - three + responses: + '200': + description: Successful Response + content: + application/json: + schema: + title: Response Get List Tests Get + type: array + items: + $ref: '#/components/schemas/AModel' + post: + tags: + - tests + summary: Post List + description: 'Post a list of things ' + operationId: postUserList + requestBody: + content: + multipart/form-data: + schema: + type: object + properties: + an_enum_value: + title: An Enum Value + type: array + items: + $ref: '#/components/schemas/AnEnum' + an_enum_value_with_null: + title: An Enum Value With Null And String Values + type: array + items: + $ref: '#/components/schemas/AnEnumWithNull' + an_enum_value_with_only_null: + title: An Enum Value With Only Null Values + type: array + items: + $ref: '#/components/schemas/AnEnumWithOnlyNull' + an_allof_enum_with_overridden_default: + title: An AllOf Enum With Overridden Default + allOf: + - $ref: '#/components/schemas/AnAllOfEnum' + default: overridden_default + an_optional_allof_enum: + title: An Optional AllOf Enum + $ref: '#/components/schemas/AnAllOfEnum' + nested_list_of_enums: + title: Nested List Of Enums + type: array + items: + type: array + items: + $ref: '#/components/schemas/DifferentEnum' + default: [] + responses: + '200': + description: Successful Response + content: + application/json: + schema: + title: Response Get List Tests Get + type: array + items: + $ref: '#/components/schemas/AModel' + /enum/int: + post: + tags: + - enums + summary: Int Enum + operationId: int_enum_tests_int_enum_post + parameters: + - required: true + schema: + $ref: '#/components/schemas/AnIntEnum' + name: int_enum + in: query + responses: + '200': + description: Successful Response + content: + application/json: + schema: {} + /enum/bool: + post: + tags: + - enums + summary: Bool Enum + operationId: bool_enum_tests_bool_enum_post + parameters: + - required: true + schema: + type: boolean + enum: + - true + - false + name: bool_enum + in: query + responses: + '200': + description: Successful Response + content: + application/json: + schema: {} +components: + schemas: + AModel: + title: AModel + required: + - an_enum_value + - an_allof_enum_with_overridden_default + type: object + properties: + any_value: {} + an_enum_value: + $ref: '#/components/schemas/AnEnum' + an_allof_enum_with_overridden_default: + allOf: + - $ref: '#/components/schemas/AnAllOfEnum' + default: overridden_default + an_optional_allof_enum: + $ref: '#/components/schemas/AnAllOfEnum' + nested_list_of_enums: + title: Nested List Of Enums + type: array + items: + type: array + items: + $ref: '#/components/schemas/DifferentEnum' + default: [] + description: 'A Model for testing all the ways enums can be used ' + additionalProperties: false + AnEnum: + title: AnEnum + enum: + - FIRST_VALUE + - SECOND_VALUE + description: 'For testing Enums in all the ways they can be used ' + AnEnumWithNull: + title: AnEnumWithNull + enum: + - FIRST_VALUE + - SECOND_VALUE + - null + description: 'For testing Enums with mixed string / null values ' + AnEnumWithOnlyNull: + title: AnEnumWithOnlyNull + enum: + - null + description: 'For testing Enums with only null values ' + AnAllOfEnum: + title: AnAllOfEnum + enum: + - foo + - bar + - a_default + - overridden_default + default: a_default + AnIntEnum: + title: AnIntEnum + enum: + - -1 + - 1 + - 2 + type: integer + description: An enumeration. + DifferentEnum: + title: DifferentEnum + enum: + - DIFFERENT + - OTHER + description: An enumeration. diff --git a/end_to_end_tests/regen_golden_record.py b/end_to_end_tests/regen_golden_record.py index 0bffe132a..425775530 100644 --- a/end_to_end_tests/regen_golden_record.py +++ b/end_to_end_tests/regen_golden_record.py @@ -1,8 +1,7 @@ -""" Regenerate golden-record """ +"""Regenerate golden-record""" + import filecmp -import os import shutil -import tempfile from pathlib import Path from typer.testing import CliRunner @@ -10,79 +9,116 @@ from openapi_python_client.cli import app -def regen_golden_record(): +def _regenerate( + *, + spec_file_name: str, + output_dir: str, + capture_golden_record: bool = False, + config_file_name: str = "config.yml", + extra_args: list[str] | None = None, +) -> None: + end_to_end_tests_base_path = Path(__file__).parent runner = CliRunner() - openapi_path = Path(__file__).parent / "baseline_openapi_3.0.json" - - gr_path = Path(__file__).parent / "golden-record" - output_path = Path.cwd() / "my-test-api-client" - config_path = Path(__file__).parent / "config.yml" + openapi_path = end_to_end_tests_base_path / spec_file_name - shutil.rmtree(gr_path, ignore_errors=True) + output_path = end_to_end_tests_base_path / "tmp" / output_dir shutil.rmtree(output_path, ignore_errors=True) - result = runner.invoke( - app, ["generate", f"--config={config_path}", f"--path={openapi_path}"] - ) + args = ["generate", f"--path={openapi_path}", f"--output-path={output_path}"] + if config_file_name: + config_path = end_to_end_tests_base_path / config_file_name + args.append(f"--config={config_path}") + if extra_args: + args.extend(extra_args) + print(f"Using {spec_file_name}{f' and {config_file_name}' if config_file_name else ''}") + + result = runner.invoke(app, args) if result.stdout: print(result.stdout) if result.exception: - raise result.exception - output_path.rename(gr_path) + raise Exception(f"{result.exception} {result.stderr}") + if capture_golden_record: + gr_path = end_to_end_tests_base_path / "golden-records" / output_dir + shutil.rmtree(gr_path, ignore_errors=True) + output_path.rename(gr_path) + + +def regen_golden_record(): + _regenerate( + spec_file_name="baseline_openapi_3.0.json", + output_dir="my-test-api-client", + capture_golden_record=True, + ) def regen_golden_record_3_1_features(): - runner = CliRunner() - openapi_path = Path(__file__).parent / "3.1_specific.openapi.yaml" + _regenerate( + spec_file_name="3.1_specific.openapi.yaml", + output_dir="test-3-1-features-client", + capture_golden_record=True, + ) - gr_path = Path(__file__).parent / "test-3-1-golden-record" - output_path = Path.cwd() / "test-3-1-features-client" - shutil.rmtree(gr_path, ignore_errors=True) - shutil.rmtree(output_path, ignore_errors=True) +def regen_literal_enums_golden_record(): + _regenerate( + spec_file_name="openapi_3.1_enums.yaml", + output_dir="my-enum-api-client", + capture_golden_record=True, + config_file_name="literal_enums.config.yml", + ) - result = runner.invoke(app, ["generate", f"--path={openapi_path}"]) - if result.stdout: - print(result.stdout) - if result.exception: - raise result.exception - output_path.rename(gr_path) +def regen_escapes_golden_record(): + _regenerate( + spec_file_name="escapes.openapi.yaml", + output_dir="escapes-client", + capture_golden_record=True, + ) def regen_metadata_snapshots(): - runner = CliRunner() - openapi_path = Path(__file__).parent / "3.1_specific.openapi.yaml" - output_path = Path.cwd() / "test-3-1-features-client" + output_path = Path(__file__).parent / "tmp" / "test-3-1-features-client" snapshots_dir = Path(__file__).parent / "metadata_snapshots" - for (meta, file, rename_to) in (("setup", "setup.py", "setup.py"), ("pdm", "pyproject.toml", "pdm.pyproject.toml"), ("poetry", "pyproject.toml", "poetry.pyproject.toml")): - shutil.rmtree(output_path, ignore_errors=True) - result = runner.invoke(app, ["generate", f"--path={openapi_path}", f"--meta={meta}"]) - - if result.stdout: - print(result.stdout) - if result.exception: - raise result.exception - + for meta, file, rename_to in ( + ("setup", "setup.py", "setup.py"), + ("pdm", "pyproject.toml", "pdm.pyproject.toml"), + ("poetry", "pyproject.toml", "poetry.pyproject.toml"), + ("uv", "pyproject.toml", "uv.pyproject.toml"), + ): + _regenerate( + spec_file_name="3.1_specific.openapi.yaml", + output_dir="test-3-1-features-client", + extra_args=[f"--meta={meta}"], + ) (output_path / file).rename(snapshots_dir / rename_to) shutil.rmtree(output_path, ignore_errors=True) +def regen_docstrings_on_attributes_golden_record(): + _regenerate( + spec_file_name="docstrings_on_attributes.yml", + output_dir="docstrings-on-attributes-golden-record", + capture_golden_record=True, + config_file_name="docstrings_on_attributes.config.yml", + ) + + def regen_custom_template_golden_record(): runner = CliRunner() openapi_path = Path(__file__).parent / "baseline_openapi_3.0.json" tpl_dir = Path(__file__).parent / "test_custom_templates" - gr_path = Path(__file__).parent / "golden-record" - tpl_gr_path = Path(__file__).parent / "custom-templates-golden-record" + gr_path = Path(__file__).parent / "golden-records" / "my-test-api-client" + tpl_gr_path = Path(__file__).parent / "golden-records" / "custom-templates" - output_path = Path.cwd() / "my-test-api-client" + output_path = Path(__file__).parent / "tmp" / "my-test-api-client" config_path = Path(__file__).parent / "config.yml" shutil.rmtree(tpl_gr_path, ignore_errors=True) + shutil.rmtree(output_path, ignore_errors=True) result = runner.invoke( app, @@ -91,6 +127,7 @@ def regen_custom_template_golden_record(): f"--config={config_path}", f"--path={openapi_path}", f"--custom-template-path={tpl_dir}", + f"--output-path={output_path}", ], ) @@ -123,4 +160,7 @@ def regen_custom_template_golden_record(): regen_golden_record() regen_golden_record_3_1_features() regen_metadata_snapshots() + regen_docstrings_on_attributes_golden_record() regen_custom_template_golden_record() + regen_literal_enums_golden_record() + regen_escapes_golden_record() diff --git a/end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/api/const/__init__.py b/end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/api/const/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/models/__init__.py b/end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/models/__init__.py deleted file mode 100644 index f923a5c37..000000000 --- a/end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/models/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -"""Contains all the data models used in inputs/outputs""" - -from .post_const_path_body import PostConstPathBody - -__all__ = ("PostConstPathBody",) diff --git a/end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/types.py b/end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/types.py deleted file mode 100644 index 21fac106f..000000000 --- a/end_to_end_tests/test-3-1-golden-record/test_3_1_features_client/types.py +++ /dev/null @@ -1,45 +0,0 @@ -"""Contains some shared types for properties""" - -from http import HTTPStatus -from typing import BinaryIO, Generic, Literal, MutableMapping, Optional, Tuple, TypeVar - -from attrs import define - - -class Unset: - def __bool__(self) -> Literal[False]: - return False - - -UNSET: Unset = Unset() - -FileJsonType = Tuple[Optional[str], BinaryIO, Optional[str]] - - -@define -class File: - """Contains information for file uploads""" - - payload: BinaryIO - file_name: Optional[str] = None - mime_type: Optional[str] = None - - def to_tuple(self) -> FileJsonType: - """Return a tuple representation that httpx will accept for multipart/form-data""" - return self.file_name, self.payload, self.mime_type - - -T = TypeVar("T") - - -@define -class Response(Generic[T]): - """A response from an endpoint""" - - status_code: HTTPStatus - content: bytes - headers: MutableMapping[str, str] - parsed: Optional[T] - - -__all__ = ["File", "Response", "FileJsonType", "Unset", "UNSET"] diff --git a/end_to_end_tests/test_custom_templates/api_init.py.jinja b/end_to_end_tests/test_custom_templates/api_init.py.jinja index 0c5720bf2..78e473147 100644 --- a/end_to_end_tests/test_custom_templates/api_init.py.jinja +++ b/end_to_end_tests/test_custom_templates/api_init.py.jinja @@ -1,6 +1,5 @@ """ Contains methods for accessing the API """ -from typing import Type {% for tag in endpoint_collections_by_tag.keys() %} from .{{ tag }} import {{ class_name(tag) }}Endpoints {% endfor %} @@ -8,6 +7,6 @@ from .{{ tag }} import {{ class_name(tag) }}Endpoints class {{ class_name(package_name) }}Api: {% for tag in endpoint_collections_by_tag.keys() %} @classmethod - def {{ tag }}(cls) -> Type[{{ class_name(tag) }}Endpoints]: + def {{ tag }}(cls) -> type[{{ class_name(tag) }}Endpoints]: return {{ class_name(tag) }}Endpoints {% endfor %} diff --git a/end_to_end_tests/test_custom_templates/endpoint_init.py.jinja b/end_to_end_tests/test_custom_templates/endpoint_init.py.jinja index dd64d942c..aa207c418 100644 --- a/end_to_end_tests/test_custom_templates/endpoint_init.py.jinja +++ b/end_to_end_tests/test_custom_templates/endpoint_init.py.jinja @@ -13,11 +13,11 @@ class {{ class_name(endpoint_collection.tag) }}Endpoints: def {{ python_identifier(endpoint.name) }}(cls) -> types.ModuleType: {% if endpoint.description %} """ - {{ endpoint.description }} + {{ endpoint.description | safe_for_docstring }} """ {% elif endpoint.summary %} """ - {{ endpoint.summary }} + {{ endpoint.summary | safe_for_docstring }} """ {% endif %} return {{ python_identifier(endpoint.name) }} diff --git a/end_to_end_tests/test_custom_templates/models_init.py.jinja b/end_to_end_tests/test_custom_templates/models_init.py.jinja new file mode 100644 index 000000000..8b0a55aee --- /dev/null +++ b/end_to_end_tests/test_custom_templates/models_init.py.jinja @@ -0,0 +1,33 @@ + +# Testing that we can access model-related information via Jinja variables. + +# To avoid having to update this file in the golden record every time the test specs are changed, +# we won't include all the classes in this output - we'll just look for one of them. + +# Using "alls" +{% for name in alls %} +{% if name == "AModel" %} +# {{ name }} +{% endif %} +{% endfor %} + +# Using "imports" +{% for import in imports %} +{% if import.endswith("import AModel") %} +# {{ import }} +{% endif %} +{% endfor %} + +# Using "openapi.models" +{% for model in openapi.models %} +{% if model.class_info.name == "AModel" %} +# {{ model.class_info.name }} ({{ model.class_info.module_name }}) +{% endif %} +{% endfor %} + +# Using "openapi.enums" +{% for enum in openapi.enums %} +{% if enum.class_info.name == "AnEnum" %} +# {{ enum.class_info.name }} ({{ enum.class_info.module_name }}) +{% endif %} +{% endfor %} diff --git a/end_to_end_tests/test_end_to_end.py b/end_to_end_tests/test_end_to_end.py index 9087beca3..aa2bb6423 100644 --- a/end_to_end_tests/test_end_to_end.py +++ b/end_to_end_tests/test_end_to_end.py @@ -1,21 +1,25 @@ import shutil +import subprocess +import sys from filecmp import cmpfiles, dircmp from pathlib import Path -from typing import Dict, List, Optional, Set import pytest -from click.testing import Result -from typer.testing import CliRunner +from typer.testing import CliRunner, Result +from end_to_end_tests.generated_client import ( + _run_command, + generate_client, +) from openapi_python_client.cli import app def _compare_directories( record: Path, test_subject: Path, - expected_differences: Dict[Path, str], - expected_missing: Optional[Set[str]] = None, - ignore: List[str] = None, + expected_differences: dict[Path, str] | None = None, + expected_missing: set[str] | None = None, + ignore: list[str] | None = None, depth=0, ): """ @@ -38,9 +42,7 @@ def _compare_directories( ) expected_differences = expected_differences or {} - _, mismatches, errors = cmpfiles( - record, test_subject, dc.common_files, shallow=False - ) + _, mismatches, _errors = cmpfiles(record, test_subject, dc.common_files, shallow=False) mismatches = set(mismatches) for file_name in mismatches: @@ -53,9 +55,7 @@ def _compare_directories( expected_content = (record / file_name).read_text() generated_content = (test_subject / file_name).read_text() - assert ( - generated_content == expected_content - ), f"Unexpected output in {mismatch_file_path}" + assert generated_content == expected_content, f"Unexpected output in {mismatch_file_path}" for sub_path in dc.common_dirs: _compare_directories( @@ -67,67 +67,41 @@ def _compare_directories( ) if depth == 0 and len(expected_differences.keys()) > 0: - failure = "\n".join( - [ - f"Expected {path} to be different but it was not" - for path in expected_differences.keys() - ] - ) + failure = "\n".join([f"Expected {path} to be different but it was not" for path in expected_differences.keys()]) pytest.fail(failure, pytrace=False) def run_e2e_test( openapi_document: str, - extra_args: List[str], - expected_differences: Optional[Dict[Path, str]] = None, - golden_record_path: str = "golden-record", + extra_args: list[str], + expected_differences: dict[Path, str] | None = None, output_path: str = "my-test-api-client", - expected_missing: Optional[Set[str]] = None, + expected_missing: set[str] | None = None, + *, + golden_record_path: str | None = None, ) -> Result: - output_path = Path.cwd() / output_path - shutil.rmtree(output_path, ignore_errors=True) - result = generate(extra_args, openapi_document) - gr_path = Path(__file__).parent / golden_record_path - - expected_differences = expected_differences or {} - # Use absolute paths for expected differences for easier comparisons - expected_differences = { - output_path.joinpath(key): value for key, value in expected_differences.items() - } - _compare_directories( - gr_path, output_path, expected_differences=expected_differences, expected_missing=expected_missing - ) - - import mypy.api - - out, err, status = mypy.api.run([str(output_path), "--strict"]) - assert status == 0, f"Type checking client failed: {out}" - - shutil.rmtree(output_path) - return result - + with generate_client(openapi_document, extra_args, output_path) as g: + if golden_record_path: + gr_path = Path(__file__).parent / "golden-records" / golden_record_path + else: + gr_path = Path(__file__).parent / "golden-records" / output_path -def generate(extra_args: Optional[List[str]], openapi_document: str) -> Result: - """Generate a client from an OpenAPI document and return the path to the generated code""" - _run_command("generate", extra_args, openapi_document) + expected_differences = expected_differences or {} + # Use absolute paths for expected differences for easier comparisons + expected_differences = {g.output_path.joinpath(key): value for key, value in expected_differences.items()} + _compare_directories( + gr_path, g.output_path, expected_differences=expected_differences, expected_missing=expected_missing + ) + result = subprocess.run( + [sys.executable, "-m", "mypy", str(g.output_path), "--strict"], + capture_output=True, + text=True, + check=True, + ) + assert result.returncode == 0, f"Type checking client failed: {result.stdout}" -def _run_command(command: str, extra_args: Optional[List[str]] = None, openapi_document: Optional[str] = None, url: Optional[str] = None, config_path: Optional[Path] = None) -> Result: - """Generate a client from an OpenAPI document and return the path to the generated code""" - runner = CliRunner() - if openapi_document is not None: - openapi_path = Path(__file__).parent / openapi_document - source_arg = f"--path={openapi_path}" - else: - source_arg = f"--url={url}" - config_path = config_path or (Path(__file__).parent / "config.yml") - args = [command, f"--config={config_path}", source_arg] - if extra_args: - args.extend(extra_args) - result = runner.invoke(app, args) - if result.exit_code != 0: - raise Exception(result.stdout) - return result + return g.generator_result def test_baseline_end_to_end_3_0(): @@ -143,62 +117,80 @@ def test_3_1_specific_features(): "3.1_specific.openapi.yaml", [], {}, - "test-3-1-golden-record", "test-3-1-features-client", ) +def test_literal_enums_end_to_end(): + config_path = Path(__file__).parent / "literal_enums.config.yml" + run_e2e_test("openapi_3.1_enums.yaml", [f"--config={config_path}"], {}, "my-enum-api-client") + + +def test_escapes_end_to_end(): + run_e2e_test( + "escapes.openapi.yaml", + [], + {}, + "escapes-client", + ) + + @pytest.mark.parametrize( "meta,generated_file,expected_file", ( ("setup", "setup.py", "setup.py"), ("pdm", "pyproject.toml", "pdm.pyproject.toml"), ("poetry", "pyproject.toml", "poetry.pyproject.toml"), - ) + ("uv", "pyproject.toml", "uv.pyproject.toml"), + ), ) -def test_meta(meta: str, generated_file: Optional[str], expected_file: Optional[str]): - output_path = Path.cwd() / "test-3-1-features-client" - shutil.rmtree(output_path, ignore_errors=True) - generate([f"--meta={meta}"], "3.1_specific.openapi.yaml") - - if generated_file and expected_file: - assert (output_path / generated_file).exists() - assert ( - (output_path / generated_file).read_text() == - (Path(__file__).parent / "metadata_snapshots" / expected_file).read_text() - ) - - shutil.rmtree(output_path) +def test_meta(meta: str, generated_file: str | None, expected_file: str | None): + with generate_client( + "3.1_specific.openapi.yaml", + extra_args=[f"--meta={meta}"], + output_path="test-3-1-features-client", + ) as g: + if generated_file and expected_file: + assert (g.output_path / generated_file).exists() + assert (g.output_path / generated_file).read_text() == ( + Path(__file__).parent / "metadata_snapshots" / expected_file + ).read_text() def test_none_meta(): run_e2e_test( "3.1_specific.openapi.yaml", ["--meta=none"], - golden_record_path="test-3-1-golden-record/test_3_1_features_client", + golden_record_path="test-3-1-features-client/test_3_1_features_client", output_path="test_3_1_features_client", expected_missing={"py.typed"}, ) +def test_docstrings_on_attributes(): + config_path = Path(__file__).parent / "docstrings_on_attributes.config.yml" + run_e2e_test( + "docstrings_on_attributes.yml", + [f"--config={config_path}"], + {}, + "docstrings-on-attributes-golden-record", + ) + + def test_custom_templates(): - expected_differences = ( - {} - ) # key: path relative to generated directory, value: expected generated content + expected_differences = {} # key: path relative to generated directory, value: expected generated content api_dir = Path("my_test_api_client").joinpath("api") - golden_tpls_root_dir = Path(__file__).parent.joinpath( - "custom-templates-golden-record" - ) + models_dir = Path("my_test_api_client").joinpath("models") + golden_tpls_root_dir = Path(__file__).parent / "golden-records" / "custom-templates" expected_difference_paths = [ Path("README.md"), api_dir.joinpath("__init__.py"), + models_dir.joinpath("__init__.py"), ] for expected_difference_path in expected_difference_paths: - expected_differences[expected_difference_path] = ( - golden_tpls_root_dir / expected_difference_path - ).read_text() + expected_differences[expected_difference_path] = (golden_tpls_root_dir / expected_difference_path).read_text() # Each API module (defined by tag) has a custom __init__.py in it now. for endpoint_mod in golden_tpls_root_dir.joinpath(api_dir).iterdir(): @@ -215,74 +207,78 @@ def test_custom_templates(): ) -@pytest.mark.parametrize( - "command", ("generate", "update") -) -def test_bad_url(command: str): +def test_bad_url(): runner = CliRunner() - result = runner.invoke(app, [command, "--url=not_a_url"]) + result = runner.invoke(app, ["generate", "--url=not_a_url"]) assert result.exit_code == 1 - assert "Could not get OpenAPI document from provided URL" in result.stdout + assert "Could not get OpenAPI document from provided URL" in result.stderr + + +ERROR_DOCUMENTS = [path for path in Path(__file__).parent.joinpath("documents_with_errors").iterdir() if path.is_file()] + + +@pytest.mark.parametrize("document", ERROR_DOCUMENTS, ids=[path.stem for path in ERROR_DOCUMENTS]) +def test_documents_with_errors(snapshot, document): + with generate_client( + document, + extra_args=["--fail-on-warning"], + output_path="test-documents-with-errors", + raise_on_error=False, + ) as g: + result = g.generator_result + assert result.exit_code == 1 + output = (result.stdout + result.stderr).replace(str(g.output_path), "/test-documents-with-errors") + assert output == snapshot def test_custom_post_hooks(): - shutil.rmtree(Path.cwd() / "my-test-api-client", ignore_errors=True) - runner = CliRunner() - openapi_document = Path(__file__).parent / "baseline_openapi_3.0.json" config_path = Path(__file__).parent / "custom_post_hooks.config.yml" - result = runner.invoke(app, ["generate", f"--path={openapi_document}", f"--config={config_path}"]) - assert result.exit_code == 1 - assert "this should fail" in result.stdout - shutil.rmtree(Path.cwd() / "my-test-api-client", ignore_errors=True) + with generate_client( + "baseline_openapi_3.0.json", + [f"--config={config_path}"], + raise_on_error=False, + ) as g: + assert g.generator_result.exit_code == 1 + assert "this should fail" in g.generator_result.stderr def test_generate_dir_already_exists(): project_dir = Path.cwd() / "my-test-api-client" if not project_dir.exists(): project_dir.mkdir() - runner = CliRunner() - openapi_document = Path(__file__).parent / "baseline_openapi_3.0.json" - result = runner.invoke(app, ["generate", f"--path={openapi_document}"]) - assert result.exit_code == 1 - assert "Directory already exists" in result.stdout - shutil.rmtree(Path.cwd() / "my-test-api-client", ignore_errors=True) - - -def test_update_dir_not_found(): - project_dir = Path.cwd() / "my-test-api-client" - shutil.rmtree(project_dir, ignore_errors=True) - runner = CliRunner() - openapi_document = Path(__file__).parent / "baseline_openapi_3.0.json" - result = runner.invoke(app, ["update", f"--path={openapi_document}"]) - assert result.exit_code == 1 - assert str(project_dir) in result.stdout - - -@pytest.mark.parametrize( - ("file_name", "content", "expected_error"), - ( - ("invalid_openapi.yaml", "not a valid openapi document", "Failed to parse OpenAPI document"), - ("invalid_json.json", "Invalid JSON", "Invalid JSON"), - ("invalid_yaml.yaml", "{", "Invalid YAML"), - ), - ids=("invalid_openapi", "invalid_json", "invalid_yaml") -) -def test_invalid_openapi_document(file_name, content, expected_error): - runner = CliRunner() - openapi_document = Path.cwd() / file_name - openapi_document.write_text(content) - result = runner.invoke(app, ["generate", f"--path={openapi_document}"]) - assert result.exit_code == 1 - assert expected_error in result.stdout - openapi_document.unlink() + try: + runner = CliRunner() + openapi_document = Path(__file__).parent / "baseline_openapi_3.0.json" + result = runner.invoke(app, ["generate", f"--path={openapi_document}"]) + assert result.exit_code == 1 + assert "Directory already exists" in result.stderr + finally: + shutil.rmtree(Path.cwd() / "my-test-api-client", ignore_errors=True) def test_update_integration_tests(): - url = "https://raw.githubusercontent.com/openapi-generators/openapi-test-server/main/openapi.json" + url = "https://raw.githubusercontent.com/openapi-generators/openapi-test-server/refs/tags/v0.2.1/openapi.yaml" source_path = Path(__file__).parent.parent / "integration-tests" - project_path = Path.cwd() / "integration-tests" - if source_path != project_path: # Just in case someone runs this from root dir - shutil.copytree(source_path, project_path) - config_path = project_path / "config.yaml" - _run_command("update", url=url, config_path=config_path) - _compare_directories(source_path, project_path, expected_differences={}) + temp_dir = Path.cwd() / "test_update_integration_tests" + shutil.rmtree(temp_dir, ignore_errors=True) + + try: + shutil.copytree(source_path, temp_dir) + config_path = source_path / "config.yaml" + _run_command( + "generate", + extra_args=["--overwrite", "--meta=pdm", f"--output-path={temp_dir}"], + url=url, + config_path=config_path, + ) + _compare_directories(source_path, temp_dir, ignore=["pyproject.toml"]) + result = subprocess.run( + [sys.executable, "-m", "mypy", str(temp_dir), "--strict"], + capture_output=True, + text=True, + check=True, + ) + assert result.returncode == 0, f"Type checking client failed: {result.stdout=} {result.stderr=}" + + finally: + shutil.rmtree(temp_dir) diff --git a/fuzz/test_codegen.py b/fuzz/test_codegen.py new file mode 100644 index 000000000..177eb4009 --- /dev/null +++ b/fuzz/test_codegen.py @@ -0,0 +1,349 @@ +import ast +import io +import json +import os +import subprocess +import tomllib +import warnings +from contextlib import redirect_stdout +from pathlib import Path +from tempfile import TemporaryDirectory +from typing import Any + +from hypothesis import given, settings +from hypothesis import strategies as st + +from openapi_python_client import Config, ErrorLevel, MetaType, generate +from openapi_python_client.config import ConfigFile +from openapi_python_client.schema import OpenAPI + +FUZZ_EXAMPLES = int(os.environ.get("OPENAPI_PYTHON_CLIENT_FUZZ_EXAMPLES", "100")) + +# Canary payload: if any untrusted string breaks out of its literal/docstring in generated code, +# this appears as a real AST Name/Call node instead of text inside a string constant. +CANARY = "PWNED_CANARY" +CALL_CANARY = "EXECUTED_CANARY" + +DANGEROUS_STRINGS = ( + "", + "'", + '"', + "\\", + "\n", + "\r\n", + "\t", + "\x00", + '"""', + "'''", + "{value!r}", + "${value}", + "{{ value }}", + "line one\\\nline two", + "\\U0000000", + "\\N{NOT A REAL NAME}", + "# type: ignore\n" + CANARY + "()", + "\n# comment with trailing slash\\", + "from os import system", + "\N{LINE SEPARATOR}", + "\N{PILE OF POO}", + f'"{CANARY}("', + f'"{CANARY}() + "', + f"'''{CANARY}()'''", + f'"""{CANARY}()"""', + f'\\"{CANARY}()', + f"\n{CANARY}()\n", + f'"; print("{CALL_CANARY}"); _fuzz = "', + f'"""\nprint("{CALL_CANARY}")\n"""', +) +UTF8_CHARACTERS = st.characters(blacklist_categories=["Cs"]) +UNTRUSTED_TEXT = st.one_of( + st.sampled_from(DANGEROUS_STRINGS), + st.text(UTF8_CHARACTERS, max_size=60), +) +NONEMPTY_UNTRUSTED_TEXT = st.one_of( + st.sampled_from(tuple(value for value in DANGEROUS_STRINGS if value)), + st.text(UTF8_CHARACTERS, min_size=1, max_size=40), +) +COMPONENT_NAME = st.one_of( + st.sampled_from(tuple(value for value in DANGEROUS_STRINGS if value and "/" not in value and "~" not in value)), + st.text(UTF8_CHARACTERS, min_size=1, max_size=30).filter(lambda value: "/" not in value and "~" not in value), +) + + +@st.composite +def schema_strategy(draw: st.DrawFn) -> dict[str, Any]: + description = draw(UNTRUSTED_TEXT) + kind = draw( + st.sampled_from( + ("string", "integer", "number", "boolean", "array", "object", "reference", "union", "const", "free_form") + ) + ) + + value: Any + schema: dict[str, Any] = {"description": description} + if kind == "string": + value = draw(UNTRUSTED_TEXT) + schema.update({"type": "string", "default": value, "example": value}) + elif kind == "integer": + value = draw(st.integers(min_value=-(2**31), max_value=2**31 - 1)) + schema.update({"type": "integer", "default": value, "example": value}) + elif kind == "number": + value = draw(st.floats(allow_nan=False, allow_infinity=False, width=32)) + schema.update({"type": "number", "default": value, "example": value}) + elif kind == "boolean": + value = draw(st.booleans()) + schema.update({"type": "boolean", "default": value, "example": value}) + elif kind == "array": + schema.update( + { + "type": "array", + "items": {"type": "string", "description": draw(UNTRUSTED_TEXT)}, + "example": [draw(UNTRUSTED_TEXT)], + } + ) + elif kind == "object": + schema.update( + { + "title": draw(UNTRUSTED_TEXT), + "type": "object", + "properties": {"nested": {"type": "string", "description": draw(UNTRUSTED_TEXT)}}, + "additionalProperties": {"type": "string", "description": draw(UNTRUSTED_TEXT)}, + "example": {"nested": draw(UNTRUSTED_TEXT)}, + } + ) + elif kind == "union": + schema = { + "oneOf": [ + {"type": "string", "description": description}, + {"type": "integer", "description": draw(UNTRUSTED_TEXT)}, + ], + "description": draw(UNTRUSTED_TEXT), + } + elif kind == "const": + schema = {"const": draw(UNTRUSTED_TEXT), "description": description} + elif kind == "free_form": + schema = {"type": "object", "additionalProperties": True, "description": description} + else: + schema = {"$ref": "#/components/schemas/Choice"} + return schema + + +@st.composite +def openapi_documents(draw: st.DrawFn) -> dict[str, Any]: + component_name = draw(COMPONENT_NAME) + property_name = draw(NONEMPTY_UNTRUSTED_TEXT) + query_name = draw(NONEMPTY_UNTRUSTED_TEXT) + header_name = draw(NONEMPTY_UNTRUSTED_TEXT) + cookie_name = draw(NONEMPTY_UNTRUSTED_TEXT) + path_segment = draw(NONEMPTY_UNTRUSTED_TEXT) + security_name = draw(NONEMPTY_UNTRUSTED_TEXT) + property_schema = draw(schema_strategy()) + parameter_schema = draw(schema_strategy()) + enum_values = draw(st.lists(UNTRUSTED_TEXT, min_size=1, max_size=4, unique=True)) + int_enum_values = draw(st.lists(st.integers(min_value=-100, max_value=100), min_size=1, max_size=4, unique=True)) + + return { + "openapi": draw(st.sampled_from(("3.0.0", "3.0.3", "3.1.0"))), + "info": { + "title": draw(UNTRUSTED_TEXT), + "description": draw(UNTRUSTED_TEXT), + "version": draw(UNTRUSTED_TEXT), + "termsOfService": draw(UNTRUSTED_TEXT), + "contact": { + "name": draw(UNTRUSTED_TEXT), + "url": draw(UNTRUSTED_TEXT), + "email": draw(UNTRUSTED_TEXT), + }, + "license": {"name": draw(NONEMPTY_UNTRUSTED_TEXT), "url": draw(UNTRUSTED_TEXT)}, + }, + "servers": [ + { + "url": draw(UNTRUSTED_TEXT), + "description": draw(UNTRUSTED_TEXT), + "variables": { + "fuzz": { + "default": draw(UNTRUSTED_TEXT), + "enum": [draw(UNTRUSTED_TEXT)], + "description": draw(UNTRUSTED_TEXT), + } + }, + } + ], + "tags": [{"name": draw(NONEMPTY_UNTRUSTED_TEXT), "description": draw(UNTRUSTED_TEXT)}], + "externalDocs": {"url": draw(UNTRUSTED_TEXT), "description": draw(UNTRUSTED_TEXT)}, + "security": [{security_name: []}], + "paths": { + f"/widgets/{{widget_id}}/{path_segment}": { + "summary": draw(UNTRUSTED_TEXT), + "description": draw(UNTRUSTED_TEXT), + "post": { + "operationId": draw(NONEMPTY_UNTRUSTED_TEXT), + "tags": [draw(UNTRUSTED_TEXT)], + "summary": draw(UNTRUSTED_TEXT), + "description": draw(UNTRUSTED_TEXT), + "parameters": [ + { + "name": "widget_id", + "in": "path", + "required": True, + "description": draw(UNTRUSTED_TEXT), + "schema": {"type": "string"}, + }, + { + "name": query_name, + "in": "query", + "description": draw(UNTRUSTED_TEXT), + "schema": parameter_schema, + }, + { + "name": header_name, + "in": "header", + "description": draw(UNTRUSTED_TEXT), + "schema": {"type": "string", "default": draw(UNTRUSTED_TEXT)}, + }, + { + "name": cookie_name, + "in": "cookie", + "description": draw(UNTRUSTED_TEXT), + "schema": {"type": "string"}, + }, + ], + "requestBody": { + "required": True, + "description": draw(UNTRUSTED_TEXT), + "content": { + "application/json": { + "schema": {"$ref": f"#/components/schemas/{component_name}"}, + } + }, + }, + "responses": { + "200": { + "description": draw(UNTRUSTED_TEXT), + "headers": { + "X-Fuzz": { + "description": draw(UNTRUSTED_TEXT), + "schema": {"type": "string"}, + } + }, + "content": { + "application/json": { + "schema": {"$ref": f"#/components/schemas/{component_name}"}, + } + }, + } + }, + }, + } + }, + "components": { + "securitySchemes": { + security_name: { + "type": "apiKey", + "name": draw(NONEMPTY_UNTRUSTED_TEXT), + "in": "header", + "description": draw(UNTRUSTED_TEXT), + } + }, + "schemas": { + component_name: { + "title": draw(UNTRUSTED_TEXT), + "type": "object", + "description": draw(UNTRUSTED_TEXT), + "externalDocs": {"url": draw(UNTRUSTED_TEXT), "description": draw(UNTRUSTED_TEXT)}, + "xml": { + "name": draw(UNTRUSTED_TEXT), + "namespace": draw(UNTRUSTED_TEXT), + "prefix": draw(UNTRUSTED_TEXT), + }, + "required": [property_name], + "properties": {property_name: property_schema}, + }, + "Choice": { + "type": "string", + "description": draw(UNTRUSTED_TEXT), + "enum": enum_values, + }, + "IntChoice": { + "type": "integer", + "description": draw(UNTRUSTED_TEXT), + "enum": int_enum_values, + }, + }, + }, + } + + +@settings(max_examples=FUZZ_EXAMPLES, deadline=None) +@given(document=openapi_documents(), meta_type=st.sampled_from(list(MetaType))) +def test_valid_openapi_never_generates_invalid_python(document: dict[str, Any], meta_type: MetaType) -> None: + # The generator's own schema model is the source of truth for "valid": anything it accepts + # must produce syntactically valid Python. + OpenAPI.model_validate(document) + + with TemporaryDirectory() as temporary_directory: + root = Path(temporary_directory) + document_path = root / "openapi.json" + output_path = root / "generated" + document_path.write_text(json.dumps(document, ensure_ascii=False), encoding="utf-8") + + config = Config.from_sources( + ConfigFile( + project_name_override="fuzz-client", + package_name_override="fuzz_client", + post_hooks=[], + ), + meta_type, + document_source=document_path, + file_encoding="utf-8", + overwrite=False, + output_path=output_path, + ) + with redirect_stdout(io.StringIO()): + errors = generate(config=config) + + fatal_errors = [error for error in errors if error.level == ErrorLevel.ERROR] + assert not fatal_errors + + python_files = sorted(output_path.rglob("*.py")) + assert python_files + for python_file in python_files: + source = python_file.read_text(encoding="utf-8") + tree = ast.parse(source, filename=str(python_file)) + with warnings.catch_warnings(): + warnings.simplefilter("error") + compile(source, str(python_file), "exec") + _assert_no_code_injection(tree, python_file) + + for pyproject_file in output_path.rglob("pyproject.toml"): + with pyproject_file.open("rb") as pyproject: + tomllib.load(pyproject) + + # Static analysis catches escapes which produce valid syntax but reference names that + # don't exist (e.g. an injected function call) — even ones the canary doesn't cover. + ruff = subprocess.run( + ["ruff", "check", "--select", "F821", "--no-cache", str(output_path)], + capture_output=True, + text=True, + check=False, + ) + assert ruff.returncode == 0, f"Generated code references undefined names:\n{ruff.stdout}" + + +def _assert_no_code_injection(tree: ast.AST, python_file: Path) -> None: + """Fail if the canary escaped a string literal/docstring and became executable code.""" + for node in ast.walk(tree): + if isinstance(node, ast.Name) and CANARY in node.id: + raise AssertionError(f"Canary escaped into a name in {python_file}: {node.id}") + if isinstance(node, ast.Attribute) and CANARY in node.attr: + raise AssertionError(f"Canary escaped into an attribute in {python_file}: {node.attr}") + if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)) and CANARY in node.name: + raise AssertionError(f"Canary escaped into a definition in {python_file}: {node.name}") + if isinstance(node, ast.ImportFrom) and node.module and CANARY in node.module: + raise AssertionError(f"Canary escaped into an import in {python_file}: {node.module}") + if isinstance(node, ast.alias) and CANARY in node.name: + raise AssertionError(f"Canary escaped into an import in {python_file}: {node.name}") + if isinstance(node, ast.Call) and any( + isinstance(child, ast.Constant) and child.value == CALL_CANARY for child in ast.walk(node) + ): + raise AssertionError(f"Built-in call canary became executable code in {python_file}") diff --git a/integration-tests/.gitignore b/integration-tests/.gitignore index ed29cb977..79a2c3d73 100644 --- a/integration-tests/.gitignore +++ b/integration-tests/.gitignore @@ -20,4 +20,4 @@ dmypy.json .idea/ /coverage.xml -/.coverage \ No newline at end of file +/.coverage diff --git a/integration-tests/README.md b/integration-tests/README.md index f92972290..ec94ebc0a 100644 --- a/integration-tests/README.md +++ b/integration-tests/README.md @@ -47,7 +47,7 @@ By default, when you're calling an HTTPS API it will attempt to verify that SSL ```python client = AuthenticatedClient( - base_url="https://internal_api.example.com", + base_url="https://internal_api.example.com", token="SuperSecretToken", verify_ssl="/path/to/certificate_bundle.pem", ) @@ -57,7 +57,7 @@ You can also disable certificate validation altogether, but beware that **this i ```python client = AuthenticatedClient( - base_url="https://internal_api.example.com", + base_url="https://internal_api.example.com", token="SuperSecretToken", verify_ssl=False ) diff --git a/integration-tests/config.yaml b/integration-tests/config.yaml index 80153f799..8b6e35763 100644 --- a/integration-tests/config.yaml +++ b/integration-tests/config.yaml @@ -1,5 +1,4 @@ project_name_override: integration-tests post_hooks: - ruff check . --fix - - ruff format . - - mypy . --strict \ No newline at end of file + - ruff format . \ No newline at end of file diff --git a/integration-tests/integration_tests/api/body/__init__.py b/integration-tests/integration_tests/api/body/__init__.py index e69de29bb..2d7c0b23d 100644 --- a/integration-tests/integration_tests/api/body/__init__.py +++ b/integration-tests/integration_tests/api/body/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/integration-tests/integration_tests/api/body/post_body_multipart.py b/integration-tests/integration_tests/api/body/post_body_multipart.py index c64b4c4c2..7ceef67b6 100644 --- a/integration-tests/integration_tests/api/body/post_body_multipart.py +++ b/integration-tests/integration_tests/api/body/post_body_multipart.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any import httpx @@ -8,39 +8,42 @@ from ...models.post_body_multipart_body import PostBodyMultipartBody from ...models.post_body_multipart_response_200 import PostBodyMultipartResponse200 from ...models.public_error import PublicError -from ...types import Response +from ...types import UNSET, Response, Unset def _get_kwargs( *, - body: PostBodyMultipartBody, -) -> Dict[str, Any]: - headers: Dict[str, Any] = {} + body: PostBodyMultipartBody | Unset = UNSET, +) -> dict[str, Any]: + headers: dict[str, Any] = {} - _kwargs: Dict[str, Any] = { + _kwargs: dict[str, Any] = { "method": "post", "url": "/body/multipart", } - _body = body.to_multipart() + if not isinstance(body, Unset): + _kwargs["files"] = body.to_multipart() - _kwargs["files"] = _body + headers["Content-Type"] = "multipart/form-data; boundary=+++" _kwargs["headers"] = headers return _kwargs def _parse_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Optional[Union[PostBodyMultipartResponse200, PublicError]]: - if response.status_code == HTTPStatus.OK: + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> PostBodyMultipartResponse200 | PublicError | None: + if response.status_code == 200: response_200 = PostBodyMultipartResponse200.from_dict(response.json()) return response_200 - if response.status_code == HTTPStatus.BAD_REQUEST: + + if response.status_code == 400: response_400 = PublicError.from_dict(response.json()) return response_400 + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: @@ -48,8 +51,8 @@ def _parse_response( def _build_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Response[Union[PostBodyMultipartResponse200, PublicError]]: + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> Response[PostBodyMultipartResponse200 | PublicError]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -60,19 +63,19 @@ def _build_response( def sync_detailed( *, - client: Union[AuthenticatedClient, Client], - body: PostBodyMultipartBody, -) -> Response[Union[PostBodyMultipartResponse200, PublicError]]: + client: AuthenticatedClient | Client, + body: PostBodyMultipartBody | Unset = UNSET, +) -> Response[PostBodyMultipartResponse200 | PublicError]: """ Args: - body (PostBodyMultipartBody): + body (PostBodyMultipartBody | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[PostBodyMultipartResponse200, PublicError]] + Response[PostBodyMultipartResponse200 | PublicError] """ kwargs = _get_kwargs( @@ -88,19 +91,19 @@ def sync_detailed( def sync( *, - client: Union[AuthenticatedClient, Client], - body: PostBodyMultipartBody, -) -> Optional[Union[PostBodyMultipartResponse200, PublicError]]: + client: AuthenticatedClient | Client, + body: PostBodyMultipartBody | Unset = UNSET, +) -> PostBodyMultipartResponse200 | PublicError | None: """ Args: - body (PostBodyMultipartBody): + body (PostBodyMultipartBody | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[PostBodyMultipartResponse200, PublicError] + PostBodyMultipartResponse200 | PublicError """ return sync_detailed( @@ -111,19 +114,19 @@ def sync( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], - body: PostBodyMultipartBody, -) -> Response[Union[PostBodyMultipartResponse200, PublicError]]: + client: AuthenticatedClient | Client, + body: PostBodyMultipartBody | Unset = UNSET, +) -> Response[PostBodyMultipartResponse200 | PublicError]: """ Args: - body (PostBodyMultipartBody): + body (PostBodyMultipartBody | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[PostBodyMultipartResponse200, PublicError]] + Response[PostBodyMultipartResponse200 | PublicError] """ kwargs = _get_kwargs( @@ -137,19 +140,19 @@ async def asyncio_detailed( async def asyncio( *, - client: Union[AuthenticatedClient, Client], - body: PostBodyMultipartBody, -) -> Optional[Union[PostBodyMultipartResponse200, PublicError]]: + client: AuthenticatedClient | Client, + body: PostBodyMultipartBody | Unset = UNSET, +) -> PostBodyMultipartResponse200 | PublicError | None: """ Args: - body (PostBodyMultipartBody): + body (PostBodyMultipartBody | Unset): Raises: errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[PostBodyMultipartResponse200, PublicError] + PostBodyMultipartResponse200 | PublicError """ return ( diff --git a/integration-tests/integration_tests/api/parameters/__init__.py b/integration-tests/integration_tests/api/parameters/__init__.py index e69de29bb..2d7c0b23d 100644 --- a/integration-tests/integration_tests/api/parameters/__init__.py +++ b/integration-tests/integration_tests/api/parameters/__init__.py @@ -0,0 +1 @@ +"""Contains endpoint functions for accessing the API""" diff --git a/integration-tests/integration_tests/api/parameters/post_parameters_header.py b/integration-tests/integration_tests/api/parameters/post_parameters_header.py index 784eaf37f..190b7efe0 100644 --- a/integration-tests/integration_tests/api/parameters/post_parameters_header.py +++ b/integration-tests/integration_tests/api/parameters/post_parameters_header.py @@ -1,5 +1,5 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import Any import httpx @@ -16,8 +16,8 @@ def _get_kwargs( string_header: str, number_header: float, integer_header: int, -) -> Dict[str, Any]: - headers: Dict[str, Any] = {} +) -> dict[str, Any]: + headers: dict[str, Any] = {} headers["Boolean-Header"] = "true" if boolean_header else "false" headers["String-Header"] = string_header @@ -26,7 +26,7 @@ def _get_kwargs( headers["Integer-Header"] = str(integer_header) - _kwargs: Dict[str, Any] = { + _kwargs: dict[str, Any] = { "method": "post", "url": "/parameters/header", } @@ -36,16 +36,18 @@ def _get_kwargs( def _parse_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Optional[Union[PostParametersHeaderResponse200, PublicError]]: - if response.status_code == HTTPStatus.OK: + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> PostParametersHeaderResponse200 | PublicError | None: + if response.status_code == 200: response_200 = PostParametersHeaderResponse200.from_dict(response.json()) return response_200 - if response.status_code == HTTPStatus.BAD_REQUEST: + + if response.status_code == 400: response_400 = PublicError.from_dict(response.json()) return response_400 + if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: @@ -53,8 +55,8 @@ def _parse_response( def _build_response( - *, client: Union[AuthenticatedClient, Client], response: httpx.Response -) -> Response[Union[PostParametersHeaderResponse200, PublicError]]: + *, client: AuthenticatedClient | Client, response: httpx.Response +) -> Response[PostParametersHeaderResponse200 | PublicError]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -65,12 +67,12 @@ def _build_response( def sync_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, boolean_header: bool, string_header: str, number_header: float, integer_header: int, -) -> Response[Union[PostParametersHeaderResponse200, PublicError]]: +) -> Response[PostParametersHeaderResponse200 | PublicError]: """ Args: boolean_header (bool): @@ -83,7 +85,7 @@ def sync_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[PostParametersHeaderResponse200, PublicError]] + Response[PostParametersHeaderResponse200 | PublicError] """ kwargs = _get_kwargs( @@ -102,12 +104,12 @@ def sync_detailed( def sync( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, boolean_header: bool, string_header: str, number_header: float, integer_header: int, -) -> Optional[Union[PostParametersHeaderResponse200, PublicError]]: +) -> PostParametersHeaderResponse200 | PublicError | None: """ Args: boolean_header (bool): @@ -120,7 +122,7 @@ def sync( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[PostParametersHeaderResponse200, PublicError] + PostParametersHeaderResponse200 | PublicError """ return sync_detailed( @@ -134,12 +136,12 @@ def sync( async def asyncio_detailed( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, boolean_header: bool, string_header: str, number_header: float, integer_header: int, -) -> Response[Union[PostParametersHeaderResponse200, PublicError]]: +) -> Response[PostParametersHeaderResponse200 | PublicError]: """ Args: boolean_header (bool): @@ -152,7 +154,7 @@ async def asyncio_detailed( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[PostParametersHeaderResponse200, PublicError]] + Response[PostParametersHeaderResponse200 | PublicError] """ kwargs = _get_kwargs( @@ -169,12 +171,12 @@ async def asyncio_detailed( async def asyncio( *, - client: Union[AuthenticatedClient, Client], + client: AuthenticatedClient | Client, boolean_header: bool, string_header: str, number_header: float, integer_header: int, -) -> Optional[Union[PostParametersHeaderResponse200, PublicError]]: +) -> PostParametersHeaderResponse200 | PublicError | None: """ Args: boolean_header (bool): @@ -187,7 +189,7 @@ async def asyncio( httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Union[PostParametersHeaderResponse200, PublicError] + PostParametersHeaderResponse200 | PublicError """ return ( diff --git a/integration-tests/integration_tests/client.py b/integration-tests/integration_tests/client.py index 63a2493b9..edb246d7e 100644 --- a/integration-tests/integration_tests/client.py +++ b/integration-tests/integration_tests/client.py @@ -1,5 +1,5 @@ import ssl -from typing import Any, Dict, Optional, Union +from typing import Any, Self import httpx from attrs import define, evolve, field @@ -36,16 +36,16 @@ class Client: raise_on_unexpected_status: bool = field(default=False, kw_only=True) _base_url: str = field(alias="base_url") - _cookies: Dict[str, str] = field(factory=dict, kw_only=True, alias="cookies") - _headers: Dict[str, str] = field(factory=dict, kw_only=True, alias="headers") - _timeout: Optional[httpx.Timeout] = field(default=None, kw_only=True, alias="timeout") - _verify_ssl: Union[str, bool, ssl.SSLContext] = field(default=True, kw_only=True, alias="verify_ssl") + _cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies") + _headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers") + _timeout: httpx.Timeout | None = field(default=None, kw_only=True, alias="timeout") + _verify_ssl: str | bool | ssl.SSLContext = field(default=True, kw_only=True, alias="verify_ssl") _follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects") - _httpx_args: Dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args") - _client: Optional[httpx.Client] = field(default=None, init=False) - _async_client: Optional[httpx.AsyncClient] = field(default=None, init=False) + _httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args") + _client: httpx.Client | None = field(default=None, init=False) + _async_client: httpx.AsyncClient | None = field(default=None, init=False) - def with_headers(self, headers: Dict[str, str]) -> "Client": + def with_headers(self, headers: dict[str, str]) -> "Client": """Get a new client matching this one with additional headers""" if self._client is not None: self._client.headers.update(headers) @@ -53,7 +53,7 @@ def with_headers(self, headers: Dict[str, str]) -> "Client": self._async_client.headers.update(headers) return evolve(self, headers={**self._headers, **headers}) - def with_cookies(self, cookies: Dict[str, str]) -> "Client": + def with_cookies(self, cookies: dict[str, str]) -> "Client": """Get a new client matching this one with additional cookies""" if self._client is not None: self._client.cookies.update(cookies) @@ -62,15 +62,15 @@ def with_cookies(self, cookies: Dict[str, str]) -> "Client": return evolve(self, cookies={**self._cookies, **cookies}) def with_timeout(self, timeout: httpx.Timeout) -> "Client": - """Get a new client matching this one with a new timeout (in seconds)""" + """Get a new client matching this one with a new timeout configuration""" if self._client is not None: self._client.timeout = timeout if self._async_client is not None: self._async_client.timeout = timeout return evolve(self, timeout=timeout) - def set_httpx_client(self, client: httpx.Client) -> "Client": - """Manually the underlying httpx.Client + def set_httpx_client(self, client: httpx.Client) -> Self: + """Manually set the underlying httpx.Client **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. """ @@ -91,7 +91,7 @@ def get_httpx_client(self) -> httpx.Client: ) return self._client - def __enter__(self) -> "Client": + def __enter__(self) -> Self: """Enter a context manager for self.client—you cannot enter twice (see httpx docs)""" self.get_httpx_client().__enter__() return self @@ -100,8 +100,8 @@ def __exit__(self, *args: Any, **kwargs: Any) -> None: """Exit a context manager for internal httpx.Client (see httpx docs)""" self.get_httpx_client().__exit__(*args, **kwargs) - def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "Client": - """Manually the underlying httpx.AsyncClient + def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> Self: + """Manually set the underlying httpx.AsyncClient **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. """ @@ -122,7 +122,7 @@ def get_async_httpx_client(self) -> httpx.AsyncClient: ) return self._async_client - async def __aenter__(self) -> "Client": + async def __aenter__(self) -> Self: """Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)""" await self.get_async_httpx_client().__aenter__() return self @@ -166,20 +166,20 @@ class AuthenticatedClient: raise_on_unexpected_status: bool = field(default=False, kw_only=True) _base_url: str = field(alias="base_url") - _cookies: Dict[str, str] = field(factory=dict, kw_only=True, alias="cookies") - _headers: Dict[str, str] = field(factory=dict, kw_only=True, alias="headers") - _timeout: Optional[httpx.Timeout] = field(default=None, kw_only=True, alias="timeout") - _verify_ssl: Union[str, bool, ssl.SSLContext] = field(default=True, kw_only=True, alias="verify_ssl") + _cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies") + _headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers") + _timeout: httpx.Timeout | None = field(default=None, kw_only=True, alias="timeout") + _verify_ssl: str | bool | ssl.SSLContext = field(default=True, kw_only=True, alias="verify_ssl") _follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects") - _httpx_args: Dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args") - _client: Optional[httpx.Client] = field(default=None, init=False) - _async_client: Optional[httpx.AsyncClient] = field(default=None, init=False) + _httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args") + _client: httpx.Client | None = field(default=None, init=False) + _async_client: httpx.AsyncClient | None = field(default=None, init=False) token: str prefix: str = "Bearer" auth_header_name: str = "Authorization" - def with_headers(self, headers: Dict[str, str]) -> "AuthenticatedClient": + def with_headers(self, headers: dict[str, str]) -> "AuthenticatedClient": """Get a new client matching this one with additional headers""" if self._client is not None: self._client.headers.update(headers) @@ -187,7 +187,7 @@ def with_headers(self, headers: Dict[str, str]) -> "AuthenticatedClient": self._async_client.headers.update(headers) return evolve(self, headers={**self._headers, **headers}) - def with_cookies(self, cookies: Dict[str, str]) -> "AuthenticatedClient": + def with_cookies(self, cookies: dict[str, str]) -> "AuthenticatedClient": """Get a new client matching this one with additional cookies""" if self._client is not None: self._client.cookies.update(cookies) @@ -196,15 +196,15 @@ def with_cookies(self, cookies: Dict[str, str]) -> "AuthenticatedClient": return evolve(self, cookies={**self._cookies, **cookies}) def with_timeout(self, timeout: httpx.Timeout) -> "AuthenticatedClient": - """Get a new client matching this one with a new timeout (in seconds)""" + """Get a new client matching this one with a new timeout configuration""" if self._client is not None: self._client.timeout = timeout if self._async_client is not None: self._async_client.timeout = timeout return evolve(self, timeout=timeout) - def set_httpx_client(self, client: httpx.Client) -> "AuthenticatedClient": - """Manually the underlying httpx.Client + def set_httpx_client(self, client: httpx.Client) -> Self: + """Manually set the underlying httpx.Client **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. """ @@ -226,7 +226,7 @@ def get_httpx_client(self) -> httpx.Client: ) return self._client - def __enter__(self) -> "AuthenticatedClient": + def __enter__(self) -> Self: """Enter a context manager for self.client—you cannot enter twice (see httpx docs)""" self.get_httpx_client().__enter__() return self @@ -235,8 +235,8 @@ def __exit__(self, *args: Any, **kwargs: Any) -> None: """Exit a context manager for internal httpx.Client (see httpx docs)""" self.get_httpx_client().__exit__(*args, **kwargs) - def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "AuthenticatedClient": - """Manually the underlying httpx.AsyncClient + def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> Self: + """Manually set the underlying httpx.AsyncClient **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. """ @@ -258,7 +258,7 @@ def get_async_httpx_client(self) -> httpx.AsyncClient: ) return self._async_client - async def __aenter__(self) -> "AuthenticatedClient": + async def __aenter__(self) -> Self: """Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)""" await self.get_async_httpx_client().__aenter__() return self diff --git a/integration-tests/integration_tests/models/__init__.py b/integration-tests/integration_tests/models/__init__.py index 275cf6faa..257cfe9fa 100644 --- a/integration-tests/integration_tests/models/__init__.py +++ b/integration-tests/integration_tests/models/__init__.py @@ -1,5 +1,7 @@ """Contains all the data models used in inputs/outputs""" +from .an_object import AnObject +from .file import File from .post_body_multipart_body import PostBodyMultipartBody from .post_body_multipart_response_200 import PostBodyMultipartResponse200 from .post_parameters_header_response_200 import PostParametersHeaderResponse200 @@ -7,6 +9,8 @@ from .public_error import PublicError __all__ = ( + "AnObject", + "File", "PostBodyMultipartBody", "PostBodyMultipartResponse200", "PostParametersHeaderResponse200", diff --git a/integration-tests/integration_tests/models/an_object.py b/integration-tests/integration_tests/models/an_object.py new file mode 100644 index 000000000..228568b8c --- /dev/null +++ b/integration-tests/integration_tests/models/an_object.py @@ -0,0 +1,69 @@ +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +T = TypeVar("T", bound="AnObject") + + +@_attrs_define +class AnObject: + """ + Attributes: + an_int (int): + a_float (float): + """ + + an_int: int + a_float: float + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + an_int = self.an_int + + a_float = self.a_float + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update( + { + "an_int": an_int, + "a_float": a_float, + } + ) + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + an_int = d.pop("an_int") + + a_float = d.pop("a_float") + + an_object = cls( + an_int=an_int, + a_float=a_float, + ) + + an_object.additional_properties = d + return an_object + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/integration-tests/integration_tests/models/file.py b/integration-tests/integration_tests/models/file.py new file mode 100644 index 000000000..2380e8737 --- /dev/null +++ b/integration-tests/integration_tests/models/file.py @@ -0,0 +1,79 @@ +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar + +from attrs import define as _attrs_define +from attrs import field as _attrs_field + +from ..types import UNSET, Unset + +T = TypeVar("T", bound="File") + + +@_attrs_define +class File: + """ + Attributes: + data (str | Unset): Echo of content of the 'file' input parameter from the form. + name (str | Unset): The name of the file uploaded. + content_type (str | Unset): The content type of the file uploaded. + """ + + data: str | Unset = UNSET + name: str | Unset = UNSET + content_type: str | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) + + def to_dict(self) -> dict[str, Any]: + data = self.data + + name = self.name + + content_type = self.content_type + + field_dict: dict[str, Any] = {} + field_dict.update(self.additional_properties) + field_dict.update({}) + if data is not UNSET: + field_dict["data"] = data + if name is not UNSET: + field_dict["name"] = name + if content_type is not UNSET: + field_dict["content_type"] = content_type + + return field_dict + + @classmethod + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) + data = d.pop("data", UNSET) + + name = d.pop("name", UNSET) + + content_type = d.pop("content_type", UNSET) + + file = cls( + data=data, + name=name, + content_type=content_type, + ) + + file.additional_properties = d + return file + + @property + def additional_keys(self) -> list[str]: + return list(self.additional_properties.keys()) + + def __getitem__(self, key: str) -> Any: + return self.additional_properties[key] + + def __setitem__(self, key: str, value: Any) -> None: + self.additional_properties[key] = value + + def __delitem__(self, key: str) -> None: + del self.additional_properties[key] + + def __contains__(self, key: str) -> bool: + return key in self.additional_properties diff --git a/integration-tests/integration_tests/models/post_body_multipart_body.py b/integration-tests/integration_tests/models/post_body_multipart_body.py index de9992232..0882f881b 100644 --- a/integration-tests/integration_tests/models/post_body_multipart_body.py +++ b/integration-tests/integration_tests/models/post_body_multipart_body.py @@ -1,10 +1,20 @@ +from __future__ import annotations + +import datetime +import json +from collections.abc import Mapping from io import BytesIO -from typing import Any, Dict, List, Type, TypeVar, Union +from typing import TYPE_CHECKING, Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field -from ..types import UNSET, File, Unset +from .. import types +from ..types import File + +if TYPE_CHECKING: + from ..models.an_object import AnObject + T = TypeVar("T", bound="PostBodyMultipartBody") @@ -14,84 +24,118 @@ class PostBodyMultipartBody: """ Attributes: a_string (str): - file (File): For the sake of this test, include a file name and content type. The payload should also be valid - UTF-8. - description (Union[Unset, str]): + files (list[File]): + description (str): + objects (list[AnObject]): + times (list[datetime.datetime]): """ a_string: str - file: File - description: Union[Unset, str] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + files: list[File] + description: str + objects: list[AnObject] + times: list[datetime.datetime] + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: a_string = self.a_string - file = self.file.to_tuple() + files = [] + for files_item_data in self.files: + files_item = files_item_data.to_tuple() + + files.append(files_item) description = self.description - field_dict: Dict[str, Any] = {} + objects = [] + for objects_item_data in self.objects: + objects_item = objects_item_data.to_dict() + objects.append(objects_item) + + times = [] + for times_item_data in self.times: + times_item = times_item_data.isoformat() + times.append(times_item) + + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update( { "a_string": a_string, - "file": file, + "files": files, + "description": description, + "objects": objects, + "times": times, } ) - if description is not UNSET: - field_dict["description"] = description return field_dict - def to_multipart(self) -> Dict[str, Any]: - a_string = ( - self.a_string if isinstance(self.a_string, Unset) else (None, str(self.a_string).encode(), "text/plain") - ) + def to_multipart(self) -> types.RequestFiles: + files: types.RequestFiles = [] - file = self.file.to_tuple() + files.append(("a_string", (None, str(self.a_string).encode(), "text/plain"))) - description = ( - self.description - if isinstance(self.description, Unset) - else (None, str(self.description).encode(), "text/plain") - ) + for files_item_element in self.files: + files.append(("files", files_item_element.to_tuple())) - field_dict: Dict[str, Any] = {} - field_dict.update( - {key: (None, str(value).encode(), "text/plain") for key, value in self.additional_properties.items()} - ) - field_dict.update( - { - "a_string": a_string, - "file": file, - } - ) - if description is not UNSET: - field_dict["description"] = description + files.append(("description", (None, str(self.description).encode(), "text/plain"))) - return field_dict + for objects_item_element in self.objects: + files.append(("objects", (None, json.dumps(objects_item_element.to_dict()).encode(), "application/json"))) + + for times_item_element in self.times: + files.append(("times", (None, times_item_element.isoformat().encode(), "text/plain"))) + + for prop_name, prop in self.additional_properties.items(): + files.append((prop_name, (None, str(prop).encode(), "text/plain"))) + + return files @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + from ..models.an_object import AnObject # noqa: PLC0415 + + d = dict(src_dict) a_string = d.pop("a_string") - file = File(payload=BytesIO(d.pop("file"))) + files = [] + _files = d.pop("files") + for files_item_data in _files: + files_item = File(payload=BytesIO(files_item_data)) + + files.append(files_item) + + description = d.pop("description") + + objects = [] + _objects = d.pop("objects") + for objects_item_data in _objects: + objects_item = AnObject.from_dict(objects_item_data) + + objects.append(objects_item) + + times = [] + _times = d.pop("times") + for times_item_data in _times: + times_item = datetime.datetime.fromisoformat(times_item_data) - description = d.pop("description", UNSET) + times.append(times_item) post_body_multipart_body = cls( a_string=a_string, - file=file, + files=files, description=description, + objects=objects, + times=times, ) post_body_multipart_body.additional_properties = d return post_body_multipart_body @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/integration-tests/integration_tests/models/post_body_multipart_response_200.py b/integration-tests/integration_tests/models/post_body_multipart_response_200.py index 79359ec41..be63512d2 100644 --- a/integration-tests/integration_tests/models/post_body_multipart_response_200.py +++ b/integration-tests/integration_tests/models/post_body_multipart_response_200.py @@ -1,8 +1,17 @@ -from typing import Any, Dict, List, Type, TypeVar +from __future__ import annotations + +import datetime +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field +if TYPE_CHECKING: + from ..models.an_object import AnObject + from ..models.file import File + + T = TypeVar("T", bound="PostBodyMultipartResponse200") @@ -11,70 +20,97 @@ class PostBodyMultipartResponse200: """ Attributes: a_string (str): Echo of the 'a_string' input parameter from the form. - file_data (str): Echo of content of the 'file' input parameter from the form. description (str): Echo of the 'description' input parameter from the form. - file_name (str): The name of the file uploaded. - file_content_type (str): The content type of the file uploaded. + files (list[File]): + times (list[datetime.datetime]): + objects (list[AnObject]): """ a_string: str - file_data: str description: str - file_name: str - file_content_type: str - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + files: list[File] + times: list[datetime.datetime] + objects: list[AnObject] + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: a_string = self.a_string - file_data = self.file_data - description = self.description - file_name = self.file_name + files = [] + for files_item_data in self.files: + files_item = files_item_data.to_dict() + files.append(files_item) + + times = [] + for times_item_data in self.times: + times_item = times_item_data.isoformat() + times.append(times_item) - file_content_type = self.file_content_type + objects = [] + for objects_item_data in self.objects: + objects_item = objects_item_data.to_dict() + objects.append(objects_item) - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update( { "a_string": a_string, - "file_data": file_data, "description": description, - "file_name": file_name, - "file_content_type": file_content_type, + "files": files, + "times": times, + "objects": objects, } ) return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() - a_string = d.pop("a_string") + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + from ..models.an_object import AnObject # noqa: PLC0415 + from ..models.file import File # noqa: PLC0415 - file_data = d.pop("file_data") + d = dict(src_dict) + a_string = d.pop("a_string") description = d.pop("description") - file_name = d.pop("file_name") + files = [] + _files = d.pop("files") + for files_item_data in _files: + files_item = File.from_dict(files_item_data) + + files.append(files_item) + + times = [] + _times = d.pop("times") + for times_item_data in _times: + times_item = datetime.datetime.fromisoformat(times_item_data) + + times.append(times_item) + + objects = [] + _objects = d.pop("objects") + for objects_item_data in _objects: + objects_item = AnObject.from_dict(objects_item_data) - file_content_type = d.pop("file_content_type") + objects.append(objects_item) post_body_multipart_response_200 = cls( a_string=a_string, - file_data=file_data, description=description, - file_name=file_name, - file_content_type=file_content_type, + files=files, + times=times, + objects=objects, ) post_body_multipart_response_200.additional_properties = d return post_body_multipart_response_200 @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/integration-tests/integration_tests/models/post_parameters_header_response_200.py b/integration-tests/integration_tests/models/post_parameters_header_response_200.py index 03e688ba1..d5baeabbd 100644 --- a/integration-tests/integration_tests/models/post_parameters_header_response_200.py +++ b/integration-tests/integration_tests/models/post_parameters_header_response_200.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -20,9 +23,9 @@ class PostParametersHeaderResponse200: string: str number: float integer: int - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: boolean = self.boolean string = self.string @@ -31,7 +34,7 @@ def to_dict(self) -> Dict[str, Any]: integer = self.integer - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update( { @@ -45,8 +48,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) boolean = d.pop("boolean") string = d.pop("string") @@ -66,7 +69,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return post_parameters_header_response_200 @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/integration-tests/integration_tests/models/problem.py b/integration-tests/integration_tests/models/problem.py index bde5b6d37..a7f270874 100644 --- a/integration-tests/integration_tests/models/problem.py +++ b/integration-tests/integration_tests/models/problem.py @@ -1,4 +1,7 @@ -from typing import Any, Dict, List, Type, TypeVar, Union +from __future__ import annotations + +from collections.abc import Mapping +from typing import Any, TypeVar from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -12,20 +15,20 @@ class Problem: """ Attributes: - parameter_name (Union[Unset, str]): - description (Union[Unset, str]): + parameter_name (str | Unset): + description (str | Unset): """ - parameter_name: Union[Unset, str] = UNSET - description: Union[Unset, str] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + parameter_name: str | Unset = UNSET + description: str | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: + def to_dict(self) -> dict[str, Any]: parameter_name = self.parameter_name description = self.description - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if parameter_name is not UNSET: @@ -36,8 +39,8 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - d = src_dict.copy() + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + d = dict(src_dict) parameter_name = d.pop("parameter_name", UNSET) description = d.pop("description", UNSET) @@ -51,7 +54,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return problem @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/integration-tests/integration_tests/models/public_error.py b/integration-tests/integration_tests/models/public_error.py index 993bd8ad3..b4ca256d2 100644 --- a/integration-tests/integration_tests/models/public_error.py +++ b/integration-tests/integration_tests/models/public_error.py @@ -1,4 +1,7 @@ -from typing import TYPE_CHECKING, Any, Dict, List, Type, TypeVar, Union, cast +from __future__ import annotations + +from collections.abc import Mapping +from typing import TYPE_CHECKING, Any, TypeVar, cast from attrs import define as _attrs_define from attrs import field as _attrs_field @@ -16,39 +19,39 @@ class PublicError: """ Attributes: - errors (Union[Unset, List[str]]): - extra_parameters (Union[Unset, List[str]]): - invalid_parameters (Union[Unset, List['Problem']]): - missing_parameters (Union[Unset, List[str]]): + errors (list[str] | Unset): + extra_parameters (list[str] | Unset): + invalid_parameters (list[Problem] | Unset): + missing_parameters (list[str] | Unset): """ - errors: Union[Unset, List[str]] = UNSET - extra_parameters: Union[Unset, List[str]] = UNSET - invalid_parameters: Union[Unset, List["Problem"]] = UNSET - missing_parameters: Union[Unset, List[str]] = UNSET - additional_properties: Dict[str, Any] = _attrs_field(init=False, factory=dict) + errors: list[str] | Unset = UNSET + extra_parameters: list[str] | Unset = UNSET + invalid_parameters: list[Problem] | Unset = UNSET + missing_parameters: list[str] | Unset = UNSET + additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) - def to_dict(self) -> Dict[str, Any]: - errors: Union[Unset, List[str]] = UNSET + def to_dict(self) -> dict[str, Any]: + errors: list[str] | Unset = UNSET if not isinstance(self.errors, Unset): errors = self.errors - extra_parameters: Union[Unset, List[str]] = UNSET + extra_parameters: list[str] | Unset = UNSET if not isinstance(self.extra_parameters, Unset): extra_parameters = self.extra_parameters - invalid_parameters: Union[Unset, List[Dict[str, Any]]] = UNSET + invalid_parameters: list[dict[str, Any]] | Unset = UNSET if not isinstance(self.invalid_parameters, Unset): invalid_parameters = [] for invalid_parameters_item_data in self.invalid_parameters: invalid_parameters_item = invalid_parameters_item_data.to_dict() invalid_parameters.append(invalid_parameters_item) - missing_parameters: Union[Unset, List[str]] = UNSET + missing_parameters: list[str] | Unset = UNSET if not isinstance(self.missing_parameters, Unset): missing_parameters = self.missing_parameters - field_dict: Dict[str, Any] = {} + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) if errors is not UNSET: @@ -63,22 +66,24 @@ def to_dict(self) -> Dict[str, Any]: return field_dict @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - from ..models.problem import Problem + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + from ..models.problem import Problem # noqa: PLC0415 - d = src_dict.copy() - errors = cast(List[str], d.pop("errors", UNSET)) + d = dict(src_dict) + errors = cast(list[str], d.pop("errors", UNSET)) - extra_parameters = cast(List[str], d.pop("extra_parameters", UNSET)) + extra_parameters = cast(list[str], d.pop("extra_parameters", UNSET)) - invalid_parameters = [] _invalid_parameters = d.pop("invalid_parameters", UNSET) - for invalid_parameters_item_data in _invalid_parameters or []: - invalid_parameters_item = Problem.from_dict(invalid_parameters_item_data) + invalid_parameters: list[Problem] | Unset = UNSET + if _invalid_parameters is not UNSET: + invalid_parameters = [] + for invalid_parameters_item_data in _invalid_parameters: + invalid_parameters_item = Problem.from_dict(invalid_parameters_item_data) - invalid_parameters.append(invalid_parameters_item) + invalid_parameters.append(invalid_parameters_item) - missing_parameters = cast(List[str], d.pop("missing_parameters", UNSET)) + missing_parameters = cast(list[str], d.pop("missing_parameters", UNSET)) public_error = cls( errors=errors, @@ -91,7 +96,7 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: return public_error @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> Any: diff --git a/integration-tests/integration_tests/types.py b/integration-tests/integration_tests/types.py index 21fac106f..b64af0952 100644 --- a/integration-tests/integration_tests/types.py +++ b/integration-tests/integration_tests/types.py @@ -1,7 +1,8 @@ """Contains some shared types for properties""" +from collections.abc import Mapping, MutableMapping from http import HTTPStatus -from typing import BinaryIO, Generic, Literal, MutableMapping, Optional, Tuple, TypeVar +from typing import IO, BinaryIO, Generic, Literal, TypeVar from attrs import define @@ -13,7 +14,15 @@ def __bool__(self) -> Literal[False]: UNSET: Unset = Unset() -FileJsonType = Tuple[Optional[str], BinaryIO, Optional[str]] +# The types that `httpx.Client(files=)` can accept, copied from that library. +FileContent = IO[bytes] | bytes | str +FileTypes = ( + # (filename, file (or bytes), content_type) + tuple[str | None, FileContent, str | None] + # (filename, file (or bytes), content_type, headers) + | tuple[str | None, FileContent, str | None, Mapping[str, str]] +) +RequestFiles = list[tuple[str, FileTypes]] @define @@ -21,10 +30,10 @@ class File: """Contains information for file uploads""" payload: BinaryIO - file_name: Optional[str] = None - mime_type: Optional[str] = None + file_name: str | None = None + mime_type: str | None = None - def to_tuple(self) -> FileJsonType: + def to_tuple(self) -> FileTypes: """Return a tuple representation that httpx will accept for multipart/form-data""" return self.file_name, self.payload, self.mime_type @@ -39,7 +48,7 @@ class Response(Generic[T]): status_code: HTTPStatus content: bytes headers: MutableMapping[str, str] - parsed: Optional[T] + parsed: T | None -__all__ = ["File", "Response", "FileJsonType", "Unset", "UNSET"] +__all__ = ["UNSET", "File", "FileTypes", "RequestFiles", "Response", "Unset"] diff --git a/integration-tests/pdm.lock b/integration-tests/pdm.lock index 3978f8633..ffae47bd6 100644 --- a/integration-tests/pdm.lock +++ b/integration-tests/pdm.lock @@ -3,47 +3,91 @@ [metadata] groups = ["default", "dev"] -strategy = ["cross_platform", "inherit_metadata"] -lock_version = "4.4.1" -content_hash = "sha256:21f2d31fc91486810f21163e5ce7d73ebd8265f44bbef79d817d14c61d97c34a" +strategy = ["inherit_metadata"] +lock_version = "4.5.0" +content_hash = "sha256:eaf8c822d09eaa6cb6b1cb2ac7deb1746c24e404459a1a79f5c35df71b8883c7" + +[[metadata.targets]] +requires_python = "~=3.11" [[package]] name = "anyio" -version = "4.2.0" -requires_python = ">=3.8" -summary = "High level compatibility layer for multiple asynchronous event loop implementations" +version = "4.14.0" +requires_python = ">=3.10" +summary = "High-level concurrency and networking framework on top of asyncio or Trio" groups = ["default"] dependencies = [ "exceptiongroup>=1.0.2; python_version < \"3.11\"", "idna>=2.8", - "sniffio>=1.1", - "typing-extensions>=4.1; python_version < \"3.11\"", + "typing-extensions>=4.5; python_version < \"3.13\"", ] files = [ - {file = "anyio-4.2.0-py3-none-any.whl", hash = "sha256:745843b39e829e108e518c489b31dc757de7d2131d53fac32bd8df268227bfee"}, - {file = "anyio-4.2.0.tar.gz", hash = "sha256:e1875bb4b4e2de1669f4bc7869b6d3f54231cdced71605e6e64c9be77e3be50f"}, + {file = "anyio-4.14.0-py3-none-any.whl", hash = "sha256:dd9b7a2a9799ed6552fde617b2c5df02b7fdd7d88392fc48101e51bae46164d9"}, + {file = "anyio-4.14.0.tar.gz", hash = "sha256:b47c1f9ccf73e67021df785332508f99379c68fa7d0684e8e3492cb1d4b23f89"}, ] [[package]] -name = "attrs" -version = "23.2.0" +name = "ast-serialize" +version = "0.5.0" requires_python = ">=3.7" +summary = "Python bindings for mypy AST serialization" +groups = ["dev"] +files = [ + {file = "ast_serialize-0.5.0-cp314-cp314t-macosx_10_12_x86_64.whl", hash = "sha256:8f5c14f169eb0972c0c21bada5358b23d6047c76583b005234f865b11f1fa00a"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:7d1a2de9de5be04652f0ed60738356ef94f66db37924a9499fffe98dc491aa0b"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:be5173fb66f9b49026d9d5a2ff0fc7c7009077107c0eb285b2d60fdf1fe10bd1"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:f8015cd071ac1339924ee2b8098c93e00e155f30a16f40ec9816fcf84f4753f6"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:5499e8797edff2a9186aa313ed382c6b422e798e9332d9953badcee6e69a88f2"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:6848f2a093fb5548751a9a09bff8fcd229e2bbeb0e3331f391b6ae6d26cd9903"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:832d4c998e0b091fd60a6d6bceee535483c4d490de9ba85003af835225719261"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-manylinux_2_31_riscv64.whl", hash = "sha256:16db7c62ec0b8efe1d7afd283a388d8f74f2605d56032e5a37747d2de8dba027"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:baf5eb061eb5bccade4128ad42da33787d72f6013809cd1b590376ece8b3c937"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:104e4a35bd7c124173c41760ef9aaea17ddb3f86c65cb643671d59afbe3ee94c"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-musllinux_1_2_armv7l.whl", hash = "sha256:36be371028fc1675acb38a331bde160dbab7ff907fdf00b67eb6911aa106951b"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-musllinux_1_2_i686.whl", hash = "sha256:061ee58bdb52341c8201a6df41182a977736bae3b7ded87ca7176ca25a8a47ab"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:b15219e9cdc9f53f6f4cb51c009203507228226148c05c5e8fe451c28b435eb3"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-win32.whl", hash = "sha256:842d1c004bb466c7df036f95fabef789570541922b10976b12f5592a69cf0b38"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-win_amd64.whl", hash = "sha256:b0c06d760909b095cc466356dfccd05a1c7233a6ca191c020dca2c6a6f16c24c"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-win_arm64.whl", hash = "sha256:787baedb0262cc49e8ce37cc15c00ae818e46a165a3b36f5e21ed174998104cb"}, + {file = "ast_serialize-0.5.0-cp39-abi3-macosx_10_12_x86_64.whl", hash = "sha256:0668aa9459cfa8c9c49ddd2163ebcf43088ba045ef7492af6fe22e0098303101"}, + {file = "ast_serialize-0.5.0-cp39-abi3-macosx_11_0_arm64.whl", hash = "sha256:bf683d6363edf2b39eed6b6d4fe22d34b6203867a67e27134d9e2a2680c4bc4a"}, + {file = "ast_serialize-0.5.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9cc22cf0c9be65e71cf88fda130af60d61eb4a79370ad4cfe7900d48a4aa2211"}, + {file = "ast_serialize-0.5.0-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:f66173891548c9f2726bf27957b41cabce12fa679dc6da505ddbde4d4b3b31cf"}, + {file = "ast_serialize-0.5.0-cp39-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:e42d729ef2be96a14efbad355093284739e3670ece3e534f82cc8832790911d9"}, + {file = "ast_serialize-0.5.0-cp39-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b725026bafa801dbd7310eb13a75f0a2e370e7e51b2cb225f9d21fcfadf919ee"}, + {file = "ast_serialize-0.5.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b54f60c1d78767a53b67eaa663f0dfac3afe606aa07f1301572f588b73d64809"}, + {file = "ast_serialize-0.5.0-cp39-abi3-manylinux_2_31_riscv64.whl", hash = "sha256:27d51654fc240a1e87e742d353d98eb45b75f62f129086b3596ab53df2ac2a43"}, + {file = "ast_serialize-0.5.0-cp39-abi3-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:2782c36237c46dd1674542f2109740ea5ea485a169bf1431939ada0434e17934"}, + {file = "ast_serialize-0.5.0-cp39-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:1943db345233cc7194a470f13afa9c59772c0b123dea0c9414c4d4ca54369759"}, + {file = "ast_serialize-0.5.0-cp39-abi3-musllinux_1_2_armv7l.whl", hash = "sha256:df1c00022cbbcb064bfaa505aa9c9295362443ce5dacb459d1331d3da353f887"}, + {file = "ast_serialize-0.5.0-cp39-abi3-musllinux_1_2_i686.whl", hash = "sha256:cae65289fc456fde04af979a2be09302ef5d8ab92ef23e596d6746dc267ada27"}, + {file = "ast_serialize-0.5.0-cp39-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:239a4c354e8d676e9d94631d1d4a64edc6b266f86ff3a5a80aedd344f342c01d"}, + {file = "ast_serialize-0.5.0-cp39-abi3-win32.whl", hash = "sha256:143a4ef63285a075871908fda3672dc21864b83a8ec3ee12304aa3e4c5387b9a"}, + {file = "ast_serialize-0.5.0-cp39-abi3-win_amd64.whl", hash = "sha256:cf25572c526add400f26a4750dc6ce0c3bb93fc1f75e7ae0cad4ce4f2cd5c590"}, + {file = "ast_serialize-0.5.0-cp39-abi3-win_arm64.whl", hash = "sha256:92a31c9c20d25a076edaeec76b128a3535d74a24f340b9a8a7e96c9b86dc9642"}, + {file = "ast_serialize-0.5.0.tar.gz", hash = "sha256:5880091bfe6f4f986f22866375c2e884843e7a0b6343ae41aeea659613d879b6"}, +] + +[[package]] +name = "attrs" +version = "26.1.0" +requires_python = ">=3.9" summary = "Classes Without Boilerplate" groups = ["default"] files = [ - {file = "attrs-23.2.0-py3-none-any.whl", hash = "sha256:99b87a485a5820b23b879f04c2305b44b951b502fd64be915879d77a7e8fc6f1"}, - {file = "attrs-23.2.0.tar.gz", hash = "sha256:935dc3b529c262f6cf76e50877d35a4bd3c1de194fd41f47a2b7ae8f19971f30"}, + {file = "attrs-26.1.0-py3-none-any.whl", hash = "sha256:c647aa4a12dfbad9333ca4e71fe62ddc36f4e63b2d260a37a8b83d2f043ac309"}, + {file = "attrs-26.1.0.tar.gz", hash = "sha256:d03ceb89cb322a8fd706d4fb91940737b6642aa36998fe130a9bc96c985eff32"}, ] [[package]] name = "certifi" -version = "2023.11.17" -requires_python = ">=3.6" +version = "2026.6.17" +requires_python = ">=3.7" summary = "Python package for providing Mozilla's CA Bundle." groups = ["default"] files = [ - {file = "certifi-2023.11.17-py3-none-any.whl", hash = "sha256:e036ab49d5b79556f99cfc2d9320b34cfbe5be05c5871b51de9329f0603b0474"}, - {file = "certifi-2023.11.17.tar.gz", hash = "sha256:9b469f3a900bf28dc19b8cfbf8019bf47f7fdd1a65a1d4ffb98fc14166beb4d1"}, + {file = "certifi-2026.6.17-py3-none-any.whl", hash = "sha256:2227dcbaafe0d2f59279d1762ddddc37783ed4354594f194ffc31d20f41fc3db"}, + {file = "certifi-2026.6.17.tar.gz", hash = "sha256:024c88eeec92ca068db80f02b8b07c9cef7b9fe261d1d535abfd5abd6f6af432"}, ] [[package]] @@ -58,47 +102,35 @@ files = [ {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, ] -[[package]] -name = "exceptiongroup" -version = "1.2.0" -requires_python = ">=3.7" -summary = "Backport of PEP 654 (exception groups)" -groups = ["default", "dev"] -marker = "python_version < \"3.11\"" -files = [ - {file = "exceptiongroup-1.2.0-py3-none-any.whl", hash = "sha256:4bfd3996ac73b41e9b9628b04e079f193850720ea5945fc96a08633c66912f14"}, - {file = "exceptiongroup-1.2.0.tar.gz", hash = "sha256:91f5c769735f051a4290d52edd0858999b57e5876e9f85937691bd4c9fa3ed68"}, -] - [[package]] name = "h11" -version = "0.14.0" -requires_python = ">=3.7" +version = "0.16.0" +requires_python = ">=3.8" summary = "A pure-Python, bring-your-own-I/O implementation of HTTP/1.1" groups = ["default"] files = [ - {file = "h11-0.14.0-py3-none-any.whl", hash = "sha256:e3fe4ac4b851c468cc8363d500db52c2ead036020723024a109d37346efaa761"}, - {file = "h11-0.14.0.tar.gz", hash = "sha256:8f19fbbe99e72420ff35c00b27a34cb9937e902a8b810e2c88300c6f0a3b699d"}, + {file = "h11-0.16.0-py3-none-any.whl", hash = "sha256:63cf8bbe7522de3bf65932fda1d9c2772064ffb3dae62d55932da54b31cb6c86"}, + {file = "h11-0.16.0.tar.gz", hash = "sha256:4e35b956cf45792e4caa5885e69fba00bdbc6ffafbfa020300e549b208ee5ff1"}, ] [[package]] name = "httpcore" -version = "1.0.2" +version = "1.0.9" requires_python = ">=3.8" summary = "A minimal low-level HTTP client." groups = ["default"] dependencies = [ "certifi", - "h11<0.15,>=0.13", + "h11>=0.16", ] files = [ - {file = "httpcore-1.0.2-py3-none-any.whl", hash = "sha256:096cc05bca73b8e459a1fc3dcf585148f63e534eae4339559c9b8a8d6399acc7"}, - {file = "httpcore-1.0.2.tar.gz", hash = "sha256:9fc092e4799b26174648e54b74ed5f683132a464e95643b226e00c2ed2fa6535"}, + {file = "httpcore-1.0.9-py3-none-any.whl", hash = "sha256:2d400746a40668fc9dec9810239072b40b4484b640a8c38fd654a024c7a1bf55"}, + {file = "httpcore-1.0.9.tar.gz", hash = "sha256:6e34463af53fd2ab5d807f399a9b45ea31c3dfa2276f15a2c3f00afff6e176e8"}, ] [[package]] name = "httpx" -version = "0.27.0" +version = "0.28.1" requires_python = ">=3.8" summary = "The next generation HTTP client." groups = ["default"] @@ -107,197 +139,263 @@ dependencies = [ "certifi", "httpcore==1.*", "idna", - "sniffio", ] files = [ - {file = "httpx-0.27.0-py3-none-any.whl", hash = "sha256:71d5465162c13681bff01ad59b2cc68dd838ea1f10e51574bac27103f00c91a5"}, - {file = "httpx-0.27.0.tar.gz", hash = "sha256:a0cb88a46f32dc874e04ee956e4c2764aba2aa228f650b06788ba6bda2962ab5"}, + {file = "httpx-0.28.1-py3-none-any.whl", hash = "sha256:d909fcccc110f8c7faf814ca82a9a4d816bc5a6dbfea25d6591d6985b8ba59ad"}, + {file = "httpx-0.28.1.tar.gz", hash = "sha256:75e98c5f16b0f35b567856f597f06ff2270a374470a5c2392242528e3e3e42fc"}, ] [[package]] name = "idna" -version = "3.6" -requires_python = ">=3.5" +version = "3.18" +requires_python = ">=3.9" summary = "Internationalized Domain Names in Applications (IDNA)" groups = ["default"] files = [ - {file = "idna-3.6-py3-none-any.whl", hash = "sha256:c05567e9c24a6b9faaa835c4821bad0590fbb9d5779e7caa6e1cc4978e7eb24f"}, - {file = "idna-3.6.tar.gz", hash = "sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca"}, + {file = "idna-3.18-py3-none-any.whl", hash = "sha256:7f952cbe720b688055e3f87de14f5c3e5fdaa8bc3928985c4077ca689de849a2"}, + {file = "idna-3.18.tar.gz", hash = "sha256:ffb385a7e039654cef1ab9ef32c6fafe283c0c0467bba1d9029738ce4a14a848"}, ] [[package]] name = "iniconfig" -version = "2.0.0" -requires_python = ">=3.7" +version = "2.3.0" +requires_python = ">=3.10" summary = "brain-dead simple config-ini parsing" groups = ["dev"] files = [ - {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"}, - {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, + {file = "iniconfig-2.3.0-py3-none-any.whl", hash = "sha256:f631c04d2c48c52b84d0d0549c99ff3859c98df65b3101406327ecc7d53fbf12"}, + {file = "iniconfig-2.3.0.tar.gz", hash = "sha256:c76315c77db068650d49c5b56314774a7804df16fee4402c1f19d6d15d8c4730"}, +] + +[[package]] +name = "librt" +version = "0.11.0" +requires_python = ">=3.9" +summary = "Mypyc runtime library" +groups = ["dev"] +marker = "platform_python_implementation != \"PyPy\"" +files = [ + {file = "librt-0.11.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:93d95bd45b7d58343d8b90d904450a545144eec19a002511163426f8ab1fae29"}, + {file = "librt-0.11.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:4ee278c769a713638cdacd4c0436d72156e75df3ebc0166ab2b9dc43acc386c9"}, + {file = "librt-0.11.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:f230cb1cbc9faaa616f9a678f530ebcf186e414b6bcbd88b960e4ba1b92428d5"}, + {file = "librt-0.11.0-cp311-cp311-manylinux2014_i686.manylinux_2_17_i686.manylinux_2_28_i686.whl", hash = "sha256:5d63c855d86938d9de93e265c9bd8c705b51ec494de5738340ee93767a686e4b"}, + {file = "librt-0.11.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:993f028be9e96a08d31df3479ac80d99be374d17f3b78e4796b3fd3c913d4e89"}, + {file = "librt-0.11.0-cp311-cp311-manylinux_2_34_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:258d73a0aa66a055e65b2e4d1b8cdb23b9d132c5bb915d9547d804fcaed116cc"}, + {file = "librt-0.11.0-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:0827efe7854718f04aaddf6496e96960a956e676fe1d0f04eb41511fd8ad06d5"}, + {file = "librt-0.11.0-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:7753e57d6e12d019c0d8786f1c09c709f4c3fcc57c3887b24e36e6c06ec938b7"}, + {file = "librt-0.11.0-cp311-cp311-musllinux_1_2_riscv64.whl", hash = "sha256:11bd19822431cc21af9f27374e7ae2e58103c7d98bda823536a6c47f6bb2bb3d"}, + {file = "librt-0.11.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:22bdf239b219d3993761a148ffa134b19e52e9989c84f845d5d7b71d70a17412"}, + {file = "librt-0.11.0-cp311-cp311-win32.whl", hash = "sha256:46c60b61e308eb535fbd6fa622b1ee1bb2815691c1ad9c98bf7b84952ec3bc8d"}, + {file = "librt-0.11.0-cp311-cp311-win_amd64.whl", hash = "sha256:902e546ff044f579ff1c953ff5fce97b636fe9e3943996b2177710c6ef076f73"}, + {file = "librt-0.11.0-cp311-cp311-win_arm64.whl", hash = "sha256:65ac3bc20f78aa0ee5ae84baa68917f89fef4af63e941084dd019a0d0e749f0c"}, + {file = "librt-0.11.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:b87504f1690a23b9a2cca841191a04f83895d4fc2dd04df91d82b1a04ca2ad46"}, + {file = "librt-0.11.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40071fc5fe0ce8daa6de616702314a01e1250711682b0523d6ab8d4525910cb3"}, + {file = "librt-0.11.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:137e79445c896a0ea7b265f52d23954e05b64222ee1af69e2cb34219067cbb67"}, + {file = "librt-0.11.0-cp312-cp312-manylinux2014_i686.manylinux_2_17_i686.manylinux_2_28_i686.whl", hash = "sha256:cca6644054e78746d8d4ef238681f9c34ff8b584fe6b988ecebb8db3b15e622a"}, + {file = "librt-0.11.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:d5b0eea49f5562861ee8d757a32ef7d559c1d35be2aaaa1ec28941d74c9ffc8a"}, + {file = "librt-0.11.0-cp312-cp312-manylinux_2_34_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:0d1029d7e1ae1a7e647ed6fb5df8c4ce2dffefb7a9f5fd1376a4554d96dac09f"}, + {file = "librt-0.11.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:bc3ce6b33c5828d9e80592011a5c584cb2ce86edbc4088405f70da47dc1d1b3b"}, + {file = "librt-0.11.0-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:936c5995f3514a42111f20099397d8177c79b4d7e70961e396c6f5a0a3566766"}, + {file = "librt-0.11.0-cp312-cp312-musllinux_1_2_riscv64.whl", hash = "sha256:9bc0ca6ad9381cbe8e4aa6e5726e4c80c78115a6e9723c599ed1d73e092bc49d"}, + {file = "librt-0.11.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:070aa8c26c0a74774317a72df8851facc7f0f012a5b406557ac56992d92e1ec8"}, + {file = "librt-0.11.0-cp312-cp312-win32.whl", hash = "sha256:6bf14feb84b05ae945277395451998c89c54d0def4070eb5c08de544930b245a"}, + {file = "librt-0.11.0-cp312-cp312-win_amd64.whl", hash = "sha256:75672f0bc524ede266287d532d7923dbce94c7514ad07627bac3d0c6d92cc4d9"}, + {file = "librt-0.11.0-cp312-cp312-win_arm64.whl", hash = "sha256:2f10cf143e4a9bb0f4f5af568a00df94a2d69ef41c2579584454bb0fe5cc642c"}, + {file = "librt-0.11.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:78dc31f7fdfe9c9d0eb0e8f42d139db230e826415bbcabd9f0e9faaaee909894"}, + {file = "librt-0.11.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:fa475675db22290c3158e1d42326d0f5a65f04f44a0e68c3630a25b53560fb9c"}, + {file = "librt-0.11.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:621db29691044bdeda22e789e482e1b0f3a985d90e3426c9c6d17606416205ea"}, + {file = "librt-0.11.0-cp313-cp313-manylinux2014_i686.manylinux_2_17_i686.manylinux_2_28_i686.whl", hash = "sha256:a9010e2ed5b3a9e158c5fd966b3ab7e834bb3d3aacc8f66c91dd4b57a3799230"}, + {file = "librt-0.11.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:7c39513d8b7477a2e1ed8c43fc21c524e8d5a0f8d4e8b7b074dbdbe7820a08e2"}, + {file = "librt-0.11.0-cp313-cp313-manylinux_2_34_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:7aef3cf1d5af86e770ab04bfd993dfc4ae8b8c17f66fb77dd4a7d50de7bbb1a3"}, + {file = "librt-0.11.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:557183ddc36babe46b27dd60facbd5adb4492181a5be887587d57cda6e092f21"}, + {file = "librt-0.11.0-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:83d3e1f72bd42f6c5c0b7daec530c3f829bd02db42c70b8ddf0c2d90a2459930"}, + {file = "librt-0.11.0-cp313-cp313-musllinux_1_2_riscv64.whl", hash = "sha256:4ce1f21fbe589bc1afd7872dece84fb0e1144f794a288e58a10d2c54a55c43be"}, + {file = "librt-0.11.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:970b09f7044ea2b64c9da42fd3d335666518cfd1c6e8a182c95da73d0214b41e"}, + {file = "librt-0.11.0-cp313-cp313-win32.whl", hash = "sha256:78fddc31cd4d3caa897ad5d31f856b1faadc9474021ad6cb182b9018793e254e"}, + {file = "librt-0.11.0-cp313-cp313-win_amd64.whl", hash = "sha256:8ca8aa88751a775870b764e93bad5135385f563cb8dcee399abf034ea4d3cb47"}, + {file = "librt-0.11.0-cp313-cp313-win_arm64.whl", hash = "sha256:96f044bb325fd9cf1a723015638c219e9143f0dfbc0ca54c565df2b7fc748b44"}, + {file = "librt-0.11.0-cp314-cp314-macosx_10_13_x86_64.whl", hash = "sha256:4a017a95e5837dc15a8c5661d60e05daa96b90908b1aa6b7acdf443cd25c8ebd"}, + {file = "librt-0.11.0-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:b1ecbd9819deccc39b7542bf4d2a740d8a620694d39989e58661d3763458f8d4"}, + {file = "librt-0.11.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:7da327dacd7be8f8ec36547373550744a3cc0e536d54665cd83f8bcd961200e8"}, + {file = "librt-0.11.0-cp314-cp314-manylinux2014_i686.manylinux_2_17_i686.manylinux_2_28_i686.whl", hash = "sha256:0dc56b1f8d06e60db362cc3fdae206681817f86ce4725d34511473487f12a34b"}, + {file = "librt-0.11.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:05fb8fb2ab90e21c8d12ea240d744ad514da9baf381ebfa70d91d20d21713175"}, + {file = "librt-0.11.0-cp314-cp314-manylinux_2_34_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:cae74872be221df4374d10fec61f93ed1513b9546ea84f2c0bf73ab3e9bd0b03"}, + {file = "librt-0.11.0-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:32bcc918c0148eb7e3d57385125bac7e5f9e4359d05f07448b09f6f778c2f31c"}, + {file = "librt-0.11.0-cp314-cp314-musllinux_1_2_i686.whl", hash = "sha256:f9743fc99135d5f78d2454435615f6dec0473ca507c26ce9d92b10b562a280d3"}, + {file = "librt-0.11.0-cp314-cp314-musllinux_1_2_riscv64.whl", hash = "sha256:5ba067f4aadae8fda802d91d2124c90c42195ff32d9161d3549e6d05cfe26f96"}, + {file = "librt-0.11.0-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:de3bf945454d032f9e390b85c4072e0a0570bf825421c8be0e71209fa65e1abe"}, + {file = "librt-0.11.0-cp314-cp314-win32.whl", hash = "sha256:d2277a05f6dcb9fd13db9566aac4fabd68c3ea1ea46ee5567d4eef8efa495a2f"}, + {file = "librt-0.11.0-cp314-cp314-win_amd64.whl", hash = "sha256:ab73e8db5e3f564d812c1f5c3a175930a5f9bc96ccb5e3b22a34d7858b401cf7"}, + {file = "librt-0.11.0-cp314-cp314-win_arm64.whl", hash = "sha256:aea3caa317752e3a466fa8af45d91ee0ea8c7fdd96e42b0a8dd9b76a7931eba1"}, + {file = "librt-0.11.0-cp314-cp314t-macosx_10_13_x86_64.whl", hash = "sha256:d1b36540d7aaf9b9101b3a6f376c8d8e9f7a9aec93ed05918f2c69d493ffef72"}, + {file = "librt-0.11.0-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:efbb343ab2ce3540f4ecbe6315d677ed70f37cd9a72b1e58066c918ca83acbaa"}, + {file = "librt-0.11.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:aa0dd688aab3f7914d3e6e5e3554978e0383312fb8e771d84be008a35b9ee548"}, + {file = "librt-0.11.0-cp314-cp314t-manylinux2014_i686.manylinux_2_17_i686.manylinux_2_28_i686.whl", hash = "sha256:f5fb36b8c6c63fdcbb1d526d94c0d1331610d43f4118cc1beb4efef4f3faacb2"}, + {file = "librt-0.11.0-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:4a9a237d13addb93715b6fee74023d5ee3469b53fce527626c0e088aa585805f"}, + {file = "librt-0.11.0-cp314-cp314t-manylinux_2_34_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:5ddd17bd87b2c56ddd60e546a7984a2e64c4e8eab92fb4cf3830a48ad5469d51"}, + {file = "librt-0.11.0-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:bd43992b4473d42f12ff9e68326079f0696d9d4e6000e8f39a0238d482ba6ee2"}, + {file = "librt-0.11.0-cp314-cp314t-musllinux_1_2_i686.whl", hash = "sha256:f8e3e8056dd674e279741485e2e512d6e9a751c7455809d0114e6ebf8d781085"}, + {file = "librt-0.11.0-cp314-cp314t-musllinux_1_2_riscv64.whl", hash = "sha256:c1f708d8ae9c56cf38a903c44297243d2ec83fd82b396b977e0144a3e76217e3"}, + {file = "librt-0.11.0-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:0add982e0e7b9fc14cf4b33789d5f13f66581889b88c2f58099f6ce8f92617bd"}, + {file = "librt-0.11.0-cp314-cp314t-win32.whl", hash = "sha256:2b481d846ac894c4e8403c5fd0e87c5d11d6499e404b474602508a224ff531c8"}, + {file = "librt-0.11.0-cp314-cp314t-win_amd64.whl", hash = "sha256:28edb433edde181112a908c78907af28f964eabc15f4dd16c9d66c834302677c"}, + {file = "librt-0.11.0-cp314-cp314t-win_arm64.whl", hash = "sha256:dee008f20b542e3cd162ba338a7f9ec0f6d23d395f66fe8aeeec3c9d067ea253"}, + {file = "librt-0.11.0.tar.gz", hash = "sha256:075dc3ef4458a278e0195cbf6ac9d38808d9b906c5a6c7f7f79c3888276a3fb1"}, ] [[package]] name = "mypy" -version = "1.9.0" -requires_python = ">=3.8" +version = "2.1.0" +requires_python = ">=3.10" summary = "Optional static typing for Python" groups = ["dev"] dependencies = [ + "ast-serialize<1.0.0,>=0.3.0", + "librt>=0.11.0; platform_python_implementation != \"PyPy\"", "mypy-extensions>=1.0.0", + "pathspec>=1.0.0", "tomli>=1.1.0; python_version < \"3.11\"", - "typing-extensions>=4.1.0", + "typing-extensions>=4.14.0; python_version >= \"3.15\"", + "typing-extensions>=4.6.0; python_version < \"3.15\"", ] files = [ - {file = "mypy-1.9.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:f8a67616990062232ee4c3952f41c779afac41405806042a8126fe96e098419f"}, - {file = "mypy-1.9.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:d357423fa57a489e8c47b7c85dfb96698caba13d66e086b412298a1a0ea3b0ed"}, - {file = "mypy-1.9.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:49c87c15aed320de9b438ae7b00c1ac91cd393c1b854c2ce538e2a72d55df150"}, - {file = "mypy-1.9.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:48533cdd345c3c2e5ef48ba3b0d3880b257b423e7995dada04248725c6f77374"}, - {file = "mypy-1.9.0-cp310-cp310-win_amd64.whl", hash = "sha256:4d3dbd346cfec7cb98e6cbb6e0f3c23618af826316188d587d1c1bc34f0ede03"}, - {file = "mypy-1.9.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:653265f9a2784db65bfca694d1edd23093ce49740b2244cde583aeb134c008f3"}, - {file = "mypy-1.9.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:3a3c007ff3ee90f69cf0a15cbcdf0995749569b86b6d2f327af01fd1b8aee9dc"}, - {file = "mypy-1.9.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2418488264eb41f69cc64a69a745fad4a8f86649af4b1041a4c64ee61fc61129"}, - {file = "mypy-1.9.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:68edad3dc7d70f2f17ae4c6c1b9471a56138ca22722487eebacfd1eb5321d612"}, - {file = "mypy-1.9.0-cp311-cp311-win_amd64.whl", hash = "sha256:85ca5fcc24f0b4aeedc1d02f93707bccc04733f21d41c88334c5482219b1ccb3"}, - {file = "mypy-1.9.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:aceb1db093b04db5cd390821464504111b8ec3e351eb85afd1433490163d60cd"}, - {file = "mypy-1.9.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:0235391f1c6f6ce487b23b9dbd1327b4ec33bb93934aa986efe8a9563d9349e6"}, - {file = "mypy-1.9.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d4d5ddc13421ba3e2e082a6c2d74c2ddb3979c39b582dacd53dd5d9431237185"}, - {file = "mypy-1.9.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:190da1ee69b427d7efa8aa0d5e5ccd67a4fb04038c380237a0d96829cb157913"}, - {file = "mypy-1.9.0-cp312-cp312-win_amd64.whl", hash = "sha256:fe28657de3bfec596bbeef01cb219833ad9d38dd5393fc649f4b366840baefe6"}, - {file = "mypy-1.9.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:e54396d70be04b34f31d2edf3362c1edd023246c82f1730bbf8768c28db5361b"}, - {file = "mypy-1.9.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:5e6061f44f2313b94f920e91b204ec600982961e07a17e0f6cd83371cb23f5c2"}, - {file = "mypy-1.9.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:81a10926e5473c5fc3da8abb04119a1f5811a236dc3a38d92015cb1e6ba4cb9e"}, - {file = "mypy-1.9.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:b685154e22e4e9199fc95f298661deea28aaede5ae16ccc8cbb1045e716b3e04"}, - {file = "mypy-1.9.0-cp38-cp38-win_amd64.whl", hash = "sha256:5d741d3fc7c4da608764073089e5f58ef6352bedc223ff58f2f038c2c4698a89"}, - {file = "mypy-1.9.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:587ce887f75dd9700252a3abbc9c97bbe165a4a630597845c61279cf32dfbf02"}, - {file = "mypy-1.9.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:f88566144752999351725ac623471661c9d1cd8caa0134ff98cceeea181789f4"}, - {file = "mypy-1.9.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:61758fabd58ce4b0720ae1e2fea5cfd4431591d6d590b197775329264f86311d"}, - {file = "mypy-1.9.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:e49499be624dead83927e70c756970a0bc8240e9f769389cdf5714b0784ca6bf"}, - {file = "mypy-1.9.0-cp39-cp39-win_amd64.whl", hash = "sha256:571741dc4194b4f82d344b15e8837e8c5fcc462d66d076748142327626a1b6e9"}, - {file = "mypy-1.9.0-py3-none-any.whl", hash = "sha256:a260627a570559181a9ea5de61ac6297aa5af202f06fd7ab093ce74e7181e43e"}, - {file = "mypy-1.9.0.tar.gz", hash = "sha256:3cc5da0127e6a478cddd906068496a97a7618a21ce9b54bde5bf7e539c7af974"}, + {file = "mypy-2.1.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:a683016b16fe2f572dc04c72be7ee0504ac1605a265d0200f5cea695fb788f41"}, + {file = "mypy-2.1.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:1a293c534adb55271fef24a26da04b855540a8c13cc07bc5917b9fd2c394f2ca"}, + {file = "mypy-2.1.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:7406f4d048e71e576f5356d317e5b0a9e666dfd966bd99f9d14ca06e1a341538"}, + {file = "mypy-2.1.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:e0210d626fc8b31ccc90233754c7bc90e1f43205e85d96387f7db1285b55c398"}, + {file = "mypy-2.1.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:3712c20deed54e814eaaa825603bada8ea1c390670a397c95b98405347acc563"}, + {file = "mypy-2.1.0-cp311-cp311-win_amd64.whl", hash = "sha256:fcaa0e479066e31f7cceb6a3bea39cb22b2ff51a6b2f24f193d19179ba17c389"}, + {file = "mypy-2.1.0-cp311-cp311-win_arm64.whl", hash = "sha256:0b1a5260c95aa443083f9ed3592662941951bca3d4ca224a5dc517c38b7cf666"}, + {file = "mypy-2.1.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:244358bf1c0da7722230bce60683d52e8e9fd030554926f15b747a84efb5b3af"}, + {file = "mypy-2.1.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:4ec7c57657493c7a75534df2751c8ae2cda383c16ecc55d2106c54476b1b16f6"}, + {file = "mypy-2.1.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:d8161b6ff4392410023224f0969d17db93e1e154bc3e4ba62598e720723ae211"}, + {file = "mypy-2.1.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:bf03e12003084a67395184d3eb8cbd6a489dc3655b5664b28c210a9e2403ab0b"}, + {file = "mypy-2.1.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:20509760fd791c51579d573153407d226385ec1f8bcce55d730b354f3336bc22"}, + {file = "mypy-2.1.0-cp312-cp312-win_amd64.whl", hash = "sha256:6753d0c1fdd6b1a23b9e4f283ce80b2153b724adcb2653b20b85a8a28ac6436b"}, + {file = "mypy-2.1.0-cp312-cp312-win_arm64.whl", hash = "sha256:98ebb6589bb3b6d0c6f0c459d53ca55b8091fbc13d277c4041c885392e8195e8"}, + {file = "mypy-2.1.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:35aac3bb114e03888f535d5eb51b8bafbb3266586b599da1940f9b1be3ec5bd5"}, + {file = "mypy-2.1.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:8de55a8c861f2a49331f807be98d90caeceeef520bde13d43a160207f8af613e"}, + {file = "mypy-2.1.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:5fdf2941a07434af755837d9880f7d7d25f1dacb1af9dcd4b9b66f2220a3024e"}, + {file = "mypy-2.1.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:e195b817c13f02352a9c124301f9f30f078405444679b6753c1b96b6eed37285"}, + {file = "mypy-2.1.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:5431d42af987ebd92ba2f71d45c85ed41d8e6ca9f5fd209a69f68f707d2469e5"}, + {file = "mypy-2.1.0-cp313-cp313-win_amd64.whl", hash = "sha256:767fe8c66dc3e01e19e1737d4c38ebefead16125e1b8e58ad421903b376f5c65"}, + {file = "mypy-2.1.0-cp313-cp313-win_arm64.whl", hash = "sha256:ecfe70d43775ab99562ab128ce49854a362044c9f894961f68f898c23cb7429d"}, + {file = "mypy-2.1.0-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:7354c5a7f69d9345c3d6e69921d57088eea3ddeeb6b20d34c1b3855b02c36ec2"}, + {file = "mypy-2.1.0-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:49890d4f76ac9e06ec117f9e09f3174da70a620a0c300953d8595c926e80947f"}, + {file = "mypy-2.1.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:761be68e023ef5d94678772396a8af1220030f80837a3afd8d0aef3b419666f4"}, + {file = "mypy-2.1.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:c90345fc182dc363b891350457ec69c35140858538f38b4540845afcc32b1aef"}, + {file = "mypy-2.1.0-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:b84802e7b5a6daf1f5e15bc9fcd7ddae77be13981ffab037f1c67bb84d67d135"}, + {file = "mypy-2.1.0-cp314-cp314-win_amd64.whl", hash = "sha256:022c771234936ceac541ebaf836fe9e2abeb3f5e09aff21588fe543ff006fe21"}, + {file = "mypy-2.1.0-cp314-cp314-win_arm64.whl", hash = "sha256:498207db725cec88829a6a5c2fc771205fd043719ef98bc49aba8fb9fc4e6d57"}, + {file = "mypy-2.1.0-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:7d5e5cad0efeba72b93cd17490cc0d69c5ac9ca132994fe3fb0314808aeeb83e"}, + {file = "mypy-2.1.0-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:ff715050c127d724fd260a2e666e7747fdd83511c0c47d449d98238970aef780"}, + {file = "mypy-2.1.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:82208da9e09414d520e912d3e462d454854bed0810b71540bb016dcbca7308fd"}, + {file = "mypy-2.1.0-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:e79ebc1b904b84f0310dff7469655a9c36c7a68bddb37bdd42b67a332df61d08"}, + {file = "mypy-2.1.0-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:e583edc957cfb0deb142079162ae826f58449b116c1d442f2d91c69d9fced081"}, + {file = "mypy-2.1.0-cp314-cp314t-win_amd64.whl", hash = "sha256:b33b6cd332695bba180d55e717a79d3038e479a2c49cc5eb3d53603409b9a5d7"}, + {file = "mypy-2.1.0-cp314-cp314t-win_arm64.whl", hash = "sha256:4f910fe825376a7b66ef7ca8c98e5a149e8cd64c19ae71d84047a74ee060d4e6"}, + {file = "mypy-2.1.0-py3-none-any.whl", hash = "sha256:a663814603a5c563fb87a4f96fb473eeb30d1f5a4885afcf44f9db000a366289"}, + {file = "mypy-2.1.0.tar.gz", hash = "sha256:81e76ad12c2d804512e9b13240d1588316531bfba07558286078bfbce9613633"}, ] [[package]] name = "mypy-extensions" -version = "1.0.0" -requires_python = ">=3.5" +version = "1.1.0" +requires_python = ">=3.8" summary = "Type system extensions for programs checked with the mypy type checker." groups = ["dev"] files = [ - {file = "mypy_extensions-1.0.0-py3-none-any.whl", hash = "sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d"}, - {file = "mypy_extensions-1.0.0.tar.gz", hash = "sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782"}, + {file = "mypy_extensions-1.1.0-py3-none-any.whl", hash = "sha256:1be4cccdb0f2482337c4743e60421de3a356cd97508abadd57d47403e94f5505"}, + {file = "mypy_extensions-1.1.0.tar.gz", hash = "sha256:52e68efc3284861e772bbcd66823fde5ae21fd2fdb51c62a211403730b916558"}, ] [[package]] name = "packaging" -version = "23.2" -requires_python = ">=3.7" +version = "26.2" +requires_python = ">=3.8" summary = "Core utilities for Python packages" groups = ["dev"] files = [ - {file = "packaging-23.2-py3-none-any.whl", hash = "sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7"}, - {file = "packaging-23.2.tar.gz", hash = "sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5"}, + {file = "packaging-26.2-py3-none-any.whl", hash = "sha256:5fc45236b9446107ff2415ce77c807cee2862cb6fac22b8a73826d0693b0980e"}, + {file = "packaging-26.2.tar.gz", hash = "sha256:ff452ff5a3e828ce110190feff1178bb1f2ea2281fa2075aadb987c2fb221661"}, ] [[package]] -name = "pluggy" -version = "1.4.0" -requires_python = ">=3.8" -summary = "plugin and hook calling mechanisms for python" +name = "pathspec" +version = "1.1.1" +requires_python = ">=3.9" +summary = "Utility library for gitignore style pattern matching of file paths." groups = ["dev"] files = [ - {file = "pluggy-1.4.0-py3-none-any.whl", hash = "sha256:7db9f7b503d67d1c5b95f59773ebb58a8c1c288129a88665838012cfb07b8981"}, - {file = "pluggy-1.4.0.tar.gz", hash = "sha256:8c85c2876142a764e5b7548e7d9a0e0ddb46f5185161049a79b7e974454223be"}, + {file = "pathspec-1.1.1-py3-none-any.whl", hash = "sha256:a00ce642f577bf7f473932318056212bc4f8bfdf53128c78bbd5af0b9b20b189"}, + {file = "pathspec-1.1.1.tar.gz", hash = "sha256:17db5ecd524104a120e173814c90367a96a98d07c45b2e10c2f3919fff91bf5a"}, ] [[package]] -name = "pytest" -version = "8.1.1" -requires_python = ">=3.8" -summary = "pytest: simple powerful testing with Python" +name = "pluggy" +version = "1.6.0" +requires_python = ">=3.9" +summary = "plugin and hook calling mechanisms for python" groups = ["dev"] -dependencies = [ - "colorama; sys_platform == \"win32\"", - "exceptiongroup>=1.0.0rc8; python_version < \"3.11\"", - "iniconfig", - "packaging", - "pluggy<2.0,>=1.4", - "tomli>=1; python_version < \"3.11\"", -] files = [ - {file = "pytest-8.1.1-py3-none-any.whl", hash = "sha256:2a8386cfc11fa9d2c50ee7b2a57e7d898ef90470a7a34c4b949ff59662bb78b7"}, - {file = "pytest-8.1.1.tar.gz", hash = "sha256:ac978141a75948948817d360297b7aae0fcb9d6ff6bc9ec6d514b85d5a65c044"}, + {file = "pluggy-1.6.0-py3-none-any.whl", hash = "sha256:e920276dd6813095e9377c0bc5566d94c932c33b27a3e3945d8389c374dd4746"}, + {file = "pluggy-1.6.0.tar.gz", hash = "sha256:7dcc130b76258d33b90f61b658791dede3486c3e6bfb003ee5c9bfb396dd22f3"}, ] [[package]] -name = "pytest-asyncio" -version = "0.23.6" -requires_python = ">=3.8" -summary = "Pytest support for asyncio" +name = "pygments" +version = "2.20.0" +requires_python = ">=3.9" +summary = "Pygments is a syntax highlighting package written in Python." groups = ["dev"] -dependencies = [ - "pytest<9,>=7.0.0", -] files = [ - {file = "pytest-asyncio-0.23.6.tar.gz", hash = "sha256:ffe523a89c1c222598c76856e76852b787504ddb72dd5d9b6617ffa8aa2cde5f"}, - {file = "pytest_asyncio-0.23.6-py3-none-any.whl", hash = "sha256:68516fdd1018ac57b846c9846b954f0393b26f094764a28c955eabb0536a4e8a"}, + {file = "pygments-2.20.0-py3-none-any.whl", hash = "sha256:81a9e26dd42fd28a23a2d169d86d7ac03b46e2f8b59ed4698fb4785f946d0176"}, + {file = "pygments-2.20.0.tar.gz", hash = "sha256:6757cd03768053ff99f3039c1a36d6c0aa0b263438fcab17520b30a303a82b5f"}, ] [[package]] -name = "python-dateutil" -version = "2.9.0.post0" -requires_python = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7" -summary = "Extensions to the standard Python datetime module" -groups = ["default"] +name = "pytest" +version = "9.1.1" +requires_python = ">=3.10" +summary = "pytest: simple powerful testing with Python" +groups = ["dev"] dependencies = [ - "six>=1.5", -] -files = [ - {file = "python-dateutil-2.9.0.post0.tar.gz", hash = "sha256:37dd54208da7e1cd875388217d5e00ebd4179249f90fb72437e91a35459a0ad3"}, - {file = "python_dateutil-2.9.0.post0-py2.py3-none-any.whl", hash = "sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427"}, + "colorama>=0.4; sys_platform == \"win32\"", + "exceptiongroup>=1; python_version < \"3.11\"", + "iniconfig>=1.0.1", + "packaging>=22", + "pluggy<2,>=1.5", + "pygments>=2.7.2", + "tomli>=1; python_version < \"3.11\"", ] - -[[package]] -name = "six" -version = "1.16.0" -requires_python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" -summary = "Python 2 and 3 compatibility utilities" -groups = ["default"] files = [ - {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"}, - {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"}, + {file = "pytest-9.1.1-py3-none-any.whl", hash = "sha256:37a86b45efb9a47a61a36449063e8e18d0cab3161329fc099eb21783169c4f0c"}, + {file = "pytest-9.1.1.tar.gz", hash = "sha256:1088fbde8f2b49d95a549a195707afa7a76a3ce9bcadc26b6d71f0ffda5fe313"}, ] [[package]] -name = "sniffio" -version = "1.3.0" -requires_python = ">=3.7" -summary = "Sniff out which async library your code is running under" -groups = ["default"] -files = [ - {file = "sniffio-1.3.0-py3-none-any.whl", hash = "sha256:eecefdce1e5bbfb7ad2eeaabf7c1eeb404d7757c379bd1f7e5cce9d8bf425384"}, - {file = "sniffio-1.3.0.tar.gz", hash = "sha256:e60305c5e5d314f5389259b7f22aaa33d8f7dee49763119234af3755c55b9101"}, -] - -[[package]] -name = "tomli" -version = "2.0.1" -requires_python = ">=3.7" -summary = "A lil' TOML parser" +name = "pytest-asyncio" +version = "1.4.0" +requires_python = ">=3.10" +summary = "Pytest support for asyncio" groups = ["dev"] -marker = "python_version < \"3.11\"" +dependencies = [ + "backports-asyncio-runner<2,>=1.1; python_version < \"3.11\"", + "pytest<10,>=8.4", + "typing-extensions>=4.12; python_version < \"3.13\"", +] files = [ - {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, - {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, + {file = "pytest_asyncio-1.4.0-py3-none-any.whl", hash = "sha256:933ca923a23075a87fb7070c0ec272a6848489824d887c85c812670932835aa1"}, + {file = "pytest_asyncio-1.4.0.tar.gz", hash = "sha256:c6c0d2259945122819f171a32ecea2c349ead889ee28176caaf492143424be42"}, ] [[package]] name = "typing-extensions" -version = "4.9.0" -requires_python = ">=3.8" -summary = "Backported and Experimental Type Hints for Python 3.8+" +version = "4.15.0" +requires_python = ">=3.9" +summary = "Backported and Experimental Type Hints for Python 3.9+" groups = ["default", "dev"] files = [ - {file = "typing_extensions-4.9.0-py3-none-any.whl", hash = "sha256:af72aea155e91adfc61c3ae9e0e342dbc0cba726d6cba4b6c72c1f34e47291cd"}, - {file = "typing_extensions-4.9.0.tar.gz", hash = "sha256:23478f88c37f27d76ac8aee6c905017a143b0b1b886c3c9f66bc2fd94f9f5783"}, + {file = "typing_extensions-4.15.0-py3-none-any.whl", hash = "sha256:f0fa19c6845758ab08074a0cfa8b7aecb71c999ca73d62883bc25cc018c4e548"}, + {file = "typing_extensions-4.15.0.tar.gz", hash = "sha256:0cea48d173cc12fa28ecabc3b837ea3cf6f38c6d1136f85cbaaf598984861466"}, ] diff --git a/integration-tests/pdm.minimal.lock b/integration-tests/pdm.minimal.lock new file mode 100644 index 000000000..52a719b9f --- /dev/null +++ b/integration-tests/pdm.minimal.lock @@ -0,0 +1,275 @@ +# This file is @generated by PDM. +# It is not intended for manual editing. + +[metadata] +groups = ["default", "dev"] +strategy = ["direct_minimal_versions", "inherit_metadata"] +lock_version = "4.5.0" +content_hash = "sha256:eaf8c822d09eaa6cb6b1cb2ac7deb1746c24e404459a1a79f5c35df71b8883c7" + +[[metadata.targets]] +requires_python = "~=3.11" + +[[package]] +name = "anyio" +version = "4.13.0" +requires_python = ">=3.10" +summary = "High-level concurrency and networking framework on top of asyncio or Trio" +groups = ["default"] +dependencies = [ + "exceptiongroup>=1.0.2; python_version < \"3.11\"", + "idna>=2.8", + "typing-extensions>=4.5; python_version < \"3.13\"", +] +files = [ + {file = "anyio-4.13.0-py3-none-any.whl", hash = "sha256:08b310f9e24a9594186fd75b4f73f4a4152069e3853f1ed8bfbf58369f4ad708"}, + {file = "anyio-4.13.0.tar.gz", hash = "sha256:334b70e641fd2221c1505b3890c69882fe4a2df910cba14d97019b90b24439dc"}, +] + +[[package]] +name = "attrs" +version = "22.2.0" +requires_python = ">=3.6" +summary = "Classes Without Boilerplate" +groups = ["default"] +files = [ + {file = "attrs-22.2.0-py3-none-any.whl", hash = "sha256:29e95c7f6778868dbd49170f98f8818f78f3dc5e0e37c0b1f474e3561b240836"}, + {file = "attrs-22.2.0.tar.gz", hash = "sha256:c9227bfc2f01993c03f68db37d1d15c9690188323c067c641f1a35ca58185f99"}, +] + +[[package]] +name = "certifi" +version = "2026.5.20" +requires_python = ">=3.7" +summary = "Python package for providing Mozilla's CA Bundle." +groups = ["default"] +files = [ + {file = "certifi-2026.5.20-py3-none-any.whl", hash = "sha256:3c52e209ba0a4ad7aebe60436a4ab349c39e1e602e8c134221e546902ad25897"}, + {file = "certifi-2026.5.20.tar.gz", hash = "sha256:69dea482ab64caa7b9f6aba1c6bf48bb6a5448d1c0f1b17ab42ad8c763a5344d"}, +] + +[[package]] +name = "colorama" +version = "0.4.6" +requires_python = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" +summary = "Cross-platform colored terminal text." +groups = ["dev"] +marker = "sys_platform == \"win32\"" +files = [ + {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, + {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, +] + +[[package]] +name = "h11" +version = "0.14.0" +requires_python = ">=3.7" +summary = "A pure-Python, bring-your-own-I/O implementation of HTTP/1.1" +groups = ["default"] +dependencies = [ + "typing-extensions; python_version < \"3.8\"", +] +files = [ + {file = "h11-0.14.0-py3-none-any.whl", hash = "sha256:e3fe4ac4b851c468cc8363d500db52c2ead036020723024a109d37346efaa761"}, + {file = "h11-0.14.0.tar.gz", hash = "sha256:8f19fbbe99e72420ff35c00b27a34cb9937e902a8b810e2c88300c6f0a3b699d"}, +] + +[[package]] +name = "httpcore" +version = "0.16.3" +requires_python = ">=3.7" +summary = "A minimal low-level HTTP client." +groups = ["default"] +dependencies = [ + "anyio<5.0,>=3.0", + "certifi", + "h11<0.15,>=0.13", + "sniffio==1.*", +] +files = [ + {file = "httpcore-0.16.3-py3-none-any.whl", hash = "sha256:da1fb708784a938aa084bde4feb8317056c55037247c787bd7e19eb2c2949dc0"}, + {file = "httpcore-0.16.3.tar.gz", hash = "sha256:c5d6f04e2fc530f39e0c077e6a30caa53f1451096120f1f38b954afd0b17c0cb"}, +] + +[[package]] +name = "httpx" +version = "0.23.1" +requires_python = ">=3.7" +summary = "The next generation HTTP client." +groups = ["default"] +dependencies = [ + "certifi", + "httpcore<0.17.0,>=0.15.0", + "rfc3986[idna2008]<2,>=1.3", + "sniffio", +] +files = [ + {file = "httpx-0.23.1-py3-none-any.whl", hash = "sha256:0b9b1f0ee18b9978d637b0776bfd7f54e2ca278e063e3586d8f01cda89e042a8"}, + {file = "httpx-0.23.1.tar.gz", hash = "sha256:202ae15319be24efe9a8bd4ed4360e68fde7b38bcc2ce87088d416f026667d19"}, +] + +[[package]] +name = "idna" +version = "3.17" +requires_python = ">=3.9" +summary = "Internationalized Domain Names in Applications (IDNA)" +groups = ["default"] +files = [ + {file = "idna-3.17-py3-none-any.whl", hash = "sha256:466e48829084efe2548012b855df21540b96f2e20e51bd124c851536556a592c"}, + {file = "idna-3.17.tar.gz", hash = "sha256:5eb0cb53bc467c12eadcf6de83163ad8527cec9416f44b9b61b19caedad2b87f"}, +] + +[[package]] +name = "iniconfig" +version = "2.3.0" +requires_python = ">=3.10" +summary = "brain-dead simple config-ini parsing" +groups = ["dev"] +files = [ + {file = "iniconfig-2.3.0-py3-none-any.whl", hash = "sha256:f631c04d2c48c52b84d0d0549c99ff3859c98df65b3101406327ecc7d53fbf12"}, + {file = "iniconfig-2.3.0.tar.gz", hash = "sha256:c76315c77db068650d49c5b56314774a7804df16fee4402c1f19d6d15d8c4730"}, +] + +[[package]] +name = "mypy" +version = "1.13.0" +requires_python = ">=3.8" +summary = "Optional static typing for Python" +groups = ["dev"] +dependencies = [ + "mypy-extensions>=1.0.0", + "tomli>=1.1.0; python_version < \"3.11\"", + "typing-extensions>=4.6.0", +] +files = [ + {file = "mypy-1.13.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:581665e6f3a8a9078f28d5502f4c334c0c8d802ef55ea0e7276a6e409bc0d82d"}, + {file = "mypy-1.13.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:3ddb5b9bf82e05cc9a627e84707b528e5c7caaa1c55c69e175abb15a761cec2d"}, + {file = "mypy-1.13.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:20c7ee0bc0d5a9595c46f38beb04201f2620065a93755704e141fcac9f59db2b"}, + {file = "mypy-1.13.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:3790ded76f0b34bc9c8ba4def8f919dd6a46db0f5a6610fb994fe8efdd447f73"}, + {file = "mypy-1.13.0-cp311-cp311-win_amd64.whl", hash = "sha256:51f869f4b6b538229c1d1bcc1dd7d119817206e2bc54e8e374b3dfa202defcca"}, + {file = "mypy-1.13.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:5c7051a3461ae84dfb5dd15eff5094640c61c5f22257c8b766794e6dd85e72d5"}, + {file = "mypy-1.13.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:39bb21c69a5d6342f4ce526e4584bc5c197fd20a60d14a8624d8743fffb9472e"}, + {file = "mypy-1.13.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:164f28cb9d6367439031f4c81e84d3ccaa1e19232d9d05d37cb0bd880d3f93c2"}, + {file = "mypy-1.13.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:a4c1bfcdbce96ff5d96fc9b08e3831acb30dc44ab02671eca5953eadad07d6d0"}, + {file = "mypy-1.13.0-cp312-cp312-win_amd64.whl", hash = "sha256:a0affb3a79a256b4183ba09811e3577c5163ed06685e4d4b46429a271ba174d2"}, + {file = "mypy-1.13.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:a7b44178c9760ce1a43f544e595d35ed61ac2c3de306599fa59b38a6048e1aa7"}, + {file = "mypy-1.13.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:5d5092efb8516d08440e36626f0153b5006d4088c1d663d88bf79625af3d1d62"}, + {file = "mypy-1.13.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:de2904956dac40ced10931ac967ae63c5089bd498542194b436eb097a9f77bc8"}, + {file = "mypy-1.13.0-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:7bfd8836970d33c2105562650656b6846149374dc8ed77d98424b40b09340ba7"}, + {file = "mypy-1.13.0-cp313-cp313-win_amd64.whl", hash = "sha256:9f73dba9ec77acb86457a8fc04b5239822df0c14a082564737833d2963677dbc"}, + {file = "mypy-1.13.0-py3-none-any.whl", hash = "sha256:9c250883f9fd81d212e0952c92dbfcc96fc237f4b7c92f56ac81fd48460b3e5a"}, + {file = "mypy-1.13.0.tar.gz", hash = "sha256:0291a61b6fbf3e6673e3405cfcc0e7650bebc7939659fdca2702958038bd835e"}, +] + +[[package]] +name = "mypy-extensions" +version = "1.1.0" +requires_python = ">=3.8" +summary = "Type system extensions for programs checked with the mypy type checker." +groups = ["dev"] +files = [ + {file = "mypy_extensions-1.1.0-py3-none-any.whl", hash = "sha256:1be4cccdb0f2482337c4743e60421de3a356cd97508abadd57d47403e94f5505"}, + {file = "mypy_extensions-1.1.0.tar.gz", hash = "sha256:52e68efc3284861e772bbcd66823fde5ae21fd2fdb51c62a211403730b916558"}, +] + +[[package]] +name = "packaging" +version = "26.2" +requires_python = ">=3.8" +summary = "Core utilities for Python packages" +groups = ["dev"] +files = [ + {file = "packaging-26.2-py3-none-any.whl", hash = "sha256:5fc45236b9446107ff2415ce77c807cee2862cb6fac22b8a73826d0693b0980e"}, + {file = "packaging-26.2.tar.gz", hash = "sha256:ff452ff5a3e828ce110190feff1178bb1f2ea2281fa2075aadb987c2fb221661"}, +] + +[[package]] +name = "pluggy" +version = "1.6.0" +requires_python = ">=3.9" +summary = "plugin and hook calling mechanisms for python" +groups = ["dev"] +files = [ + {file = "pluggy-1.6.0-py3-none-any.whl", hash = "sha256:e920276dd6813095e9377c0bc5566d94c932c33b27a3e3945d8389c374dd4746"}, + {file = "pluggy-1.6.0.tar.gz", hash = "sha256:7dcc130b76258d33b90f61b658791dede3486c3e6bfb003ee5c9bfb396dd22f3"}, +] + +[[package]] +name = "pytest" +version = "8.0.1" +requires_python = ">=3.8" +summary = "pytest: simple powerful testing with Python" +groups = ["dev"] +dependencies = [ + "colorama; sys_platform == \"win32\"", + "exceptiongroup>=1.0.0rc8; python_version < \"3.11\"", + "iniconfig", + "packaging", + "pluggy<2.0,>=1.3.0", + "tomli>=1.0.0; python_version < \"3.11\"", +] +files = [ + {file = "pytest-8.0.1-py3-none-any.whl", hash = "sha256:3e4f16fe1c0a9dc9d9389161c127c3edc5d810c38d6793042fb81d9f48a59fca"}, + {file = "pytest-8.0.1.tar.gz", hash = "sha256:267f6563751877d772019b13aacbe4e860d73fe8f651f28112e9ac37de7513ae"}, +] + +[[package]] +name = "pytest-asyncio" +version = "0.23.5" +requires_python = ">=3.8" +summary = "Pytest support for asyncio" +groups = ["dev"] +dependencies = [ + "pytest<9,>=7.0.0", +] +files = [ + {file = "pytest-asyncio-0.23.5.tar.gz", hash = "sha256:3a048872a9c4ba14c3e90cc1aa20cbc2def7d01c7c8db3777ec281ba9c057675"}, + {file = "pytest_asyncio-0.23.5-py3-none-any.whl", hash = "sha256:4e7093259ba018d58ede7d5315131d21923a60f8a6e9ee266ce1589685c89eac"}, +] + +[[package]] +name = "rfc3986" +version = "1.5.0" +summary = "Validating URI References per RFC 3986" +groups = ["default"] +files = [ + {file = "rfc3986-1.5.0-py2.py3-none-any.whl", hash = "sha256:a86d6e1f5b1dc238b218b012df0aa79409667bb209e58da56d0b94704e712a97"}, + {file = "rfc3986-1.5.0.tar.gz", hash = "sha256:270aaf10d87d0d4e095063c65bf3ddbc6ee3d0b226328ce21e036f946e421835"}, +] + +[[package]] +name = "rfc3986" +version = "1.5.0" +extras = ["idna2008"] +summary = "Validating URI References per RFC 3986" +groups = ["default"] +dependencies = [ + "idna", + "rfc3986==1.5.0", +] +files = [ + {file = "rfc3986-1.5.0-py2.py3-none-any.whl", hash = "sha256:a86d6e1f5b1dc238b218b012df0aa79409667bb209e58da56d0b94704e712a97"}, + {file = "rfc3986-1.5.0.tar.gz", hash = "sha256:270aaf10d87d0d4e095063c65bf3ddbc6ee3d0b226328ce21e036f946e421835"}, +] + +[[package]] +name = "sniffio" +version = "1.3.1" +requires_python = ">=3.7" +summary = "Sniff out which async library your code is running under" +groups = ["default"] +files = [ + {file = "sniffio-1.3.1-py3-none-any.whl", hash = "sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2"}, + {file = "sniffio-1.3.1.tar.gz", hash = "sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc"}, +] + +[[package]] +name = "typing-extensions" +version = "4.15.0" +requires_python = ">=3.9" +summary = "Backported and Experimental Type Hints for Python 3.9+" +groups = ["default", "dev"] +files = [ + {file = "typing_extensions-4.15.0-py3-none-any.whl", hash = "sha256:f0fa19c6845758ab08074a0cfa8b7aecb71c999ca73d62883bc25cc018c4e548"}, + {file = "typing_extensions-4.15.0.tar.gz", hash = "sha256:0cea48d173cc12fa28ecabc3b837ea3cf6f38c6d1136f85cbaaf598984861466"}, +] diff --git a/integration-tests/pyproject.toml b/integration-tests/pyproject.toml index 67b0d7f52..0811b4b42 100644 --- a/integration-tests/pyproject.toml +++ b/integration-tests/pyproject.toml @@ -1,32 +1,34 @@ [project] name = "integration-tests" -version = "0.0.1" +version = "0.1.0" description = "A client library for accessing OpenAPI Test Server" authors = [] readme = "README.md" +requires-python = ">=3.11,<4.0" dependencies = [ - "httpx>=0.20.0,<0.28.0", - "attrs>=21.3.0", - "python-dateutil>=2.8.0", + "httpx>=0.23.1,<0.29.0", + "attrs>=22.2.0", ] -requires-python = ">=3.8,<4.0" [tool.pdm] distribution = true [tool.pdm.dev-dependencies] dev = [ - "pytest", - "mypy", + "pytest>8", + "mypy>=1.13", "pytest-asyncio>=0.23.5", ] [build-system] requires = ["pdm-backend"] build-backend = "pdm.backend" - + [tool.ruff] line-length = 120 [tool.ruff.lint] select = ["F", "I"] + +[tool.mypy] +# Just to get mypy to _not_ look at the parent directory's config diff --git a/integration-tests/tests/test_api/test_body/test_post_body_multipart.py b/integration-tests/tests/test_api/test_body/test_post_body_multipart.py index 54498ebc5..fbb87a1d0 100644 --- a/integration-tests/tests/test_api/test_body/test_post_body_multipart.py +++ b/integration-tests/tests/test_api/test_body/test_post_body_multipart.py @@ -1,3 +1,4 @@ +from datetime import UTC, datetime, timedelta from io import BytesIO from typing import Any @@ -5,49 +6,67 @@ from integration_tests.api.body import post_body_multipart from integration_tests.client import Client +from integration_tests.models import AnObject, PublicError from integration_tests.models.post_body_multipart_body import PostBodyMultipartBody from integration_tests.models.post_body_multipart_response_200 import PostBodyMultipartResponse200 -from integration_tests.types import File +from integration_tests.types import File, Response + +body = PostBodyMultipartBody( + a_string="a test string", + description="super descriptive thing", + files=[ + File( + payload=BytesIO(b"some file content"), + file_name="cool_stuff.txt", + mime_type="application/openapi-python-client", + ), + File( + payload=BytesIO(b"more file content"), + file_name=None, + mime_type=None, + ), + ], + times=[datetime.now(UTC) - timedelta(days=1), datetime.now(UTC)], + objects=[ + AnObject( + an_int=1, + a_float=2.3, + ), + AnObject( + an_int=4, + a_float=5.6, + ), + ], +) -def test(client: Client) -> None: - a_string = "a test string" - payload = b"some file content" - file_name = "cool_stuff.txt" - mime_type = "application/openapi-python-client" - description = "super descriptive thing" +def check_response(response: Response[PostBodyMultipartResponse200 | PublicError]) -> None: + content = response.parsed + if not isinstance(content, PostBodyMultipartResponse200): + raise AssertionError(f"Received status {response.status_code} from test server with payload: {content!r}") + + assert content.a_string == body.a_string + assert content.description == body.description + assert content.times == body.times + assert content.objects == body.objects + assert len(content.files) == len(body.files) + for i, file in enumerate(content.files): + body.files[i].payload.seek(0) + assert file.data == body.files[i].payload.read().decode() + assert file.name == body.files[i].file_name + assert file.content_type == body.files[i].mime_type + +def test(client: Client) -> None: response = post_body_multipart.sync_detailed( client=client, - body=PostBodyMultipartBody( - a_string=a_string, - file=File( - payload=BytesIO(payload), - file_name=file_name, - mime_type=mime_type, - ), - description=description, - ), + body=body, ) - content = response.parsed - if not isinstance(content, PostBodyMultipartResponse200): - raise AssertionError(f"Received status {response.status_code} from test server with payload: {content!r}") - - assert content.a_string == a_string - assert content.file_name == file_name - assert content.file_content_type == mime_type - assert content.file_data.encode() == payload - assert content.description == description + check_response(response) def test_custom_hooks() -> None: - a_string = "a test string" - payload = b"some file content" - file_name = "cool_stuff.txt" - mime_type = "application/openapi-python-client" - description = "super descriptive thing" - request_hook_called = False response_hook_called = False @@ -65,15 +84,7 @@ def log_response(*_: Any, **__: Any) -> None: post_body_multipart.sync_detailed( client=client, - body=PostBodyMultipartBody( - a_string=a_string, - file=File( - payload=BytesIO(payload), - file_name=file_name, - mime_type=mime_type, - ), - description=description, - ), + body=body, ) assert request_hook_called @@ -81,149 +92,51 @@ def log_response(*_: Any, **__: Any) -> None: def test_context_manager(client: Client) -> None: - a_string = "a test string" - payload = b"some file content" - file_name = "cool_stuff.txt" - mime_type = "application/openapi-python-client" - description = "super descriptive thing" - with client as client: post_body_multipart.sync_detailed( client=client, - body=PostBodyMultipartBody( - a_string=a_string, - file=File( - payload=BytesIO(payload), - file_name=file_name, - mime_type=mime_type, - ), - description=description, - ), + body=body, ) response = post_body_multipart.sync_detailed( client=client, - body=PostBodyMultipartBody( - a_string=a_string, - file=File( - payload=BytesIO(payload), - file_name=file_name, - mime_type=mime_type, - ), - description=description, - ), + body=body, ) with pytest.raises(RuntimeError): post_body_multipart.sync_detailed( client=client, - body=PostBodyMultipartBody( - a_string=a_string, - file=File( - payload=BytesIO(payload), - file_name=file_name, - mime_type=mime_type, - ), - description=description, - ), + body=body, ) - content = response.parsed - if not isinstance(content, PostBodyMultipartResponse200): - raise AssertionError(f"Received status {response.status_code} from test server with payload: {content!r}") - - assert content.a_string == a_string - assert content.file_name == file_name - assert content.file_content_type == mime_type - assert content.file_data.encode() == payload - assert content.description == description + check_response(response) @pytest.mark.asyncio async def test_async(client: Client) -> None: - a_string = "a test string" - payload = b"some file content" - file_name = "cool_stuff.txt" - mime_type = "application/openapi-python-client" - description = "super descriptive thing" - response = await post_body_multipart.asyncio_detailed( client=client, - body=PostBodyMultipartBody( - a_string=a_string, - file=File( - payload=BytesIO(payload), - file_name=file_name, - mime_type=mime_type, - ), - description=description, - ), + body=body, ) - content = response.parsed - if not isinstance(content, PostBodyMultipartResponse200): - raise AssertionError(f"Received status {response.status_code} from test server with payload: {content!r}") - - assert content.a_string == a_string - assert content.file_name == file_name - assert content.file_content_type == mime_type - assert content.file_data.encode() == payload - assert content.description == description + check_response(response) @pytest.mark.asyncio async def test_async_context_manager(client: Client) -> None: - a_string = "a test string" - payload = b"some file content" - file_name = "cool_stuff.txt" - mime_type = "application/openapi-python-client" - description = "super descriptive thing" - async with client as client: await post_body_multipart.asyncio_detailed( client=client, - body=PostBodyMultipartBody( - a_string=a_string, - file=File( - payload=BytesIO(payload), - file_name=file_name, - mime_type=mime_type, - ), - description=description, - ), + body=body, ) response = await post_body_multipart.asyncio_detailed( client=client, - body=PostBodyMultipartBody( - a_string=a_string, - file=File( - payload=BytesIO(payload), - file_name=file_name, - mime_type=mime_type, - ), - description=description, - ), + body=body, ) with pytest.raises(RuntimeError): await post_body_multipart.asyncio_detailed( client=client, - body=PostBodyMultipartBody( - a_string=a_string, - file=File( - payload=BytesIO(payload), - file_name=file_name, - mime_type=mime_type, - ), - description=description, - ), + body=body, ) - content = response.parsed - if not isinstance(content, PostBodyMultipartResponse200): - raise AssertionError(f"Received status {response.status_code} from test server with payload: {content!r}") - - assert content.a_string == a_string - assert content.file_name == file_name - assert content.file_content_type == mime_type - assert content.file_data.encode() == payload - assert content.description == description + check_response(response) diff --git a/knope.toml b/knope.toml index 3b5317975..53b453bf4 100644 --- a/knope.toml +++ b/knope.toml @@ -1,50 +1,17 @@ [package] versioned_files = ["pyproject.toml"] changelog = "CHANGELOG.md" - -[[workflows]] -name = "prepare-release" - -[[workflows.steps]] -type = "Command" -shell = true -command = "git switch -c release" - -[[workflows.steps]] -type = "PrepareRelease" - -[[workflows.steps]] -type = "Command" -shell = true -command = "git commit -m \"chore: prepare release $version\" && git push --force --set-upstream origin release" - -[workflows.steps.variables] -"$version" = "Version" - -[[workflows.steps]] -type = "CreatePullRequest" -base = "main" - -[workflows.steps.title] -template = "chore: prepare release $version" -variables = { "$version" = "Version" } - -[workflows.steps.body] -template = "This PR was created by Knope. Merging it will create a new release\n\n$changelog" -variables = { "$changelog" = "ChangelogEntry" } - -[[workflows]] -name = "release" - -[[workflows.steps]] -type = "Release" - -[[workflows]] -name = "document-change" - -[[workflows.steps]] -type = "CreateChangeFile" +extra_changelog_sections = [ + { types = ["security"], name = "🚨Security" }, + { types = ["major"], name = "❗️Breaking ❗" }, + { types = ["minor"], name = "🚀 Features" }, + { types = ["patch"], name = "🐛 Fixes" }, + { types = ["note"], name = "📝Notes" } +] [github] owner = "openapi-generators" repo = "openapi-python-client" + +[bot.releases] +enabled = true diff --git a/openapi_python_client/__init__.py b/openapi_python_client/__init__.py index 23d972eac..c3b766338 100644 --- a/openapi_python_client/__init__.py +++ b/openapi_python_client/__init__.py @@ -4,29 +4,37 @@ import mimetypes import shutil import subprocess +from collections.abc import Callable, Sequence from importlib.metadata import version from pathlib import Path from subprocess import CalledProcessError -from typing import Any, Dict, List, Optional, Sequence, Union +from typing import Any import httpcore import httpx -import yaml from jinja2 import BaseLoader, ChoiceLoader, Environment, FileSystemLoader, PackageLoader +from ruamel.yaml import YAML +from ruamel.yaml.error import YAMLError -from openapi_python_client import utils +from openapi_python_client import strings from .config import Config, MetaType from .parser import GeneratorData, import_string_from_class from .parser.errors import ErrorLevel, GeneratorError +from .parser.properties import LiteralEnumProperty __version__ = version(__package__) +from .schema.untrusted_string import UntrustedString -TEMPLATE_FILTERS = { - "snakecase": utils.snake_case, - "kebabcase": utils.kebab_case, - "pascalcase": utils.pascal_case, +TEMPLATE_FILTERS: dict[str, Callable[..., object]] = { + "snakecase": strings.snake_case, + "kebabcase": strings.kebab_case, + "pascalcase": strings.pascal_case, + "safe_for_docstring": strings.safe_for_docstring, + "in_double_quote_literal": strings.in_double_quote_literal, + "in_f_string_literal": strings.in_f_string_literal, + "as_unembedded_code": strings.PythonCode.as_unembedded_code, "any": any, } @@ -39,7 +47,7 @@ def __init__( *, openapi: GeneratorData, config: Config, - custom_template_path: Optional[Path] = None, + custom_template_path: Path | None = None, ) -> None: self.openapi: GeneratorData = openapi self.config = config @@ -63,23 +71,37 @@ def __init__( keep_trailing_newline=True, ) - self.project_name: str = config.project_name_override or f"{utils.kebab_case(openapi.title).lower()}-client" - self.project_dir: Path = Path.cwd() - if config.meta_type != MetaType.NONE: - self.project_dir /= self.project_name - + self.project_name: str = config.project_name_override or f"{strings.kebab_case(openapi.title).lower()}-client" self.package_name: str = config.package_name_override or self.project_name.replace("-", "_") - self.package_dir: Path = self.project_dir / self.package_name - self.package_description: str = utils.remove_string_escapes( - f"A client library for accessing {self.openapi.title}" + self.project_dir: Path # Where the generated code will be placed + self.package_dir: Path # Where the generated Python module will be placed (same as project_dir if no meta) + + if config.output_path is not None: + self.project_dir = config.output_path + elif config.meta_type == MetaType.NONE: # pragma: no cover + self.project_dir = Path.cwd() / self.package_name + else: + self.project_dir = Path.cwd() / self.project_name + + if config.meta_type == MetaType.NONE: + self.package_dir = self.project_dir + else: + self.package_dir = self.project_dir / self.package_name + + self.package_description = UntrustedString( + f"A client library for accessing {self.openapi.title.get_untrusted_value()}" + ) + self.version: UntrustedString = ( + UntrustedString(config.package_version_override) if config.package_version_override else openapi.version ) - self.version: str = config.package_version_override or openapi.version self.env.filters.update(TEMPLATE_FILTERS) self.env.globals.update( - utils=utils, - python_identifier=lambda x: utils.PythonIdentifier(x, config.field_prefix), - class_name=lambda x: utils.ClassName(x, config.field_prefix), + config=config, + strings=strings, + PythonCode=strings.PythonCode, + python_identifier=lambda x: strings.PythonIdentifier(x, config.field_prefix), + class_name=lambda x: strings.ClassName(x, config.field_prefix), package_name=self.package_name, package_dir=self.package_dir, package_description=self.package_description, @@ -89,19 +111,17 @@ def __init__( openapi=self.openapi, endpoint_collections_by_tag=self.openapi.endpoint_collections_by_tag, ) - self.errors: List[GeneratorError] = [] + self.errors: list[GeneratorError] = [] def build(self) -> Sequence[GeneratorError]: """Create the project from templates""" - if self.config.meta_type == MetaType.NONE: - print(f"Generating {self.package_name}") - else: - print(f"Generating {self.project_name}") - try: - self.project_dir.mkdir() - except FileExistsError: - return [GeneratorError(detail="Directory already exists. Delete it or use the update command.")] + print(f"Generating {self.project_dir}") + try: + self.project_dir.mkdir(parents=True) + except FileExistsError: + if not self.config.overwrite: + return [GeneratorError(detail="Directory already exists. Delete it or use the --overwrite option.")] self._create_package() self._build_metadata() self._build_models() @@ -109,25 +129,12 @@ def build(self) -> Sequence[GeneratorError]: self._run_post_hooks() return self._get_errors() - def update(self) -> Sequence[GeneratorError]: - """Update an existing project""" - - if not self.package_dir.is_dir(): - return [GeneratorError(detail=f"Directory {self.package_dir} not found")] - print(f"Updating {self.package_name}") - shutil.rmtree(self.package_dir) - self._create_package() - self._build_models() - self._build_api() - self._run_post_hooks() - return self._get_errors() - def _run_post_hooks(self) -> None: for command in self.config.post_hooks: self._run_command(command) def _run_command(self, cmd: str) -> None: - cmd_name = cmd.split(" ")[0] + cmd_name = cmd.split(" ", maxsplit=1)[0] command_exists = shutil.which(cmd_name) if not command_exists: self.errors.append( @@ -137,7 +144,7 @@ def _run_command(self, cmd: str) -> None: ) return try: - cwd = self.package_dir if self.config.meta_type == MetaType.NONE else self.project_dir + cwd = self.project_dir subprocess.run(cmd, cwd=cwd, shell=True, capture_output=True, check=True) except CalledProcessError as err: self.errors.append( @@ -148,8 +155,8 @@ def _run_command(self, cmd: str) -> None: ) ) - def _get_errors(self) -> List[GeneratorError]: - errors: List[GeneratorError] = [] + def _get_errors(self) -> list[GeneratorError]: + errors: list[GeneratorError] = [] for collection in self.openapi.endpoint_collections_by_tag.values(): errors.extend(collection.parse_errors) errors.extend(self.openapi.errors) @@ -157,7 +164,8 @@ def _get_errors(self) -> List[GeneratorError]: return errors def _create_package(self) -> None: - self.package_dir.mkdir() + if self.package_dir != self.project_dir: + self.package_dir.mkdir(exist_ok=True) # Package __init__.py package_init = self.package_dir / "__init__.py" @@ -184,7 +192,7 @@ def _build_metadata(self) -> None: readme = self.project_dir / "README.md" readme_template = self.env.get_template("README.md.jinja") readme.write_text( - readme_template.render(poetry=self.config.meta_type == MetaType.POETRY), + readme_template.render(meta=self.config.meta_type), encoding=self.config.file_encoding, ) @@ -213,6 +221,7 @@ def _build_setup_py(self) -> None: def _build_models(self) -> None: # Generate models models_dir = self.package_dir / "models" + shutil.rmtree(models_dir, ignore_errors=True) models_dir.mkdir() models_init = models_dir / "__init__.py" imports = [] @@ -228,9 +237,12 @@ def _build_models(self) -> None: # Generate enums str_enum_template = self.env.get_template("str_enum.py.jinja") int_enum_template = self.env.get_template("int_enum.py.jinja") + literal_enum_template = self.env.get_template("literal_enum.py.jinja") for enum in self.openapi.enums: module_path = models_dir / f"{enum.class_info.module_name}.py" - if enum.value_type is int: + if isinstance(enum, LiteralEnumProperty): + module_path.write_text(literal_enum_template.render(enum=enum), encoding=self.config.file_encoding) + elif enum.value_type is int: module_path.write_text(int_enum_template.render(enum=enum), encoding=self.config.file_encoding) else: module_path.write_text(str_enum_template.render(enum=enum), encoding=self.config.file_encoding) @@ -255,6 +267,7 @@ def _build_api(self) -> None: # Generate endpoints api_dir = self.package_dir / "api" + shutil.rmtree(api_dir, ignore_errors=True) api_dir.mkdir() api_init_path = api_dir / "__init__.py" api_init_template = self.env.get_template("api_init.py.jinja") @@ -262,7 +275,8 @@ def _build_api(self) -> None: endpoint_collections_by_tag = self.openapi.endpoint_collections_by_tag endpoint_template = self.env.get_template( - "endpoint_module.py.jinja", globals={"isbool": lambda obj: obj.get_base_type_string() == "bool"} + "endpoint_module.py.jinja", + globals={"isbool": lambda obj: obj.get_base_type_string() == strings.PythonCode("bool")}, ) for tag, collection in endpoint_collections_by_tag.items(): tag_dir = api_dir / tag @@ -276,7 +290,7 @@ def _build_api(self) -> None: ) for endpoint in collection.endpoints: - module_path = tag_dir / f"{utils.PythonIdentifier(endpoint.name, self.config.field_prefix)}.py" + module_path = tag_dir / f"{strings.PythonIdentifier(endpoint.name, self.config.field_prefix)}.py" module_path.write_text( endpoint_template.render( endpoint=endpoint, @@ -287,8 +301,8 @@ def _build_api(self) -> None: def _get_project_for_url_or_path( config: Config, - custom_template_path: Optional[Path] = None, -) -> Union[Project, GeneratorError]: + custom_template_path: Path | None = None, +) -> Project | GeneratorError: data_dict = _get_document(source=config.document_source, timeout=config.http_timeout) if isinstance(data_dict, GeneratorError): return data_dict @@ -302,10 +316,10 @@ def _get_project_for_url_or_path( ) -def create_new_client( +def generate( *, config: Config, - custom_template_path: Optional[Path] = None, + custom_template_path: Path | None = None, ) -> Sequence[GeneratorError]: """ Generate the client library @@ -322,27 +336,7 @@ def create_new_client( return project.build() -def update_existing_client( - *, - config: Config, - custom_template_path: Optional[Path] = None, -) -> Sequence[GeneratorError]: - """ - Update an existing client library - - Returns: - A list containing any errors encountered when generating. - """ - project = _get_project_for_url_or_path( - custom_template_path=custom_template_path, - config=config, - ) - if isinstance(project, GeneratorError): - return [project] - return project.update() - - -def _load_yaml_or_json(data: bytes, content_type: Optional[str]) -> Union[Dict[str, Any], GeneratorError]: +def _load_yaml_or_json(data: bytes, content_type: str | None) -> dict[str, Any] | GeneratorError: if content_type == "application/json": try: return json.loads(data.decode()) @@ -350,14 +344,15 @@ def _load_yaml_or_json(data: bytes, content_type: Optional[str]) -> Union[Dict[s return GeneratorError(header=f"Invalid JSON from provided source: {err}") else: try: - return yaml.safe_load(data) - except yaml.YAMLError as err: + yaml = YAML(typ="safe") + return yaml.load(data) + except YAMLError as err: return GeneratorError(header=f"Invalid YAML from provided source: {err}") -def _get_document(*, source: Union[str, Path], timeout: int) -> Union[Dict[str, Any], GeneratorError]: +def _get_document(*, source: str | Path, timeout: int) -> dict[str, Any] | GeneratorError: yaml_bytes: bytes - content_type: Optional[str] + content_type: str | None if isinstance(source, str): try: response = httpx.get(source, timeout=timeout) diff --git a/openapi_python_client/cli.py b/openapi_python_client/cli.py index 22478ab04..863ebbb5a 100644 --- a/openapi_python_client/cli.py +++ b/openapi_python_client/cli.py @@ -1,29 +1,33 @@ import codecs +from collections.abc import Sequence from pathlib import Path -from pprint import pformat -from typing import Optional, Sequence, Union import typer -from openapi_python_client import MetaType +from openapi_python_client import MetaType, __version__ from openapi_python_client.config import Config, ConfigFile from openapi_python_client.parser.errors import ErrorLevel, GeneratorError, ParseError -app = typer.Typer() +app = typer.Typer(name="openapi-python-client") def _version_callback(value: bool) -> None: - from openapi_python_client import __version__ - if value: typer.echo(f"openapi-python-client version: {__version__}") raise typer.Exit() def _process_config( - *, url: Optional[str], path: Optional[Path], config_path: Optional[Path], meta_type: MetaType, file_encoding: str + *, + url: str | None, + path: Path | None, + config_path: Path | None, + meta_type: MetaType, + file_encoding: str, + overwrite: bool, + output_path: Path | None, ) -> Config: - source: Union[Path, str] + source: Path | str if url and not path: source = url elif path and not url: @@ -49,13 +53,13 @@ def _process_config( except Exception as err: raise typer.BadParameter("Unable to parse config") from err - return Config.from_sources(config_file, meta_type, source, file_encoding) + return Config.from_sources(config_file, meta_type, source, file_encoding, overwrite, output_path=output_path) # noinspection PyUnusedLocal -@app.callback(name="openapi-python-client") +@app.callback() def cli( version: bool = typer.Option(False, "--version", callback=_version_callback, help="Print the version and exit"), ) -> None: @@ -64,16 +68,16 @@ def cli( def _print_parser_error(err: GeneratorError, color: str) -> None: typer.secho(err.header, bold=True, fg=color, err=True) - typer.echo() + typer.echo(err=True) if err.detail: typer.secho(err.detail, fg=color, err=True) - typer.echo() + typer.echo(err=True) if isinstance(err, ParseError) and err.data is not None: - formatted_data = pformat(err.data) + formatted_data = err.data.model_dump_json(indent=2, exclude_unset=True, by_alias=True) typer.secho(formatted_data, fg=color, err=True) - typer.echo() + typer.echo(err=True) def handle_errors(errors: Sequence[GeneratorError], fail_on_warning: bool = False) -> None: @@ -117,62 +121,46 @@ def handle_errors(errors: Sequence[GeneratorError], fail_on_warning: bool = Fals raise typer.Exit(code=1) -custom_template_path_options = { - "help": "A path to a directory containing custom template(s)", - "file_okay": False, - "dir_okay": True, - "readable": True, - "resolve_path": True, -} - -_meta_option = typer.Option( - MetaType.POETRY, - help="The type of metadata you want to generate.", -) - -CONFIG_OPTION = typer.Option(None, "--config", help="Path to the config file to use") - - @app.command() def generate( - url: Optional[str] = typer.Option(None, help="A URL to read the JSON from"), - path: Optional[Path] = typer.Option(None, help="A path to the JSON file"), - custom_template_path: Optional[Path] = typer.Option(None, **custom_template_path_options), # type: ignore - meta: MetaType = _meta_option, + url: str | None = typer.Option(None, help="A URL to read the OpenAPI document from"), + path: Path | None = typer.Option(None, help="A path to the OpenAPI document"), + custom_template_path: Path | None = typer.Option( + None, + help="A path to a directory containing custom template(s)", + file_okay=False, + dir_okay=True, + readable=True, + resolve_path=True, + ), # type: ignore + meta: MetaType = typer.Option( + MetaType.POETRY, + help="The type of metadata you want to generate.", + ), file_encoding: str = typer.Option("utf-8", help="Encoding used when writing generated"), - config_path: Optional[Path] = CONFIG_OPTION, + config_path: Path | None = typer.Option(None, "--config", help="Path to the config file to use"), fail_on_warning: bool = False, + overwrite: bool = typer.Option(False, help="Overwrite the existing client if it exists"), + output_path: Path | None = typer.Option( + None, + help="Path to write the generated code to. " + "Defaults to the OpenAPI document title converted to kebab or snake case (depending on meta type). " + "Can also be overridden with `project_name_override` or `package_name_override` in config.", + ), ) -> None: """Generate a new OpenAPI Client library""" - from . import create_new_client - - config = _process_config(url=url, path=path, config_path=config_path, meta_type=meta, file_encoding=file_encoding) - errors = create_new_client( - custom_template_path=custom_template_path, - config=config, + from . import generate # noqa: PLC0415 + + config = _process_config( + url=url, + path=path, + config_path=config_path, + meta_type=meta, + file_encoding=file_encoding, + overwrite=overwrite, + output_path=output_path, ) - handle_errors(errors, fail_on_warning) - - -@app.command() -def update( - url: Optional[str] = typer.Option(None, help="A URL to read the JSON from"), - path: Optional[Path] = typer.Option(None, help="A path to the JSON file"), - custom_template_path: Optional[Path] = typer.Option(None, **custom_template_path_options), # type: ignore - meta: MetaType = _meta_option, - file_encoding: str = typer.Option("utf-8", help="Encoding used when writing generated"), - config_path: Optional[Path] = CONFIG_OPTION, - fail_on_warning: bool = False, -) -> None: - """Update an existing OpenAPI Client library - - The update command performs the same operations as generate except it does not overwrite specific metadata for the - generated client such as the README.md, .gitignore, and pyproject.toml. - """ - from . import update_existing_client - - config = _process_config(config_path=config_path, meta_type=meta, url=url, path=path, file_encoding=file_encoding) - errors = update_existing_client( + errors = generate( custom_template_path=custom_template_path, config=config, ) diff --git a/openapi_python_client/config.py b/openapi_python_client/config.py index f779d90ac..61cf45c8d 100644 --- a/openapi_python_client/config.py +++ b/openapi_python_client/config.py @@ -1,12 +1,13 @@ import json import mimetypes -from enum import Enum +from enum import StrEnum from pathlib import Path -from typing import Dict, List, Optional, Union -import yaml from attr import define from pydantic import BaseModel +from ruamel.yaml import YAML + +from openapi_python_client.schema.untrusted_string import UntrustedString class ClassOverride(BaseModel): @@ -15,17 +16,18 @@ class ClassOverride(BaseModel): See https://github.com/openapi-generators/openapi-python-client#class_overrides """ - class_name: Optional[str] = None - module_name: Optional[str] = None + class_name: UntrustedString | None = None + module_name: str | None = None -class MetaType(str, Enum): +class MetaType(StrEnum): """The types of metadata supported for project generation.""" NONE = "none" POETRY = "poetry" SETUP = "setup" PDM = "pdm" + UV = "uv" class ConfigFile(BaseModel): @@ -34,15 +36,18 @@ class ConfigFile(BaseModel): See https://github.com/openapi-generators/openapi-python-client#configuration """ - class_overrides: Optional[Dict[str, ClassOverride]] = None - content_type_overrides: Optional[Dict[str, str]] = None - project_name_override: Optional[str] = None - package_name_override: Optional[str] = None - package_version_override: Optional[str] = None + class_overrides: dict[str, ClassOverride] | None = None + content_type_overrides: dict[str, str] | None = None + project_name_override: str | None = None + package_name_override: str | None = None + package_version_override: str | None = None use_path_prefixes_for_title_model_names: bool = True - post_hooks: Optional[List[str]] = None + post_hooks: list[str] | None = None + docstrings_on_attributes: bool = False field_prefix: str = "field_" + generate_all_tags: bool = False http_timeout: int = 5 + literal_enums: bool = False @staticmethod def load_from_path(path: Path) -> "ConfigFile": @@ -51,7 +56,8 @@ def load_from_path(path: Path) -> "ConfigFile": if mime == "application/json": config_data = json.loads(path.read_text()) else: - config_data = yaml.safe_load(path.read_text()) + yaml = YAML(typ="safe") + config_data = yaml.load(path) config = ConfigFile(**config_data) return config @@ -61,32 +67,42 @@ class Config: """Contains all the config values for the generator, from files, defaults, and CLI arguments.""" meta_type: MetaType - class_overrides: Dict[str, ClassOverride] - project_name_override: Optional[str] - package_name_override: Optional[str] - package_version_override: Optional[str] + class_overrides: dict[str, ClassOverride] + project_name_override: str | None + package_name_override: str | None + package_version_override: str | None use_path_prefixes_for_title_model_names: bool - post_hooks: List[str] + post_hooks: list[str] + docstrings_on_attributes: bool field_prefix: str + generate_all_tags: bool http_timeout: int - document_source: Union[Path, str] + literal_enums: bool + document_source: Path | str file_encoding: str - content_type_overrides: Dict[str, str] + content_type_overrides: dict[str, str] + overwrite: bool + output_path: Path | None @staticmethod def from_sources( - config_file: ConfigFile, meta_type: MetaType, document_source: Union[Path, str], file_encoding: str + config_file: ConfigFile, + meta_type: MetaType, + document_source: Path | str, + file_encoding: str, + overwrite: bool, + output_path: Path | None, ) -> "Config": if config_file.post_hooks is not None: post_hooks = config_file.post_hooks elif meta_type == MetaType.NONE: post_hooks = [ - "ruff check . --fix --extend-select=I", + "ruff check . --fix-only --extend-select=I", "ruff format .", ] else: post_hooks = [ - "ruff check --fix .", + "ruff check --fix-only .", "ruff format .", ] @@ -99,9 +115,14 @@ def from_sources( package_version_override=config_file.package_version_override, use_path_prefixes_for_title_model_names=config_file.use_path_prefixes_for_title_model_names, post_hooks=post_hooks, + docstrings_on_attributes=config_file.docstrings_on_attributes, field_prefix=config_file.field_prefix, + generate_all_tags=config_file.generate_all_tags, http_timeout=config_file.http_timeout, + literal_enums=config_file.literal_enums, document_source=document_source, file_encoding=file_encoding, + overwrite=overwrite, + output_path=output_path, ) return config diff --git a/openapi_python_client/parser/bodies.py b/openapi_python_client/parser/bodies.py index 6b8e4ad72..ae6e30fd9 100644 --- a/openapi_python_client/parser/bodies.py +++ b/openapi_python_client/parser/bodies.py @@ -1,5 +1,4 @@ -import sys -from typing import List, Tuple, Union +from enum import StrEnum import attr @@ -9,33 +8,25 @@ Schemas, property_from_data, ) +from openapi_python_client.parser.properties.schemas import get_reference_simple_name from .. import schema as oai from ..config import Config -from ..utils import get_content_type +from ..schema.untrusted_string import UntrustedString +from ..strings import get_content_type from .errors import ErrorLevel, ParseError -if sys.version_info >= (3, 11): - from enum import StrEnum - class BodyType(StrEnum): - JSON = "json" - DATA = "data" - FILES = "files" - CONTENT = "content" -else: - from enum import Enum - - class BodyType(str, Enum): - JSON = "json" - DATA = "data" - FILES = "files" - CONTENT = "content" +class BodyType(StrEnum): + JSON = "json" + DATA = "data" + FILES = "files" + CONTENT = "content" @attr.define class Body: - content_type: str + content_type: UntrustedString prop: Property body_type: BodyType @@ -44,24 +35,28 @@ def body_from_data( *, data: oai.Operation, schemas: Schemas, + request_bodies: dict[UntrustedString, oai.RequestBody | oai.Reference], config: Config, endpoint_name: str, -) -> Tuple[List[Union[Body, ParseError]], Schemas]: +) -> tuple[list[Body | ParseError], Schemas]: """Adds form or JSON body to Endpoint if included in data""" - if data.request_body is None or isinstance(data.request_body, oai.Reference): + body = _resolve_reference(data.request_body, request_bodies) + if isinstance(body, ParseError): + return [body], schemas + if body is None: return [], schemas - bodies: List[Union[Body, ParseError]] = [] - body_content = data.request_body.content + bodies: list[Body | ParseError] = [] + body_content = body.content prefix_type_names = len(body_content) > 1 for content_type, media_type in body_content.items(): - simplified_content_type = get_content_type(content_type, config) + simplified_content_type = get_content_type(content_type.get_untrusted_value(), config) if simplified_content_type is None: bodies.append( ParseError( detail="Invalid content type", - data=data.request_body, + data=body, level=ErrorLevel.WARNING, ) ) @@ -71,7 +66,7 @@ def body_from_data( bodies.append( ParseError( detail="Missing schema", - data=data.request_body, + data=body, level=ErrorLevel.WARNING, ) ) @@ -88,14 +83,14 @@ def body_from_data( bodies.append( ParseError( detail=f"Unsupported content type {simplified_content_type}", - data=data.request_body, + data=body, level=ErrorLevel.WARNING, ) ) continue prop, schemas = property_from_data( - name="body", - required=True, + name=UntrustedString("body"), + required=body.required, data=media_type_schema, schemas=schemas, parent_name=f"{endpoint_name}_{body_type}" if prefix_type_names else endpoint_name, @@ -113,6 +108,7 @@ def body_from_data( **schemas.classes_by_name, prop.class_info.name: prop, }, + models_to_process=[*schemas.models_to_process, prop], ) bodies.append( Body( @@ -123,3 +119,19 @@ def body_from_data( ) return bodies, schemas + + +def _resolve_reference( + body: oai.RequestBody | oai.Reference | None, request_bodies: dict[UntrustedString, oai.RequestBody | oai.Reference] +) -> oai.RequestBody | ParseError | None: + if body is None: + return None + references_seen = [] + while isinstance(body, oai.Reference) and body.ref not in references_seen: + references_seen.append(body.ref) + body = request_bodies.get(get_reference_simple_name(body.ref)) + if isinstance(body, oai.Reference): + return ParseError(detail="Circular $ref in request body", data=body) + if body is None and references_seen: + return ParseError(detail=f"Could not resolve $ref {references_seen[-1].get_untrusted_value()} in request body") + return body diff --git a/openapi_python_client/parser/errors.py b/openapi_python_client/parser/errors.py index 76a795b24..00f522b9e 100644 --- a/openapi_python_client/parser/errors.py +++ b/openapi_python_client/parser/errors.py @@ -1,8 +1,7 @@ from dataclasses import dataclass from enum import Enum -from typing import Optional -__all__ = ["ErrorLevel", "GeneratorError", "ParseError", "PropertyError", "ParameterError"] +__all__ = ["ErrorLevel", "GeneratorError", "ParameterError", "ParseError", "PropertyError"] from pydantic import BaseModel @@ -18,7 +17,7 @@ class ErrorLevel(Enum): class GeneratorError: """Base data struct containing info on an error that occurred""" - detail: Optional[str] = None + detail: str | None = None level: ErrorLevel = ErrorLevel.ERROR header: str = "Unable to generate the client" @@ -28,7 +27,7 @@ class ParseError(GeneratorError): """An error raised when there's a problem parsing an OpenAPI document""" level: ErrorLevel = ErrorLevel.WARNING - data: Optional[BaseModel] = None + data: BaseModel | None = None header: str = "Unable to parse this part of your OpenAPI document: " diff --git a/openapi_python_client/parser/openapi.py b/openapi_python_client/parser/openapi.py index 015966224..c16f03f2f 100644 --- a/openapi_python_client/parser/openapi.py +++ b/openapi_python_client/parser/openapi.py @@ -1,20 +1,22 @@ import re +from collections.abc import Iterator from copy import deepcopy from dataclasses import dataclass, field -from http import HTTPStatus -from typing import Any, Dict, Iterator, List, Optional, Protocol, Set, Tuple, Union +from typing import Any, Protocol from pydantic import ValidationError from .. import schema as oai -from .. import utils +from .. import strings from ..config import Config -from ..utils import PythonIdentifier +from ..schema.untrusted_string import UntrustedString +from ..strings import PythonIdentifier from .bodies import Body, body_from_data from .errors import GeneratorError, ParseError, PropertyError from .properties import ( Class, EnumProperty, + LiteralEnumProperty, ModelProperty, Parameters, Property, @@ -24,7 +26,7 @@ property_from_data, ) from .properties.schemas import parameter_from_reference -from .responses import Response, response_from_data +from .responses import HTTPStatusPattern, Responses, response_from_data _PATH_PARAM_REGEX = re.compile("{([a-zA-Z_-][a-zA-Z0-9_-]*)}") @@ -39,36 +41,48 @@ class EndpointCollection: """A bunch of endpoints grouped under a tag that will become a module""" tag: str - endpoints: List["Endpoint"] = field(default_factory=list) - parse_errors: List[ParseError] = field(default_factory=list) + endpoints: list["Endpoint"] = field(default_factory=list) + parse_errors: list[ParseError] = field(default_factory=list) @staticmethod def from_data( *, - data: Dict[str, oai.PathItem], + data: dict[UntrustedString, oai.PathItem], schemas: Schemas, parameters: Parameters, + request_bodies: dict[UntrustedString, oai.RequestBody | oai.Reference], + responses: dict[UntrustedString, oai.Response | oai.Reference], config: Config, - ) -> Tuple[Dict[utils.PythonIdentifier, "EndpointCollection"], Schemas, Parameters]: + ) -> tuple[dict[strings.PythonIdentifier, "EndpointCollection"], Schemas, Parameters]: """Parse the openapi paths data to get EndpointCollections by tag""" - endpoints_by_tag: Dict[utils.PythonIdentifier, EndpointCollection] = {} + endpoints_by_tag: dict[strings.PythonIdentifier, EndpointCollection] = {} methods = ["get", "put", "post", "delete", "options", "head", "patch", "trace"] for path, path_data in data.items(): for method in methods: - operation: Optional[oai.Operation] = getattr(path_data, method) + operation: oai.Operation | None = getattr(path_data, method) if operation is None: continue - tag = utils.PythonIdentifier(value=(operation.tags or ["default"])[0], prefix="tag") - collection = endpoints_by_tag.setdefault(tag, EndpointCollection(tag=tag)) + + tags = [ + strings.PythonIdentifier(value=tag, prefix="tag") + for tag in operation.tags or [UntrustedString("default")] + ] + if not config.generate_all_tags: + tags = tags[:1] + + collections = [endpoints_by_tag.setdefault(tag, EndpointCollection(tag=tag)) for tag in tags] + endpoint, schemas, parameters = Endpoint.from_data( data=operation, path=path, method=method, - tag=tag, + tags=tags, schemas=schemas, parameters=parameters, + request_bodies=request_bodies, + responses=responses, config=config, ) # Add `PathItem` parameters @@ -83,27 +97,30 @@ def from_data( if not isinstance(endpoint, ParseError): endpoint = Endpoint.sort_parameters(endpoint=endpoint) if isinstance(endpoint, ParseError): - endpoint.header = ( - f"WARNING parsing {method.upper()} {path} within {tag}. Endpoint will not be generated." - ) - collection.parse_errors.append(endpoint) + endpoint.header = f"WARNING parsing {method.upper()} {path.get_untrusted_value()} within {'/'.join(tags)}. Endpoint will not be generated." + for collection in collections: + collection.parse_errors.append(endpoint) continue for error in endpoint.errors: - error.header = f"WARNING parsing {method.upper()} {path} within {tag}." - collection.parse_errors.append(error) - collection.endpoints.append(endpoint) + error.header = ( + f"WARNING parsing {method.upper()} {path.get_untrusted_value()} within {'/'.join(tags)}." + ) + for collection in collections: + collection.parse_errors.append(error) + for collection in collections: + collection.endpoints.append(endpoint) return endpoints_by_tag, schemas, parameters -def generate_operation_id(*, path: str, method: str) -> str: +def generate_operation_id(*, path: UntrustedString, method: str, prefix: str) -> PythonIdentifier: """Generate an operationId from a path""" - clean_path = path.replace("{", "").replace("}", "").replace("/", "_") - if clean_path.startswith("_"): - clean_path = clean_path[1:] - if clean_path.endswith("_"): - clean_path = clean_path[:-1] - return f"{method}_{clean_path}" + unsafe_id = path.get_untrusted_value().replace("{", "").replace("}", "").replace("/", "_") + if unsafe_id.startswith("_"): + unsafe_id = unsafe_id[1:] + if unsafe_id.endswith("_"): # pragma: no cover + unsafe_id = unsafe_id[:-1] + return PythonIdentifier(f"{method}_{unsafe_id}", prefix=prefix) models_relative_prefix: str = "..." @@ -114,7 +131,7 @@ class RequestBodyParser(Protocol): def __call__( self, *, body: oai.RequestBody, schemas: Schemas, parent_name: str, config: Config - ) -> Tuple[Union[Property, PropertyError, None], Schemas]: ... # pragma: no cover + ) -> tuple[Property | PropertyError | None, Schemas]: ... # pragma: no cover @dataclass @@ -123,47 +140,43 @@ class Endpoint: Describes a single endpoint on the server """ - path: str + path: UntrustedString method: str - description: Optional[str] - name: str + description: UntrustedString + name: PythonIdentifier requires_security: bool - tag: str - summary: Optional[str] = "" - relative_imports: Set[str] = field(default_factory=set) - query_parameters: List[Property] = field(default_factory=list) - path_parameters: List[Property] = field(default_factory=list) - header_parameters: List[Property] = field(default_factory=list) - cookie_parameters: List[Property] = field(default_factory=list) - responses: List[Response] = field(default_factory=list) - bodies: List[Body] = field(default_factory=list) - errors: List[ParseError] = field(default_factory=list) + tags: list[PythonIdentifier] + summary: UntrustedString + relative_imports: set[str] = field(default_factory=set) + query_parameters: list[Property] = field(default_factory=list) + path_parameters: list[Property] = field(default_factory=list) + header_parameters: list[Property] = field(default_factory=list) + cookie_parameters: list[Property] = field(default_factory=list) + responses: Responses = field(default_factory=lambda: Responses(patterns=[], default=None)) + bodies: list[Body] = field(default_factory=list) + errors: list[ParseError] = field(default_factory=list) @staticmethod def _add_responses( - *, endpoint: "Endpoint", data: oai.Responses, schemas: Schemas, config: Config - ) -> Tuple["Endpoint", Schemas]: + *, + endpoint: "Endpoint", + data: oai.Responses, + schemas: Schemas, + responses: dict[UntrustedString, oai.Response | oai.Reference], + config: Config, + ) -> tuple["Endpoint", Schemas]: endpoint = deepcopy(endpoint) for code, response_data in data.items(): - status_code: HTTPStatus - try: - status_code = HTTPStatus(int(code)) - except ValueError: - endpoint.errors.append( - ParseError( - detail=( - f"Invalid response status code {code} (not a valid HTTP " - f"status code), response will be ommitted from generated " - f"client" - ) - ) - ) + status_code = HTTPStatusPattern.parse(code) + if isinstance(status_code, ParseError): + endpoint.errors.append(status_code) continue response, schemas = response_from_data( status_code=status_code, data=response_data, schemas=schemas, + responses=responses, parent_name=endpoint.name, config=config, ) @@ -172,8 +185,8 @@ def _add_responses( endpoint.errors.append( ParseError( detail=( - f"Cannot parse response for status code {status_code}{detail_suffix}, " - f"response will be ommitted from generated client" + f"Cannot parse response for status code {code}{detail_suffix}, " + f"response will be omitted from generated client" ), data=response.data, ) @@ -183,18 +196,22 @@ def _add_responses( # No reasons to use lazy imports in endpoints, so add lazy imports to relative here. endpoint.relative_imports |= response.prop.get_lazy_imports(prefix=models_relative_prefix) endpoint.relative_imports |= response.prop.get_imports(prefix=models_relative_prefix) - endpoint.responses.append(response) + if response.is_default(): + endpoint.responses.default = response + else: + endpoint.responses.patterns.append(response) + endpoint.responses.patterns.sort() return endpoint, schemas @staticmethod def add_parameters( *, endpoint: "Endpoint", - data: Union[oai.Operation, oai.PathItem], + data: oai.Operation | oai.PathItem, schemas: Schemas, parameters: Parameters, config: Config, - ) -> Tuple[Union["Endpoint", ParseError], Schemas, Parameters]: + ) -> tuple["Endpoint | ParseError", Schemas, Parameters]: """Process the defined `parameters` for an Endpoint. Any existing parameters will be ignored, so earlier instances of a parameter take precedence. PathItem @@ -223,8 +240,8 @@ def add_parameters( endpoint = deepcopy(endpoint) - unique_parameters: Set[Tuple[str, oai.ParameterLocation]] = set() - parameters_by_location: Dict[str, List[Property]] = { + unique_parameters: set[tuple[UntrustedString, oai.ParameterLocation]] = set() + parameters_by_location: dict[str, list[Property]] = { oai.ParameterLocation.QUERY: endpoint.query_parameters, oai.ParameterLocation.PATH: endpoint.path_parameters, oai.ParameterLocation.HEADER: endpoint.header_parameters, @@ -249,7 +266,7 @@ def add_parameters( detail=( "Parameters MUST NOT contain duplicates. " "A unique parameter is defined by a combination of a name and location. " - f"Duplicated parameters named `{param.name}` detected in `{param.param_in}`." + f"Duplicated parameters named `{param.name.get_untrusted_value()}` detected in `{param.param_in}`." ), ), schemas, @@ -301,8 +318,8 @@ def _check_parameters_for_conflicts( self, *, config: Config, - previously_modified_params: Optional[Set[Tuple[oai.ParameterLocation, str]]] = None, - ) -> Union["Endpoint", ParseError]: + previously_modified_params: set[tuple[oai.ParameterLocation, UntrustedString]] | None = None, + ) -> "Endpoint | ParseError": """Check for conflicting parameters For parameters that have the same python_name but are in different locations, append the location to the @@ -313,13 +330,13 @@ def _check_parameters_for_conflicts( unique python_name. """ modified_params = previously_modified_params or set() - used_python_names: Dict[PythonIdentifier, Tuple[oai.ParameterLocation, Property]] = {} + used_python_names: dict[PythonIdentifier, tuple[oai.ParameterLocation, Property]] = {} reserved_names = ["client", "url"] for parameter in self.iter_all_parameters(): location, prop = parameter if prop.python_name in reserved_names: - prop.set_python_name(new_name=f"{prop.python_name}_{location}", config=config) + prop.set_python_name(new_name=UntrustedString(f"{prop.python_name}_{location}"), config=config) modified_params.add((location, prop.name)) continue @@ -338,9 +355,9 @@ def _check_parameters_for_conflicts( if location != conflicting_location: conflicting_prop.set_python_name( - new_name=f"{conflicting_prop.python_name}_{conflicting_location}", config=config + new_name=UntrustedString(f"{conflicting_prop.python_name}_{conflicting_location}"), config=config ) - prop.set_python_name(new_name=f"{prop.python_name}_{location}", config=config) + prop.set_python_name(new_name=UntrustedString(f"{prop.python_name}_{location}"), config=config) elif conflicting_prop.name != prop.name: # Use the name to differentiate conflicting_prop.set_python_name(new_name=conflicting_prop.name, config=config, skip_snake_case=True) prop.set_python_name(new_name=prop.name, config=config, skip_snake_case=True) @@ -355,7 +372,7 @@ def _check_parameters_for_conflicts( return self @staticmethod - def sort_parameters(*, endpoint: "Endpoint") -> Union["Endpoint", ParseError]: + def sort_parameters(*, endpoint: "Endpoint") -> "Endpoint | ParseError": """ Sorts the path parameters of an `endpoint` so that they match the order declared in `endpoint.path`. @@ -367,7 +384,7 @@ def sort_parameters(*, endpoint: "Endpoint") -> Union["Endpoint", ParseError]: the path parameters and they could not be sorted. """ endpoint = deepcopy(endpoint) - parameters_from_path = re.findall(_PATH_PARAM_REGEX, endpoint.path) + parameters_from_path = re.findall(_PATH_PARAM_REGEX, endpoint.path.get_untrusted_value()) try: endpoint.path_parameters.sort( key=lambda param: parameters_from_path.index(param.name), @@ -377,38 +394,44 @@ def sort_parameters(*, endpoint: "Endpoint") -> Union["Endpoint", ParseError]: if parameters_from_path != [param.name for param in endpoint.path_parameters]: return ParseError( - detail=f"Incorrect path templating for {endpoint.path} (Path parameters do not match with path)", + detail=f"Incorrect path templating for {endpoint.path.get_untrusted_value()} (Path parameters do not match with path)", ) for parameter in endpoint.path_parameters: - endpoint.path = endpoint.path.replace(f"{{{parameter.name}}}", f"{{{parameter.python_name}}}") + endpoint.path = UntrustedString( + endpoint.path.get_untrusted_value().replace( + f"{{{parameter.name.get_untrusted_value()}}}", f"{{{parameter.python_name}}}" + ) + ) return endpoint @staticmethod def from_data( *, data: oai.Operation, - path: str, + path: UntrustedString, method: str, - tag: str, + tags: list[PythonIdentifier], schemas: Schemas, parameters: Parameters, + request_bodies: dict[UntrustedString, oai.RequestBody | oai.Reference], + responses: dict[UntrustedString, oai.Response | oai.Reference], config: Config, - ) -> Tuple[Union["Endpoint", ParseError], Schemas, Parameters]: + ) -> tuple["Endpoint | ParseError", Schemas, Parameters]: """Construct an endpoint from the OpenAPI data""" if data.operationId is None: - name = generate_operation_id(path=path, method=method) + name = generate_operation_id(path=path, method=method, prefix=config.field_prefix) else: - name = data.operationId + name = PythonIdentifier(data.operationId, prefix=config.field_prefix) endpoint = Endpoint( path=path, method=method, - summary=utils.remove_string_escapes(data.summary) if data.summary else "", - description=utils.remove_string_escapes(data.description) if data.description else "", + summary=data.summary if data.summary else UntrustedString(""), + description=data.description if data.description else UntrustedString(""), name=name, requires_security=bool(data.security), - tag=tag, + tags=tags, ) result, schemas, parameters = Endpoint.add_parameters( @@ -420,10 +443,18 @@ def from_data( ) if isinstance(result, ParseError): return result, schemas, parameters - result, schemas = Endpoint._add_responses(endpoint=result, data=data.responses, schemas=schemas, config=config) - if isinstance(result, ParseError): + result, schemas = Endpoint._add_responses( + endpoint=result, + data=data.responses, + schemas=schemas, + responses=responses, + config=config, + ) + if isinstance(result, ParseError): # pragma: no cover return result, schemas, parameters - bodies, schemas = body_from_data(data=data, schemas=schemas, config=config, endpoint_name=result.name) + bodies, schemas = body_from_data( + data=data, schemas=schemas, config=config, endpoint_name=result.name, request_bodies=request_bodies + ) body_errors = [] for body in bodies: if isinstance(body, ParseError): @@ -446,24 +477,24 @@ def from_data( return result, schemas, parameters - def response_type(self) -> str: + def response_type(self) -> strings.PythonCode: """Get the Python type of any response from this endpoint""" - types = sorted({response.prop.get_type_string(quoted=False) for response in self.responses}) + types = sorted({response.prop.get_type_string().as_unembedded_code() for response in self.responses}) if len(types) == 0: - return "Any" + return strings.PythonCode("Any") if len(types) == 1: - return self.responses[0].prop.get_type_string(quoted=False) - return f"Union[{', '.join(types)}]" + return strings.PythonCode(types[0]) + return strings.PythonCode(" | ".join(types)) - def iter_all_parameters(self) -> Iterator[Tuple[oai.ParameterLocation, Property]]: + def iter_all_parameters(self) -> Iterator[tuple[oai.ParameterLocation, Property]]: """Iterate through all the parameters of this endpoint""" yield from ((oai.ParameterLocation.PATH, param) for param in self.path_parameters) yield from ((oai.ParameterLocation.QUERY, param) for param in self.query_parameters) yield from ((oai.ParameterLocation.HEADER, param) for param in self.header_parameters) yield from ((oai.ParameterLocation.COOKIE, param) for param in self.cookie_parameters) - def list_all_parameters(self) -> List[Property]: - """Return a List of all the parameters of this endpoint""" + def list_all_parameters(self) -> list[Property]: + """Return a list of all the parameters of this endpoint""" return ( self.path_parameters + self.query_parameters @@ -477,16 +508,16 @@ def list_all_parameters(self) -> List[Property]: class GeneratorData: """All the data needed to generate a client""" - title: str - description: Optional[str] - version: str - models: Iterator[ModelProperty] - errors: List[ParseError] - endpoint_collections_by_tag: Dict[utils.PythonIdentifier, EndpointCollection] - enums: Iterator[EnumProperty] + title: UntrustedString + description: UntrustedString | None + version: UntrustedString + models: list[ModelProperty] + errors: list[ParseError] + endpoint_collections_by_tag: dict[strings.PythonIdentifier, EndpointCollection] + enums: list[EnumProperty | LiteralEnumProperty] @staticmethod - def from_dict(data: Dict[str, Any], *, config: Config) -> Union["GeneratorData", GeneratorError]: + def from_dict(data: dict[str, Any], *, config: Config) -> "GeneratorData | GeneratorError": """Create an OpenAPI from dict""" try: openapi = oai.OpenAPI.model_validate(data) @@ -507,12 +538,21 @@ def from_dict(data: Dict[str, Any], *, config: Config) -> Union["GeneratorData", parameters=parameters, config=config, ) + request_bodies = (openapi.components and openapi.components.requestBodies) or {} + responses = (openapi.components and openapi.components.responses) or {} endpoint_collections_by_tag, schemas, parameters = EndpointCollection.from_data( - data=openapi.paths, schemas=schemas, parameters=parameters, config=config + data=openapi.paths, + schemas=schemas, + parameters=parameters, + request_bodies=request_bodies, + responses=responses, + config=config, ) - enums = (prop for prop in schemas.classes_by_name.values() if isinstance(prop, EnumProperty)) - models = (prop for prop in schemas.classes_by_name.values() if isinstance(prop, ModelProperty)) + enums = [ + prop for prop in schemas.classes_by_name.values() if isinstance(prop, EnumProperty | LiteralEnumProperty) + ] + models = [prop for prop in schemas.classes_by_name.values() if isinstance(prop, ModelProperty)] return GeneratorData( title=openapi.info.title, diff --git a/openapi_python_client/parser/properties/__init__.py b/openapi_python_client/parser/properties/__init__.py index e692ce5bb..09aab386b 100644 --- a/openapi_python_client/parser/properties/__init__.py +++ b/openapi_python_client/parser/properties/__init__.py @@ -4,21 +4,24 @@ "AnyProperty", "Class", "EnumProperty", + "LiteralEnumProperty", "ModelProperty", "Parameters", "Property", "Schemas", - "build_schemas", "build_parameters", + "build_schemas", "property_from_data", ] -from typing import Iterable +from collections.abc import Iterable from attrs import evolve -from ... import Config, utils +from ... import Config, strings from ... import schema as oai +from ...schema.ref import Ref +from ...schema.untrusted_string import UntrustedString from ..errors import ParameterError, ParseError, PropertyError from .any import AnyProperty from .boolean import BooleanProperty @@ -30,6 +33,7 @@ from .float import FloatProperty from .int import IntProperty from .list_property import ListProperty +from .literal_enum_property import LiteralEnumProperty from .model_property import ModelProperty, process_model from .none import NoneProperty from .property import Property @@ -38,20 +42,22 @@ Parameters, ReferencePath, Schemas, + get_reference_simple_name, parse_reference_path, update_parameters_with_data, update_schemas_with_data, ) from .string import StringProperty from .union import UnionProperty +from .uuid import UuidProperty def _string_based_property( - name: str, required: bool, data: oai.Schema, config: Config -) -> StringProperty | DateProperty | DateTimeProperty | FileProperty | PropertyError: + name: UntrustedString, required: bool, data: oai.Schema, config: Config +) -> StringProperty | DateProperty | DateTimeProperty | FileProperty | UuidProperty | PropertyError: """Construct a Property from the type "string" """ string_format = data.schema_format - python_name = utils.PythonIdentifier(value=name, prefix=config.field_prefix) + python_name = strings.PythonIdentifier(value=name, prefix=config.field_prefix) if string_format == "date-time": return DateTimeProperty.build( name=name, @@ -79,11 +85,19 @@ def _string_based_property( description=data.description, example=data.example, ) + if string_format == "uuid": + return UuidProperty.build( + name=name, + required=required, + default=data.default, + python_name=python_name, + description=data.description, + example=data.example, + ) return StringProperty.build( name=name, default=data.default, required=required, - pattern=data.pattern, python_name=python_name, description=data.description, example=data.example, @@ -91,16 +105,16 @@ def _string_based_property( def _property_from_ref( - name: str, + name: UntrustedString, required: bool, parent: oai.Schema | None, data: oai.Reference, schemas: Schemas, config: Config, - roots: set[ReferencePath | utils.ClassName], + roots: set[ReferencePath | strings.ClassName], ) -> tuple[Property | PropertyError, Schemas]: ref_path = parse_reference_path(data.ref) - if isinstance(ref_path, ParseError): + if isinstance(ref_path, ParseError): # pragma: no cover return PropertyError(data=data, detail=ref_path.detail), schemas existing = schemas.classes_by_reference.get(ref_path) if not existing: @@ -118,7 +132,7 @@ def _property_from_ref( existing, required=required, name=name, - python_name=utils.PythonIdentifier(value=name, prefix=config.field_prefix), + python_name=strings.PythonIdentifier(value=name, prefix=config.field_prefix), default=default, # type: ignore # mypy can't tell that default comes from the same class... ) @@ -126,19 +140,18 @@ def _property_from_ref( return prop, schemas -def property_from_data( # noqa: PLR0911 - name: str, +def property_from_data( # noqa: PLR0911, PLR0912 + name: UntrustedString, required: bool, data: oai.Reference | oai.Schema, schemas: Schemas, parent_name: str, config: Config, process_properties: bool = True, - roots: set[ReferencePath | utils.ClassName] | None = None, + roots: set[ReferencePath | strings.ClassName] | None = None, ) -> tuple[Property | PropertyError, Schemas]: """Generate a Property from the OpenAPI dictionary representation of it""" roots = roots or set() - name = utils.remove_string_escapes(name) if isinstance(data, oai.Reference): return _property_from_ref( name=name, @@ -153,7 +166,7 @@ def property_from_data( # noqa: PLR0911 sub_data: list[oai.Schema | oai.Reference] = data.allOf + data.anyOf + data.oneOf # A union of a single reference should just be passed through to that reference (don't create copy class) if len(sub_data) == 1 and isinstance(sub_data[0], oai.Reference): - return _property_from_ref( + prop, schemas = _property_from_ref( name=name, required=required, parent=data, @@ -162,19 +175,38 @@ def property_from_data( # noqa: PLR0911 config=config, roots=roots, ) + # We won't be generating a separate Python class for this schema - references to it will just use + # the class for the schema it's referencing - so we don't add it to classes_by_name; but we do + # add it to models_to_process, if it's a model, because its properties still need to be resolved. + if isinstance(prop, ModelProperty): + schemas = evolve( + schemas, + models_to_process=[*schemas.models_to_process, prop], + ) + return prop, schemas + if data.type == oai.DataType.BOOLEAN: return ( BooleanProperty.build( name=name, required=required, default=data.default, - python_name=utils.PythonIdentifier(value=name, prefix=config.field_prefix), + python_name=strings.PythonIdentifier(value=name, prefix=config.field_prefix), description=data.description, example=data.example, ), schemas, ) if data.enum: + if config.literal_enums: + return LiteralEnumProperty.build( + data=data, + name=name, + required=required, + schemas=schemas, + parent_name=parent_name, + config=config, + ) return EnumProperty.build( data=data, name=name, @@ -199,7 +231,7 @@ def property_from_data( # noqa: PLR0911 required=required, default=data.default, const=data.const, - python_name=utils.PythonIdentifier(value=name, prefix=config.field_prefix), + python_name=strings.PythonIdentifier(value=name, prefix=config.field_prefix), description=data.description, ), schemas, @@ -215,7 +247,7 @@ def property_from_data( # noqa: PLR0911 name=name, default=data.default, required=required, - python_name=utils.PythonIdentifier(value=name, prefix=config.field_prefix), + python_name=strings.PythonIdentifier(value=name, prefix=config.field_prefix), description=data.description, example=data.example, ), @@ -227,7 +259,7 @@ def property_from_data( # noqa: PLR0911 name=name, default=data.default, required=required, - python_name=utils.PythonIdentifier(value=name, prefix=config.field_prefix), + python_name=strings.PythonIdentifier(value=name, prefix=config.field_prefix), description=data.description, example=data.example, ), @@ -239,7 +271,7 @@ def property_from_data( # noqa: PLR0911 name=name, required=required, default=None, - python_name=utils.PythonIdentifier(value=name, prefix=config.field_prefix), + python_name=strings.PythonIdentifier(value=name, prefix=config.field_prefix), description=data.description, example=data.example, ), @@ -271,8 +303,8 @@ def property_from_data( # noqa: PLR0911 AnyProperty.build( name=name, required=required, - default=None, - python_name=utils.PythonIdentifier(value=name, prefix=config.field_prefix), + default=data.default, + python_name=strings.PythonIdentifier(value=name, prefix=config.field_prefix), description=data.description, example=data.example, ), @@ -282,11 +314,11 @@ def property_from_data( # noqa: PLR0911 def _create_schemas( *, - components: dict[str, oai.Reference | oai.Schema], + components: dict[UntrustedString, oai.Reference | oai.Schema], schemas: Schemas, config: Config, ) -> Schemas: - to_process: Iterable[tuple[str, oai.Reference | oai.Schema]] = components.items() + to_process: Iterable[tuple[UntrustedString, oai.Reference | oai.Schema]] = components.items() still_making_progress = True errors: list[PropertyError] = [] @@ -294,17 +326,30 @@ def _create_schemas( while still_making_progress: still_making_progress = False errors = [] - next_round = [] + next_round: list[tuple[UntrustedString, oai.Reference | oai.Schema]] = [] # Only accumulate errors from the last round, since we might fix some along the way for name, data in to_process: - if isinstance(data, oai.Reference): - schemas.errors.append(PropertyError(data=data, detail="Reference schemas are not supported.")) - continue - ref_path = parse_reference_path(f"#/components/schemas/{name}") - if isinstance(ref_path, ParseError): + schema_data: oai.Reference | oai.Schema | None = data + ref_path = parse_reference_path(Ref(f"#/components/schemas/{name.get_untrusted_value()}")) + if isinstance(ref_path, ParseError): # pragma: no cover schemas.errors.append(PropertyError(detail=ref_path.detail, data=data)) continue - schemas_or_err = update_schemas_with_data(ref_path=ref_path, data=data, schemas=schemas, config=config) + if isinstance(data, oai.Reference): + # Fully dereference reference schemas + seen = [name] + while isinstance(schema_data, oai.Reference): + data_ref_schema = get_reference_simple_name(schema_data.ref) + if data_ref_schema in seen: + schemas.errors.append(PropertyError(detail="Circular schema references found", data=data)) + break + # use derefenced schema definition for this schema + schema_data = components.get(data_ref_schema) + if isinstance(schema_data, oai.Schema): + schemas_or_err = update_schemas_with_data( + ref_path=ref_path, data=schema_data, schemas=schemas, config=config + ) + else: + schemas.errors.append(PropertyError(detail="Referent schema not found", data=data)) if isinstance(schemas_or_err, PropertyError): next_round.append((name, data)) errors.append(schemas_or_err) @@ -317,13 +362,13 @@ def _create_schemas( return schemas -def _propogate_removal(*, root: ReferencePath | utils.ClassName, schemas: Schemas, error: PropertyError) -> None: - if isinstance(root, utils.ClassName): +def _propogate_removal(*, root: ReferencePath | strings.ClassName, schemas: Schemas, error: PropertyError) -> None: + if isinstance(root, strings.ClassName): schemas.classes_by_name.pop(root, None) return if root in schemas.classes_by_reference: error.detail = error.detail or "" - error.detail += f"\n{root}" + error.detail += f"\n{root.get_untrusted_value()}" del schemas.classes_by_reference[root] for child in schemas.dependencies.get(root, set()): _propogate_removal(root=child, schemas=schemas, error=error) @@ -341,7 +386,7 @@ def _process_model_errors( def _process_models(*, schemas: Schemas, config: Config) -> Schemas: - to_process = (prop for prop in schemas.classes_by_name.values() if isinstance(prop, ModelProperty)) + to_process = schemas.models_to_process still_making_progress = True final_model_errors: list[tuple[ModelProperty, PropertyError]] = [] latest_model_errors: list[tuple[ModelProperty, PropertyError]] = [] @@ -355,10 +400,10 @@ def _process_models(*, schemas: Schemas, config: Config) -> Schemas: for model_prop in to_process: schemas_or_err = process_model(model_prop, schemas=schemas, config=config) if isinstance(schemas_or_err, PropertyError): - schemas_or_err.header = f"\nUnable to process schema {model_prop.name}:" + schemas_or_err.header = f"\nUnable to process schema {model_prop.name.get_untrusted_value()}:" if isinstance(schemas_or_err.data, oai.Reference) and schemas_or_err.data.ref.endswith( f"/{model_prop.class_info.name}" - ): + ): # pragma: no cover schemas_or_err.detail = schemas_or_err.detail or "" schemas_or_err.detail += "\n\nRecursive allOf reference found" final_model_errors.append((model_prop, schemas_or_err)) @@ -368,17 +413,16 @@ def _process_models(*, schemas: Schemas, config: Config) -> Schemas: continue schemas = schemas_or_err still_making_progress = True - to_process = (prop for prop in next_round) + to_process = next_round final_model_errors.extend(latest_model_errors) errors = _process_model_errors(final_model_errors, schemas=schemas) - schemas.errors.extend(errors) - return schemas + return evolve(schemas, errors=[*schemas.errors, *errors], models_to_process=to_process) def build_schemas( *, - components: dict[str, oai.Reference | oai.Schema], + components: dict[UntrustedString, oai.Reference | oai.Schema], schemas: Schemas, config: Config, ) -> Schemas: @@ -390,12 +434,12 @@ def build_schemas( def build_parameters( *, - components: dict[str, oai.Reference | oai.Parameter], + components: dict[UntrustedString, oai.Reference | oai.Parameter], parameters: Parameters, config: Config, ) -> Parameters: """Get a list of Parameters from an OpenAPI dict""" - to_process: Iterable[tuple[str, oai.Reference | oai.Parameter]] = [] + to_process: Iterable[tuple[UntrustedString, oai.Reference | oai.Parameter]] = [] if components is not None: to_process = components.items() still_making_progress = True @@ -408,17 +452,17 @@ def build_parameters( next_round = [] # Only accumulate errors from the last round, since we might fix some along the way for name, data in to_process: - if isinstance(data, oai.Reference): + if isinstance(data, oai.Reference): # pragma: no cover parameters.errors.append(ParameterError(data=data, detail="Reference parameters are not supported.")) continue - ref_path = parse_reference_path(f"#/components/parameters/{name}") - if isinstance(ref_path, ParseError): + ref_path = parse_reference_path(Ref(f"#/components/parameters/{name.get_untrusted_value()}")) + if isinstance(ref_path, ParseError): # pragma: no cover parameters.errors.append(ParameterError(detail=ref_path.detail, data=data)) continue parameters_or_err = update_parameters_with_data( ref_path=ref_path, data=data, parameters=parameters, config=config ) - if isinstance(parameters_or_err, ParameterError): + if isinstance(parameters_or_err, ParameterError): # pragma: no cover next_round.append((name, data)) errors.append(parameters_or_err) continue diff --git a/openapi_python_client/parser/properties/any.py b/openapi_python_client/parser/properties/any.py index fdeef93a1..e739c9c86 100644 --- a/openapi_python_client/parser/properties/any.py +++ b/openapi_python_client/parser/properties/any.py @@ -2,10 +2,11 @@ from typing import Any, ClassVar -from attr import define +from attr import define, field -from ...utils import PythonIdentifier -from .protocol import PropertyProtocol, Value +from ...schema.untrusted_string import UntrustedString +from ...strings import PythonCode, PythonIdentifier +from .protocol import PropertyProtocol, Value, convert_example @define @@ -15,12 +16,12 @@ class AnyProperty(PropertyProtocol): @classmethod def build( cls, - name: str, + name: UntrustedString, required: bool, default: Any, python_name: PythonIdentifier, - description: str | None, - example: str | None, + description: UntrustedString | None, + example: Any, ) -> AnyProperty: return cls( name=name, @@ -33,15 +34,19 @@ def build( @classmethod def convert_value(cls, value: Any) -> Value | None: - if value is None or isinstance(value, Value): + from .string import StringProperty # noqa: PLC0415 + + if value is None: return value - return Value(str(value)) + if isinstance(value, str): + return StringProperty.convert_value(value) + return Value(python_code=PythonCode(str(value)), raw_value=value) - name: str + name: UntrustedString required: bool default: Value | None python_name: PythonIdentifier - description: str | None - example: str | None + description: UntrustedString | None + example: UntrustedString | None = field(converter=convert_example) _type_string: ClassVar[str] = "Any" _json_type_string: ClassVar[str] = "Any" diff --git a/openapi_python_client/parser/properties/boolean.py b/openapi_python_client/parser/properties/boolean.py index e6bb883a8..7c9b1941e 100644 --- a/openapi_python_client/parser/properties/boolean.py +++ b/openapi_python_client/parser/properties/boolean.py @@ -2,24 +2,24 @@ from typing import Any, ClassVar -from attr import define +from attr import define, field from ... import schema as oai -from ...utils import PythonIdentifier +from ...strings import PythonCode, PythonIdentifier from ..errors import PropertyError -from .protocol import PropertyProtocol, Value +from .protocol import PropertyProtocol, Value, convert_example @define class BooleanProperty(PropertyProtocol): """Property for bool""" - name: str + name: oai.UntrustedString required: bool default: Value | None python_name: PythonIdentifier - description: str | None - example: str | None + description: oai.UntrustedString | None + example: oai.UntrustedString | None = field(converter=convert_example) _type_string: ClassVar[str] = "bool" _json_type_string: ClassVar[str] = "bool" @@ -34,12 +34,12 @@ class BooleanProperty(PropertyProtocol): @classmethod def build( cls, - name: str, + name: oai.UntrustedString, required: bool, default: Any, python_name: PythonIdentifier, - description: str | None, - example: str | None, + description: oai.UntrustedString | None, + example: Any, ) -> BooleanProperty | PropertyError: checked_default = cls.convert_value(default) if isinstance(checked_default, PropertyError): @@ -54,14 +54,14 @@ def build( ) @classmethod - def convert_value(cls, value: Any) -> Value | None | PropertyError: + def convert_value(cls, value: Any) -> Value | PropertyError | None: if isinstance(value, Value) or value is None: return value if isinstance(value, str): if value.lower() == "true": - return Value("True") + return Value(python_code=PythonCode("True"), raw_value=value) elif value.lower() == "false": - return Value("False") + return Value(python_code=PythonCode("False"), raw_value=value) if isinstance(value, bool): - return Value(str(value)) + return Value(python_code=PythonCode(str(value)), raw_value=value) return PropertyError(f"Invalid boolean value: {value}") diff --git a/openapi_python_client/parser/properties/const.py b/openapi_python_client/parser/properties/const.py index aec624afd..9480c3e05 100644 --- a/openapi_python_client/parser/properties/const.py +++ b/openapi_python_client/parser/properties/const.py @@ -4,7 +4,8 @@ from attr import define -from ...utils import PythonIdentifier +from ... import schema as oai +from ...strings import PythonCode, PythonIdentifier from ..errors import PropertyError from .protocol import PropertyProtocol, Value from .string import StringProperty @@ -14,12 +15,12 @@ class ConstProperty(PropertyProtocol): """A property representing a const value""" - name: str + name: oai.UntrustedString required: bool value: Value default: Value | None python_name: PythonIdentifier - description: str | None + description: oai.UntrustedString | None example: None template: ClassVar[str] = "const_property.py.jinja" @@ -27,12 +28,12 @@ class ConstProperty(PropertyProtocol): def build( cls, *, - const: str | int, + const: str | int | float | bool, default: Any, - name: str, + name: oai.UntrustedString, python_name: PythonIdentifier, required: bool, - description: str | None, + description: oai.UntrustedString | None, ) -> ConstProperty | PropertyError: """ Create a `ConstProperty` the right way. @@ -62,14 +63,14 @@ def build( prop.default = converted_default return prop - def convert_value(self, value: Any) -> Value | None | PropertyError: - if isinstance(value, Value): - return value + def convert_value(self, value: Any) -> Value | PropertyError | None: value = self._convert_value(value) if value is None: return value if value != self.value: - return PropertyError(detail=f"Invalid value for const {self.name}; {value} != {self.value}") + return PropertyError( + detail=f"Invalid value for const {self.name}; {value.raw_value} != {self.value.raw_value}" + ) return value @staticmethod @@ -85,23 +86,18 @@ def _convert_value(value: Any) -> Value: ... # pragma: no cover def _convert_value(value: Any) -> Value | None: if value is None or isinstance(value, Value): return value - if isinstance(value, Value): - return value # pragma: no cover if isinstance(value, str): return StringProperty.convert_value(value) - return Value(str(value)) + return Value(python_code=PythonCode(str(value)), raw_value=value) def get_type_string( self, no_optional: bool = False, json: bool = False, - *, - multipart: bool = False, - quoted: bool = False, - ) -> str: - lit = f"Literal[{self.value}]" + ) -> PythonCode: + lit = PythonCode(f"Literal[{self.value.python_code.as_unembedded_code()}]") if not no_optional and not self.required: - return f"Union[{lit}, Unset]" + return PythonCode(f"{lit.as_unembedded_code()} | Unset") return lit def get_imports(self, *, prefix: str) -> set[str]: @@ -113,8 +109,8 @@ def get_imports(self, *, prefix: str) -> set[str]: back to the root of the generated client. """ if self.required: - return {"from typing import Literal"} + return {"from typing import Literal, cast"} return { - "from typing import Literal, Union", + "from typing import Literal, cast", f"from {prefix}types import UNSET, Unset", } diff --git a/openapi_python_client/parser/properties/date.py b/openapi_python_client/parser/properties/date.py index 24e0c34fe..ab0c4b21a 100644 --- a/openapi_python_client/parser/properties/date.py +++ b/openapi_python_client/parser/properties/date.py @@ -1,25 +1,26 @@ from __future__ import annotations +import datetime from typing import Any, ClassVar -from attr import define -from dateutil.parser import isoparse +from attr import define, field -from ...utils import PythonIdentifier +from ... import schema as oai +from ...strings import PythonCode, PythonIdentifier from ..errors import PropertyError -from .protocol import PropertyProtocol, Value +from .protocol import PropertyProtocol, Value, convert_example @define class DateProperty(PropertyProtocol): """A property of type datetime.date""" - name: str + name: oai.UntrustedString required: bool default: Value | None python_name: PythonIdentifier - description: str | None - example: str | None + description: oai.UntrustedString | None + example: oai.UntrustedString | None = field(converter=convert_example) _type_string: ClassVar[str] = "datetime.date" _json_type_string: ClassVar[str] = "str" @@ -28,12 +29,12 @@ class DateProperty(PropertyProtocol): @classmethod def build( cls, - name: str, + name: oai.UntrustedString, required: bool, default: Any, python_name: PythonIdentifier, - description: str | None, - example: str | None, + description: oai.UntrustedString | None, + example: Any, ) -> DateProperty | PropertyError: checked_default = cls.convert_value(default) if isinstance(checked_default, PropertyError): @@ -49,15 +50,15 @@ def build( ) @classmethod - def convert_value(cls, value: Any) -> Value | None | PropertyError: + def convert_value(cls, value: Any) -> Value | PropertyError | None: if isinstance(value, Value) or value is None: return value if isinstance(value, str): try: - isoparse(value).date() # make sure it's a valid value + datetime.date.fromisoformat(value) # make sure it's a valid value except ValueError as e: return PropertyError(f"Invalid date: {e}") - return Value(f"isoparse({value!r}).date()") + return Value(python_code=PythonCode(f"datetime.date.fromisoformat({value!r})"), raw_value=value) return PropertyError(f"Cannot convert {value} to a date") def get_imports(self, *, prefix: str) -> set[str]: @@ -69,5 +70,5 @@ def get_imports(self, *, prefix: str) -> set[str]: back to the root of the generated client. """ imports = super().get_imports(prefix=prefix) - imports.update({"import datetime", "from typing import cast", "from dateutil.parser import isoparse"}) + imports.update({"import datetime", "from typing import cast"}) return imports diff --git a/openapi_python_client/parser/properties/datetime.py b/openapi_python_client/parser/properties/datetime.py index abb28ac22..c5b773979 100644 --- a/openapi_python_client/parser/properties/datetime.py +++ b/openapi_python_client/parser/properties/datetime.py @@ -1,13 +1,14 @@ from __future__ import annotations +import datetime from typing import Any, ClassVar -from attr import define -from dateutil.parser import isoparse +from attr import define, field -from ...utils import PythonIdentifier +from ... import schema as oai +from ...strings import PythonCode, PythonIdentifier from ..errors import PropertyError -from .protocol import PropertyProtocol, Value +from .protocol import PropertyProtocol, Value, convert_example @define @@ -16,12 +17,12 @@ class DateTimeProperty(PropertyProtocol): A property of type datetime.datetime """ - name: str + name: oai.UntrustedString required: bool default: Value | None python_name: PythonIdentifier - description: str | None - example: str | None + description: oai.UntrustedString | None + example: oai.UntrustedString | None = field(converter=convert_example) _type_string: ClassVar[str] = "datetime.datetime" _json_type_string: ClassVar[str] = "str" @@ -30,12 +31,12 @@ class DateTimeProperty(PropertyProtocol): @classmethod def build( cls, - name: str, + name: oai.UntrustedString, required: bool, default: Any, python_name: PythonIdentifier, - description: str | None, - example: str | None, + description: oai.UntrustedString | None, + example: Any, ) -> DateTimeProperty | PropertyError: checked_default = cls.convert_value(default) if isinstance(checked_default, PropertyError): @@ -51,15 +52,15 @@ def build( ) @classmethod - def convert_value(cls, value: Any) -> Value | None | PropertyError: + def convert_value(cls, value: Any) -> Value | PropertyError | None: if value is None or isinstance(value, Value): return value if isinstance(value, str): try: - isoparse(value) # make sure it's a valid value + datetime.datetime.fromisoformat(value) # make sure it's a valid value except ValueError as e: return PropertyError(f"Invalid datetime: {e}") - return Value(f"isoparse({value!r})") + return Value(python_code=PythonCode(f"datetime.datetime.fromisoformat({value!r})"), raw_value=value) return PropertyError(f"Cannot convert {value} to a datetime") def get_imports(self, *, prefix: str) -> set[str]: @@ -71,5 +72,5 @@ def get_imports(self, *, prefix: str) -> set[str]: back to the root of the generated client. """ imports = super().get_imports(prefix=prefix) - imports.update({"import datetime", "from typing import cast", "from dateutil.parser import isoparse"}) + imports.update({"import datetime", "from typing import cast"}) return imports diff --git a/openapi_python_client/parser/properties/enum_property.py b/openapi_python_client/parser/properties/enum_property.py index 0f0db0d61..573d5f0d8 100644 --- a/openapi_python_client/parser/properties/enum_property.py +++ b/openapi_python_client/parser/properties/enum_property.py @@ -1,34 +1,34 @@ from __future__ import annotations -__all__ = ["EnumProperty"] +__all__ = ["EnumProperty", "ValueType"] -from typing import Any, ClassVar, List, Union, cast +from typing import Any, ClassVar, cast from attr import evolve -from attrs import define +from attrs import define, field -from ... import Config, utils +from ... import Config, strings from ... import schema as oai from ...schema import DataType from ..errors import PropertyError from .none import NoneProperty -from .protocol import PropertyProtocol, Value +from .protocol import PropertyProtocol, Value, convert_example from .schemas import Class, Schemas from .union import UnionProperty -ValueType = Union[str, int] +ValueType = str | int @define class EnumProperty(PropertyProtocol): """A property that should use an enum""" - name: str + name: oai.UntrustedString required: bool default: Value | None - python_name: utils.PythonIdentifier - description: str | None - example: str | None + python_name: strings.PythonIdentifier + description: oai.UntrustedString | None + example: oai.UntrustedString | None = field(converter=convert_example) values: dict[str, ValueType] class_info: Class value_type: type[ValueType] @@ -47,7 +47,7 @@ def build( # noqa: PLR0911 cls, *, data: oai.Schema, - name: str, + name: oai.UntrustedString, required: bool, schemas: Schemas, parent_name: str, @@ -83,7 +83,7 @@ def build( # noqa: PLR0911 name=name, required=required, default="None", - python_name=utils.PythonIdentifier(value=name, prefix=config.field_prefix), + python_name=strings.PythonIdentifier(value=name, prefix=config.field_prefix), description=None, example=None, ), @@ -98,9 +98,7 @@ def build( # noqa: PLR0911 value_type = next(iter(value_types)) if value_type not in (str, int): return PropertyError(header=f"Unsupported enum type {value_type}", data=data), schemas - value_list = cast( - Union[List[int], List[str]], unchecked_value_list - ) # We checked this with all the value_types stuff + value_list = cast(list[int] | list[str], unchecked_value_list) # We checked this with all the value_types stuff if len(value_list) < len(enum): # Only one of the values was None, that becomes a union data.oneOf = [ @@ -117,11 +115,12 @@ def build( # noqa: PLR0911 config=config, ) - class_name = data.title or name + class_name: str | oai.UntrustedString = data.title or name if parent_name: - class_name = f"{utils.pascal_case(parent_name)}{utils.pascal_case(class_name)}" + class_name = f"{strings.pascal_case(parent_name)}{strings.pascal_case(class_name)}" class_info = Class.from_string(string=class_name, config=config) - values = EnumProperty.values_from_list(value_list) + var_names = data.model_extra.get("x-enum-varnames", []) if data.model_extra else [] + values = EnumProperty.values_from_list(value_list, class_info, var_names) if class_info.name in schemas.classes_by_name: existing = schemas.classes_by_name[class_info.name] @@ -140,7 +139,7 @@ def build( # noqa: PLR0911 values=values, value_type=value_type, default=None, - python_name=utils.PythonIdentifier(value=name, prefix=config.field_prefix), + python_name=strings.PythonIdentifier(value=name, prefix=config.field_prefix), description=data.description, example=data.example, ) @@ -159,16 +158,19 @@ def convert_value(self, value: Any) -> Value | PropertyError | None: if isinstance(value, self.value_type): inverse_values = {v: k for k, v in self.values.items()} try: - return Value(f"{self.class_info.name}.{inverse_values[value]}") + return Value( + python_code=strings.PythonCode(f"{self.class_info.name}.{inverse_values[value]}"), + raw_value=value, + ) except KeyError: return PropertyError(detail=f"Value {value} is not valid for enum {self.name}") return PropertyError(detail=f"Cannot convert {value} to enum {self.name} of type {self.value_type}") - def get_base_type_string(self, *, quoted: bool = False) -> str: - return self.class_info.name + def get_base_type_string(self) -> strings.PythonCode: + return strings.PythonCode(self.class_info.name) - def get_base_json_type_string(self, *, quoted: bool = False) -> str: - return self.value_type.__name__ + def get_base_json_type_string(self) -> strings.PythonCode: + return strings.PythonCode(self.value_type.__name__) def get_imports(self, *, prefix: str) -> set[str]: """ @@ -183,24 +185,36 @@ def get_imports(self, *, prefix: str) -> set[str]: return imports @staticmethod - def values_from_list(values: list[str] | list[int]) -> dict[str, ValueType]: + def values_from_list( + values: list[str] | list[int], class_info: Class, var_names: list[str] + ) -> dict[str, ValueType]: """Convert a list of values into dict of {name: value}, where value can sometimes be None""" output: dict[str, ValueType] = {} + use_var_names = len(var_names) == len(values) for i, value in enumerate(values): - value = cast(Union[str, int], value) + value = cast(str | int, value) if isinstance(value, int): - if value < 0: + if use_var_names: + key = var_names[i] + sanitized_key = strings.snake_case(key).upper() + output[sanitized_key] = value + elif value < 0: output[f"VALUE_NEGATIVE_{-value}"] = value else: output[f"VALUE_{value}"] = value continue - if value and value[0].isalpha(): + if use_var_names: + key = var_names[i] + elif value and value[0].isalpha(): key = value.upper() else: key = f"VALUE_{i}" if key in output: - raise ValueError(f"Duplicate key {key} in Enum") - sanitized_key = utils.snake_case(key).upper() - output[sanitized_key] = utils.remove_string_escapes(value) + raise ValueError( + f"Duplicate key {key} in enum {class_info.module_name}.{class_info.name}; " + f"consider setting literal_enums in your config" + ) + sanitized_key = strings.snake_case(key).upper() + output[sanitized_key] = strings.in_double_quote_literal(value) return output diff --git a/openapi_python_client/parser/properties/file.py b/openapi_python_client/parser/properties/file.py index 505876b63..eb1f6b0ab 100644 --- a/openapi_python_client/parser/properties/file.py +++ b/openapi_python_client/parser/properties/file.py @@ -2,38 +2,39 @@ from typing import Any, ClassVar -from attr import define +from attr import define, field -from ...utils import PythonIdentifier +from ... import schema as oai +from ...strings import PythonIdentifier from ..errors import PropertyError -from .protocol import PropertyProtocol +from .protocol import PropertyProtocol, convert_example @define class FileProperty(PropertyProtocol): """A property used for uploading files""" - name: str + name: oai.UntrustedString required: bool default: None python_name: PythonIdentifier - description: str | None - example: str | None + description: oai.UntrustedString | None + example: oai.UntrustedString | None = field(converter=convert_example) _type_string: ClassVar[str] = "File" # Return type of File.to_tuple() - _json_type_string: ClassVar[str] = "FileJsonType" + _json_type_string: ClassVar[str] = "FileTypes" template: ClassVar[str] = "file_property.py.jinja" @classmethod def build( cls, - name: str, + name: oai.UntrustedString, required: bool, default: Any, python_name: PythonIdentifier, - description: str | None, - example: str | None, + description: oai.UntrustedString | None, + example: Any, ) -> FileProperty | PropertyError: default_or_err = cls.convert_value(default) if isinstance(default_or_err, PropertyError): @@ -49,7 +50,7 @@ def build( ) @classmethod - def convert_value(cls, value: Any) -> None | PropertyError: + def convert_value(cls, value: Any) -> PropertyError | None: if value is not None: return PropertyError(detail="File properties cannot have a default value") return value @@ -63,5 +64,5 @@ def get_imports(self, *, prefix: str) -> set[str]: back to the root of the generated client. """ imports = super().get_imports(prefix=prefix) - imports.update({f"from {prefix}types import File, FileJsonType", "from io import BytesIO"}) + imports.update({f"from {prefix}types import File, FileTypes", "from io import BytesIO"}) return imports diff --git a/openapi_python_client/parser/properties/float.py b/openapi_python_client/parser/properties/float.py index d8f469c69..0d5caa72a 100644 --- a/openapi_python_client/parser/properties/float.py +++ b/openapi_python_client/parser/properties/float.py @@ -2,24 +2,24 @@ from typing import Any, ClassVar -from attr import define +from attr import define, field from ... import schema as oai -from ...utils import PythonIdentifier +from ...strings import PythonCode, PythonIdentifier from ..errors import PropertyError -from .protocol import PropertyProtocol, Value +from .protocol import PropertyProtocol, Value, convert_example @define class FloatProperty(PropertyProtocol): """A property of type float""" - name: str + name: oai.UntrustedString required: bool default: Value | None python_name: PythonIdentifier - description: str | None - example: str | None + description: oai.UntrustedString | None + example: oai.UntrustedString | None = field(converter=convert_example) _type_string: ClassVar[str] = "float" _json_type_string: ClassVar[str] = "float" @@ -34,12 +34,12 @@ class FloatProperty(PropertyProtocol): @classmethod def build( cls, - name: str, + name: oai.UntrustedString, required: bool, default: Any, python_name: PythonIdentifier, - description: str | None, - example: str | None, + description: oai.UntrustedString | None, + example: Any, ) -> FloatProperty | PropertyError: checked_default = cls.convert_value(default) if isinstance(checked_default, PropertyError): @@ -55,17 +55,17 @@ def build( ) @classmethod - def convert_value(cls, value: Any) -> Value | None | PropertyError: + def convert_value(cls, value: Any) -> Value | PropertyError | None: if isinstance(value, Value) or value is None: return value if isinstance(value, str): try: parsed = float(value) - return Value(str(parsed)) + return Value(python_code=PythonCode(str(parsed)), raw_value=value) except ValueError: return PropertyError(f"Invalid float value: {value}") if isinstance(value, float): - return Value(str(value)) + return Value(python_code=PythonCode(str(value)), raw_value=value) if isinstance(value, int) and not isinstance(value, bool): - return Value(str(float(value))) + return Value(python_code=PythonCode(str(float(value))), raw_value=value) return PropertyError(f"Cannot convert {value} to a float") diff --git a/openapi_python_client/parser/properties/int.py b/openapi_python_client/parser/properties/int.py index ab7173d3d..579564f24 100644 --- a/openapi_python_client/parser/properties/int.py +++ b/openapi_python_client/parser/properties/int.py @@ -2,24 +2,24 @@ from typing import Any, ClassVar -from attr import define +from attr import define, field from ... import schema as oai -from ...utils import PythonIdentifier +from ...strings import PythonCode, PythonIdentifier from ..errors import PropertyError -from .protocol import PropertyProtocol, Value +from .protocol import PropertyProtocol, Value, convert_example @define class IntProperty(PropertyProtocol): """A property of type int""" - name: str + name: oai.UntrustedString required: bool default: Value | None python_name: PythonIdentifier - description: str | None - example: str | None + description: oai.UntrustedString | None + example: oai.UntrustedString | None = field(converter=convert_example) _type_string: ClassVar[str] = "int" _json_type_string: ClassVar[str] = "int" @@ -34,12 +34,12 @@ class IntProperty(PropertyProtocol): @classmethod def build( cls, - name: str, + name: oai.UntrustedString, required: bool, default: Any, python_name: PythonIdentifier, - description: str | None, - example: str | None, + description: oai.UntrustedString | None, + example: Any, ) -> IntProperty | PropertyError: checked_default = cls.convert_value(default) if isinstance(checked_default, PropertyError): @@ -55,15 +55,19 @@ def build( ) @classmethod - def convert_value(cls, value: Any) -> Value | None | PropertyError: + def convert_value(cls, value: Any) -> Value | PropertyError | None: if value is None or isinstance(value, Value): return value - if isinstance(value, str): + converted = value + if isinstance(converted, str): try: - int(value) + converted = float(converted) except ValueError: - return PropertyError(f"Invalid int value: {value}") - return Value(value) - if isinstance(value, int) and not isinstance(value, bool): - return Value(str(value)) + return PropertyError(f"Invalid int value: {converted}") + if isinstance(converted, float): + as_int = int(converted) + if converted == as_int: + converted = as_int + if isinstance(converted, int) and not isinstance(converted, bool): + return Value(python_code=PythonCode(str(converted)), raw_value=value) return PropertyError(f"Invalid int value: {value}") diff --git a/openapi_python_client/parser/properties/list_property.py b/openapi_python_client/parser/properties/list_property.py index c78e50513..e331cddb4 100644 --- a/openapi_python_client/parser/properties/list_property.py +++ b/openapi_python_client/parser/properties/list_property.py @@ -2,12 +2,12 @@ from typing import Any, ClassVar -from attr import define +from attr import define, field -from ... import Config, utils +from ... import Config, strings from ... import schema as oai from ..errors import PropertyError -from .protocol import PropertyProtocol, Value +from .protocol import PropertyProtocol, Value, convert_example from .schemas import ReferencePath, Schemas @@ -15,12 +15,12 @@ class ListProperty(PropertyProtocol): """A property representing a list (array) of other properties""" - name: str + name: oai.UntrustedString required: bool default: Value | None - python_name: utils.PythonIdentifier - description: str | None - example: str | None + python_name: strings.PythonIdentifier + description: oai.UntrustedString | None + example: oai.UntrustedString | None = field(converter=convert_example) inner_property: PropertyProtocol template: ClassVar[str] = "list_property.py.jinja" @@ -29,13 +29,13 @@ def build( cls, *, data: oai.Schema, - name: str, + name: oai.UntrustedString, required: bool, schemas: Schemas, parent_name: str, config: Config, process_properties: bool, - roots: set[ReferencePath | utils.ClassName], + roots: set[ReferencePath | strings.ClassName], ) -> tuple[ListProperty | PropertyError, Schemas]: """ Build a ListProperty the right way, use this instead of the normal constructor. @@ -56,14 +56,30 @@ def build( `(result, schemas)` where `schemas` is an updated version of the input named the same including any inner classes that were defined and `result` is either the `ListProperty` or a `PropertyError`. """ - from . import property_from_data + from . import property_from_data # noqa: PLC0415 + + if data.items is None and not data.prefixItems: + return ( + PropertyError( + data=data, + detail="type array must have items or prefixItems defined", + ), + schemas, + ) + + items = data.prefixItems or [] + if data.items: + items.append(data.items) + + if len(items) == 1: + inner_schema = items[0] + else: + inner_schema = oai.Schema(anyOf=items) - if data.items is None: - return PropertyError(data=data, detail="type array must have items defined"), schemas inner_prop, schemas = property_from_data( - name=f"{name}_item", + name=oai.UntrustedString(f"{name.get_untrusted_value()}_item"), required=True, - data=data.items, + data=inner_schema, schemas=schemas, parent_name=parent_name, config=config, @@ -79,25 +95,25 @@ def build( required=required, default=None, inner_property=inner_prop, - python_name=utils.PythonIdentifier(value=name, prefix=config.field_prefix), + python_name=strings.PythonIdentifier(value=name, prefix=config.field_prefix), description=data.description, example=data.example, ), schemas, ) - def convert_value(self, value: Any) -> Value | None | PropertyError: + def convert_value(self, value: Any) -> Value | PropertyError | None: return None # pragma: no cover - def get_base_type_string(self, *, quoted: bool = False) -> str: - return f"List[{self.inner_property.get_type_string(quoted=not self.inner_property.is_base_type)}]" + def get_base_type_string(self) -> strings.PythonCode: + return strings.PythonCode(f"list[{self.inner_property.get_type_string().as_unembedded_code()}]") - def get_base_json_type_string(self, *, quoted: bool = False) -> str: - return f"List[{self.inner_property.get_type_string(json=True, quoted=not self.inner_property.is_base_type)}]" + def get_base_json_type_string(self) -> strings.PythonCode: + return strings.PythonCode(f"list[{self.inner_property.get_type_string(json=True).as_unembedded_code()}]") - def get_instance_type_string(self) -> str: - """Get a string representation of runtime type that should be used for `isinstance` checks""" - return "list" + def get_instance_type_string(self) -> strings.PythonCode: + """Get a code representation of runtime type that should be used for `isinstance` checks""" + return strings.PythonCode("list") def get_imports(self, *, prefix: str) -> set[str]: """ @@ -109,7 +125,7 @@ def get_imports(self, *, prefix: str) -> set[str]: """ imports = super().get_imports(prefix=prefix) imports.update(self.inner_property.get_imports(prefix=prefix)) - imports.add("from typing import cast, List") + imports.add("from typing import cast") return imports def get_lazy_imports(self, *, prefix: str) -> set[str]: @@ -121,12 +137,9 @@ def get_type_string( self, no_optional: bool = False, json: bool = False, - *, - multipart: bool = False, - quoted: bool = False, - ) -> str: + ) -> strings.PythonCode: """ - Get a string representation of type that should be used when declaring this property + Get a Python code representation of type that should be used when declaring this property Args: no_optional: Do not include Optional or Unset even if the value is optional (needed for isinstance checks) @@ -134,11 +147,9 @@ def get_type_string( """ if json: type_string = self.get_base_json_type_string() - elif multipart: - type_string = "Tuple[None, bytes, str]" else: type_string = self.get_base_type_string() if no_optional or self.required: return type_string - return f"Union[Unset, {type_string}]" + return strings.PythonCode(f"{type_string.as_unembedded_code()} | Unset") diff --git a/openapi_python_client/parser/properties/literal_enum_property.py b/openapi_python_client/parser/properties/literal_enum_property.py new file mode 100644 index 000000000..0388fe04e --- /dev/null +++ b/openapi_python_client/parser/properties/literal_enum_property.py @@ -0,0 +1,189 @@ +from __future__ import annotations + +__all__ = ["LiteralEnumProperty"] + +from typing import Any, ClassVar, cast + +from attr import evolve +from attrs import define, field + +from ... import Config, strings +from ... import schema as oai +from ...schema import DataType +from ..errors import PropertyError +from .none import NoneProperty +from .protocol import PropertyProtocol, Value, convert_example +from .schemas import Class, Schemas +from .union import UnionProperty + +ValueType = str | int + + +@define +class LiteralEnumProperty(PropertyProtocol): + """A property that should use a literal enum""" + + name: oai.UntrustedString + required: bool + default: Value | None + python_name: strings.PythonIdentifier + description: oai.UntrustedString | None + example: oai.UntrustedString | None = field(converter=convert_example) + values: set[ValueType] + class_info: Class + value_type: type[ValueType] + + template: ClassVar[str] = "literal_enum_property.py.jinja" + + _allowed_locations: ClassVar[set[oai.ParameterLocation]] = { + oai.ParameterLocation.QUERY, + oai.ParameterLocation.PATH, + oai.ParameterLocation.COOKIE, + oai.ParameterLocation.HEADER, + } + + @classmethod + def build( # noqa: PLR0911 + cls, + *, + data: oai.Schema, + name: oai.UntrustedString, + required: bool, + schemas: Schemas, + parent_name: str, + config: Config, + ) -> tuple[LiteralEnumProperty | NoneProperty | UnionProperty | PropertyError, Schemas]: + """ + Create a LiteralEnumProperty from schema data. + + Args: + data: The OpenAPI Schema which defines this enum. + name: The name to use for variables which receive this Enum's value (e.g. model property name) + required: Whether or not this Property is required in the calling context + schemas: The Schemas which have been defined so far (used to prevent naming collisions) + parent_name: The context in which this LiteralEnumProperty is defined, used to create more specific class names. + config: The global config for this run of the generator + + Returns: + A tuple containing either the created property or a PropertyError AND update schemas. + """ + + enum = data.enum or [] # The outer function checks for this, but mypy doesn't know that + + # OpenAPI allows for null as an enum value, but it doesn't make sense with how enums are constructed in Python. + # So instead, if null is a possible value, make the property nullable. + # Mypy is not smart enough to know that the type is right though + unchecked_value_list = [value for value in enum if value is not None] # type: ignore + + # It's legal to have an enum that only contains null as a value, we don't bother constructing an enum for that + if len(unchecked_value_list) == 0: + return ( + NoneProperty.build( + name=name, + required=required, + default="None", + python_name=strings.PythonIdentifier(value=name, prefix=config.field_prefix), + description=None, + example=None, + ), + schemas, + ) + + value_types = {type(value) for value in unchecked_value_list} + if len(value_types) > 1: + return PropertyError( + header="Enum values must all be the same type", detail=f"Got {value_types}", data=data + ), schemas + value_type = next(iter(value_types)) + if value_type not in (str, int): + return PropertyError(header=f"Unsupported enum type {value_type}", data=data), schemas + value_list = cast(list[int] | list[str], unchecked_value_list) # We checked this with all the value_types stuff + + if len(value_list) < len(enum): # Only one of the values was None, that becomes a union + data.oneOf = [ + oai.Schema(type=DataType.NULL), + data.model_copy(update={"enum": value_list, "default": data.default}), + ] + data.enum = None + return UnionProperty.build( + data=data, + name=name, + required=required, + schemas=schemas, + parent_name=parent_name, + config=config, + ) + + class_name: str | oai.UntrustedString = data.title or name + if parent_name: + class_name = f"{strings.pascal_case(parent_name)}{strings.pascal_case(class_name)}" + class_info = Class.from_string(string=class_name, config=config) + values: set[str | int] = set(value_list) + + if class_info.name in schemas.classes_by_name: + existing = schemas.classes_by_name[class_info.name] + if not isinstance(existing, LiteralEnumProperty) or values != existing.values: + return ( + PropertyError( + detail=f"Found conflicting enums named {class_info.name} with incompatible values.", data=data + ), + schemas, + ) + + prop = LiteralEnumProperty( + name=name, + required=required, + class_info=class_info, + values=values, + value_type=value_type, + default=None, + python_name=strings.PythonIdentifier(value=name, prefix=config.field_prefix), + description=data.description, + example=data.example, + ) + checked_default = prop.convert_value(data.default) + if isinstance(checked_default, PropertyError): + checked_default.data = data + return checked_default, schemas + prop = evolve(prop, default=checked_default) + + schemas = evolve(schemas, classes_by_name={**schemas.classes_by_name, class_info.name: prop}) + return prop, schemas + + def convert_value(self, value: Any) -> Value | PropertyError | None: + if value is None or isinstance(value, Value): + return value + if isinstance(value, self.value_type): + if value in self.values: + return Value(python_code=strings.PythonCode(repr(value)), raw_value=value) + else: + return PropertyError(detail=f"Value {value} is not valid for enum {self.name}") + return PropertyError(detail=f"Cannot convert {value} to enum {self.name} of type {self.value_type}") + + def get_base_type_string(self) -> strings.PythonCode: + return strings.PythonCode(self.class_info.name) + + def get_base_json_type_string(self) -> strings.PythonCode: + return strings.PythonCode(self.value_type.__name__) + + def get_instance_type_string(self) -> strings.PythonCode: + return strings.PythonCode(self.value_type.__name__) + + def get_imports(self, *, prefix: str) -> set[str]: + """ + Get a set of import strings that should be included when this property is used somewhere + + Args: + prefix: A prefix to put before any relative (local) module names. This should be the number of . to get + back to the root of the generated client. + """ + imports = super().get_imports(prefix=prefix) + imports.add("from typing import cast") + imports.add(f"from {prefix}models.{self.class_info.module_name} import {self.class_info.name}") + imports.add( + f"from {prefix}models.{self.class_info.module_name} import check_{self.get_class_name_snake_case()}" + ) + return imports + + def get_class_name_snake_case(self) -> str: + return strings.snake_case(self.class_info.name) diff --git a/openapi_python_client/parser/properties/merge_properties.py b/openapi_python_client/parser/properties/merge_properties.py new file mode 100644 index 000000000..2ccf7f9e4 --- /dev/null +++ b/openapi_python_client/parser/properties/merge_properties.py @@ -0,0 +1,201 @@ +from __future__ import annotations + +from openapi_python_client.parser.properties.date import DateProperty +from openapi_python_client.parser.properties.datetime import DateTimeProperty +from openapi_python_client.parser.properties.file import FileProperty +from openapi_python_client.parser.properties.literal_enum_property import LiteralEnumProperty + +__all__ = ["merge_properties"] + +from typing import TypeVar, cast + +from attr import evolve + +from ..errors import PropertyError +from . import FloatProperty +from .any import AnyProperty +from .enum_property import EnumProperty +from .int import IntProperty +from .list_property import ListProperty +from .property import Property +from .protocol import PropertyProtocol +from .string import StringProperty + +PropertyT = TypeVar("PropertyT", bound=PropertyProtocol) + + +STRING_WITH_FORMAT_TYPES = (DateProperty, DateTimeProperty, FileProperty) + + +def merge_properties(prop1: Property, prop2: Property) -> Property | PropertyError: # noqa: PLR0911 + """Attempt to create a new property that incorporates the behavior of both. + + This is used when merging schemas with allOf, when two schemas define a property with the same name. + + OpenAPI defines allOf in terms of validation behavior: the input must pass the validation rules + defined in all the listed schemas. Our task here is slightly more difficult, since we must end + up with a single Property object that will be used to generate a single class property in the + generated code. Due to limitations of our internal model, this may not be possible for some + combinations of property attributes that OpenAPI supports (for instance, we have no way to represent + a string property that must match two different regexes). + + Properties can also have attributes that do not represent validation rules, such as "description" + and "example". OpenAPI does not define any overriding/aggregation rules for these in allOf. The + implementation here is, assuming prop1 and prop2 are in the same order that the schemas were in the + allOf, any such attributes that prop2 specifies will override the ones from prop1. + """ + if isinstance(prop2, AnyProperty): + return _merge_common_attributes(prop1, prop2) + + if isinstance(prop1, AnyProperty): + # Use the base type of `prop2`, but keep the override order + return _merge_common_attributes(prop2, prop1, prop2) + + if isinstance(prop1, EnumProperty) or isinstance(prop2, EnumProperty): + return _merge_with_enum(prop1, prop2) + + if isinstance(prop1, LiteralEnumProperty) or isinstance(prop2, LiteralEnumProperty): + return _merge_with_literal_enum(prop1, prop2) + + if (merged := _merge_same_type(prop1, prop2)) is not None: + return merged + + if (merged := _merge_numeric(prop1, prop2)) is not None: + return merged + + if (merged := _merge_string_with_format(prop1, prop2)) is not None: + return merged + + return PropertyError( + detail=f"{prop1.get_type_string(no_optional=True).as_unembedded_code()} can't be merged with " + f"{prop2.get_type_string(no_optional=True).as_unembedded_code()}" + ) + + +def _merge_same_type(prop1: Property, prop2: Property) -> Property | PropertyError | None: + if type(prop1) is not type(prop2): + return None + + if prop1 == prop2: + # It's always OK to redefine a property with everything exactly the same + return prop1 + + if isinstance(prop1, ListProperty) and isinstance(prop2, ListProperty): + inner_property = merge_properties(prop1.inner_property, prop2.inner_property) # type: ignore + if isinstance(inner_property, PropertyError): + return PropertyError(detail=f"can't merge list properties: {inner_property.detail}") + prop1.inner_property = inner_property + + # For all other property types, there aren't any special attributes that affect validation, so just + # apply the rules for common attributes like "description". + return _merge_common_attributes(prop1, prop2) + + +def _merge_string_with_format(prop1: Property, prop2: Property) -> Property | PropertyError | None: + """Merge a string that has no format with a string that has a format""" + # Here we need to use the DateProperty/DateTimeProperty/FileProperty as the base so that we preserve + # its class, but keep the correct override order for merging the attributes. + if isinstance(prop1, StringProperty) and isinstance(prop2, STRING_WITH_FORMAT_TYPES): + # Use the more specific class as a base, but keep the correct override order + return _merge_common_attributes(prop2, prop1, prop2) + elif isinstance(prop2, StringProperty) and isinstance(prop1, STRING_WITH_FORMAT_TYPES): + return _merge_common_attributes(prop1, prop2) + else: + return None + + +def _merge_numeric(prop1: Property, prop2: Property) -> IntProperty | PropertyError | None: + """Merge IntProperty with FloatProperty""" + if isinstance(prop1, IntProperty) and isinstance(prop2, IntProperty | FloatProperty): + return _merge_common_attributes(prop1, prop2) + elif isinstance(prop2, IntProperty) and isinstance(prop1, IntProperty | FloatProperty): + # Use the IntProperty as a base since it's more restrictive, but keep the correct override order + return _merge_common_attributes(prop2, prop1, prop2) + else: + return None + + +def _merge_with_enum(prop1: PropertyProtocol, prop2: PropertyProtocol) -> EnumProperty | PropertyError: + if isinstance(prop1, EnumProperty) and isinstance(prop2, EnumProperty): + # We want the narrowest validation rules that fit both, so use whichever values list is a + # subset of the other. + if _values_are_subset(prop1, prop2): + values = prop1.values + class_info = prop1.class_info + elif _values_are_subset(prop2, prop1): + values = prop2.values + class_info = prop2.class_info + else: + return PropertyError(detail="can't redefine an enum property with incompatible lists of values") + return _merge_common_attributes(evolve(prop1, values=values, class_info=class_info), prop2) + + # If enum values were specified for just one of the properties, use those. + enum_prop = prop1 if isinstance(prop1, EnumProperty) else cast(EnumProperty, prop2) + non_enum_prop = prop2 if isinstance(prop1, EnumProperty) else prop1 + if (isinstance(non_enum_prop, IntProperty) and enum_prop.value_type is int) or ( + isinstance(non_enum_prop, StringProperty) and enum_prop.value_type is str + ): + return _merge_common_attributes(enum_prop, prop1, prop2) + return PropertyError( + detail=f"can't combine enum of type {enum_prop.value_type} with " + f"{non_enum_prop.get_type_string(no_optional=True).as_unembedded_code()}" + ) + + +def _merge_with_literal_enum(prop1: PropertyProtocol, prop2: PropertyProtocol) -> LiteralEnumProperty | PropertyError: + if isinstance(prop1, LiteralEnumProperty) and isinstance(prop2, LiteralEnumProperty): + # We want the narrowest validation rules that fit both, so use whichever values list is a + # subset of the other. + if prop1.values <= prop2.values: + values = prop1.values + class_info = prop1.class_info + elif prop2.values <= prop1.values: + values = prop2.values + class_info = prop2.class_info + else: + return PropertyError(detail="can't redefine a literal enum property with incompatible lists of values") + return _merge_common_attributes(evolve(prop1, values=values, class_info=class_info), prop2) + + # If enum values were specified for just one of the properties, use those. + enum_prop = prop1 if isinstance(prop1, LiteralEnumProperty) else cast(LiteralEnumProperty, prop2) + non_enum_prop = prop2 if isinstance(prop1, LiteralEnumProperty) else prop1 + if (isinstance(non_enum_prop, IntProperty) and enum_prop.value_type is int) or ( + isinstance(non_enum_prop, StringProperty) and enum_prop.value_type is str + ): + return _merge_common_attributes(enum_prop, prop1, prop2) + return PropertyError( + detail=f"can't combine literal enum of type {enum_prop.value_type} with " + f"{non_enum_prop.get_type_string(no_optional=True).as_unembedded_code()}" + ) + + +def _merge_common_attributes(base: PropertyT, *extend_with: PropertyProtocol) -> PropertyT | PropertyError: + """Create a new instance based on base, overriding basic attributes with values from extend_with, in order. + + For "default", "description", and "example", a non-None value overrides any value from a previously + specified property. The behavior is similar to using the spread operator with dictionaries, except + that None means "not specified". + + For "required", any True value overrides all other values (a property that was previously required + cannot become optional). + """ + current = base + for override in extend_with: + if override.default is not None: + override_default = current.convert_value(override.default.raw_value) + else: + override_default = None + if isinstance(override_default, PropertyError): + return override_default + current = evolve( + current, # type: ignore # can't prove that every property type is an attrs class, but it is + required=current.required or override.required, + default=override_default or current.default, + description=override.description or current.description, + example=override.example or current.example, + ) + return current + + +def _values_are_subset(prop1: EnumProperty, prop2: EnumProperty) -> bool: + return set(prop1.values.items()) <= set(prop2.values.items()) diff --git a/openapi_python_client/parser/properties/model_property.py b/openapi_python_client/parser/properties/model_property.py index bde45ac05..7e3b545e0 100644 --- a/openapi_python_client/parser/properties/model_property.py +++ b/openapi_python_client/parser/properties/model_property.py @@ -3,13 +3,14 @@ from itertools import chain from typing import Any, ClassVar, NamedTuple -from attrs import define, evolve +from attrs import define, evolve, field -from ... import Config, utils +from ... import Config, strings from ... import schema as oai +from ...strings import PythonIdentifier from ..errors import ParseError, PropertyError -from .enum_property import EnumProperty -from .protocol import PropertyProtocol, Value +from .any import AnyProperty +from .protocol import PropertyProtocol, Value, convert_example from .schemas import Class, ReferencePath, Schemas, parse_reference_path @@ -17,21 +18,21 @@ class ModelProperty(PropertyProtocol): """A property which refers to another Schema""" - name: str + name: oai.UntrustedString required: bool default: Value | None - python_name: utils.PythonIdentifier - example: str | None + python_name: strings.PythonIdentifier + example: oai.UntrustedString | None = field(converter=convert_example) class_info: Class data: oai.Schema - description: str - roots: set[ReferencePath | utils.ClassName] + description: oai.UntrustedString | None + roots: set[ReferencePath | strings.ClassName] required_properties: list[Property] | None optional_properties: list[Property] | None relative_imports: set[str] | None lazy_imports: set[str] | None - additional_properties: bool | Property | None - _json_type_string: ClassVar[str] = "Dict[str, Any]" + additional_properties: Property | None + _json_type_string: ClassVar[str] = "dict[str, Any]" template: ClassVar[str] = "model_property.py.jinja" json_is_dict: ClassVar[bool] = True @@ -42,13 +43,13 @@ def build( cls, *, data: oai.Schema, - name: str, + name: oai.UntrustedString, schemas: Schemas, required: bool, parent_name: str | None, config: Config, process_properties: bool, - roots: set[ReferencePath | utils.ClassName], + roots: set[ReferencePath | strings.ClassName], ) -> tuple[ModelProperty | PropertyError, Schemas]: """ A single ModelProperty from its OAI data @@ -64,12 +65,13 @@ def build( roots: Set of strings that identify schema objects on which the new ModelProperty will depend process_properties: Determines whether the new ModelProperty will be initialized with property data """ + class_string: str | oai.UntrustedString if not config.use_path_prefixes_for_title_model_names and data.title: class_string = data.title else: title = data.title or name if parent_name: - class_string = f"{utils.pascal_case(parent_name)}{utils.pascal_case(title)}" + class_string = f"{strings.pascal_case(parent_name)}{strings.pascal_case(title)}" else: class_string = title class_info = Class.from_string(string=class_string, config=config) @@ -78,7 +80,7 @@ def build( optional_properties: list[Property] | None = None relative_imports: set[str] | None = None lazy_imports: set[str] | None = None - additional_properties: bool | Property | None = None + additional_properties: Property | None = None if process_properties: data_or_err, schemas = _process_property_data( data=data, schemas=schemas, class_info=class_info, config=config, roots=model_roots @@ -91,7 +93,7 @@ def build( relative_imports = property_data.relative_imports lazy_imports = property_data.lazy_imports for root in roots: - if isinstance(root, utils.ClassName): + if isinstance(root, strings.ClassName): continue schemas.add_dependencies(root, {class_info.name}) @@ -104,11 +106,11 @@ def build( relative_imports=relative_imports, lazy_imports=lazy_imports, additional_properties=additional_properties, - description=data.description or "", + description=data.description, default=None, required=required, name=name, - python_name=utils.PythonIdentifier(value=name, prefix=config.field_prefix), + python_name=strings.PythonIdentifier(value=name, prefix=config.field_prefix), example=data.example, ) if class_info.name in schemas.classes_by_name: @@ -117,11 +119,15 @@ def build( ) return error, schemas - schemas = evolve(schemas, classes_by_name={**schemas.classes_by_name, class_info.name: prop}) + schemas = evolve( + schemas, + classes_by_name={**schemas.classes_by_name, class_info.name: prop}, + models_to_process=[*schemas.models_to_process, prop], + ) return prop, schemas @classmethod - def convert_value(cls, value: Any) -> Value | None | PropertyError: + def convert_value(cls, value: Any) -> Value | PropertyError | None: if value is not None: return PropertyError(detail="ModelProperty cannot have a default value") # pragma: no cover return None @@ -135,8 +141,8 @@ def self_import(self) -> str: """Constructs a self import statement from this ModelProperty's attributes""" return f"models.{self.class_info.module_name} import {self.class_info.name}" - def get_base_type_string(self, *, quoted: bool = False) -> str: - return f'"{self.class_info.name}"' if quoted else self.class_info.name + def get_base_type_string(self) -> strings.PythonCode: + return strings.PythonCode(self.class_info.name) def get_imports(self, *, prefix: str) -> set[str]: """ @@ -149,7 +155,6 @@ def get_imports(self, *, prefix: str) -> set[str]: imports = super().get_imports(prefix=prefix) imports.update( { - "from typing import Dict", "from typing import cast", } ) @@ -184,12 +189,9 @@ def get_type_string( self, no_optional: bool = False, json: bool = False, - *, - multipart: bool = False, - quoted: bool = False, - ) -> str: + ) -> strings.PythonCode: """ - Get a string representation of type that should be used when declaring this property + Get a Python code representation of type that should be used when declaring this property Args: no_optional: Do not include Optional or Unset even if the value is optional (needed for isinstance checks) @@ -197,76 +199,17 @@ def get_type_string( """ if json: type_string = self.get_base_json_type_string() - elif multipart: - type_string = "Tuple[None, bytes, str]" else: type_string = self.get_base_type_string() - if quoted: - if type_string == self.class_info.name: - type_string = f"'{type_string}'" - if no_optional or self.required: return type_string - return f"Union[Unset, {type_string}]" + return strings.PythonCode(f"{type_string.as_unembedded_code()} | Unset") from .property import Property # noqa: E402 -def _values_are_subset(first: EnumProperty, second: EnumProperty) -> bool: - return set(first.values.items()) <= set(second.values.items()) - - -def _types_are_subset(first: EnumProperty, second: Property) -> bool: - from . import IntProperty, StringProperty - - if first.value_type == int and isinstance(second, IntProperty): - return True - if first.value_type == str and isinstance(second, StringProperty): - return True - return False - - -def _enum_subset(first: Property, second: Property) -> EnumProperty | None: - """Return the EnumProperty that is the subset of the other, if possible.""" - - if isinstance(first, EnumProperty): - if isinstance(second, EnumProperty): - if _values_are_subset(first, second): - return first - if _values_are_subset(second, first): - return second - return None - return first if _types_are_subset(first, second) else None - - if isinstance(second, EnumProperty) and _types_are_subset(second, first): - return second - return None - - -def _merge_properties(first: Property, second: Property) -> Property | PropertyError: - required = first.required or second.required - - err = None - - if first.__class__ == second.__class__: - first = evolve(first, required=required) - second = evolve(second, required=required) - if first == second: - return first - err = PropertyError(header="Cannot merge properties", detail="Properties has conflicting values") - - enum_subset = _enum_subset(first, second) - if enum_subset is not None: - return evolve(enum_subset, required=required) - - return err or PropertyError( - header="Cannot merge properties", - detail=f"{first.__class__}, {second.__class__}Properties have incompatible types", - ) - - def _resolve_naming_conflict(first: Property, second: Property, config: Config) -> PropertyError | None: first.set_python_name(first.name, config=config, skip_snake_case=True) second.set_python_name(second.name, config=config, skip_snake_case=True) @@ -290,13 +233,14 @@ def _process_properties( # noqa: PLR0912, PLR0911 *, data: oai.Schema, schemas: Schemas, - class_name: utils.ClassName, + class_name: strings.ClassName, config: Config, - roots: set[ReferencePath | utils.ClassName], + roots: set[ReferencePath | strings.ClassName], ) -> _PropertyData | PropertyError: - from . import property_from_data + from . import property_from_data # noqa: PLC0415 + from .merge_properties import merge_properties # noqa: PLC0415 - properties: dict[str, Property] = {} + properties: dict[oai.UntrustedString, Property] = {} relative_imports: set[str] = set() lazy_imports: set[str] = set() required_set = set(data.required or []) @@ -305,26 +249,26 @@ def _add_if_no_conflict(new_prop: Property) -> PropertyError | None: nonlocal properties name_conflict = properties.get(new_prop.name) - merged_prop_or_error = _merge_properties(name_conflict, new_prop) if name_conflict else new_prop - if isinstance(merged_prop_or_error, PropertyError): - merged_prop_or_error.header = ( - f"Found conflicting properties named {new_prop.name} when creating {class_name}" - ) - return merged_prop_or_error + merged_prop = merge_properties(name_conflict, new_prop) if name_conflict else new_prop + if isinstance(merged_prop, PropertyError): + merged_prop.header = f"Found conflicting properties named {new_prop.name} when creating {class_name}" + return merged_prop for other_prop in properties.values(): - if other_prop.name == merged_prop_or_error.name: + if other_prop.name == merged_prop.name: continue # Same property, probably just got merged - if other_prop.python_name != merged_prop_or_error.python_name: + if other_prop.python_name != merged_prop.python_name: continue - naming_error = _resolve_naming_conflict(merged_prop_or_error, other_prop, config) + naming_error = _resolve_naming_conflict(merged_prop, other_prop, config) if naming_error is not None: return naming_error - properties[merged_prop_or_error.name] = merged_prop_or_error + properties[merged_prop.name] = merged_prop return None - unprocessed_props = data.properties or {} + unprocessed_props: list[tuple[oai.UntrustedString, oai.Reference | oai.Schema]] = ( + list(data.properties.items()) if data.properties else [] + ) for sub_prop in data.allOf: if isinstance(sub_prop, oai.Reference): ref_path = parse_reference_path(sub_prop.ref) @@ -332,7 +276,7 @@ def _add_if_no_conflict(new_prop: Property) -> PropertyError | None: return PropertyError(detail=ref_path.detail, data=sub_prop) sub_model = schemas.classes_by_reference.get(ref_path) if sub_model is None: - return PropertyError(f"Reference {sub_prop.ref} not found") + return PropertyError(f"Reference {sub_prop.ref.get_untrusted_value()} not found") if not isinstance(sub_model, ModelProperty): return PropertyError("Cannot take allOf a non-object") # Properties of allOf references first should be processed first @@ -346,10 +290,15 @@ def _add_if_no_conflict(new_prop: Property) -> PropertyError | None: return err schemas.add_dependencies(ref_path=ref_path, roots=roots) else: - unprocessed_props.update(sub_prop.properties or {}) + unprocessed_props.extend(sub_prop.properties.items() if sub_prop.properties else []) required_set.update(sub_prop.required or []) - for key, value in unprocessed_props.items(): + # Update properties that are marked as required in the schema + for prop_name in required_set: + if prop_name in properties and not properties[prop_name].required: + properties[prop_name] = evolve(properties[prop_name], required=True) + + for key, value in unprocessed_props: prop_required = key in required_set prop_or_error: Property | (PropertyError | None) prop_or_error, schemas = property_from_data( @@ -386,28 +335,40 @@ def _add_if_no_conflict(new_prop: Property) -> PropertyError | None: ) +ANY_ADDITIONAL_PROPERTY = AnyProperty.build( + name=oai.UntrustedString("additional"), + required=True, + default=None, + description=None, + python_name=PythonIdentifier(value="additional", prefix=""), + example=None, +) + + def _get_additional_properties( *, schema_additional: None | (bool | (oai.Reference | oai.Schema)), schemas: Schemas, - class_name: utils.ClassName, + class_name: strings.ClassName, config: Config, - roots: set[ReferencePath | utils.ClassName], -) -> tuple[bool | (Property | PropertyError), Schemas]: - from . import property_from_data + roots: set[ReferencePath | strings.ClassName], +) -> tuple[Property | PropertyError | None, Schemas]: + from . import property_from_data # noqa: PLC0415 if schema_additional is None: - return True, schemas + return ANY_ADDITIONAL_PROPERTY, schemas if isinstance(schema_additional, bool): - return schema_additional, schemas + if schema_additional: + return ANY_ADDITIONAL_PROPERTY, schemas + return None, schemas if isinstance(schema_additional, oai.Schema) and not any(schema_additional.model_dump().values()): # An empty schema - return True, schemas + return ANY_ADDITIONAL_PROPERTY, schemas additional_properties, schemas = property_from_data( - name="AdditionalProperty", + name=oai.UntrustedString("AdditionalProperty"), required=True, # in the sense that if present in the dict will not be None data=schema_additional, schemas=schemas, @@ -424,8 +385,8 @@ def _process_property_data( schemas: Schemas, class_info: Class, config: Config, - roots: set[ReferencePath | utils.ClassName], -) -> tuple[tuple[_PropertyData, bool | Property] | PropertyError, Schemas]: + roots: set[ReferencePath | strings.ClassName], +) -> tuple[tuple[_PropertyData, Property | None] | PropertyError, Schemas]: property_data = _process_properties( data=data, schemas=schemas, class_name=class_info.name, config=config, roots=roots ) @@ -442,7 +403,7 @@ def _process_property_data( ) if isinstance(additional_properties, PropertyError): return additional_properties, schemas - elif isinstance(additional_properties, bool): + elif additional_properties is None: pass else: property_data.relative_imports.update(additional_properties.get_imports(prefix="..")) diff --git a/openapi_python_client/parser/properties/none.py b/openapi_python_client/parser/properties/none.py index c329dac40..54bc69a29 100644 --- a/openapi_python_client/parser/properties/none.py +++ b/openapi_python_client/parser/properties/none.py @@ -2,24 +2,24 @@ from typing import Any, ClassVar -from attr import define +from attr import define, field from ... import schema as oai -from ...utils import PythonIdentifier +from ...strings import PythonCode, PythonIdentifier from ..errors import PropertyError -from .protocol import PropertyProtocol, Value +from .protocol import PropertyProtocol, Value, convert_example @define class NoneProperty(PropertyProtocol): """A property that can only be None""" - name: str + name: oai.UntrustedString required: bool default: Value | None python_name: PythonIdentifier - description: str | None - example: str | None + description: oai.UntrustedString | None + example: oai.UntrustedString | None = field(converter=convert_example) _allowed_locations: ClassVar[set[oai.ParameterLocation]] = { oai.ParameterLocation.QUERY, @@ -32,12 +32,12 @@ class NoneProperty(PropertyProtocol): @classmethod def build( cls, - name: str, + name: oai.UntrustedString, required: bool, default: Any, python_name: PythonIdentifier, - description: str | None, - example: str | None, + description: oai.UntrustedString | None, + example: Any, ) -> NoneProperty | PropertyError: checked_default = cls.convert_value(default) if isinstance(checked_default, PropertyError): @@ -52,10 +52,10 @@ def build( ) @classmethod - def convert_value(cls, value: Any) -> Value | None | PropertyError: + def convert_value(cls, value: Any) -> Value | PropertyError | None: if value is None or isinstance(value, Value): return value if isinstance(value, str): if value == "None": - return Value(value) + return Value(python_code=PythonCode(value), raw_value=value) return PropertyError(f"Value {value} is not valid, only None is allowed") diff --git a/openapi_python_client/parser/properties/property.py b/openapi_python_client/parser/properties/property.py index fa3a26beb..5927c6e91 100644 --- a/openapi_python_client/parser/properties/property.py +++ b/openapi_python_client/parser/properties/property.py @@ -1,8 +1,7 @@ __all__ = ["Property"] -from typing import Union -from typing_extensions import TypeAlias +from typing import TypeAlias from .any import AnyProperty from .boolean import BooleanProperty @@ -14,24 +13,28 @@ from .float import FloatProperty from .int import IntProperty from .list_property import ListProperty +from .literal_enum_property import LiteralEnumProperty from .model_property import ModelProperty from .none import NoneProperty from .string import StringProperty from .union import UnionProperty +from .uuid import UuidProperty -Property: TypeAlias = Union[ - AnyProperty, - BooleanProperty, - ConstProperty, - DateProperty, - DateTimeProperty, - EnumProperty, - FileProperty, - FloatProperty, - IntProperty, - ListProperty, - ModelProperty, - NoneProperty, - StringProperty, - UnionProperty, -] +Property: TypeAlias = ( + AnyProperty + | BooleanProperty + | ConstProperty + | DateProperty + | DateTimeProperty + | EnumProperty + | LiteralEnumProperty + | FileProperty + | FloatProperty + | IntProperty + | ListProperty + | ModelProperty + | NoneProperty + | StringProperty + | UnionProperty + | UuidProperty +) diff --git a/openapi_python_client/parser/properties/protocol.py b/openapi_python_client/parser/properties/protocol.py index b8237923d..d4fabb014 100644 --- a/openapi_python_client/parser/properties/protocol.py +++ b/openapi_python_client/parser/properties/protocol.py @@ -1,23 +1,40 @@ from __future__ import annotations -__all__ = ["PropertyProtocol", "Value"] +__all__ = ["PropertyProtocol", "Value", "convert_example"] from abc import abstractmethod -from typing import TYPE_CHECKING, Any, ClassVar, Protocol, TypeVar +from dataclasses import dataclass +from typing import Any, ClassVar, Protocol, TypeVar from ... import Config from ... import schema as oai -from ...utils import PythonIdentifier +from ...strings import PythonCode, PythonIdentifier, safe_for_docstring from ..errors import ParseError, PropertyError -if TYPE_CHECKING: # pragma: no cover - from .model_property import ModelProperty -else: - ModelProperty = "ModelProperty" +def convert_example(example: Any) -> oai.UntrustedString | None: + """ + Convert a raw OpenAPI `example` (which can be anything) into an `UntrustedString` (or None). + + Examples only ever appear in docstrings, so non-string examples are stringified. Wrapping ensures a + template which uses an example without escaping renders a safe-but-broken value instead of an exploit. + """ + if example is None or isinstance(example, oai.UntrustedString): + return example + if isinstance(example, str): + return oai.UntrustedString(example) + return oai.UntrustedString(str(example)) -class Value(str): - """Represents a valid (converted) value for a property""" + +@dataclass +class Value: + """ + Some literal values in OpenAPI documents (like defaults) have to be converted into Python code safely + (with string escaping, for example). We still keep the `raw_value` around for merging `allOf`. + """ + + python_code: PythonCode + raw_value: Any PropertyType = TypeVar("PropertyType", bound="PropertyProtocol") @@ -37,7 +54,7 @@ class PropertyProtocol(Protocol): ValidationError: Raised when the default value fails to be converted to the expected type """ - name: str + name: oai.UntrustedString required: bool _type_string: ClassVar[str] = "" _json_type_string: ClassVar[str] = "" # Type of the property after JSON serialization @@ -48,26 +65,26 @@ class PropertyProtocol(Protocol): } default: Value | None python_name: PythonIdentifier - description: str | None - example: str | None + description: oai.UntrustedString | None + example: oai.UntrustedString | None template: ClassVar[str] = "any_property.py.jinja" json_is_dict: ClassVar[bool] = False @abstractmethod - def convert_value(self, value: Any) -> Value | None | PropertyError: + def convert_value(self, value: Any) -> Value | PropertyError | None: """Convert a string value to a Value object""" raise NotImplementedError() # pragma: no cover def validate_location(self, location: oai.ParameterLocation) -> ParseError | None: """Returns an error if this type of property is not allowed in the given location""" if location not in self._allowed_locations: - return ParseError(detail=f"{self.get_type_string()} is not allowed in {location}") + return ParseError(detail=f"{self.get_type_string().as_unembedded_code()} is not allowed in {location}") if location == oai.ParameterLocation.PATH and not self.required: return ParseError(detail="Path parameter must be required") return None - def set_python_name(self, new_name: str, config: Config, skip_snake_case: bool = False) -> None: + def set_python_name(self, new_name: oai.UntrustedString, config: Config, skip_snake_case: bool = False) -> None: """Mutates this Property to set a new python_name. Required to mutate due to how Properties are stored and the difficulty of updating them in-dict. @@ -80,43 +97,38 @@ def set_python_name(self, new_name: str, config: Config, skip_snake_case: bool = PythonIdentifier(value=new_name, prefix=config.field_prefix, skip_snake_case=skip_snake_case), ) - def get_base_type_string(self, *, quoted: bool = False) -> str: - """Get the string describing the Python type of this property. Base types no require quoting.""" - return f'"{self._type_string}"' if not self.is_base_type and quoted else self._type_string + def get_base_type_string(self) -> PythonCode: + """Get the code describing the Python type of this property. Base types no require quoting.""" + return PythonCode(self._type_string) - def get_base_json_type_string(self, *, quoted: bool = False) -> str: - """Get the string describing the JSON type of this property. Base types no require quoting.""" - return f'"{self._json_type_string}"' if not self.is_base_type and quoted else self._json_type_string + def get_base_json_type_string(self) -> PythonCode: + """Get the code describing the JSON type of this property. Base types no require quoting.""" + return PythonCode(self._json_type_string) def get_type_string( self, no_optional: bool = False, json: bool = False, - *, - multipart: bool = False, - quoted: bool = False, - ) -> str: + ) -> PythonCode: """ - Get a string representation of type that should be used when declaring this property + Get a Python code representation of type that should be used when declaring this property Args: no_optional: Do not include Optional or Unset even if the value is optional (needed for isinstance checks) json: True if the type refers to the property after JSON serialization - multipart: True if the type should be used in a multipart request - quoted: True if the type should be wrapped in quotes (if not a base type) """ if json: - type_string = self.get_base_json_type_string(quoted=quoted) + type_string = self.get_base_json_type_string() else: - type_string = self.get_base_type_string(quoted=quoted) + type_string = self.get_base_type_string() if no_optional or self.required: return type_string - return f"Union[Unset, {type_string}]" + return PythonCode(f"{type_string.as_unembedded_code()} | Unset") - def get_instance_type_string(self) -> str: - """Get a string representation of runtime type that should be used for `isinstance` checks""" - return self.get_type_string(no_optional=True, quoted=False) + def get_instance_type_string(self) -> PythonCode: + """Get a Python code representation of runtime type that should be used for `isinstance` checks""" + return self.get_type_string(no_optional=True) # noinspection PyUnusedLocal def get_imports(self, *, prefix: str) -> set[str]: @@ -129,7 +141,6 @@ def get_imports(self, *, prefix: str) -> set[str]: """ imports = set() if not self.required: - imports.add("from typing import Union") imports.add(f"from {prefix}types import UNSET, Unset") return imports @@ -142,36 +153,26 @@ def get_lazy_imports(self, *, prefix: str) -> set[str]: """ return set() - def to_string(self) -> str: + def to_string(self) -> PythonCode: """How this should be declared in a dataclass""" default: str | None if self.default is not None: - default = self.default + default = self.default.python_code.as_unembedded_code() elif not self.required: default = "UNSET" else: default = None + declaration = f"{self.python_name}: {self.get_type_string().as_unembedded_code()}" if default is not None: - return f"{self.python_name}: {self.get_type_string(quoted=True)} = {default}" - return f"{self.python_name}: {self.get_type_string(quoted=True)}" + declaration += f" = {default}" + return PythonCode(declaration) def to_docstring(self) -> str: """Returns property docstring""" - doc = f"{self.python_name} ({self.get_type_string()}): {self.description or ''}" + doc = f"{self.python_name} ({safe_for_docstring(self.get_type_string())}): {safe_for_docstring(self.description or '')}" if self.default: - doc += f" Default: {self.default}." + doc += f" Default: {safe_for_docstring(self.default.python_code)}." if self.example: - doc += f" Example: {self.example}." + doc += f" Example: {safe_for_docstring(self.example)}." return doc - - @property - def is_base_type(self) -> bool: - """Base types, represented by any other of `Property` than `ModelProperty` should not be quoted.""" - from . import ListProperty, ModelProperty, UnionProperty - - return self.__class__.__name__ not in { - ModelProperty.__name__, - ListProperty.__name__, - UnionProperty.__name__, - } diff --git a/openapi_python_client/parser/properties/schemas.py b/openapi_python_client/parser/properties/schemas.py index 9e4fc545e..49e278437 100644 --- a/openapi_python_client/parser/properties/schemas.py +++ b/openapi_python_client/parser/properties/schemas.py @@ -1,16 +1,16 @@ __all__ = [ "Class", - "Schemas", "Parameters", "ReferencePath", + "Schemas", + "parameter_from_data", + "parameter_from_reference", "parse_reference_path", - "update_schemas_with_data", "update_parameters_with_data", - "parameter_from_reference", - "parameter_from_data", + "update_schemas_with_data", ] -from typing import TYPE_CHECKING, Dict, List, NewType, Set, Tuple, Union, cast +from typing import TYPE_CHECKING, NewType from urllib.parse import urlparse from attrs import define, evolve, field @@ -18,19 +18,23 @@ from ... import Config from ... import schema as oai from ...schema.openapi_schema_pydantic import Parameter -from ...utils import ClassName, PythonIdentifier +from ...schema.ref import Ref +from ...schema.untrusted_string import UntrustedString +from ...strings import ClassName, PythonIdentifier from ..errors import ParameterError, ParseError, PropertyError if TYPE_CHECKING: # pragma: no cover + from .model_property import ModelProperty from .property import Property else: + ModelProperty = "ModelProperty" Property = "Property" -ReferencePath = NewType("ReferencePath", str) +ReferencePath = NewType("ReferencePath", UntrustedString) -def parse_reference_path(ref_path_raw: str) -> Union[ReferencePath, ParseError]: +def parse_reference_path(ref_path_raw: Ref) -> ReferencePath | ParseError: """ Takes a raw string provided in a `$ref` and turns it into a validated `_ReferencePath` or a `ParseError` if validation fails. @@ -38,10 +42,17 @@ def parse_reference_path(ref_path_raw: str) -> Union[ReferencePath, ParseError]: See Also: - https://swagger.io/docs/specification/using-ref/ """ - parsed = urlparse(ref_path_raw) + parsed = urlparse(ref_path_raw.get_untrusted_value()) if parsed.scheme or parsed.path: - return ParseError(detail=f"Remote references such as {ref_path_raw} are not supported yet.") - return cast(ReferencePath, parsed.fragment) + return ParseError(detail=f"Remote references such as {parsed} are not supported yet.") + return ReferencePath(UntrustedString(parsed.fragment)) + + +def get_reference_simple_name(ref_path: Ref | UntrustedString) -> UntrustedString: + """ + Takes a path like `/components/schemas/NameOfThing` and returns a string like `NameOfThing`. + """ + return UntrustedString(ref_path.get_untrusted_value().rsplit("/", maxsplit=1)[-1]) @define @@ -52,10 +63,10 @@ class Class: module_name: PythonIdentifier @staticmethod - def from_string(*, string: str, config: Config) -> "Class": + def from_string(*, string: str | UntrustedString, config: Config) -> "Class": """Get a Class from an arbitrary string""" - class_name = string.split("/")[-1] # Get rid of ref path stuff - class_name = ClassName(class_name, config.field_prefix) + untrusted_class_name = get_reference_simple_name(Ref(string)) # Get rid of ref path stuff + class_name = ClassName(untrusted_class_name, config.field_prefix) override = config.class_overrides.get(class_name) if override is not None and override.class_name is not None: @@ -74,12 +85,13 @@ def from_string(*, string: str, config: Config) -> "Class": class Schemas: """Structure for containing all defined, shareable, and reusable schemas (attr classes and Enums)""" - classes_by_reference: Dict[ReferencePath, Property] = field(factory=dict) - dependencies: Dict[ReferencePath, Set[Union[ReferencePath, ClassName]]] = field(factory=dict) - classes_by_name: Dict[ClassName, Property] = field(factory=dict) - errors: List[ParseError] = field(factory=list) + classes_by_reference: dict[ReferencePath, Property] = field(factory=dict) + dependencies: dict[ReferencePath, set[ReferencePath | ClassName]] = field(factory=dict) + classes_by_name: dict[ClassName, Property] = field(factory=dict) + models_to_process: list[ModelProperty] = field(factory=list) + errors: list[ParseError] = field(factory=list) - def add_dependencies(self, ref_path: ReferencePath, roots: Set[Union[ReferencePath, ClassName]]) -> None: + def add_dependencies(self, ref_path: ReferencePath, roots: set[ReferencePath | ClassName]) -> None: """Record new dependencies on the given ReferencePath Args: @@ -92,7 +104,7 @@ def add_dependencies(self, ref_path: ReferencePath, roots: Set[Union[ReferencePa def update_schemas_with_data( *, ref_path: ReferencePath, data: oai.Schema, schemas: Schemas, config: Config -) -> Union[Schemas, PropertyError]: +) -> Schemas | PropertyError: """ Update a `Schemas` using some new reference. @@ -108,9 +120,9 @@ def update_schemas_with_data( See Also: - https://swagger.io/docs/specification/using-ref/ """ - from . import property_from_data + from . import property_from_data # noqa: PLC0415 - prop: Union[PropertyError, Property] + prop: PropertyError | Property prop, schemas = property_from_data( data=data, name=ref_path, @@ -124,12 +136,15 @@ def update_schemas_with_data( ) if isinstance(prop, PropertyError): - prop.detail = f"{prop.header}: {prop.detail}" - prop.header = f"Unable to parse schema {ref_path}" - if isinstance(prop.data, oai.Reference) and prop.data.ref.endswith(ref_path): # pragma: nocover - prop.detail += ( + detail = f"{prop.header}: {prop.detail}" if prop.detail is not None else prop.header + prop.header = f"Unable to parse schema {ref_path.get_untrusted_value()}" + if isinstance(prop.data, oai.Reference) and prop.data.ref.endswith( + ref_path.get_untrusted_value() + ): # pragma: nocover + detail += ( "\n\nRecursive and circular references are not supported directly in an array schema's 'items' section" ) + prop.detail = detail return prop schemas = evolve(schemas, classes_by_reference={ref_path: prop, **schemas.classes_by_reference}) @@ -140,18 +155,18 @@ def update_schemas_with_data( class Parameters: """Structure for containing all defined, shareable, and reusable parameters""" - classes_by_reference: Dict[ReferencePath, Parameter] = field(factory=dict) - classes_by_name: Dict[ClassName, Parameter] = field(factory=dict) - errors: List[ParseError] = field(factory=list) + classes_by_reference: dict[ReferencePath, Parameter] = field(factory=dict) + classes_by_name: dict[ClassName, Parameter] = field(factory=dict) + errors: list[ParseError] = field(factory=list) def parameter_from_data( *, - name: str, - data: Union[oai.Reference, oai.Parameter], + name: UntrustedString, + data: oai.Reference | oai.Parameter, parameters: Parameters, config: Config, -) -> Tuple[Union[Parameter, ParameterError], Parameters]: +) -> tuple[Parameter | ParameterError, Parameters]: """Generates parameters from an OpenAPI Parameter spec.""" if isinstance(data, oai.Reference): @@ -161,10 +176,10 @@ def parameter_from_data( return ParameterError("Parameter has no schema"), parameters new_param = Parameter( - name=name, + name=name.get_untrusted_value(), required=data.required, explode=data.explode, - style=data.style, + style=data.style.get_untrusted_value() if data.style is not None else None, param_schema=data.param_schema, param_in=data.param_in, ) @@ -176,7 +191,7 @@ def parameter_from_data( def update_parameters_with_data( *, ref_path: ReferencePath, data: oai.Parameter, parameters: Parameters, config: Config -) -> Union[Parameters, ParameterError]: +) -> Parameters | ParameterError: """ Update a `Parameters` using some new reference. @@ -193,10 +208,12 @@ def update_parameters_with_data( """ param, parameters = parameter_from_data(data=data, name=data.name, parameters=parameters, config=config) - if isinstance(param, ParameterError): + if isinstance(param, ParameterError): # pragma: no cover param.detail = f"{param.header}: {param.detail}" - param.header = f"Unable to parse parameter {ref_path}" - if isinstance(param.data, oai.Reference) and param.data.ref.endswith(ref_path): # pragma: nocover + param.header = f"Unable to parse parameter {ref_path.get_untrusted_value()}" + if isinstance(param.data, oai.Reference) and param.data.ref.endswith( + ref_path.get_untrusted_value() + ): # pragma: nocover param.detail += ( "\n\nRecursive and circular references are not supported. " "See https://github.com/openapi-generators/openapi-python-client/issues/466" @@ -209,9 +226,9 @@ def update_parameters_with_data( def parameter_from_reference( *, - param: Union[oai.Reference, Parameter], + param: oai.Reference | Parameter, parameters: Parameters, -) -> Union[Parameter, ParameterError]: +) -> Parameter | ParameterError: """ Returns a Parameter from a Reference or the Parameter itself if one was provided. @@ -235,5 +252,5 @@ def parameter_from_reference( _resolved_parameter_class = parameters.classes_by_reference.get(ref_path, None) if _resolved_parameter_class is None: - return ParameterError(detail=f"Reference `{ref_path}` not found.") + return ParameterError(detail=f"Reference `{ref_path.get_untrusted_value()}` not found.") return _resolved_parameter_class diff --git a/openapi_python_client/parser/properties/string.py b/openapi_python_client/parser/properties/string.py index 1afe02c62..618984114 100644 --- a/openapi_python_client/parser/properties/string.py +++ b/openapi_python_client/parser/properties/string.py @@ -2,27 +2,24 @@ from typing import Any, ClassVar, overload -from attr import define +from attr import define, field from ... import schema as oai -from ... import utils -from ...utils import PythonIdentifier +from ...strings import PythonCode, PythonIdentifier, remove_string_escapes from ..errors import PropertyError -from .protocol import PropertyProtocol, Value +from .protocol import PropertyProtocol, Value, convert_example @define class StringProperty(PropertyProtocol): """A property of type str""" - name: str + name: oai.UntrustedString required: bool default: Value | None python_name: PythonIdentifier - description: str | None - example: str | None - max_length: int | None = None - pattern: str | None = None + description: oai.UntrustedString | None + example: oai.UntrustedString | None = field(converter=convert_example) _type_string: ClassVar[str] = "str" _json_type_string: ClassVar[str] = "str" _allowed_locations: ClassVar[set[oai.ParameterLocation]] = { @@ -35,13 +32,12 @@ class StringProperty(PropertyProtocol): @classmethod def build( cls, - name: str, + name: oai.UntrustedString, required: bool, default: Any, python_name: PythonIdentifier, - description: str | None, - example: str | None, - pattern: str | None = None, + description: oai.UntrustedString | None, + example: Any, ) -> StringProperty | PropertyError: checked_default = cls.convert_value(default) return cls( @@ -51,7 +47,6 @@ def build( python_name=python_name, description=description, example=example, - pattern=pattern, ) @classmethod @@ -69,4 +64,4 @@ def convert_value(cls, value: Any) -> Value | None: return value if not isinstance(value, str): value = str(value) - return Value(repr(utils.remove_string_escapes(value))) + return Value(python_code=PythonCode(repr(remove_string_escapes(value))), raw_value=value) diff --git a/openapi_python_client/parser/properties/union.py b/openapi_python_client/parser/properties/union.py index 8b7b02a48..788e803a6 100644 --- a/openapi_python_client/parser/properties/union.py +++ b/openapi_python_client/parser/properties/union.py @@ -1,15 +1,16 @@ from __future__ import annotations +from collections.abc import Iterator from itertools import chain from typing import Any, ClassVar, cast -from attr import define, evolve +from attr import define, evolve, field -from ... import Config +from ... import Config, strings from ... import schema as oai -from ...utils import PythonIdentifier +from ...strings import PythonIdentifier from ..errors import ParseError, PropertyError -from .protocol import PropertyProtocol, Value +from .protocol import PropertyProtocol, Value, convert_example from .schemas import Schemas @@ -17,18 +18,25 @@ class UnionProperty(PropertyProtocol): """A property representing a Union (anyOf) of other properties""" - name: str + name: oai.UntrustedString required: bool default: Value | None python_name: PythonIdentifier - description: str | None - example: str | None + description: oai.UntrustedString | None + example: oai.UntrustedString | None = field(converter=convert_example) inner_properties: list[PropertyProtocol] template: ClassVar[str] = "union_property.py.jinja" @classmethod def build( - cls, *, data: oai.Schema, name: str, required: bool, schemas: Schemas, parent_name: str, config: Config + cls, + *, + data: oai.Schema, + name: oai.UntrustedString, + required: bool, + schemas: Schemas, + parent_name: str, + config: Config, ) -> tuple[UnionProperty | PropertyError, Schemas]: """ Create a `UnionProperty` the right way. @@ -45,7 +53,7 @@ def build( `(result, schemas)` where `schemas` is the updated version of the input `schemas` and `result` is the constructed `UnionProperty` or a `PropertyError` describing what went wrong. """ - from . import property_from_data + from . import property_from_data # noqa: PLC0415 sub_properties: list[PropertyProtocol] = [] @@ -55,8 +63,19 @@ def build( type_list_data.append(data.model_copy(update={"type": _type, "default": None})) for i, sub_prop_data in enumerate(chain(data.anyOf, data.oneOf, type_list_data)): + # If a schema has a unique title property, we can use that to carry forward a descriptive name instead of "type_0" + subscript: str + if ( + isinstance(sub_prop_data, oai.Schema) + and sub_prop_data.title is not None + and sub_prop_data.title != data.title + ): + subscript = sub_prop_data.title.get_untrusted_value() + else: + subscript = f"type_{i}" + sub_prop, schemas = property_from_data( - name=f"{name}_type_{i}", + name=oai.UntrustedString(f"{name.get_untrusted_value()}_{subscript}"), required=True, data=sub_prop_data, schemas=schemas, @@ -64,25 +83,32 @@ def build( config=config, ) if isinstance(sub_prop, PropertyError): - return PropertyError(detail=f"Invalid property in union {name}", data=sub_prop_data), schemas + return ( + PropertyError(detail=f"Invalid property in union {name}", data=sub_prop_data), + schemas, + ) sub_properties.append(sub_prop) - def flatten_union_properties(sub_properties: list[PropertyProtocol]) -> list[PropertyProtocol]: - flattened = [] - for sub_prop in sub_properties: - if isinstance(sub_prop, UnionProperty): - flattened.extend(flatten_union_properties(sub_prop.inner_properties)) + def flatten_union_properties(possibly_nested: list[PropertyProtocol]) -> Iterator[PropertyProtocol]: + for to_flatten in possibly_nested: + if isinstance(to_flatten, UnionProperty): + yield from flatten_union_properties(to_flatten.inner_properties) else: - flattened.append(sub_prop) - return flattened + yield to_flatten - sub_properties = flatten_union_properties(sub_properties) + seen_types = set() + inner_properties: list[PropertyProtocol] = [] + for flattened in flatten_union_properties(sub_properties): + type_string = flattened.get_type_string(no_optional=True) + if type_string not in seen_types: + seen_types.add(type_string) + inner_properties.append(flattened) prop = UnionProperty( name=name, required=required, default=None, - inner_properties=sub_properties, + inner_properties=inner_properties, python_name=PythonIdentifier(value=name, prefix=config.field_prefix), description=data.description, example=data.example, @@ -94,7 +120,7 @@ def flatten_union_properties(sub_properties: list[PropertyProtocol]) -> list[Pro prop = evolve(prop, default=default_or_error) return prop, schemas - def convert_value(self, value: Any) -> Value | None | PropertyError: + def convert_value(self, value: Any) -> Value | PropertyError | None: if value is None or isinstance(value, Value): return None value_or_error: Value | PropertyError | None = PropertyError( @@ -106,25 +132,29 @@ def convert_value(self, value: Any) -> Value | None | PropertyError: return value_or_error return value_or_error - def _get_inner_type_strings(self, json: bool, multipart: bool) -> set[str]: + def _get_inner_type_strings(self, json: bool) -> set[strings.PythonCode]: return { - p.get_type_string(no_optional=True, json=json, multipart=multipart, quoted=not p.is_base_type) + p.get_type_string( + no_optional=True, + json=json, + ) for p in self.inner_properties } @staticmethod - def _get_type_string_from_inner_type_strings(inner_types: set[str]) -> str: + def _get_type_string_from_inner_type_strings(inner_types: set[strings.PythonCode]) -> strings.PythonCode: if len(inner_types) == 1: return inner_types.pop() - return f"Union[{', '.join(sorted(inner_types))}]" + joined = " | ".join(sorted((t.as_unembedded_code() for t in inner_types), key=str.lower)) + return strings.PythonCode(joined) - def get_base_type_string(self, *, quoted: bool = False) -> str: - return self._get_type_string_from_inner_type_strings(self._get_inner_type_strings(json=False, multipart=False)) + def get_base_type_string(self) -> strings.PythonCode: + return self._get_type_string_from_inner_type_strings(self._get_inner_type_strings(json=False)) - def get_base_json_type_string(self, *, quoted: bool = False) -> str: - return self._get_type_string_from_inner_type_strings(self._get_inner_type_strings(json=True, multipart=False)) + def get_base_json_type_string(self) -> strings.PythonCode: + return self._get_type_string_from_inner_type_strings(self._get_inner_type_strings(json=True)) - def get_type_strings_in_union(self, *, no_optional: bool = False, json: bool, multipart: bool) -> set[str]: + def get_type_strings_in_union(self, *, no_optional: bool = False, json: bool) -> set[strings.PythonCode]: """ Get the set of all the types that should appear within the `Union` representing this property. @@ -133,32 +163,28 @@ def get_type_strings_in_union(self, *, no_optional: bool = False, json: bool, mu Args: no_optional: Do not include `None` or `Unset` in this set. json: If True, this returns the JSON types, not the Python types, of this property. - multipart: If True, this returns the multipart types, not the Python types, of this property. Returns: - A set of strings containing the types that should appear within `Union`. + A set of code snippets containing the types that should appear within `Union`. """ - type_strings = self._get_inner_type_strings(json=json, multipart=multipart) + type_strings = self._get_inner_type_strings(json=json) if no_optional: return type_strings if not self.required: - type_strings.add("Unset") + type_strings.add(strings.PythonCode("Unset")) return type_strings def get_type_string( self, no_optional: bool = False, json: bool = False, - *, - multipart: bool = False, - quoted: bool = False, - ) -> str: + ) -> strings.PythonCode: """ - Get a string representation of type that should be used when declaring this property. + Get a Python code representation of type that should be used when declaring this property. This implementation differs slightly from `Property.get_type_string` in order to collapse nested union types. """ - type_strings_in_union = self.get_type_strings_in_union(no_optional=no_optional, json=json, multipart=multipart) + type_strings_in_union = self.get_type_strings_in_union(no_optional=no_optional, json=json) return self._get_type_string_from_inner_type_strings(type_strings_in_union) def get_imports(self, *, prefix: str) -> set[str]: @@ -172,7 +198,7 @@ def get_imports(self, *, prefix: str) -> set[str]: imports = super().get_imports(prefix=prefix) for inner_prop in self.inner_properties: imports.update(inner_prop.get_imports(prefix=prefix)) - imports.add("from typing import cast, Union") + imports.add("from typing import cast") return imports def get_lazy_imports(self, *, prefix: str) -> set[str]: @@ -183,9 +209,10 @@ def get_lazy_imports(self, *, prefix: str) -> set[str]: def validate_location(self, location: oai.ParameterLocation) -> ParseError | None: """Returns an error if this type of property is not allowed in the given location""" - from ..properties import Property + from ..properties import Property # noqa: PLC0415 for inner_prop in self.inner_properties: if evolve(cast(Property, inner_prop), required=self.required).validate_location(location) is not None: - return ParseError(detail=f"{self.get_type_string()} is not allowed in {location}") + type_string = self.get_type_string().as_unembedded_code() + return ParseError(detail=f"{type_string} is not allowed in {location}") return None diff --git a/openapi_python_client/parser/properties/uuid.py b/openapi_python_client/parser/properties/uuid.py new file mode 100644 index 000000000..c813fe200 --- /dev/null +++ b/openapi_python_client/parser/properties/uuid.py @@ -0,0 +1,80 @@ +from __future__ import annotations + +from typing import Any, ClassVar +from uuid import UUID + +from attr import define, field + +from ... import schema as oai +from ...strings import PythonCode, PythonIdentifier +from ..errors import PropertyError +from .protocol import PropertyProtocol, Value, convert_example + + +@define +class UuidProperty(PropertyProtocol): + """A property of type uuid.UUID""" + + name: oai.UntrustedString + required: bool + default: Value | None + python_name: PythonIdentifier + description: oai.UntrustedString | None + example: oai.UntrustedString | None = field(converter=convert_example) + + _type_string: ClassVar[str] = "UUID" + _json_type_string: ClassVar[str] = "str" + _allowed_locations: ClassVar[set[oai.ParameterLocation]] = { + oai.ParameterLocation.QUERY, + oai.ParameterLocation.PATH, + oai.ParameterLocation.COOKIE, + oai.ParameterLocation.HEADER, + } + template: ClassVar[str] = "uuid_property.py.jinja" + + @classmethod + def build( + cls, + name: oai.UntrustedString, + required: bool, + default: Any, + python_name: PythonIdentifier, + description: oai.UntrustedString | None, + example: Any, + ) -> UuidProperty | PropertyError: + checked_default = cls.convert_value(default) + if isinstance(checked_default, PropertyError): + return checked_default + + return cls( + name=name, + required=required, + default=checked_default, + python_name=python_name, + description=description, + example=example, + ) + + @classmethod + def convert_value(cls, value: Any) -> Value | PropertyError | None: + if value is None or isinstance(value, Value): + return value + if isinstance(value, str): + try: + UUID(value) + except ValueError: + return PropertyError(f"Invalid UUID value: {value}") + return Value(python_code=PythonCode(f"UUID('{value}')"), raw_value=value) + return PropertyError(f"Invalid UUID value: {value}") + + def get_imports(self, *, prefix: str) -> set[str]: + """ + Get a set of import strings that should be included when this property is used somewhere + + Args: + prefix: A prefix to put before any relative (local) module names. This should be the number of . to get + back to the root of the generated client. + """ + imports = super().get_imports(prefix=prefix) + imports.update({"from uuid import UUID"}) + return imports diff --git a/openapi_python_client/parser/responses.py b/openapi_python_client/parser/responses.py index 32412fd35..ef1c212a8 100644 --- a/openapi_python_client/parser/responses.py +++ b/openapi_python_client/parser/responses.py @@ -1,19 +1,35 @@ -__all__ = ["Response", "response_from_data"] +__all__ = ["HTTPStatusPattern", "Response", "Responses", "response_from_data"] -from http import HTTPStatus -from typing import Optional, Tuple, TypedDict, Union +from collections.abc import Iterator +from typing import TypedDict from attrs import define -from openapi_python_client import utils +from openapi_python_client import strings +from openapi_python_client.parser.properties.schemas import get_reference_simple_name, parse_reference_path from .. import Config from .. import schema as oai -from ..utils import PythonIdentifier +from ..schema.untrusted_string import UntrustedString +from ..strings import PythonIdentifier from .errors import ParseError, PropertyError from .properties import AnyProperty, Property, Schemas, property_from_data +@define +class Responses: + patterns: list["Response"] + default: "Response | None" + + def __iter__(self) -> Iterator["Response"]: + yield from self.patterns + if self.default: + yield self.default + + def __len__(self) -> int: + return len(self.patterns) + (1 if self.default else 0) + + class _ResponseSource(TypedDict): """What data should be pulled from the httpx Response object""" @@ -27,18 +43,95 @@ class _ResponseSource(TypedDict): NONE_SOURCE = _ResponseSource(attribute="None", return_type="None") -@define +class HTTPStatusPattern: + """Status code patterns come in three flavors, in order of precedence: + 1. Specific status codes, such as 200. This is represented by `min` and `max` being the same. + 2. Ranges of status codes, such as 2XX. This is represented by `min` and `max` being different. + 3. The special `default` status code, which is used when no other status codes match. `range` is `None` in this case. + + https://github.com/openapi-generators/openapi-python-client/blob/61b6c54994e2a6285bb422ee3b864c45b5d88c15/openapi_python_client/schema/3.1.0.md#responses-object + """ + + pattern: str + range: tuple[int, int] | None + + def __init__(self, *, pattern: str, code_range: tuple[int, int] | None): + """Initialize with a range of status codes or None for the default case.""" + self.pattern = pattern + self.range = code_range + + @staticmethod + def parse(pattern: UntrustedString) -> "HTTPStatusPattern | ParseError": + """Parse a status code pattern such as 2XX or 404""" + untrusted = pattern.get_untrusted_value() + if untrusted == "default": + return HTTPStatusPattern(pattern=untrusted, code_range=None) + + if len(untrusted) == 3 and untrusted.endswith("XX") and untrusted[0].isdigit(): + first_digit = int(untrusted[0]) + return HTTPStatusPattern(pattern=untrusted, code_range=(first_digit * 100, first_digit * 100 + 99)) + + try: + code = int(untrusted) + return HTTPStatusPattern(pattern=untrusted, code_range=(code, code)) + except ValueError: + return ParseError( + detail=( + f"Invalid response status code pattern: {untrusted}, response will be omitted from generated client" + ) + ) + + def is_range(self) -> bool: + """Check if this is a range of status codes, such as 2XX""" + return self.range is not None and self.range[0] != self.range[1] + + def __lt__(self, other: "HTTPStatusPattern") -> bool: + """Compare two HTTPStatusPattern objects based on the order they should be applied in""" + if self.range is None: + return False # Default gets applied last + if other.range is None: + return True # Other is default, so this one gets applied first + + # Specific codes appear before ranges + if self.is_range() and not other.is_range(): + return False + if not self.is_range() and other.is_range(): + return True + + # Order specific codes numerically + return self.range[0] < other.range[0] + + def __eq__(self, other: object) -> bool: # pragma: no cover + if not isinstance(other, HTTPStatusPattern): + return False + return self.range == other.range + + def __hash__(self) -> int: # pragma: no cover + return hash(self.range) + + def __repr__(self) -> str: # pragma: no cover + return f"" + + +@define(order=False) class Response: """Describes a single response for an endpoint""" - status_code: HTTPStatus + status_code: HTTPStatusPattern prop: Property source: _ResponseSource - data: Union[oai.Response, oai.Reference] # Original data which created this response, useful for custom templates + data: oai.Response | oai.Reference # Original data which created this response, useful for custom templates + + def is_default(self) -> bool: + return self.status_code.range is None + + def __lt__(self, other: "Response") -> bool: + """Compare two responses based on the order in which they should be applied in""" + return self.status_code < other.status_code -def _source_by_content_type(content_type: str, config: Config) -> Optional[_ResponseSource]: - parsed_content_type = utils.get_content_type(content_type, config) +def _source_by_content_type(content_type: str, config: Config) -> _ResponseSource | None: + parsed_content_type = strings.get_content_type(content_type, config) if parsed_content_type is None: return None @@ -58,10 +151,10 @@ def _source_by_content_type(content_type: str, config: Config) -> Optional[_Resp def empty_response( *, - status_code: HTTPStatus, - response_name: str, + status_code: HTTPStatusPattern, + response_name: UntrustedString, config: Config, - data: Union[oai.Response, oai.Reference], + data: oai.Response | oai.Reference, ) -> Response: """Return an untyped response, for when no response type is defined""" return Response( @@ -79,27 +172,32 @@ def empty_response( ) -def response_from_data( +def response_from_data( # noqa: PLR0911 *, - status_code: HTTPStatus, - data: Union[oai.Response, oai.Reference], + status_code: HTTPStatusPattern, + data: oai.Response | oai.Reference, schemas: Schemas, + responses: dict[UntrustedString, oai.Response | oai.Reference], parent_name: str, config: Config, -) -> Tuple[Union[Response, ParseError], Schemas]: +) -> tuple[Response | ParseError, Schemas]: """Generate a Response from the OpenAPI dictionary representation of it""" - response_name = f"response_{status_code}" + response_name = UntrustedString(f"response_{status_code.pattern}") if isinstance(data, oai.Reference): - return ( - empty_response( - status_code=status_code, - response_name=response_name, - config=config, - data=data, - ), - schemas, - ) + ref_path = parse_reference_path(data.ref) + if isinstance(ref_path, ParseError): # pragma: no cover + return ref_path, schemas + if not ref_path.startswith("/components/responses/"): # pragma: no cover + return ParseError( + data=data, detail=f"$ref to {data.ref.get_untrusted_value()} not allowed in responses" + ), schemas + resp_data = responses.get(get_reference_simple_name(ref_path), None) + if not resp_data: # pragma: no cover + return ParseError(data=data, detail=f"Could not find reference: {data.ref.get_untrusted_value()}"), schemas + if not isinstance(resp_data, oai.Response): # pragma: no cover + return ParseError(data=data, detail="Top-level $ref inside components/responses is not supported"), schemas + data = resp_data content = data.content if not content: @@ -114,13 +212,16 @@ def response_from_data( ) for content_type, media_type in content.items(): - source = _source_by_content_type(content_type, config) + source = _source_by_content_type(content_type.get_untrusted_value(), config) if source is not None: schema_data = media_type.media_type_schema break else: return ( - ParseError(data=data, detail=f"Unsupported content_type {content}"), + ParseError( + data=data, + detail=f"Unsupported content_type {', '.join(key.get_untrusted_value() for key in content)}", + ), schemas, ) diff --git a/openapi_python_client/schema/__init__.py b/openapi_python_client/schema/__init__.py index d3de0e493..41ed92cf2 100644 --- a/openapi_python_client/schema/__init__.py +++ b/openapi_python_client/schema/__init__.py @@ -1,17 +1,17 @@ __all__ = [ + "DataType", "MediaType", "OpenAPI", "Operation", "Parameter", "ParameterLocation", - "DataType", "PathItem", - "Parameter", "Reference", "RequestBody", "Response", "Responses", "Schema", + "UntrustedString", ] @@ -29,3 +29,4 @@ Schema, ) from .parameter_location import ParameterLocation +from .untrusted_string import UntrustedString diff --git a/openapi_python_client/schema/data_type.py b/openapi_python_client/schema/data_type.py index 1c104142e..e80f39803 100644 --- a/openapi_python_client/schema/data_type.py +++ b/openapi_python_client/schema/data_type.py @@ -1,7 +1,7 @@ -from enum import Enum +from enum import StrEnum -class DataType(str, Enum): +class DataType(StrEnum): """The data type of a schema is defined by the type keyword References: diff --git a/openapi_python_client/schema/openapi_schema_pydantic/__init__.py b/openapi_python_client/schema/openapi_schema_pydantic/__init__.py index 6b02446a8..b61cefc66 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/__init__.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/__init__.py @@ -7,6 +7,8 @@ """ __all__ = [ + "XML", + "Callback", "Components", "Contact", "Discriminator", @@ -35,8 +37,6 @@ "Server", "ServerVariable", "Tag", - "XML", - "Callback", ] @@ -70,3 +70,14 @@ from .server_variable import ServerVariable from .tag import Tag from .xml import XML + +PathItem.model_rebuild() +Operation.model_rebuild() +Components.model_rebuild() +Encoding.model_rebuild() +MediaType.model_rebuild() +OpenAPI.model_rebuild() +Parameter.model_rebuild() +Header.model_rebuild() +RequestBody.model_rebuild() +Response.model_rebuild() diff --git a/openapi_python_client/schema/openapi_schema_pydantic/callback.py b/openapi_python_client/schema/openapi_schema_pydantic/callback.py index 22426d925..ddf6a3434 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/callback.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/callback.py @@ -1,11 +1,13 @@ -from typing import TYPE_CHECKING, Dict +from typing import TYPE_CHECKING + +from ..untrusted_string import UntrustedString if TYPE_CHECKING: # pragma: no cover from .path_item import PathItem else: PathItem = "PathItem" -Callback = Dict[str, PathItem] +Callback = dict[UntrustedString, PathItem] """ A map of possible out-of band callbacks related to the parent operation. Each value in the map is a [Path Item Object](#pathItemObject) diff --git a/openapi_python_client/schema/openapi_schema_pydantic/components.py b/openapi_python_client/schema/openapi_schema_pydantic/components.py index f366a2ec8..8423247d7 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/components.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/components.py @@ -1,13 +1,12 @@ -from typing import Dict, Optional, Union - from pydantic import BaseModel, ConfigDict +from ..untrusted_string import UntrustedString from .callback import Callback from .example import Example from .header import Header from .link import Link from .parameter import Parameter -from .reference import Reference +from .reference import ReferenceOr from .request_body import RequestBody from .response import Response from .schema import Schema @@ -25,16 +24,18 @@ class Components(BaseModel): - https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#componentsObject """ - schemas: Optional[Dict[str, Union[Schema, Reference]]] = None - responses: Optional[Dict[str, Union[Response, Reference]]] = None - parameters: Optional[Dict[str, Union[Parameter, Reference]]] = None - examples: Optional[Dict[str, Union[Example, Reference]]] = None - requestBodies: Optional[Dict[str, Union[RequestBody, Reference]]] = None - headers: Optional[Dict[str, Union[Header, Reference]]] = None - securitySchemes: Optional[Dict[str, Union[SecurityScheme, Reference]]] = None - links: Optional[Dict[str, Union[Link, Reference]]] = None - callbacks: Optional[Dict[str, Union[Callback, Reference]]] = None + schemas: dict[UntrustedString, ReferenceOr[Schema]] | None = None + responses: dict[UntrustedString, ReferenceOr[Response]] | None = None + parameters: dict[UntrustedString, ReferenceOr[Parameter]] | None = None + examples: dict[UntrustedString, ReferenceOr[Example]] | None = None + requestBodies: dict[UntrustedString, ReferenceOr[RequestBody]] | None = None + headers: dict[UntrustedString, ReferenceOr[Header]] | None = None + securitySchemes: dict[UntrustedString, ReferenceOr[SecurityScheme]] | None = None + links: dict[UntrustedString, ReferenceOr[Link]] | None = None + callbacks: dict[UntrustedString, ReferenceOr[Callback]] | None = None model_config = ConfigDict( + # `Callback` contains an unresolvable forward reference, will rebuild in `__init__.py`: + defer_build=True, extra="allow", json_schema_extra={ "examples": [ diff --git a/openapi_python_client/schema/openapi_schema_pydantic/contact.py b/openapi_python_client/schema/openapi_schema_pydantic/contact.py index c04fdbbe0..ea7cbe33d 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/contact.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/contact.py @@ -1,7 +1,7 @@ -from typing import Optional - from pydantic import BaseModel, ConfigDict +from openapi_python_client.schema.untrusted_string import UntrustedString + class Contact(BaseModel): """ @@ -11,9 +11,9 @@ class Contact(BaseModel): - https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#contactObject """ - name: Optional[str] = None - url: Optional[str] = None - email: Optional[str] = None + name: UntrustedString | None = None + url: UntrustedString | None = None + email: UntrustedString | None = None model_config = ConfigDict( extra="allow", json_schema_extra={ diff --git a/openapi_python_client/schema/openapi_schema_pydantic/discriminator.py b/openapi_python_client/schema/openapi_schema_pydantic/discriminator.py index 95161d07a..3a10ce7f3 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/discriminator.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/discriminator.py @@ -1,7 +1,7 @@ -from typing import Dict, Optional - from pydantic import BaseModel, ConfigDict +from ..untrusted_string import UntrustedString + class Discriminator(BaseModel): """ @@ -18,8 +18,8 @@ class Discriminator(BaseModel): - https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#discriminatorObject """ - propertyName: str - mapping: Optional[Dict[str, str]] = None + propertyName: UntrustedString + mapping: dict[UntrustedString, UntrustedString] | None = None model_config = ConfigDict( extra="allow", json_schema_extra={ diff --git a/openapi_python_client/schema/openapi_schema_pydantic/encoding.py b/openapi_python_client/schema/openapi_schema_pydantic/encoding.py index b7434c50c..f09a7602e 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/encoding.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/encoding.py @@ -1,13 +1,12 @@ -from typing import TYPE_CHECKING, Dict, Optional, Union +from typing import TYPE_CHECKING from pydantic import BaseModel, ConfigDict -from .reference import Reference +from ..untrusted_string import UntrustedString +from .reference import ReferenceOr if TYPE_CHECKING: # pragma: no cover from .header import Header -else: - Header = "Header" class Encoding(BaseModel): @@ -18,12 +17,14 @@ class Encoding(BaseModel): - https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#encodingObject """ - contentType: Optional[str] = None - headers: Optional[Dict[str, Union[Header, Reference]]] = None - style: Optional[str] = None + contentType: UntrustedString | None = None + headers: dict[UntrustedString, ReferenceOr["Header"]] | None = None + style: UntrustedString | None = None explode: bool = False allowReserved: bool = False model_config = ConfigDict( + # `Header` is an unresolvable forward reference, will rebuild in `__init__.py`: + defer_build=True, extra="allow", json_schema_extra={ "examples": [ diff --git a/openapi_python_client/schema/openapi_schema_pydantic/example.py b/openapi_python_client/schema/openapi_schema_pydantic/example.py index 90db2530e..bd3d188aa 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/example.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/example.py @@ -1,7 +1,9 @@ -from typing import Any, Optional +from typing import Any from pydantic import BaseModel, ConfigDict +from ..untrusted_string import UntrustedString + class Example(BaseModel): """Examples added to parameters / components to help clarify usage. @@ -11,10 +13,10 @@ class Example(BaseModel): - https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#exampleObject """ - summary: Optional[str] = None - description: Optional[str] = None - value: Optional[Any] = None - externalValue: Optional[str] = None + summary: UntrustedString | None = None + description: UntrustedString | None = None + value: Any | None = None + externalValue: UntrustedString | None = None model_config = ConfigDict( extra="allow", json_schema_extra={ diff --git a/openapi_python_client/schema/openapi_schema_pydantic/external_documentation.py b/openapi_python_client/schema/openapi_schema_pydantic/external_documentation.py index 2c0c39b7c..b5565beb8 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/external_documentation.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/external_documentation.py @@ -1,7 +1,7 @@ -from typing import Optional - from pydantic import BaseModel, ConfigDict +from openapi_python_client.schema.untrusted_string import UntrustedString + class ExternalDocumentation(BaseModel): """Allows referencing an external resource for extended documentation. @@ -10,8 +10,8 @@ class ExternalDocumentation(BaseModel): - https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#externalDocumentationObject """ - description: Optional[str] = None - url: str + description: UntrustedString | None = None + url: UntrustedString model_config = ConfigDict( extra="allow", json_schema_extra={"examples": [{"description": "Find more info here", "url": "https://example.com"}]}, diff --git a/openapi_python_client/schema/openapi_schema_pydantic/header.py b/openapi_python_client/schema/openapi_schema_pydantic/header.py index 3223c199b..e81300459 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/header.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/header.py @@ -1,10 +1,15 @@ -from pydantic import ConfigDict, Field +from typing import Any -from ..parameter_location import ParameterLocation -from .parameter import Parameter +from pydantic import BaseModel, ConfigDict, Field +from ..untrusted_string import UntrustedString +from .example import Example +from .media_type import MediaType +from .reference import ReferenceOr +from .schema import Schema -class Header(Parameter): + +class Header(BaseModel): """ The Header Object follows the structure of the [Parameter Object](#parameterObject) with the following changes: @@ -18,9 +23,20 @@ class Header(Parameter): - https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#headerObject """ - name: str = Field(default="") - param_in: ParameterLocation = Field(default=ParameterLocation.HEADER, alias="in") + description: UntrustedString | None = None + required: bool = False + deprecated: bool = False + allowEmptyValue: bool = False + style: UntrustedString | None = None + explode: bool = False + allowReserved: bool = False + param_schema: ReferenceOr[Schema] | None = Field(default=None, alias="schema") + example: Any | None = None + examples: dict[UntrustedString, ReferenceOr[Example]] | None = None + content: dict[UntrustedString, MediaType] | None = None model_config = ConfigDict( + # `Parameter` is not build yet, will rebuild in `__init__.py`: + defer_build=True, extra="allow", populate_by_name=True, json_schema_extra={ diff --git a/openapi_python_client/schema/openapi_schema_pydantic/info.py b/openapi_python_client/schema/openapi_schema_pydantic/info.py index bec1354da..316ed538e 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/info.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/info.py @@ -1,7 +1,6 @@ -from typing import Optional - from pydantic import BaseModel, ConfigDict +from ..untrusted_string import UntrustedString from .contact import Contact from .license import License @@ -17,12 +16,12 @@ class Info(BaseModel): -https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#infoObject """ - title: str - description: Optional[str] = None - termsOfService: Optional[str] = None - contact: Optional[Contact] = None - license: Optional[License] = None - version: str + title: UntrustedString + description: UntrustedString | None = None + termsOfService: UntrustedString | None = None + contact: Contact | None = None + license: License | None = None + version: UntrustedString model_config = ConfigDict( extra="allow", json_schema_extra={ diff --git a/openapi_python_client/schema/openapi_schema_pydantic/license.py b/openapi_python_client/schema/openapi_schema_pydantic/license.py index 185eec1db..1c40b285a 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/license.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/license.py @@ -1,7 +1,7 @@ -from typing import Optional - from pydantic import BaseModel, ConfigDict +from ..untrusted_string import UntrustedString + class License(BaseModel): """ @@ -11,8 +11,8 @@ class License(BaseModel): - https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#licenseObject """ - name: str - url: Optional[str] = None + name: UntrustedString + url: UntrustedString | None = None model_config = ConfigDict( extra="allow", json_schema_extra={ diff --git a/openapi_python_client/schema/openapi_schema_pydantic/link.py b/openapi_python_client/schema/openapi_schema_pydantic/link.py index 9f823c4a2..feccecccc 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/link.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/link.py @@ -1,7 +1,8 @@ -from typing import Any, Dict, Optional +from typing import Any from pydantic import BaseModel, ConfigDict +from ..untrusted_string import UntrustedString from .server import Server @@ -23,12 +24,12 @@ class Link(BaseModel): - https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#linkObject """ - operationRef: Optional[str] = None - operationId: Optional[str] = None - parameters: Optional[Dict[str, Any]] = None - requestBody: Optional[Any] = None - description: Optional[str] = None - server: Optional[Server] = None + operationRef: UntrustedString | None = None + operationId: UntrustedString | None = None + parameters: dict[UntrustedString, Any] | None = None + requestBody: Any | None = None + description: UntrustedString | None = None + server: Server | None = None model_config = ConfigDict( extra="allow", json_schema_extra={ diff --git a/openapi_python_client/schema/openapi_schema_pydantic/media_type.py b/openapi_python_client/schema/openapi_schema_pydantic/media_type.py index 1bda99560..7418b9715 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/media_type.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/media_type.py @@ -1,10 +1,11 @@ -from typing import Any, Dict, Optional, Union +from typing import Any from pydantic import BaseModel, ConfigDict, Field +from ..untrusted_string import UntrustedString from .encoding import Encoding from .example import Example -from .reference import Reference +from .reference import ReferenceOr from .schema import Schema @@ -16,11 +17,13 @@ class MediaType(BaseModel): - https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#mediaTypeObject """ - media_type_schema: Optional[Union[Reference, Schema]] = Field(default=None, alias="schema") - example: Optional[Any] = None - examples: Optional[Dict[str, Union[Example, Reference]]] = None - encoding: Optional[Dict[str, Encoding]] = None + media_type_schema: ReferenceOr[Schema] | None = Field(default=None, alias="schema") + example: Any | None = None + examples: dict[UntrustedString, ReferenceOr[Example]] | None = None + encoding: dict[UntrustedString, Encoding] | None = None model_config = ConfigDict( + # `Encoding` is not build yet, will rebuild in `__init__.py`: + defer_build=True, extra="allow", populate_by_name=True, json_schema_extra={ diff --git a/openapi_python_client/schema/openapi_schema_pydantic/oauth_flow.py b/openapi_python_client/schema/openapi_schema_pydantic/oauth_flow.py index c7485814f..8320c148a 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/oauth_flow.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/oauth_flow.py @@ -1,7 +1,7 @@ -from typing import Dict, Optional - from pydantic import BaseModel, ConfigDict +from ..untrusted_string import UntrustedString + class OAuthFlow(BaseModel): """ @@ -12,10 +12,10 @@ class OAuthFlow(BaseModel): - https://swagger.io/docs/specification/authentication/oauth2/ """ - authorizationUrl: Optional[str] = None - tokenUrl: Optional[str] = None - refreshUrl: Optional[str] = None - scopes: Dict[str, str] + authorizationUrl: UntrustedString | None = None + tokenUrl: UntrustedString | None = None + refreshUrl: UntrustedString | None = None + scopes: dict[UntrustedString, UntrustedString] model_config = ConfigDict( extra="allow", json_schema_extra={ diff --git a/openapi_python_client/schema/openapi_schema_pydantic/oauth_flows.py b/openapi_python_client/schema/openapi_schema_pydantic/oauth_flows.py index dba193713..602a34cb5 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/oauth_flows.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/oauth_flows.py @@ -1,5 +1,3 @@ -from typing import Optional - from pydantic import BaseModel, ConfigDict from .oauth_flow import OAuthFlow @@ -14,8 +12,8 @@ class OAuthFlows(BaseModel): - https://swagger.io/docs/specification/authentication/oauth2/ """ - implicit: Optional[OAuthFlow] = None - password: Optional[OAuthFlow] = None - clientCredentials: Optional[OAuthFlow] = None - authorizationCode: Optional[OAuthFlow] = None + implicit: OAuthFlow | None = None + password: OAuthFlow | None = None + clientCredentials: OAuthFlow | None = None + authorizationCode: OAuthFlow | None = None model_config = ConfigDict(extra="allow") diff --git a/openapi_python_client/schema/openapi_schema_pydantic/open_api.py b/openapi_python_client/schema/openapi_schema_pydantic/open_api.py index 6a1b5ae12..890cf5793 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/open_api.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/open_api.py @@ -1,13 +1,9 @@ -from typing import List, Optional - from pydantic import BaseModel, ConfigDict, field_validator +from ..untrusted_string import UntrustedString from .components import Components from .external_documentation import ExternalDocumentation from .info import Info - -# Required to update forward ref after object creation -from .path_item import PathItem # noqa: F401 from .paths import Paths from .security_requirement import SecurityRequirement from .server import Server @@ -25,19 +21,24 @@ class OpenAPI(BaseModel): """ info: Info - servers: List[Server] = [Server(url="/")] + servers: list[Server] = [Server(url="/")] paths: Paths - components: Optional[Components] = None - security: Optional[List[SecurityRequirement]] = None - tags: Optional[List[Tag]] = None - externalDocs: Optional[ExternalDocumentation] = None - openapi: str - model_config = ConfigDict(extra="allow") + components: Components | None = None + security: list[SecurityRequirement] | None = None + tags: list[Tag] | None = None + externalDocs: ExternalDocumentation | None = None + openapi: UntrustedString + model_config = ConfigDict( + # `Components` is not build yet, will rebuild in `__init__.py`: + defer_build=True, + extra="allow", + ) @field_validator("openapi") @classmethod - def check_openapi_version(cls, value: str) -> str: + def check_openapi_version(cls, untrusted: UntrustedString) -> UntrustedString: """Validates that the declared OpenAPI version is a supported one""" + value = untrusted.get_untrusted_value() parts = value.split(".") if len(parts) != NUM_SEMVER_PARTS: raise ValueError(f"Invalid OpenAPI version {value}") @@ -45,7 +46,4 @@ def check_openapi_version(cls, value: str) -> str: raise ValueError(f"Only OpenAPI versions 3.* are supported, got {value}") if int(parts[1]) > 1: raise ValueError(f"Only OpenAPI versions 3.1.* are supported, got {value}") - return value - - -OpenAPI.model_rebuild() + return untrusted diff --git a/openapi_python_client/schema/openapi_schema_pydantic/operation.py b/openapi_python_client/schema/openapi_schema_pydantic/operation.py index 41f5e7100..9bc1dbef3 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/operation.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/operation.py @@ -1,15 +1,10 @@ -from typing import Dict, List, Optional, Union - from pydantic import BaseModel, ConfigDict, Field +from ..untrusted_string import UntrustedString from .callback import Callback from .external_documentation import ExternalDocumentation -from .header import Header # noqa: F401 from .parameter import Parameter - -# Required to update forward ref after object creation, as this is not imported yet -from .path_item import PathItem # noqa: F401 -from .reference import Reference +from .reference import ReferenceOr from .request_body import RequestBody from .responses import Responses from .security_requirement import SecurityRequirement @@ -24,20 +19,22 @@ class Operation(BaseModel): - https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operationObject """ - tags: Optional[List[str]] = None - summary: Optional[str] = None - description: Optional[str] = None - externalDocs: Optional[ExternalDocumentation] = None - operationId: Optional[str] = None - parameters: Optional[List[Union[Parameter, Reference]]] = None - request_body: Optional[Union[RequestBody, Reference]] = Field(None, alias="requestBody") + tags: list[UntrustedString] | None = None + summary: UntrustedString | None = None + description: UntrustedString | None = None + externalDocs: ExternalDocumentation | None = None + operationId: UntrustedString | None = None + parameters: list[ReferenceOr[Parameter]] | None = None + request_body: ReferenceOr[RequestBody] | None = Field(None, alias="requestBody") responses: Responses - callbacks: Optional[Dict[str, Callback]] = None + callbacks: dict[UntrustedString, Callback] | None = None deprecated: bool = False - security: Optional[List[SecurityRequirement]] = None - servers: Optional[List[Server]] = None + security: list[SecurityRequirement] | None = None + servers: list[Server] | None = None model_config = ConfigDict( + # `Callback` contains an unresolvable forward reference, will rebuild in `__init__.py`: + defer_build=True, extra="allow", json_schema_extra={ "examples": [ @@ -89,7 +86,3 @@ class Operation(BaseModel): ] }, ) - - -# PathItem in Callback uses Operation, so we need to update forward refs due to circular dependency -Operation.model_rebuild() diff --git a/openapi_python_client/schema/openapi_schema_pydantic/parameter.py b/openapi_python_client/schema/openapi_schema_pydantic/parameter.py index 25ba819f1..880cc6560 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/parameter.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/parameter.py @@ -1,11 +1,12 @@ -from typing import Any, Dict, Optional, Union +from typing import Any from pydantic import BaseModel, ConfigDict, Field from ..parameter_location import ParameterLocation +from ..untrusted_string import UntrustedString from .example import Example from .media_type import MediaType -from .reference import Reference +from .reference import ReferenceOr from .schema import Schema @@ -21,20 +22,22 @@ class Parameter(BaseModel): - https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#parameterObject """ - name: str + name: UntrustedString param_in: ParameterLocation = Field(alias="in") - description: Optional[str] = None + description: UntrustedString | None = None required: bool = False deprecated: bool = False allowEmptyValue: bool = False - style: Optional[str] = None + style: UntrustedString | None = None explode: bool = False allowReserved: bool = False - param_schema: Optional[Union[Reference, Schema]] = Field(default=None, alias="schema") - example: Optional[Any] = None - examples: Optional[Dict[str, Union[Example, Reference]]] = None - content: Optional[Dict[str, MediaType]] = None + param_schema: ReferenceOr[Schema] | None = Field(default=None, alias="schema") + example: Any | None = None + examples: dict[UntrustedString, ReferenceOr[Example]] | None = None + content: dict[UntrustedString, MediaType] | None = None model_config = ConfigDict( + # `MediaType` is not build yet, will rebuild in `__init__.py`: + defer_build=True, extra="allow", populate_by_name=True, json_schema_extra={ diff --git a/openapi_python_client/schema/openapi_schema_pydantic/path_item.py b/openapi_python_client/schema/openapi_schema_pydantic/path_item.py index 36edee0e3..5e1116f3d 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/path_item.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/path_item.py @@ -1,11 +1,16 @@ -from typing import List, Optional, Union +from typing import TYPE_CHECKING from pydantic import BaseModel, ConfigDict, Field +from ..ref import Ref +from ..untrusted_string import UntrustedString from .parameter import Parameter -from .reference import Reference +from .reference import ReferenceOr from .server import Server +if TYPE_CHECKING: + from .operation import Operation # pragma: no cover + class PathItem(BaseModel): """ @@ -19,20 +24,22 @@ class PathItem(BaseModel): - https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#pathItemObject """ - ref: Optional[str] = Field(default=None, alias="$ref") - summary: Optional[str] = None - description: Optional[str] = None - get: Optional["Operation"] = None - put: Optional["Operation"] = None - post: Optional["Operation"] = None - delete: Optional["Operation"] = None - options: Optional["Operation"] = None - head: Optional["Operation"] = None - patch: Optional["Operation"] = None - trace: Optional["Operation"] = None - servers: Optional[List[Server]] = None - parameters: Optional[List[Union[Parameter, Reference]]] = None + ref: Ref | None = Field(default=None, alias="$ref") + summary: UntrustedString | None = None + description: UntrustedString | None = None + get: "Operation | None" = None + put: "Operation | None" = None + post: "Operation | None" = None + delete: "Operation | None" = None + options: "Operation | None" = None + head: "Operation | None" = None + patch: "Operation | None" = None + trace: "Operation | None" = None + servers: list[Server] | None = None + parameters: list[ReferenceOr[Parameter]] | None = None model_config = ConfigDict( + # `Operation` is an unresolvable forward reference, will rebuild in `__init__.py`: + defer_build=True, extra="allow", populate_by_name=True, json_schema_extra={ @@ -69,9 +76,3 @@ class PathItem(BaseModel): ] }, ) - - -# Operation uses PathItem via Callback, so we need late import and to update forward refs due to circular dependency -from .operation import Operation # noqa: E402 - -PathItem.model_rebuild() diff --git a/openapi_python_client/schema/openapi_schema_pydantic/paths.py b/openapi_python_client/schema/openapi_schema_pydantic/paths.py index d61ea7b18..bc7181edf 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/paths.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/paths.py @@ -1,8 +1,7 @@ -from typing import Dict - +from ..untrusted_string import UntrustedString from .path_item import PathItem -Paths = Dict[str, PathItem] +Paths = dict[UntrustedString, PathItem] """ Holds the relative paths to the individual endpoints and their operations. The path is appended to the URL from the [`Server Object`](#serverObject) in order to construct the full URL. diff --git a/openapi_python_client/schema/openapi_schema_pydantic/reference.py b/openapi_python_client/schema/openapi_schema_pydantic/reference.py index 50d26064f..c62a7538d 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/reference.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/reference.py @@ -1,4 +1,8 @@ -from pydantic import BaseModel, ConfigDict, Field +from typing import Annotated, Any, Literal, TypeAlias, TypeVar + +from pydantic import BaseModel, ConfigDict, Discriminator, Field, Tag + +from openapi_python_client.schema.ref import Ref class Reference(BaseModel): @@ -16,7 +20,7 @@ class Reference(BaseModel): - https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#referenceObject """ - ref: str = Field(alias="$ref") + ref: Ref = Field(alias="$ref") model_config = ConfigDict( extra="allow", populate_by_name=True, @@ -24,3 +28,17 @@ class Reference(BaseModel): "examples": [{"$ref": "#/components/schemas/Pet"}, {"$ref": "Pet.json"}, {"$ref": "definitions.json#/Pet"}] }, ) + + +T = TypeVar("T") + + +def _reference_discriminator(obj: Any) -> Literal["ref", "other"]: + if isinstance(obj, dict): + return "ref" if "$ref" in obj else "other" + return "ref" if isinstance(obj, Reference) else "other" + + +ReferenceOr: TypeAlias = Annotated[ + Annotated[Reference, Tag("ref")] | Annotated[T, Tag("other")], Discriminator(_reference_discriminator) +] diff --git a/openapi_python_client/schema/openapi_schema_pydantic/request_body.py b/openapi_python_client/schema/openapi_schema_pydantic/request_body.py index 6b1847215..361ac8102 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/request_body.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/request_body.py @@ -1,7 +1,6 @@ -from typing import Dict, Optional - from pydantic import BaseModel, ConfigDict +from ..untrusted_string import UntrustedString from .media_type import MediaType @@ -13,10 +12,12 @@ class RequestBody(BaseModel): - https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#requestBodyObject """ - description: Optional[str] = None - content: Dict[str, MediaType] + description: UntrustedString | None = None + content: dict[UntrustedString, MediaType] required: bool = False model_config = ConfigDict( + # `MediaType` is not build yet, will rebuild in `__init__.py`: + defer_build=True, extra="allow", json_schema_extra={ "examples": [ diff --git a/openapi_python_client/schema/openapi_schema_pydantic/response.py b/openapi_python_client/schema/openapi_schema_pydantic/response.py index a7c5d08ec..ae972c16c 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/response.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/response.py @@ -1,11 +1,10 @@ -from typing import Dict, Optional, Union - from pydantic import BaseModel, ConfigDict +from ..untrusted_string import UntrustedString from .header import Header from .link import Link from .media_type import MediaType -from .reference import Reference +from .reference import ReferenceOr class Response(BaseModel): @@ -18,11 +17,13 @@ class Response(BaseModel): - https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#responseObject """ - description: str - headers: Optional[Dict[str, Union[Header, Reference]]] = None - content: Optional[Dict[str, MediaType]] = None - links: Optional[Dict[str, Union[Link, Reference]]] = None + description: UntrustedString + headers: dict[UntrustedString, ReferenceOr[Header]] | None = None + content: dict[UntrustedString, MediaType] | None = None + links: dict[UntrustedString, ReferenceOr[Link]] | None = None model_config = ConfigDict( + # `MediaType` is not build yet, will rebuild in `__init__.py`: + defer_build=True, extra="allow", json_schema_extra={ "examples": [ diff --git a/openapi_python_client/schema/openapi_schema_pydantic/responses.py b/openapi_python_client/schema/openapi_schema_pydantic/responses.py index 53306ae1c..9714bd535 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/responses.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/responses.py @@ -1,9 +1,8 @@ -from typing import Dict, Union - -from .reference import Reference +from ..untrusted_string import UntrustedString +from .reference import ReferenceOr from .response import Response -Responses = Dict[str, Union[Response, Reference]] +Responses = dict[UntrustedString, ReferenceOr[Response]] """ A container for the expected responses of an operation. The container maps a HTTP response code to the expected response. diff --git a/openapi_python_client/schema/openapi_schema_pydantic/schema.py b/openapi_python_client/schema/openapi_schema_pydantic/schema.py index e2201c6e7..39ee4ffd8 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/schema.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/schema.py @@ -1,11 +1,12 @@ -from typing import Any, Dict, List, Optional, Union +from typing import Any -from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr, model_validator +from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictFloat, StrictInt, StrictStr, model_validator from ..data_type import DataType +from ..untrusted_string import UntrustedString from .discriminator import Discriminator from .external_documentation import ExternalDocumentation -from .reference import Reference +from .reference import ReferenceOr from .xml import XML @@ -20,42 +21,43 @@ class Schema(BaseModel): - https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schemaObject """ - title: Optional[str] = None - multipleOf: Optional[float] = Field(default=None, gt=0.0) - maximum: Optional[float] = None - exclusiveMaximum: Optional[bool] = None - minimum: Optional[float] = None - exclusiveMinimum: Optional[bool] = None - maxLength: Optional[int] = Field(default=None, ge=0) - minLength: Optional[int] = Field(default=None, ge=0) - pattern: Optional[str] = None - maxItems: Optional[int] = Field(default=None, ge=0) - minItems: Optional[int] = Field(default=None, ge=0) - uniqueItems: Optional[bool] = None - maxProperties: Optional[int] = Field(default=None, ge=0) - minProperties: Optional[int] = Field(default=None, ge=0) - required: Optional[List[str]] = Field(default=None, min_length=1) - enum: Union[None, List[Any]] = Field(default=None, min_length=1) - const: Union[None, StrictStr, StrictInt] = None - type: Union[DataType, List[DataType], None] = Field(default=None) - allOf: List[Union[Reference, "Schema"]] = Field(default_factory=list) - oneOf: List[Union[Reference, "Schema"]] = Field(default_factory=list) - anyOf: List[Union[Reference, "Schema"]] = Field(default_factory=list) - schema_not: Optional[Union[Reference, "Schema"]] = Field(default=None, alias="not") - items: Optional[Union[Reference, "Schema"]] = None - properties: Optional[Dict[str, Union[Reference, "Schema"]]] = None - additionalProperties: Optional[Union[bool, Reference, "Schema"]] = None - description: Optional[str] = None - schema_format: Optional[str] = Field(default=None, alias="format") - default: Optional[Any] = None + title: UntrustedString | None = None + multipleOf: float | None = Field(default=None, gt=0.0) + maximum: float | None = None + exclusiveMaximum: bool | float | None = None + minimum: float | None = None + exclusiveMinimum: bool | float | None = None + maxLength: int | None = Field(default=None, ge=0) + minLength: int | None = Field(default=None, ge=0) + pattern: UntrustedString | None = None + maxItems: int | None = Field(default=None, ge=0) + minItems: int | None = Field(default=None, ge=0) + uniqueItems: bool | None = None + maxProperties: int | None = Field(default=None, ge=0) + minProperties: int | None = Field(default=None, ge=0) + required: list[UntrustedString] | None = Field(default=None) + enum: None | list[Any] = Field(default=None, min_length=1) + const: None | StrictStr | StrictInt | StrictFloat | StrictBool = None + type: DataType | list[DataType] | None = Field(default=None) + allOf: list[ReferenceOr["Schema"]] = Field(default_factory=list) + oneOf: list[ReferenceOr["Schema"]] = Field(default_factory=list) + anyOf: list[ReferenceOr["Schema"]] = Field(default_factory=list) + schema_not: ReferenceOr["Schema"] | None = Field(default=None, alias="not") + items: ReferenceOr["Schema"] | None = None + prefixItems: list[ReferenceOr["Schema"]] = Field(default_factory=list) + properties: dict[UntrustedString, ReferenceOr["Schema"]] | None = None + additionalProperties: bool | ReferenceOr["Schema"] | None = None + description: UntrustedString | None = None + schema_format: UntrustedString | None = Field(default=None, alias="format") + default: Any | None = None nullable: bool = Field(default=False) - discriminator: Optional[Discriminator] = None - readOnly: Optional[bool] = None - writeOnly: Optional[bool] = None - xml: Optional[XML] = None - externalDocs: Optional[ExternalDocumentation] = None - example: Optional[Any] = None - deprecated: Optional[bool] = None + discriminator: Discriminator | None = None + readOnly: bool | None = None + writeOnly: bool | None = None + xml: XML | None = None + externalDocs: ExternalDocumentation | None = None + example: Any | None = None + deprecated: bool | None = None model_config = ConfigDict( extra="allow", populate_by_name=True, @@ -160,6 +162,33 @@ class Schema(BaseModel): }, ) + @model_validator(mode="after") + def handle_exclusive_min_max(self) -> "Schema": + """ + Convert exclusiveMinimum/exclusiveMaximum between OpenAPI v3.0 (bool) and v3.1 (numeric). + """ + # Handle exclusiveMinimum + if isinstance(self.exclusiveMinimum, bool) and self.minimum is not None: + if self.exclusiveMinimum: + self.exclusiveMinimum = self.minimum + self.minimum = None + else: + self.exclusiveMinimum = None + elif isinstance(self.exclusiveMinimum, float): + self.minimum = None + + # Handle exclusiveMaximum + if isinstance(self.exclusiveMaximum, bool) and self.maximum is not None: + if self.exclusiveMaximum: + self.exclusiveMaximum = self.maximum + self.maximum = None + else: + self.exclusiveMaximum = None + elif isinstance(self.exclusiveMaximum, float): + self.maximum = None + + return self + @model_validator(mode="after") def handle_nullable(self) -> "Schema": """Convert the old 3.0 `nullable` property into the new 3.1 style""" @@ -178,6 +207,3 @@ def handle_nullable(self) -> "Schema": self.oneOf = [Schema(type=DataType.NULL), Schema(allOf=self.allOf)] self.allOf = [] return self - - -Schema.model_rebuild() diff --git a/openapi_python_client/schema/openapi_schema_pydantic/security_requirement.py b/openapi_python_client/schema/openapi_schema_pydantic/security_requirement.py index b3cca3b08..c299895ce 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/security_requirement.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/security_requirement.py @@ -1,6 +1,6 @@ -from typing import Dict, List +from ..untrusted_string import UntrustedString -SecurityRequirement = Dict[str, List[str]] +SecurityRequirement = dict[UntrustedString, list[UntrustedString]] """ Lists the required security schemes to execute this operation. The name used for each property MUST correspond to a security scheme declared in the diff --git a/openapi_python_client/schema/openapi_schema_pydantic/security_scheme.py b/openapi_python_client/schema/openapi_schema_pydantic/security_scheme.py index df385440c..77c681c59 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/security_scheme.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/security_scheme.py @@ -1,7 +1,6 @@ -from typing import Optional - from pydantic import BaseModel, ConfigDict, Field +from ..untrusted_string import UntrustedString from .oauth_flows import OAuthFlows @@ -19,14 +18,14 @@ class SecurityScheme(BaseModel): - https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#componentsObject """ - type: str - description: Optional[str] = None - name: Optional[str] = None - security_scheme_in: Optional[str] = Field(default=None, alias="in") - scheme: Optional[str] = None - bearerFormat: Optional[str] = None - flows: Optional[OAuthFlows] = None - openIdConnectUrl: Optional[str] = None + type: UntrustedString + description: UntrustedString | None = None + name: UntrustedString | None = None + security_scheme_in: UntrustedString | None = Field(default=None, alias="in") + scheme: UntrustedString | None = None + bearerFormat: UntrustedString | None = None + flows: OAuthFlows | None = None + openIdConnectUrl: UntrustedString | None = None model_config = ConfigDict( extra="allow", populate_by_name=True, diff --git a/openapi_python_client/schema/openapi_schema_pydantic/server.py b/openapi_python_client/schema/openapi_schema_pydantic/server.py index d573a93fe..a975dcf06 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/server.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/server.py @@ -1,7 +1,6 @@ -from typing import Dict, Optional - from pydantic import BaseModel, ConfigDict +from ..untrusted_string import UntrustedString from .server_variable import ServerVariable @@ -13,9 +12,9 @@ class Server(BaseModel): - https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#serverObject """ - url: str - description: Optional[str] = None - variables: Optional[Dict[str, ServerVariable]] = None + url: UntrustedString + description: UntrustedString | None = None + variables: dict[UntrustedString, ServerVariable] | None = None model_config = ConfigDict( extra="allow", json_schema_extra={ diff --git a/openapi_python_client/schema/openapi_schema_pydantic/server_variable.py b/openapi_python_client/schema/openapi_schema_pydantic/server_variable.py index 3b63c9ad2..4517783bc 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/server_variable.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/server_variable.py @@ -1,7 +1,7 @@ -from typing import List, Optional - from pydantic import BaseModel, ConfigDict +from ..untrusted_string import UntrustedString + class ServerVariable(BaseModel): """An object representing a Server Variable for server URL template substitution. @@ -11,7 +11,7 @@ class ServerVariable(BaseModel): - https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#serverVariableObject """ - enum: Optional[List[str]] = None - default: str - description: Optional[str] = None + enum: list[UntrustedString] | None = None + default: UntrustedString + description: UntrustedString | None = None model_config = ConfigDict(extra="allow") diff --git a/openapi_python_client/schema/openapi_schema_pydantic/tag.py b/openapi_python_client/schema/openapi_schema_pydantic/tag.py index acb5fdc28..a433988b5 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/tag.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/tag.py @@ -1,7 +1,6 @@ -from typing import Optional - from pydantic import BaseModel, ConfigDict +from ..untrusted_string import UntrustedString from .external_documentation import ExternalDocumentation @@ -15,9 +14,9 @@ class Tag(BaseModel): - https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#tagObject """ - name: str - description: Optional[str] = None - externalDocs: Optional[ExternalDocumentation] = None + name: UntrustedString + description: UntrustedString | None = None + externalDocs: ExternalDocumentation | None = None model_config = ConfigDict( extra="allow", json_schema_extra={"examples": [{"name": "pet", "description": "Pets operations"}]} ) diff --git a/openapi_python_client/schema/openapi_schema_pydantic/xml.py b/openapi_python_client/schema/openapi_schema_pydantic/xml.py index 986aa44f4..53b178aa9 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/xml.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/xml.py @@ -1,7 +1,7 @@ -from typing import Optional - from pydantic import BaseModel, ConfigDict +from ..untrusted_string import UntrustedString + class XML(BaseModel): """ @@ -16,9 +16,9 @@ class XML(BaseModel): - https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#xmlObject """ - name: Optional[str] = None - namespace: Optional[str] = None - prefix: Optional[str] = None + name: UntrustedString | None = None + namespace: UntrustedString | None = None + prefix: UntrustedString | None = None attribute: bool = False wrapped: bool = False model_config = ConfigDict( diff --git a/openapi_python_client/schema/parameter_location.py b/openapi_python_client/schema/parameter_location.py index 162a7cb13..61f9dae14 100644 --- a/openapi_python_client/schema/parameter_location.py +++ b/openapi_python_client/schema/parameter_location.py @@ -1,25 +1,10 @@ -# Python 3.11 has StrEnum but breaks the old `str, Enum` hack. -# Unless this gets fixed, we need to have two implementations :( -import sys +from enum import StrEnum -if sys.version_info >= (3, 11): - from enum import StrEnum - class ParameterLocation(StrEnum): - """The places Parameters can be put when calling an Endpoint""" +class ParameterLocation(StrEnum): + """The places Parameters can be put when calling an Endpoint""" - QUERY = "query" - PATH = "path" - HEADER = "header" - COOKIE = "cookie" - -else: - from enum import Enum - - class ParameterLocation(str, Enum): - """The places Parameters can be put when calling an Endpoint""" - - QUERY = "query" - PATH = "path" - HEADER = "header" - COOKIE = "cookie" + QUERY = "query" + PATH = "path" + HEADER = "header" + COOKIE = "cookie" diff --git a/openapi_python_client/schema/ref.py b/openapi_python_client/schema/ref.py new file mode 100644 index 000000000..35d228055 --- /dev/null +++ b/openapi_python_client/schema/ref.py @@ -0,0 +1,52 @@ +from typing import Any + +from pydantic import GetCoreSchemaHandler +from pydantic_core import core_schema + +from .untrusted_string import UntrustedString + + +class Ref: + """A $ref in the schema, the raw value is protected to make sure we don't accidentally place it in the generated code.""" + + def __init__(self, value: str | UntrustedString) -> None: + if isinstance(value, UntrustedString): + value = value.get_untrusted_value() + self._value = value + + @classmethod + def __get_pydantic_core_schema__(cls, _source_type: Any, _handler: GetCoreSchemaHandler) -> core_schema.CoreSchema: + return core_schema.no_info_after_validator_function( + cls, + core_schema.str_schema(), + serialization=core_schema.plain_serializer_function_ser_schema( + cls._serialize, info_arg=True, return_schema=core_schema.any_schema() + ), + ) + + @staticmethod + def _serialize(value: "Ref", info: core_schema.SerializationInfo) -> Any: + # Only unwrap in JSON mode (used for error messages); Python mode keeps the wrapper so it + # can't leak into generated code. Returning the wrapper also avoids serializer warnings. + if info.mode == "json": + return value.get_untrusted_value() + return value + + def get_untrusted_value(self) -> str: + """ + Get the raw $ref value. + + DO NOT place this in generated code. + """ + return self._value + + def endswith(self, suffix: str) -> bool: + return self._value.endswith(suffix) + + def __hash__(self) -> int: + return hash(self._value) + + def __eq__(self, other: object) -> bool: + if isinstance(other, Ref): + return self._value == other._value + return False # pragma: no cover diff --git a/openapi_python_client/schema/untrusted_string.py b/openapi_python_client/schema/untrusted_string.py new file mode 100644 index 000000000..e54bf2858 --- /dev/null +++ b/openapi_python_client/schema/untrusted_string.py @@ -0,0 +1,56 @@ +from typing import Any, TypeVar + +from pydantic import GetCoreSchemaHandler +from pydantic_core import CoreSchema, core_schema + +T = TypeVar("T") + + +class UntrustedString: + """A raw string in the OpenAPI document which should not be directly placed in the generated code.""" + + def __init__(self, value: str) -> None: + self._value = value + + @classmethod + def __get_pydantic_core_schema__(cls, _source_type: Any, _handler: GetCoreSchemaHandler) -> CoreSchema: + return core_schema.no_info_after_validator_function( + cls, + core_schema.str_schema(), + serialization=core_schema.plain_serializer_function_ser_schema( + cls._serialize, info_arg=True, return_schema=core_schema.any_schema() + ), + ) + + @staticmethod + def _serialize(value: "UntrustedString", info: core_schema.SerializationInfo) -> Any: + # Only unwrap in JSON mode (used for error messages); Python mode keeps the wrapper so it + # can't leak into generated code. Returning the wrapper also avoids serializer warnings. + if info.mode == "json": + return value.get_untrusted_value() + return value + + def get_untrusted_value(self) -> str: + """ + Return the raw string with no transformations. + + DO NOT use this for generating code directly. It can result in arbitrary code generation. + """ + return self._value + + def startswith(self, prefix: str) -> bool: + return self._value.startswith(prefix) + + def __bool__(self) -> bool: + """Whether the raw value is non-empty. Emptiness is not sensitive, so this is safe to expose.""" + return bool(self._value) + + def __hash__(self) -> int: + return hash(self._value) + + def __eq__(self, other: object) -> bool: + if isinstance(other, UntrustedString): + return self._value == other._value + if isinstance(other, str): + return self._value == other + return False diff --git a/openapi_python_client/strings.py b/openapi_python_client/strings.py new file mode 100644 index 000000000..bfbfc9e4f --- /dev/null +++ b/openapi_python_client/strings.py @@ -0,0 +1,245 @@ +from __future__ import annotations + +import builtins +import json +import re +import unicodedata +from dataclasses import dataclass +from email.message import Message +from keyword import iskeyword +from typing import Any + +from .config import Config +from .schema.untrusted_string import UntrustedString + +DELIMITERS = r"\. _-" + + +@dataclass(frozen=True, repr=False, slots=True) +class PythonCode: + """ + A snippet of Python source code generated from `UnstrustedString`s. + + It's safe to treat as code, but _may not_ be safe to place in docstrings, f-strings, etc. + """ + + _code: str + + def as_unembedded_code(self) -> str: + """ + Return the raw source code with no transformations. + + DO NOT use this inside a string context (docstrings, string literals, f-string literal text). + Pass this through the appropriate escaping function first (e.g. `safe_for_docstring`). + """ + return self._code + + +class PythonIdentifier(str): + """A snake_case string which has been validated / transformed into a valid identifier for Python""" + + def __new__(cls, value: UntrustedString | str, prefix: str, skip_snake_case: bool = False) -> PythonIdentifier: + if isinstance(value, UntrustedString): + value = value.get_untrusted_value() + safe_value = sanitize(value) + leading_underscore = safe_value.startswith("_") + if skip_snake_case: + # Keep the name as close to the original as possible (to disambiguate conflicts); + # only strip the delimiters sanitize() preserved, as they aren't valid in identifiers + safe_value = re.sub(r"[^\w]+", "", safe_value) + else: + safe_value = snake_case(safe_value) + safe_value = fix_reserved_words(safe_value) + + if not safe_value.isidentifier() or leading_underscore: + safe_value = f"{prefix}{safe_value}" + return str.__new__(cls, safe_value) + + def __deepcopy__(self, _: Any) -> PythonIdentifier: + return self + + +class ClassName(str): + """A PascalCase string which has been validated / transformed into a valid class name for Python""" + + def __new__(cls, value: UntrustedString | str, prefix: str) -> ClassName: + safe_value = fix_reserved_words(pascal_case(value)) + + if not safe_value.isidentifier(): + safe_value = f"{prefix}{safe_value}" + safe_value = fix_reserved_words(pascal_case(safe_value)) + return str.__new__(cls, safe_value) + + def __deepcopy__(self, _: Any) -> ClassName: + return self + + +def sanitize(value: str) -> str: + """Removes every character that isn't 0-9, A-Z, a-z, or a known delimiter""" + return "".join(c for c in value if c.isidentifier() or c.isdecimal() or c in DELIMITERS) + + +def split_words(value: str) -> list[str]: + """Split a string on words and known delimiters""" + if any(c.isupper() for c in value): + value = " ".join(re.split("([A-Z]?[a-z]+)", value)) + return re.findall(rf"[^{re.escape(DELIMITERS)}]+", value) + + +RESERVED_WORDS = (set(dir(builtins)) | {"self", "true", "false", "datetime"}) - { + "id", +} + + +def fix_reserved_words(value: str) -> str: + """ + Using reserved Python words as identifiers in generated code causes problems, so this function renames them. + + Args: + value: The identifier to-be that should be renamed if it's a reserved word. + + Returns: + `value` suffixed with `_` if it was a reserved word. + """ + if value in RESERVED_WORDS or iskeyword(value): + return f"{value}_" + return value + + +def snake_case(value: str | UntrustedString) -> str: + """Converts to snake_case identifier, stripping all non-alphanumeric characters""" + if isinstance(value, UntrustedString): + value = value.get_untrusted_value() + words = split_words(sanitize(value)) + return "_".join(words).lower() + + +def pascal_case(value: str | UntrustedString) -> str: + """Converts to PascalCase identifier, stripping all non-alphanumeric characters""" + if isinstance(value, UntrustedString): + value = value.get_untrusted_value() + words = split_words(sanitize(value)) + capitalized_words = (word.capitalize() if not word.isupper() else word for word in words) + return "".join(capitalized_words) + + +def kebab_case(value: str | UntrustedString) -> str: + """Converts to kebab-case identifier, stripping all non-alphanumeric characters""" + if isinstance(value, UntrustedString): + value = value.get_untrusted_value() + words = split_words(sanitize(value)) + return "-".join(words).lower() + + +#: Escaped words in docstring content are kept shorter than this so the ``wordwrap`` filter +#: never hard-splits inside an escape sequence (the narrowest wordwrap width in templates is 90). +_MAX_ESCAPED_WORD_LENGTH = 76 + + +def _split_long_word_safely(word: str) -> str: + """Insert newlines into an over-long escaped word where they can't interrupt an escape sequence. + + wordwrap hard-splits words longer than its width at arbitrary positions. A split between the + backslashes of ``\\\\`` leaves a lone backslash at the start of the next line, where it forms an + invalid escape (``\\ `` warns today and will error in a future Python) or even a ``SyntaxError`` + (``\\U`` + non-hex is a truncated escape). Splits right after an even number of backslashes are + always safe: the prefix ends with complete escapes and the suffix can't start a dangling one. + """ + chunks: list[str] = [] + start = 0 + while len(word) - start > _MAX_ESCAPED_WORD_LENGTH: + end = start + _MAX_ESCAPED_WORD_LENGTH + run = 0 + while end > start and word[end - 1] == "\\": + end -= 1 + run += 1 + # Keep an even number of trailing backslashes in this chunk. Odd runs only occur right + # before an escaped quote, so the one left behind always forms a valid `\"`. + end += run - (run % 2) + chunks.append(word[start:end]) + start = end + chunks.append(word[start:]) + return "\n".join(chunks) + + +def safe_for_docstring(value: Any) -> str: + """ + Remove any risky escapes from docstring content. + + The output is safe to run through the ``wordwrap`` filter at any width greater than + ``_MAX_ESCAPED_WORD_LENGTH``: over-long words containing escape sequences are pre-split where + no escape sequence is interrupted, so wordwrap's hard-splitting can't create invalid escapes. + """ + if isinstance(value, UntrustedString): + value = value.get_untrusted_value() + if isinstance(value, PythonCode): + value = value.as_unembedded_code() + if not isinstance(value, str): + value = str(value) + # Strip control characters which are illegal in Python source (e.g. null bytes) + value = "".join(c for c in value if unicodedata.category(c) != "Cc" or c in "\n\r\t") + + value = value.replace("\\", "\\\\").replace('"""', '\\"\\"\\"') + # Words without backslashes can be hard-split anywhere safely, so leave them alone + return re.sub( + r"\S+", + lambda match: _split_long_word_safely(match.group()) if "\\" in match.group() else match.group(), + value, + ) + + +def in_double_quote_literal(value: UntrustedString | PythonCode | str) -> str: + """Escape a string so it can be safely embedded inside a double-quoted string literal. + + The result does NOT include surrounding quotes; the caller is expected to place it inside its own `"..."` + (e.g. a Python string literal or a TOML string in generated code). JSON encoding is used for the escaping, + which is valid inside both Python and TOML double-quoted strings. + """ + if isinstance(value, UntrustedString): + value = value.get_untrusted_value() + if isinstance(value, PythonCode): + value = value.as_unembedded_code() + value = "".join( + character + for character in value + if (character in "\b\t\f" or not unicodedata.category(character).startswith("C")) + and unicodedata.category(character) not in {"Zl", "Zp"} + ) + return json.dumps(value, ensure_ascii=False)[1:-1] + + +def in_f_string_literal(value: UntrustedString | PythonCode | str) -> str: + """Escape a string so it can be safely embedded as literal text inside a double-quoted f-string. + + In addition to the double-quoted-string escaping (quotes, backslashes), this escapes `{` and `}` as + `{{` and `}}` so the value cannot be interpreted as an f-string replacement field or format specifier. + Without this, an untrusted value could inject arbitrary expressions into the generated f-string. + """ + return in_double_quote_literal(value).replace("{", "{{").replace("}", "}}") + + +def remove_string_escapes(value: str) -> str: + """Used when parsing string-literal defaults to prevent escaping the string to write arbitrary Python + + **REMOVING OR CHANGING THE USAGE OF THIS FUNCTION HAS SECURITY IMPLICATIONS** + + See Also: + - https://github.com/openapi-generators/openapi-python-client/security/advisories/GHSA-9x4c-63pf-525f + """ + return value.replace("\\", "\\\\").replace('"', r"\"") + + +def get_content_type(content_type: str, config: Config) -> str | None: + """ + Given a string representing a content type with optional parameters, returns the content type only + """ + content_type = config.content_type_overrides.get(content_type, content_type) + message = Message() + message.add_header("Content-Type", content_type) + + parsed_content_type = message.get_content_type() + if not content_type.startswith(parsed_content_type): + # Always defaults to `text/plain` if it's not recognized. We want to return an error, not default. + return None + + return parsed_content_type diff --git a/openapi_python_client/templates/README.md.jinja b/openapi_python_client/templates/README.md.jinja index ea31c83d7..d4b60f303 100644 --- a/openapi_python_client/templates/README.md.jinja +++ b/openapi_python_client/templates/README.md.jinja @@ -1,5 +1,5 @@ # {{ project_name }} -{{ package_description }} +{{ package_description.get_untrusted_value() }} ## Usage First, create a client: @@ -47,7 +47,7 @@ By default, when you're calling an HTTPS API it will attempt to verify that SSL ```python client = AuthenticatedClient( - base_url="https://internal_api.example.com", + base_url="https://internal_api.example.com", token="SuperSecretToken", verify_ssl="/path/to/certificate_bundle.pem", ) @@ -57,7 +57,7 @@ You can also disable certificate validation altogether, but beware that **this i ```python client = AuthenticatedClient( - base_url="https://internal_api.example.com", + base_url="https://internal_api.example.com", token="SuperSecretToken", verify_ssl=False ) @@ -109,7 +109,7 @@ client = Client( client.set_httpx_client(httpx.Client(base_url="https://api.example.com", proxies="http://localhost:8030")) ``` -{% if poetry %} +{% if meta == "poetry" %} ## Building / publishing this package This project uses [Poetry](https://python-poetry.org/) to manage dependencies and packaging. Here are the basics: 1. Update the metadata in pyproject.toml (e.g. authors, version) @@ -123,4 +123,17 @@ If you want to install this client into another project without publishing it (e 1. If that project is not using Poetry: 1. Build a wheel with `poetry build -f wheel` 1. Install that wheel from the other project `pip install ` +{% elif meta == 'uv' %} +## Building / publishing this package +This project uses [uv](https://github.com/astral-sh/uv) to manage dependencies and packaging. Here are the basics: +1. Update the metadata in `pyproject.toml` (e.g. authors, version). +2. If you're using a private repository: https://docs.astral.sh/uv/guides/integration/alternative-indexes/ +3. Build a distribution with `uv build`, builds `sdist` and `wheel` by default. +1. Publish the client with `uv publish`, see documentation for publishing to private indexes. + +If you want to install this client into another project without publishing it (e.g. for development) then: +1. If that project **is using uv**, you can simply do `uv add ` from that project +1. If that project is not using uv: + 1. Build a wheel with `uv build --wheel`. + 1. Install that wheel from the other project `pip install `. {% endif %} \ No newline at end of file diff --git a/openapi_python_client/templates/client.py.jinja b/openapi_python_client/templates/client.py.jinja index f54f31e7f..a8c4ac5c1 100644 --- a/openapi_python_client/templates/client.py.jinja +++ b/openapi_python_client/templates/client.py.jinja @@ -1,10 +1,35 @@ import ssl -from typing import Any, Dict, Union, Optional +from typing import Any, Self from attrs import define, field, evolve import httpx +{% set attrs_info = { + "raise_on_unexpected_status": namespace( + type="bool", + default="field(default=False, kw_only=True)", + docstring="Whether or not to raise an errors.UnexpectedStatus if the API returns a status code" + " that was not documented in the source OpenAPI document. Can also be provided as a keyword" + " argument to the constructor." + ), + "token": namespace(type="str", default="", docstring="The token to use for authentication"), + "prefix": namespace(type="str", default='"Bearer"', docstring="The prefix to use for the Authorization header"), + "auth_header_name": namespace(type="str", default='"Authorization"', docstring="The name of the Authorization header"), +} %} + +{% macro attr_in_class_docstring(name) %} +{{ name }}: {{ attrs_info[name].docstring }} +{%- endmacro %} + +{% macro declare_attr(name) %} +{% set attr = attrs_info[name] %} +{{ name }}: {{ attr.type }}{% if attr.default %} = {{ attr.default }}{% endif %} +{% if attr.docstring and config.docstrings_on_attributes +%} +"""{{ attr.docstring }}""" +{%- endif %} +{% endmacro %} + @define class Client: """A class for keeping track of data related to the API @@ -29,26 +54,26 @@ class Client: ``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor. {% endmacro %} {{ httpx_args_docstring() }} +{% if not config.docstrings_on_attributes %} Attributes: - raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a - status code that was not documented in the source OpenAPI document. Can also be provided as a keyword - argument to the constructor. + {{ attr_in_class_docstring("raise_on_unexpected_status") | wordwrap(101) | indent(12) }} +{% endif %} """ {% macro attributes() %} - raise_on_unexpected_status: bool = field(default=False, kw_only=True) + {{ declare_attr("raise_on_unexpected_status") | indent(4) }} _base_url: str = field(alias="base_url") - _cookies: Dict[str, str] = field(factory=dict, kw_only=True, alias="cookies") - _headers: Dict[str, str] = field(factory=dict, kw_only=True, alias="headers") - _timeout: Optional[httpx.Timeout] = field(default=None, kw_only=True, alias="timeout") - _verify_ssl: Union[str, bool, ssl.SSLContext] = field(default=True, kw_only=True, alias="verify_ssl") + _cookies: dict[str, str] = field(factory=dict, kw_only=True, alias="cookies") + _headers: dict[str, str] = field(factory=dict, kw_only=True, alias="headers") + _timeout: httpx.Timeout | None = field(default=None, kw_only=True, alias="timeout") + _verify_ssl: str | bool | ssl.SSLContext = field(default=True, kw_only=True, alias="verify_ssl") _follow_redirects: bool = field(default=False, kw_only=True, alias="follow_redirects") - _httpx_args: Dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args") - _client: Optional[httpx.Client] = field(default=None, init=False) - _async_client: Optional[httpx.AsyncClient] = field(default=None, init=False) + _httpx_args: dict[str, Any] = field(factory=dict, kw_only=True, alias="httpx_args") + _client: httpx.Client | None = field(default=None, init=False) + _async_client: httpx.AsyncClient | None = field(default=None, init=False) {% endmacro %}{{ attributes() }} {% macro builders(self) %} - def with_headers(self, headers: Dict[str, str]) -> "{{ self }}": + def with_headers(self, headers: dict[str, str]) -> "{{ self }}": """Get a new client matching this one with additional headers""" if self._client is not None: self._client.headers.update(headers) @@ -56,7 +81,7 @@ class Client: self._async_client.headers.update(headers) return evolve(self, headers={**self._headers, **headers}) - def with_cookies(self, cookies: Dict[str, str]) -> "{{ self }}": + def with_cookies(self, cookies: dict[str, str]) -> "{{ self }}": """Get a new client matching this one with additional cookies""" if self._client is not None: self._client.cookies.update(cookies) @@ -65,7 +90,7 @@ class Client: return evolve(self, cookies={**self._cookies, **cookies}) def with_timeout(self, timeout: httpx.Timeout) -> "{{ self }}": - """Get a new client matching this one with a new timeout (in seconds)""" + """Get a new client matching this one with a new timeout configuration""" if self._client is not None: self._client.timeout = timeout if self._async_client is not None: @@ -73,8 +98,8 @@ class Client: return evolve(self, timeout=timeout) {% endmacro %}{{ builders("Client") }} {% macro httpx_stuff(name, custom_constructor=None) %} - def set_httpx_client(self, client: httpx.Client) -> "{{ name }}": - """Manually the underlying httpx.Client + def set_httpx_client(self, client: httpx.Client) -> Self: + """Manually set the underlying httpx.Client **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. """ @@ -98,7 +123,7 @@ class Client: ) return self._client - def __enter__(self) -> "{{ name }}": + def __enter__(self) -> Self: """Enter a context manager for self.client—you cannot enter twice (see httpx docs)""" self.get_httpx_client().__enter__() return self @@ -107,8 +132,8 @@ class Client: """Exit a context manager for internal httpx.Client (see httpx docs)""" self.get_httpx_client().__exit__(*args, **kwargs) - def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "{{ name }}": - """Manually the underlying httpx.AsyncClient + def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> Self: + """Manually set the underlying httpx.AsyncClient **NOTE**: This will override any other settings on the client, including cookies, headers, and timeout. """ @@ -132,7 +157,7 @@ class Client: ) return self._async_client - async def __aenter__(self) -> "{{ name }}": + async def __aenter__(self) -> Self: """Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)""" await self.get_async_httpx_client().__aenter__() return self @@ -147,20 +172,20 @@ class AuthenticatedClient: """A Client which has been authenticated for use on secured endpoints {{ httpx_args_docstring() }} +{% if not config.docstrings_on_attributes %} Attributes: - raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a - status code that was not documented in the source OpenAPI document. Can also be provided as a keyword - argument to the constructor. - token: The token to use for authentication - prefix: The prefix to use for the Authorization header - auth_header_name: The name of the Authorization header + {{ attr_in_class_docstring("raise_on_unexpected_status") | wordwrap(101) | indent(12) }} + {{ attr_in_class_docstring("token") | indent(8) }} + {{ attr_in_class_docstring("prefix") | indent(8) }} + {{ attr_in_class_docstring("auth_header_name") | indent(8) }} +{% endif %} """ {{ attributes() }} - token: str - prefix: str = "Bearer" - auth_header_name: str = "Authorization" + {{ declare_attr("token") | indent(4) }} + {{ declare_attr("prefix") | indent(4) }} + {{ declare_attr("auth_header_name") | indent(4) }} {{ builders("AuthenticatedClient") }} {{ httpx_stuff("AuthenticatedClient", "self._headers[self.auth_header_name] = f\"{self.prefix} {self.token}\" if self.prefix else self.token") }} diff --git a/openapi_python_client/templates/endpoint_init.py.jinja b/openapi_python_client/templates/endpoint_init.py.jinja index e69de29bb..c9921b5fd 100644 --- a/openapi_python_client/templates/endpoint_init.py.jinja +++ b/openapi_python_client/templates/endpoint_init.py.jinja @@ -0,0 +1 @@ +""" Contains endpoint functions for accessing the API """ diff --git a/openapi_python_client/templates/endpoint_macros.py.jinja b/openapi_python_client/templates/endpoint_macros.py.jinja index da02b5c4a..493c3551c 100644 --- a/openapi_python_client/templates/endpoint_macros.py.jinja +++ b/openapi_python_client/templates/endpoint_macros.py.jinja @@ -1,9 +1,9 @@ {% from "property_templates/helpers.jinja" import guarded_statement %} -{% from "helpers.jinja" import safe_docstring %} +{% from "helpers.jinja" import docstring as _docstring %} {% macro header_params(endpoint) %} {% if endpoint.header_parameters or endpoint.bodies | length > 0 %} -headers: Dict[str, Any] = {} +headers: dict[str, Any] = {} {% if endpoint.header_parameters %} {% for parameter in endpoint.header_parameters %} {% import "property_templates/" + parameter.template as param_template %} @@ -12,7 +12,7 @@ headers: Dict[str, Any] = {} {% else %} {% set expression = parameter.python_name %} {% endif %} - {% set statement = 'headers["' + parameter.name + '"]' + " = " + expression %} + {% set statement = 'headers["' + (parameter.name | in_double_quote_literal) + '"]' + " = " + expression %} {{ guarded_statement(parameter, parameter.python_name, statement) }} {% endfor %} {% endif %} @@ -24,10 +24,10 @@ headers: Dict[str, Any] = {} cookies = {} {% for parameter in endpoint.cookie_parameters %} {% if parameter.required %} -cookies["{{ parameter.name}}"] = {{ parameter.python_name }} +cookies["{{ parameter.name | in_double_quote_literal }}"] = {{ parameter.python_name }} {% else %} if {{ parameter.python_name }} is not UNSET: - cookies["{{ parameter.name}}"] = {{ parameter.python_name }} + cookies["{{ parameter.name | in_double_quote_literal }}"] = {{ parameter.python_name }} {% endif %} {% endfor %} @@ -37,7 +37,7 @@ if {{ parameter.python_name }} is not UNSET: {% macro query_params(endpoint) %} {% if endpoint.query_parameters %} -params: Dict[str, Any] = {} +params: dict[str, Any] = {} {% for property in endpoint.query_parameters %} {% set destination = property.python_name %} @@ -47,7 +47,7 @@ params: Dict[str, Any] = {} {{ prop_template.transform(property, property.python_name, destination) }} {% endif %} {%- if not property.json_is_dict %} -params["{{ property.name }}"] = {{ destination }} +params["{{ property.name | in_double_quote_literal }}"] = {{ destination }} {% else %} {{ guarded_statement(property, destination, "params.update(" + destination + ")") }} {% endif %} @@ -58,33 +58,46 @@ params = {k: v for k, v in params.items() if v is not UNSET and v is not None} {% endif %} {% endmacro %} -{% macro body_to_kwarg(body, destination) %} +{% macro body_to_kwarg(body) %} {% if body.body_type == "data" %} -{{ destination }} = body.to_dict() + {% if body.prop.required %} +_kwargs["data"] = body.to_dict() + {% else %} +if not isinstance(body, Unset): + _kwargs["data"] = body.to_dict() + {% endif %} {% elif body.body_type == "files"%} -{{ multipart_body(body, destination) }} +{{ multipart_body(body) }} {% elif body.body_type == "json" %} -{{ json_body(body, destination) }} +{{ json_body(body) }} {% elif body.body_type == "content" %} -{{ destination }} = body.payload + {% if body.prop.required %} +_kwargs["content"] = body.payload + {% else %} +if not isinstance(body, Unset): + _kwargs["content"] = body.payload + {% endif %} {% endif %} {% endmacro %} -{% macro json_body(body, destination) %} +{% macro json_body(body) %} {% set property = body.prop %} {% import "property_templates/" + property.template as prop_template %} {% if prop_template.transform %} -{{ prop_template.transform(property, property.python_name, destination) }} +{{ prop_template.transform(property, property.python_name, "_kwargs[\"json\"]", skip_unset=True, declare_type=False) }} +{% elif property.required %} +_kwargs["json"] = {{ property.python_name }} {% else %} -{{ destination }} = {{ property.python_name }} +if not isinstance({{property.python_name}}, Unset): + _kwargs["json"] = {{ property.python_name }} {% endif %} {% endmacro %} -{% macro multipart_body(body, destination) %} +{% macro multipart_body(body) %} {% set property = body.prop %} {% import "property_templates/" + property.template as prop_template %} -{% if prop_template.transform_multipart %} -{{ prop_template.transform_multipart(property, property.python_name, destination) }} +{% if prop_template.transform_multipart_body %} +{{ prop_template.transform_multipart_body(property) }} {% endif %} {% endmacro %} @@ -92,7 +105,7 @@ params = {k: v for k, v in params.items() if v is not UNSET and v is not None} {% macro arguments(endpoint, include_client=True) %} {# path parameters #} {% for parameter in endpoint.path_parameters %} -{{ parameter.to_string() }}, +{{ parameter.to_string() | as_unembedded_code }}, {% endfor %} {% if include_client or ((endpoint.list_all_parameters() | length) > (endpoint.path_parameters | length)) %} *, @@ -102,29 +115,29 @@ params = {k: v for k, v in params.items() if v is not UNSET and v is not None} {% if endpoint.requires_security %} client: AuthenticatedClient, {% else %} -client: Union[AuthenticatedClient, Client], +client: AuthenticatedClient | Client, {% endif %} {% endif %} {# Any allowed bodies #} {% if endpoint.bodies | length == 1 %} -body: {{ endpoint.bodies[0].prop.get_type_string() }}, +body: {{ endpoint.bodies[0].prop.get_type_string() | as_unembedded_code }}{% if not endpoint.bodies[0].prop.required %} = UNSET{% endif %}, {% elif endpoint.bodies | length > 1 %} -body: Union[ - {% for body in endpoint.bodies %} - {{ body.prop.get_type_string() }}, - {% endfor %} -], +body: + {%- for body in endpoint.bodies -%}{% set body_required = body_required and body.prop.required %} + {{ body.prop.get_type_string(no_optional=True) | as_unembedded_code }} {% if not loop.last %} | {% endif %} + {%- endfor -%}{% if not body_required %} | Unset = UNSET{% endif %} +, {% endif %} {# query parameters #} {% for parameter in endpoint.query_parameters %} -{{ parameter.to_string() }}, +{{ parameter.to_string() | as_unembedded_code }}, {% endfor %} {% for parameter in endpoint.header_parameters %} -{{ parameter.to_string() }}, +{{ parameter.to_string() | as_unembedded_code }}, {% endfor %} {# cookie parameters #} {% for parameter in endpoint.cookie_parameters %} -{{ parameter.to_string() }}, +{{ parameter.to_string() | as_unembedded_code }}, {% endfor %} {% endmacro %} @@ -151,10 +164,10 @@ body=body, {% endmacro %} {% macro docstring_content(endpoint, return_string, is_detailed) %} -{% if endpoint.summary %}{{ endpoint.summary | wordwrap(100)}} +{% if endpoint.summary %}{{ endpoint.summary | safe_for_docstring | wordwrap(100)}} {% endif -%} -{%- if endpoint.description %} {{ endpoint.description | wordwrap(100) }} +{%- if endpoint.description %} {{ endpoint.description | safe_for_docstring | wordwrap(100) }} {% endif %} {% if not endpoint.summary and not endpoint.description %} @@ -175,12 +188,27 @@ Raises: Returns: {% if is_detailed %} - Response[{{ return_string }}] + Response[{{ return_string | safe_for_docstring }}] {% else %} - {{ return_string }} + {{ return_string | safe_for_docstring }} {% endif %} {% endmacro %} {% macro docstring(endpoint, return_string, is_detailed) %} -{{ safe_docstring(docstring_content(endpoint, return_string, is_detailed)) }} +{{ _docstring(docstring_content(endpoint, return_string, is_detailed)) }} +{% endmacro %} + +{% macro parse_response(parsed_responses, response) %} +{% if parsed_responses %}{% import "property_templates/" + response.prop.template as prop_template %} +{% if prop_template.construct %} +{{ prop_template.construct(response.prop, response.source.attribute) }} +{% elif response.source.return_type == response.prop.get_type_string() | as_unembedded_code %} +{{ response.prop.python_name }} = {{ response.source.attribute }} +{% else %} +{{ response.prop.python_name }} = cast({{ response.prop.get_type_string() | as_unembedded_code }}, {{ response.source.attribute }}) +{% endif %} +return {{ response.prop.python_name }} +{% else %} +return None +{% endif %} {% endmacro %} diff --git a/openapi_python_client/templates/endpoint_module.py.jinja b/openapi_python_client/templates/endpoint_module.py.jinja index 4db1c3546..97f30a2b8 100644 --- a/openapi_python_client/templates/endpoint_module.py.jinja +++ b/openapi_python_client/templates/endpoint_module.py.jinja @@ -1,5 +1,6 @@ from http import HTTPStatus -from typing import Any, Dict, List, Optional, Union, cast +from typing import Any, cast +from urllib.parse import quote import httpx @@ -7,7 +8,7 @@ from ...client import AuthenticatedClient, Client from ...types import Response, UNSET from ... import errors -{% for relative in endpoint.relative_imports %} +{% for relative in endpoint.relative_imports | sort %} {{ relative }} {% endfor %} @@ -15,27 +16,27 @@ from ... import errors arguments, client, kwargs, parse_response, docstring, body_to_kwarg %} {% set return_string = endpoint.response_type() %} -{% set parsed_responses = (endpoint.responses | length > 0) and return_string != "Any" %} +{% set parsed_responses = (endpoint.responses | length > 0) and return_string != PythonCode("Any") %} def _get_kwargs( {{ arguments(endpoint, include_client=False) | indent(4) }} -) -> Dict[str, Any]: +) -> dict[str, Any]: {{ header_params(endpoint) | indent(4) }} {{ cookie_params(endpoint) | indent(4) }} {{ query_params(endpoint) | indent(4) }} - _kwargs: Dict[str, Any] = { + _kwargs: dict[str, Any] = { "method": "{{ endpoint.method }}", {% if endpoint.path_parameters %} - "url": "{{ endpoint.path }}".format( + "url": "{{ endpoint.path | in_double_quote_literal }}".format( {%- for parameter in endpoint.path_parameters -%} - {{parameter.python_name}}={{parameter.python_name}}, + {{parameter.python_name}}=quote(str({{parameter.python_name}}), safe=""), {%- endfor -%} ), {% else %} - "url": "{{ endpoint.path }}", + "url": "{{ endpoint.path | in_double_quote_literal }}", {% endif %} {% if endpoint.query_parameters %} "params": params, @@ -47,18 +48,21 @@ def _get_kwargs( {% if endpoint.bodies | length > 1 %} {% for body in endpoint.bodies %} - if isinstance(body, {{body.prop.get_type_string() }}): - {% set destination = "_" + body.body_type + "_body" %} - {{ body_to_kwarg(body, destination) | indent(8) }} - _kwargs["{{ body.body_type.value }}"] = {{ destination }} - headers["Content-Type"] = "{{ body.content_type }}" + if isinstance(body, {{body.prop.get_type_string(no_optional=True) | as_unembedded_code }}): + {{ body_to_kwarg(body) | indent(8) }} + {%- if body.content_type == "multipart/form-data" %} + headers["Content-Type"] = "multipart/form-data; boundary=+++" + {% else %} + headers["Content-Type"] = "{{ body.content_type | in_double_quote_literal }}" + {% endif %} {% endfor %} {% elif endpoint.bodies | length == 1 %} {% set body = endpoint.bodies[0] %} - {{ body_to_kwarg(body, "_body") | indent(4) }} - _kwargs["{{ body.body_type.value }}"] = _body - {% if body.content_type != "multipart/form-data" %}{# Need httpx to set the boundary automatically #} - headers["Content-Type"] = "{{ body.content_type }}" + {{ body_to_kwarg(body) | indent(4) }} + {%- if body.content_type == "multipart/form-data" %} + headers["Content-Type"] = "multipart/form-data; boundary=+++" + {% else %} + headers["Content-Type"] = "{{ body.content_type | in_double_quote_literal }}" {% endif %} {% endif %} @@ -67,30 +71,34 @@ def _get_kwargs( {% endif %} return _kwargs +{% if endpoint.responses.default %} + {% set return_type = return_string | as_unembedded_code %} +{% else %} + {% set return_type = (return_string | as_unembedded_code) + " | None" %} +{% endif %} -def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[{{ return_string }}]: - {% for response in endpoint.responses %} - if response.status_code == HTTPStatus.{{ response.status_code.name }}: - {% if parsed_responses %}{% import "property_templates/" + response.prop.template as prop_template %} - {% if prop_template.construct %} - {{ prop_template.construct(response.prop, response.source.attribute) | indent(8) }} - {% elif response.source.return_type == response.prop.get_type_string() %} - {{ response.prop.python_name }} = {{ response.source.attribute }} - {% else %} - {{ response.prop.python_name }} = cast({{ response.prop.get_type_string() }}, {{ response.source.attribute }}) - {% endif %} - return {{ response.prop.python_name }} - {% else %} - return None - {% endif %} + +def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> {{return_type}}: + {% for response in endpoint.responses.patterns %} + {% set code_range = response.status_code.range %} + {% if code_range[0] == code_range[1] %} + if response.status_code == {{ code_range[0] }}: + {% else %} + if {{ code_range[0] }} <= response.status_code <= {{ code_range[1] }}: + {% endif %} + {{ parse_response(parsed_responses, response) | indent(8) }} {% endfor %} + {% if endpoint.responses.default %} + {{ parse_response(parsed_responses, endpoint.responses.default) | indent(4) }} + {% else %} if client.raise_on_unexpected_status: raise errors.UnexpectedStatus(response.status_code, response.content) else: return None + {% endif %} -def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[{{ return_string }}]: +def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[{{ return_string | as_unembedded_code }}]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -101,7 +109,7 @@ def _build_response(*, client: Union[AuthenticatedClient, Client], response: htt def sync_detailed( {{ arguments(endpoint) | indent(4) }} -) -> Response[{{ return_string }}]: +) -> Response[{{ return_string | as_unembedded_code }}]: {{ docstring(endpoint, return_string, is_detailed=true) | indent(4) }} kwargs = _get_kwargs( @@ -117,7 +125,7 @@ def sync_detailed( {% if parsed_responses %} def sync( {{ arguments(endpoint) | indent(4) }} -) -> Optional[{{ return_string }}]: +) -> {{ return_string | as_unembedded_code }} | None: {{ docstring(endpoint, return_string, is_detailed=false) | indent(4) }} return sync_detailed( @@ -127,7 +135,7 @@ def sync( async def asyncio_detailed( {{ arguments(endpoint) | indent(4) }} -) -> Response[{{ return_string }}]: +) -> Response[{{ return_string | as_unembedded_code }}]: {{ docstring(endpoint, return_string, is_detailed=true) | indent(4) }} kwargs = _get_kwargs( @@ -143,7 +151,7 @@ async def asyncio_detailed( {% if parsed_responses %} async def asyncio( {{ arguments(endpoint) | indent(4) }} -) -> Optional[{{ return_string }}]: +) -> {{ return_string | as_unembedded_code }} | None: {{ docstring(endpoint, return_string, is_detailed=false) | indent(4) }} return (await asyncio_detailed( diff --git a/openapi_python_client/templates/helpers.jinja b/openapi_python_client/templates/helpers.jinja index 180613c02..4302dbc09 100644 --- a/openapi_python_client/templates/helpers.jinja +++ b/openapi_python_client/templates/helpers.jinja @@ -1,8 +1,6 @@ -{% macro safe_docstring(content) %} -{# This macro returns the provided content as a docstring, set to a raw string if it contains a backslash #} -{% if '\\' in content -%} -r""" {{ content }} """ -{%- else -%} +{% macro docstring(content) %} +{# This macro returns the provided content as a docstring unless it's empty, then it emits nothing. #} +{% if (content | trim) %} """ {{ content }} """ {%- endif -%} {% endmacro %} \ No newline at end of file diff --git a/openapi_python_client/templates/literal_enum.py.jinja b/openapi_python_client/templates/literal_enum.py.jinja new file mode 100644 index 000000000..852c533bc --- /dev/null +++ b/openapi_python_client/templates/literal_enum.py.jinja @@ -0,0 +1,10 @@ +from typing import Literal + +{{ enum.class_info.name }} = Literal{{ "%r" | format(enum.values|list|sort) }} + +{{ enum.get_class_name_snake_case() | upper }}_VALUES: set[{{ enum.class_info.name }}] = { {% for v in enum.values|list|sort %}{{"%r"|format(v)}}, {% endfor %} } + +def check_{{ enum.get_class_name_snake_case() }}(value: {{ enum.get_instance_type_string() | as_unembedded_code }}) -> {{ enum.class_info.name}}: + if value in {{ enum.get_class_name_snake_case() | upper }}_VALUES: + return value + raise TypeError(f"Unexpected value {value!r}. Expected one of {{"{"}}{{ enum.get_class_name_snake_case() | upper }}_VALUES!r}") diff --git a/openapi_python_client/templates/model.py.jinja b/openapi_python_client/templates/model.py.jinja index 0df641ea4..141635127 100644 --- a/openapi_python_client/templates/model.py.jinja +++ b/openapi_python_client/templates/model.py.jinja @@ -1,23 +1,22 @@ -from typing import Any, Dict, Type, TypeVar, Tuple, Optional, BinaryIO, TextIO, TYPE_CHECKING +from __future__ import annotations -{% if model.additional_properties %} -from typing import List - -{% endif %} +from collections.abc import Mapping +from typing import Any, TypeVar, BinaryIO, TextIO, TYPE_CHECKING, Generator from attrs import define as _attrs_define from attrs import field as _attrs_field {% if model.is_multipart_body %} import json +from .. import types {% endif %} from ..types import UNSET, Unset -{% for relative in model.relative_imports %} +{% for relative in model.relative_imports | sort %} {{ relative }} {% endfor %} -{% for lazy_import in model.lazy_imports %} +{% for lazy_import in model.lazy_imports | sort %} {% if loop.first %} if TYPE_CHECKING: {% endif %} @@ -26,21 +25,21 @@ if TYPE_CHECKING: {% if model.additional_properties %} -{% set additional_property_type = 'Any' if model.additional_properties == True else model.additional_properties.get_type_string(quoted=not model.additional_properties.is_base_type) %} +{% set additional_property_type = 'Any' if model.additional_properties == True else model.additional_properties.get_type_string() | as_unembedded_code %} {% endif %} {% set class_name = model.class_info.name %} {% set module_name = model.class_info.module_name %} -{% from "helpers.jinja" import safe_docstring %} +{% from "helpers.jinja" import docstring %} T = TypeVar("T", bound="{{ class_name }}") {% macro class_docstring_content(model) %} - {% if model.title %}{{ model.title | wordwrap(116) }} + {% if model.title %}{{ model.title | safe_for_docstring | wordwrap(116) }} {% endif -%} - {%- if model.description %}{{ model.description | wordwrap(116) }} + {%- if model.description %}{{ model.description | safe_for_docstring | wordwrap(116) }} {% endif %} {% if not model.title and not model.description %} @@ -49,71 +48,87 @@ T = TypeVar("T", bound="{{ class_name }}") {% endif %} {% if model.example %} Example: - {{ model.example | string | wordwrap(112) | indent(12) }} + {{ model.example | safe_for_docstring | wordwrap(112) | indent(12) }} {% endif %} - {% if model.required_properties or model.optional_properties %} + {% if (not config.docstrings_on_attributes) and (model.required_properties or model.optional_properties) %} Attributes: {% for property in model.required_properties + model.optional_properties %} {{ property.to_docstring() | wordwrap(112) | indent(12) }} {% endfor %}{% endif %} {% endmacro %} +{% macro declare_property(property) %} +{%- if config.docstrings_on_attributes and property.description -%} +{{ property.to_string() | as_unembedded_code }} +{{ docstring(property.description | safe_for_docstring) | wordwrap(112) }} +{%- else -%} +{{ property.to_string() | as_unembedded_code }} +{%- endif -%} +{% endmacro %} + @_attrs_define class {{ class_name }}: - {{ safe_docstring(class_docstring_content(model)) | indent(4) }} + {{ docstring(class_docstring_content(model)) | indent(4) }} {% for property in model.required_properties + model.optional_properties %} {% if property.default is none and property.required %} - {{ property.to_string() }} + {{ declare_property(property) | indent(4) }} {% endif %} {% endfor %} {% for property in model.required_properties + model.optional_properties %} {% if property.default is not none or not property.required %} - {{ property.to_string() }} + {{ declare_property(property) | indent(4) }} {% endif %} {% endfor %} {% if model.additional_properties %} - additional_properties: Dict[str, {{ additional_property_type }}] = _attrs_field(init=False, factory=dict) + additional_properties: dict[str, {{ additional_property_type }}] = _attrs_field(init=False, factory=dict) {% endif %} -{% macro _to_dict(multipart=False) %} -{% for property in model.required_properties + model.optional_properties %} +{% macro _transform_property(property, content) %} {% import "property_templates/" + property.template as prop_template %} -{% if prop_template.transform %} -{{ prop_template.transform(property, "self." + property.python_name, property.python_name, multipart=multipart) }} -{% elif multipart %} -{{ property.python_name }} = self.{{ property.python_name }} if isinstance(self.{{ property.python_name }}, Unset) else (None, str(self.{{ property.python_name }}).encode(), "text/plain") +{%- if prop_template.transform -%} +{{ prop_template.transform(property=property, source=content, destination=property.python_name) }} +{%- else -%} +{{ property.python_name }} = {{ content }} +{%- endif -%} +{% endmacro %} + +{% macro multipart(property, source, destination) %} +{% import "property_templates/" + property.template as prop_template %} +{% if not property.required %} +if not isinstance({{source}}, Unset): + {{ prop_template.multipart(property, source, destination) | indent(4) }} {% else %} -{{ property.python_name }} = self.{{ property.python_name }} +{{ prop_template.multipart(property, source, destination) }} {% endif %} +{% endmacro %} -{% endfor %} - -field_dict: Dict[str, Any] = {} +{% macro _prepare_field_dict() %} +field_dict: dict[str, Any] = {} {% if model.additional_properties %} -{% if model.additional_properties.template %}{# Can be a bool instead of an object #} - {% import "property_templates/" + model.additional_properties.template as prop_template %} -{% else %} - {% set prop_template = None %} -{% endif %} -{% if prop_template and prop_template.transform %} +{% import "property_templates/" + model.additional_properties.template as prop_template %} +{% if prop_template.transform %} for prop_name, prop in self.additional_properties.items(): - {{ prop_template.transform(model.additional_properties, "prop", "field_dict[prop_name]", multipart=multipart, declare_type=false) | indent(4) }} -{% elif multipart %} -field_dict.update({ - key: (None, str(value).encode(), "text/plain") - for key, value in self.additional_properties.items() -}) + {{ prop_template.transform(model.additional_properties, "prop", "field_dict[prop_name]", declare_type=false) | indent(4) }} {% else %} field_dict.update(self.additional_properties) -{% endif %} -{% endif %} +{%- endif -%} +{%- endif -%} +{% endmacro %} + +{% macro _to_dict() %} +{% for property in model.required_properties + model.optional_properties -%} +{{ _transform_property(property, "self." + property.python_name) }} + +{% endfor %} + +{{ _prepare_field_dict() }} {% if model.required_properties | length > 0 or model.optional_properties | length > 0 %} field_dict.update({ {% for property in model.required_properties + model.optional_properties %} {% if property.required %} - "{{ property.name }}": {{ property.python_name }}, + "{{ property.name | in_double_quote_literal }}": {{ property.python_name }}, {% endif %} {% endfor %} }) @@ -121,35 +136,53 @@ field_dict.update({ {% for property in model.optional_properties %} {% if not property.required %} if {{ property.python_name }} is not UNSET: - field_dict["{{ property.name }}"] = {{ property.python_name }} + field_dict["{{ property.name | in_double_quote_literal }}"] = {{ property.python_name }} {% endif %} {% endfor %} return field_dict {% endmacro %} - def to_dict(self) -> Dict[str, Any]: - {% for lazy_import in model.lazy_imports %} - {{ lazy_import }} + def to_dict(self) -> dict[str, Any]: + {% for lazy_import in model.lazy_imports | sort %} + {{ lazy_import }} # noqa: PLC0415 {% endfor %} {{ _to_dict() | indent(8) }} {% if model.is_multipart_body %} - def to_multipart(self) -> Dict[str, Any]: - {{ _to_dict(multipart=True) | indent(8) }} + def to_multipart(self) -> types.RequestFiles: + {% for lazy_import in model.lazy_imports | sort %} + {{ lazy_import }} # noqa: PLC0415 + {% endfor %} + files: types.RequestFiles = [] + + {% for property in model.required_properties + model.optional_properties %} + {% set destination = "\"" + (property.name | in_double_quote_literal) + "\"" %} + {{ multipart(property, "self." + property.python_name, destination) | indent(8) }} + + {% endfor %} + + {% if model.additional_properties %} + for prop_name, prop in self.additional_properties.items(): + {{ multipart(model.additional_properties, "prop", "prop_name") | indent(4) }} + {% endif %} + + return files + {% endif %} @classmethod - def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: - {% for lazy_import in model.lazy_imports %} - {{ lazy_import }} + def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: + {% for lazy_import in model.lazy_imports | sort %} + {{ lazy_import }} # noqa: PLC0415 {% endfor %} - d = src_dict.copy() +{% if (model.required_properties or model.optional_properties or model.additional_properties) %} + d = dict(src_dict) {% for property in model.required_properties + model.optional_properties %} {% if property.required %} - {% set property_source = 'd.pop("' + property.name + '")' %} + {% set property_source = 'd.pop("' + (property.name | in_double_quote_literal) + '")' %} {% else %} - {% set property_source = 'd.pop("' + property.name + '", UNSET)' %} + {% set property_source = 'd.pop("' + (property.name | in_double_quote_literal) + '", UNSET)' %} {% endif %} {% import "property_templates/" + property.template as prop_template %} {% if prop_template.construct %} @@ -159,6 +192,7 @@ return field_dict {% endif %} {% endfor %} +{% endif %} {{ module_name }} = cls( {% for property in model.required_properties + model.optional_properties %} {{ property.python_name }}={{ property.python_name }}, @@ -170,8 +204,8 @@ return field_dict {% import "property_templates/" + model.additional_properties.template as prop_template %} {% if model.additional_properties.lazy_imports %} - {% for lazy_import in model.additional_properties.lazy_imports %} - {{ lazy_import }} + {% for lazy_import in model.additional_properties.lazy_imports | sort %} + {{ lazy_import }} # noqa: PLC0415 {% endfor %} {% endif %} {% else %} @@ -192,7 +226,7 @@ return field_dict {% if model.additional_properties %} @property - def additional_keys(self) -> List[str]: + def additional_keys(self) -> list[str]: return list(self.additional_properties.keys()) def __getitem__(self, key: str) -> {{ additional_property_type }}: diff --git a/openapi_python_client/templates/package_init.py.jinja b/openapi_python_client/templates/package_init.py.jinja index ecf60e74d..2854eb6f1 100644 --- a/openapi_python_client/templates/package_init.py.jinja +++ b/openapi_python_client/templates/package_init.py.jinja @@ -1,6 +1,6 @@ -{% from "helpers.jinja" import safe_docstring %} +{% from "helpers.jinja" import docstring %} -{{ safe_docstring(package_description) }} +{{ docstring(package_description | safe_for_docstring) }} from .client import AuthenticatedClient, Client __all__ = ( diff --git a/openapi_python_client/templates/property_templates/any_property.py.jinja b/openapi_python_client/templates/property_templates/any_property.py.jinja index e69de29bb..ad3f195a4 100644 --- a/openapi_python_client/templates/property_templates/any_property.py.jinja +++ b/openapi_python_client/templates/property_templates/any_property.py.jinja @@ -0,0 +1,3 @@ +{% macro multipart(property, source, name) %} +files.append(({{ name }}, (None, str({{source}}).encode(), "text/plain"))) +{% endmacro %} \ No newline at end of file diff --git a/openapi_python_client/templates/property_templates/boolean_property.py.jinja b/openapi_python_client/templates/property_templates/boolean_property.py.jinja index 3b16b7d20..e2c3392a1 100644 --- a/openapi_python_client/templates/property_templates/boolean_property.py.jinja +++ b/openapi_python_client/templates/property_templates/boolean_property.py.jinja @@ -1,3 +1,7 @@ {% macro transform_header(source) %} "true" if {{ source }} else "false" {% endmacro %} + +{% macro multipart(property, source, name) %} +files.append(({{ name }}, (None, str({{source}}).encode(), "text/plain"))) +{% endmacro %} diff --git a/openapi_python_client/templates/property_templates/const_property.py.jinja b/openapi_python_client/templates/property_templates/const_property.py.jinja index ea48ab73e..8be52e752 100644 --- a/openapi_python_client/templates/property_templates/const_property.py.jinja +++ b/openapi_python_client/templates/property_templates/const_property.py.jinja @@ -1,5 +1,9 @@ {% macro construct(property, source) %} -{{ property.python_name }} = cast({{ property.get_type_string() }} , {{ source }}) -if {{ property.python_name }} != {{ property.value }}{% if not property.required %}and not isinstance({{ property.python_name }}, Unset){% endif %}: - raise ValueError(f"{{ property.name }} must match const {{ property.value }}, got '{{'{' + property.python_name + '}' }}'") +{{ property.python_name }} = cast({{ property.get_type_string() | as_unembedded_code }} , {{ source }}) +if {{ property.python_name }} != {{ property.value.python_code | as_unembedded_code }}{% if not property.required %}and not isinstance({{ property.python_name }}, Unset){% endif %}: + raise ValueError(f"{{ property.name | in_f_string_literal }} must match const {{ property.value.python_code | in_f_string_literal }}, got '{{'{' + property.python_name + '}' }}'") {%- endmacro %} + +{% macro multipart(property, source, name) %} +files.append(({{ name }}, (None, {{ source }}, "text/plain"))) +{% endmacro %} diff --git a/openapi_python_client/templates/property_templates/date_property.py.jinja b/openapi_python_client/templates/property_templates/date_property.py.jinja index 5a3fdeafc..8bf8d53fa 100644 --- a/openapi_python_client/templates/property_templates/date_property.py.jinja +++ b/openapi_python_client/templates/property_templates/date_property.py.jinja @@ -1,5 +1,5 @@ {% macro construct_function(property, source) %} -isoparse({{ source }}).date() +datetime.date.fromisoformat({{ source }}) {% endmacro %} {% from "property_templates/property_macros.py.jinja" import construct_template %} @@ -10,22 +10,24 @@ isoparse({{ source }}).date() {% macro check_type_for_construct(property, source) %}isinstance({{ source }}, str){% endmacro %} -{% macro transform(property, source, destination, declare_type=True, multipart=False) %} +{% macro transform(property, source, destination, declare_type=True, skip_unset=False) %} {% set transformed = source + ".isoformat()" %} -{% if multipart %}{# Multipart data must be bytes, not str #} -{% set transformed = transformed + ".encode()" %} -{% endif %} {% if property.required %} {{ destination }} = {{ transformed }} {%- else %} -{% if declare_type %} -{% set type_annotation = property.get_type_string(json=True) %} -{% if multipart %}{% set type_annotation = type_annotation | replace("str", "bytes") %}{% endif %} +{% if not skip_unset %} + {% if declare_type %} + {% set type_annotation = property.get_type_string(json=True) | as_unembedded_code %} {{ destination }}: {{ type_annotation }} = UNSET -{% else %} + {% else %} {{ destination }} = UNSET + {% endif %} {% endif %} if not isinstance({{ source }}, Unset): {{ destination }} = {{ transformed }} {%- endif %} {% endmacro %} + +{% macro multipart(property, source, name) %} +files.append(({{ name }}, (None, {{ source }}.isoformat().encode(), "text/plain"))) +{% endmacro %} diff --git a/openapi_python_client/templates/property_templates/datetime_property.py.jinja b/openapi_python_client/templates/property_templates/datetime_property.py.jinja index 2ff54f4dc..f8a35e677 100644 --- a/openapi_python_client/templates/property_templates/datetime_property.py.jinja +++ b/openapi_python_client/templates/property_templates/datetime_property.py.jinja @@ -1,5 +1,5 @@ {% macro construct_function(property, source) %} -isoparse({{ source }}) +datetime.datetime.fromisoformat({{ source }}) {% endmacro %} {% from "property_templates/property_macros.py.jinja" import construct_template %} @@ -10,22 +10,24 @@ isoparse({{ source }}) {% macro check_type_for_construct(property, source) %}isinstance({{ source }}, str){% endmacro %} -{% macro transform(property, source, destination, declare_type=True, multipart=False) %} +{% macro transform(property, source, destination, declare_type=True, skip_unset=False) %} {% set transformed = source + ".isoformat()" %} -{% if multipart %}{# Multipart data must be bytes, not str #} -{% set transformed = transformed + ".encode()" %} -{% endif %} {% if property.required %} {{ destination }} = {{ transformed }} {%- else %} -{% if declare_type %} -{% set type_annotation = property.get_type_string(json=True) %} -{% if multipart %}{% set type_annotation = type_annotation | replace("str", "bytes") %}{% endif %} + {% if not skip_unset %} + {% if declare_type %} + {% set type_annotation = property.get_type_string(json=True) | as_unembedded_code %} {{ destination }}: {{ type_annotation }} = UNSET -{% else %} + {% else %} {{ destination }} = UNSET -{% endif %} + {% endif %} + {% endif %} if not isinstance({{ source }}, Unset): {{ destination }} = {{ transformed }} {%- endif %} {% endmacro %} + +{% macro multipart(property, source, name) %} +files.append(({{ name }}, (None, {{ source }}.isoformat().encode(), "text/plain"))) +{% endmacro %} diff --git a/openapi_python_client/templates/property_templates/enum_property.py.jinja b/openapi_python_client/templates/property_templates/enum_property.py.jinja index d01137f03..4943ef992 100644 --- a/openapi_python_client/templates/property_templates/enum_property.py.jinja +++ b/openapi_python_client/templates/property_templates/enum_property.py.jinja @@ -10,22 +10,22 @@ {% macro check_type_for_construct(property, source) %}isinstance({{ source }}, {{ property.value_type.__name__ }}){% endmacro %} -{% macro transform(property, source, destination, declare_type=True, multipart=False) %} +{% macro transform(property, source, destination, declare_type=True, skip_unset=False) %} {% set transformed = source + ".value" %} -{% set type_string = property.get_type_string(json=True) %} -{% if multipart %} - {% set transformed = "(None, str(" + transformed + ").encode(), \"text/plain\")" %} - {% set type_string = "Union[Unset, Tuple[None, bytes, str]]" %} -{% endif %} +{% set type_string = property.get_type_string(json=True) | as_unembedded_code %} {% if property.required %} {{ destination }} = {{ transformed }} {%- else %} -{{ destination }}{% if declare_type %}: {{ type_string }}{% endif %} = UNSET +{% if not skip_unset %}{{ destination }}{% if declare_type %}: {{ type_string }}{% endif %} = UNSET{% endif +%} if not isinstance({{ source }}, Unset): {{ destination }} = {{ transformed }} {% endif %} {% endmacro %} +{% macro multipart(property, source, name) %} +files.append(({{ name }}, (None, str({{ source }}.value).encode(), "text/plain"))) +{% endmacro %} + {% macro transform_header(source) %} str({{ source }}) {% endmacro %} diff --git a/openapi_python_client/templates/property_templates/file_property.py.jinja b/openapi_python_client/templates/property_templates/file_property.py.jinja index c19a068c5..df531af81 100644 --- a/openapi_python_client/templates/property_templates/file_property.py.jinja +++ b/openapi_python_client/templates/property_templates/file_property.py.jinja @@ -12,12 +12,16 @@ File( {% macro check_type_for_construct(property, source) %}isinstance({{ source }}, bytes){% endmacro %} -{% macro transform(property, source, destination, declare_type=True, multipart=False) %} +{% macro transform(property, source, destination, declare_type=True, skip_unset=False) %} {% if property.required %} {{ destination }} = {{ source }}.to_tuple() {% else %} -{{ destination }}{% if declare_type %}: {{ property.get_type_string(json=True) }}{% endif %} = UNSET +{% if not skip_unset %}{{ destination }}{% if declare_type %}: {{ property.get_type_string(json=True) | as_unembedded_code }}{% endif %} = UNSET{% endif +%} if not isinstance({{ source }}, Unset): {{ destination }} = {{ source }}.to_tuple() {% endif %} {% endmacro %} + +{% macro multipart(property, source, name) %} +files.append(({{ name }}, {{ source }}.to_tuple())) +{% endmacro %} diff --git a/openapi_python_client/templates/property_templates/float_property.py.jinja b/openapi_python_client/templates/property_templates/float_property.py.jinja index 0d433c22e..dc982cb68 100644 --- a/openapi_python_client/templates/property_templates/float_property.py.jinja +++ b/openapi_python_client/templates/property_templates/float_property.py.jinja @@ -1,3 +1,7 @@ {% macro transform_header(source) %} str({{ source }}) {% endmacro %} + +{% macro multipart(property, source, name) %} +files.append(({{ name }}, (None, str({{source}}).encode(), "text/plain"))) +{% endmacro %} diff --git a/openapi_python_client/templates/property_templates/int_property.py.jinja b/openapi_python_client/templates/property_templates/int_property.py.jinja index 0d433c22e..dc982cb68 100644 --- a/openapi_python_client/templates/property_templates/int_property.py.jinja +++ b/openapi_python_client/templates/property_templates/int_property.py.jinja @@ -1,3 +1,7 @@ {% macro transform_header(source) %} str({{ source }}) {% endmacro %} + +{% macro multipart(property, source, name) %} +files.append(({{ name }}, (None, str({{source}}).encode(), "text/plain"))) +{% endmacro %} diff --git a/openapi_python_client/templates/property_templates/list_property.py.jinja b/openapi_python_client/templates/property_templates/list_property.py.jinja index 0e5d1b5e3..0665412fb 100644 --- a/openapi_python_client/templates/property_templates/list_property.py.jinja +++ b/openapi_python_client/templates/property_templates/list_property.py.jinja @@ -3,26 +3,28 @@ {% import "property_templates/" + inner_property.template as inner_template %} {% if inner_template.construct %} {% set inner_source = inner_property.python_name + "_data" %} +{% if property.required %} {{ property.python_name }} = [] _{{ property.python_name }} = {{ source }} -{% if property.required %} for {{ inner_source }} in (_{{ property.python_name }}): -{% else %} -for {{ inner_source }} in (_{{ property.python_name }} or []): -{% endif %} {{ inner_template.construct(inner_property, inner_source) | indent(4) }} {{ property.python_name }}.append({{ inner_property.python_name }}) {% else %} -{{ property.python_name }} = cast({{ property.get_type_string(no_optional=True) }}, {{ source }}) +_{{ property.python_name }} = {{ source }} +{{ property.python_name }}: {{ property.get_type_string() | as_unembedded_code }} = UNSET +if _{{ property.python_name }} is not UNSET: + {{ property.python_name }} = [] + for {{ inner_source }} in _{{ property.python_name }}: + {{ inner_template.construct(inner_property, inner_source) | indent(8) }} + {{ property.python_name }}.append({{ inner_property.python_name }}) +{% endif %} +{% else %} +{{ property.python_name }} = cast({{ property.get_type_string(no_optional=True) | as_unembedded_code }}, {{ source }}) {% endif %} {% endmacro %} -{% macro _transform(property, source, destination, multipart, transform_method) %} +{% macro _transform(property, source, destination, transform_method) %} {% set inner_property = property.inner_property %} -{% if multipart %} -{% set multipart_destination = destination %} -{% set destination = "_temp_" + destination %} -{% endif %} {% import "property_templates/" + inner_property.template as inner_template %} {% if inner_template.transform %} {% set inner_source = inner_property.python_name + "_data" %} @@ -33,31 +35,26 @@ for {{ inner_source }} in {{ source }}: {% else %} {{ destination }} = {{ source }} {% endif %} -{% if multipart %} -{{ multipart_destination }} = (None, json.dumps({{ destination }}).encode(), 'application/json') -{% endif %} {% endmacro %} {% macro check_type_for_construct(property, source) %}isinstance({{ source }}, list){% endmacro %} -{% macro transform(property, source, destination, declare_type=True, multipart=False, transform_method="to_dict") %} +{% macro transform(property, source, destination, declare_type=True, skip_unset=False) %} {% set inner_property = property.inner_property %} -{% if multipart %} - {% set type_string = "Union[Unset, Tuple[None, bytes, str]]" %} -{% else %} - {% set type_string = property.get_type_string(json=True) %} -{% endif %} +{% set type_string = property.get_type_string(json=True) | as_unembedded_code %} {% if property.required %} -{{ _transform(property, source, destination, multipart, transform_method) }} +{{ _transform(property, source, destination, "to_dict") }} {% else %} -{{ destination }}{% if declare_type %}: {{ type_string }}{% endif %} = UNSET +{% if not skip_unset %}{{ destination }}{% if declare_type %}: {{ type_string }}{% endif %} = UNSET{% endif +%} if not isinstance({{ source }}, Unset): - {{ _transform(property, source, destination, multipart, transform_method) | indent(4)}} + {{ _transform(property, source, destination, "to_dict") | indent(4)}} {% endif %} - - {% endmacro %} -{% macro transform_multipart(property, source, destination) %} -{{ transform(property, source, destination, transform_method="to_multipart") }} +{% macro multipart(property, source, destination) %} +{% set inner_property = property.inner_property %} +{% import "property_templates/" + inner_property.template as inner_template %} +{% set inner_source = inner_property.python_name + "_element" %} +for {{ inner_source }} in {{ source }}: + {{ inner_template.multipart(inner_property, inner_source, destination) | indent(4) }} {% endmacro %} diff --git a/openapi_python_client/templates/property_templates/literal_enum_property.py.jinja b/openapi_python_client/templates/property_templates/literal_enum_property.py.jinja new file mode 100644 index 000000000..b718a409b --- /dev/null +++ b/openapi_python_client/templates/property_templates/literal_enum_property.py.jinja @@ -0,0 +1,30 @@ +{% macro construct_function(property, source) %} +check_{{ property.get_class_name_snake_case() }}({{ source }}) +{% endmacro %} + +{% from "property_templates/property_macros.py.jinja" import construct_template %} + +{% macro construct(property, source) %} +{{ construct_template(construct_function, property, source) }} +{% endmacro %} + +{% macro check_type_for_construct(property, source) %}isinstance({{ source }}, {{ property.get_instance_type_string() | as_unembedded_code }}){% endmacro %} + +{% macro transform(property, source, destination, declare_type=True, skip_unset=False) %} +{% set type_string = property.get_type_string(json=True) | as_unembedded_code %} +{% if property.required %} +{{ destination }}{% if declare_type %}: {{ type_string }}{% endif %} = {{ source }} +{%- else %} +{% if not skip_unset %}{{ destination }}{% if declare_type %}: {{ type_string }}{% endif %} = UNSET{% endif +%} +if not isinstance({{ source }}, Unset): + {{ destination }} = {{ source }} +{% endif %} +{% endmacro %} + +{% macro multipart(property, source, name) %} +files.append(({{ name }}, (None, str({{ source }}).encode(), "text/plain"))) +{% endmacro %} + +{% macro transform_header(source) %} +str({{ source }}) +{% endmacro %} diff --git a/openapi_python_client/templates/property_templates/model_property.py.jinja b/openapi_python_client/templates/property_templates/model_property.py.jinja index e7f779563..629a63c82 100644 --- a/openapi_python_client/templates/property_templates/model_property.py.jinja +++ b/openapi_python_client/templates/property_templates/model_property.py.jinja @@ -10,23 +10,29 @@ {% macro check_type_for_construct(property, source) %}isinstance({{ source }}, dict){% endmacro %} -{% macro transform(property, source, destination, declare_type=True, multipart=False, transform_method="to_dict") %} -{% set transformed = source + "." + transform_method + "()" %} -{% if multipart %} - {% set transformed = "(None, json.dumps(" + transformed + ").encode(), 'application/json')" %} - {% set type_string = property.get_type_string(multipart=True) %} -{% else %} - {% set type_string = property.get_type_string(json=True) %} -{% endif %} +{% macro transform(property, source, destination, declare_type=True, skip_unset=False) %} +{% set transformed = source + ".to_dict()" %} +{% set type_string = property.get_type_string(json=True) | as_unembedded_code %} {% if property.required %} {{ destination }} = {{ transformed }} {%- else %} -{{ destination }}{% if declare_type %}: {{ type_string }}{% endif %} = UNSET +{% if not skip_unset %}{{ destination }}{% if declare_type %}: {{ type_string }}{% endif %} = UNSET{% endif %} + if not isinstance({{ source }}, Unset): {{ destination }} = {{ transformed }} {%- endif %} {% endmacro %} -{% macro transform_multipart(property, source, destination) %} -{{ transform(property, source, destination, transform_method="to_multipart") }} +{% macro transform_multipart_body(property) %} +{% set transformed = property.python_name + ".to_multipart()" %} +{% if property.required %} +_kwargs["files"] = {{ transformed }} +{%- else %} +if not isinstance({{ property.python_name }}, Unset): + _kwargs["files"] = {{ transformed }} +{%- endif %} +{% endmacro %} + +{% macro multipart(property, source, name) %} +files.append(({{ name }}, (None, json.dumps( {{source}}.to_dict()).encode(), "application/json"))) {% endmacro %} diff --git a/openapi_python_client/templates/property_templates/property_macros.py.jinja b/openapi_python_client/templates/property_templates/property_macros.py.jinja index 52e1d41bc..238f8560b 100644 --- a/openapi_python_client/templates/property_templates/property_macros.py.jinja +++ b/openapi_python_client/templates/property_templates/property_macros.py.jinja @@ -3,7 +3,7 @@ {{ property.python_name }} = {{ construct_function(property, source) }} {% else %}{# Must be non-required #} _{{ property.python_name }} = {{ source }} -{{ property.python_name }}: {{ property.get_type_string() }} +{{ property.python_name }}: {{ property.get_type_string() | as_unembedded_code }} {% if not property.required %} if isinstance(_{{ property.python_name }}, Unset): {{ property.python_name }} = UNSET diff --git a/openapi_python_client/templates/property_templates/union_property.py.jinja b/openapi_python_client/templates/property_templates/union_property.py.jinja index b8ab1962d..45f350f5e 100644 --- a/openapi_python_client/templates/property_templates/union_property.py.jinja +++ b/openapi_python_client/templates/property_templates/union_property.py.jinja @@ -1,10 +1,10 @@ {% macro construct(property, source) %} -def _parse_{{ property.python_name }}(data: object) -> {{ property.get_type_string() }}: - {% if "None" in property.get_type_strings_in_union(json=True, multipart=False) %} +def _parse_{{ property.python_name }}(data: object) -> {{ property.get_type_string() | as_unembedded_code }}: + {% if PythonCode("None") in property.get_type_strings_in_union(json=True) %} if data is None: return data {% endif %} - {% if "Unset" in property.get_type_strings_in_union(json=True, multipart=False) %} + {% if PythonCode("Unset") in property.get_type_strings_in_union(json=True) %} if isinstance(data, Unset): return data {% endif %} @@ -21,7 +21,7 @@ def _parse_{{ property.python_name }}(data: object) -> {{ property.get_type_stri raise TypeError() {{ inner_template.construct(inner_property, "data") | indent(8) }} return {{ inner_property.python_name }} - except: # noqa: E722 + except (TypeError, ValueError, AttributeError, KeyError): pass {% else %}{# Don't do try/except for the last one nor any properties with no type checking #} {% if inner_template.check_type_for_construct %} @@ -33,17 +33,17 @@ def _parse_{{ property.python_name }}(data: object) -> {{ property.get_type_stri {% endif %} {% endfor %} {% if ns.contains_unmodified_properties %} - return cast({{ property.get_type_string() }}, data) + return cast({{ property.get_type_string() | as_unembedded_code }}, data) {% endif %} {{ property.python_name }} = _parse_{{ property.python_name }}({{ source }}) {% endmacro %} -{% macro transform(property, source, destination, declare_type=True, multipart=False) %} +{% macro transform(property, source, destination, declare_type=True, skip_unset=False) %} {% set ns = namespace(contains_properties_without_transform = false, contains_modified_properties = not property.required, has_if = false) %} -{% if declare_type %}{{ destination }}: {{ property.get_type_string(json=not multipart, multipart=multipart) }}{% endif %} +{% if declare_type %}{{ destination }}: {{ property.get_type_string(json=True) | as_unembedded_code }}{% endif %} -{% if not property.required %} +{% if not property.required and not skip_unset %} if isinstance({{ source }}, Unset): {{ destination }} = UNSET {% set ns.has_if = true %} @@ -57,14 +57,14 @@ if isinstance({{ source }}, Unset): {% set ns.contains_modified_properties = true %} {% endif %} {% if not ns.has_if %} -if isinstance({{ source }}, {{ inner_property.get_instance_type_string() }}): +if isinstance({{ source }}, {{ inner_property.get_instance_type_string() | as_unembedded_code }}): {% set ns.has_if = true %} {% elif not loop.last or ns.contains_properties_without_transform %} -elif isinstance({{ source }}, {{ inner_property.get_instance_type_string() }}): +elif isinstance({{ source }}, {{ inner_property.get_instance_type_string() | as_unembedded_code }}): {% else %} else: {% endif %} - {{ inner_template.transform(inner_property, source, destination, declare_type=False, multipart=multipart) | indent(4) }} + {{ inner_template.transform(inner_property, source, destination, declare_type=False) | indent(4) }} {% endfor %} {% if ns.contains_properties_without_transform and ns.contains_modified_properties %} else: @@ -73,3 +73,30 @@ else: {{ destination }} = {{ source }} {%- endif %} {% endmacro %} + + +{% macro instance_check(inner_property, source) %} +{% if inner_property.get_instance_type_string() == PythonCode("None") %} +if {{ source }} is None: +{% else %} +if isinstance({{ source }}, {{ inner_property.get_instance_type_string() | as_unembedded_code }}): +{% endif %} +{% endmacro %} + +{% macro multipart(property, source, destination) %} +{% set ns = namespace(has_if = false) %} +{% for inner_property in property.inner_properties %} +{% if not ns.has_if %} +{{ instance_check(inner_property, source) }} +{% set ns.has_if = true %} +{% elif not loop.last %} + +el{{ instance_check(inner_property, source) }} +{% else %} + +else: +{% endif %} +{% import "property_templates/" + inner_property.template as inner_template %} + {{ inner_template.multipart(inner_property, source, destination) | indent(4) | trim }} +{%- endfor -%} +{% endmacro %} diff --git a/openapi_python_client/templates/property_templates/uuid_property.py.jinja b/openapi_python_client/templates/property_templates/uuid_property.py.jinja new file mode 100644 index 000000000..1f2910008 --- /dev/null +++ b/openapi_python_client/templates/property_templates/uuid_property.py.jinja @@ -0,0 +1,33 @@ +{% macro construct_function(property, source) %} +UUID({{ source }}) +{% endmacro %} + +{% from "property_templates/property_macros.py.jinja" import construct_template %} + +{% macro construct(property, source) %} +{{ construct_template(construct_function, property, source) }} +{% endmacro %} + +{% macro check_type_for_construct(property, source) %}isinstance({{ source }}, str){% endmacro %} + +{% macro transform(property, source, destination, declare_type=True, skip_unset=False) %} +{% set transformed = "str(" + source + ")" %} +{% if property.required %} +{{ destination }} = {{ transformed }} +{%- else %} +{% if not skip_unset %} + {% if declare_type %} + {% set type_annotation = property.get_type_string(json=True) | as_unembedded_code %} +{{ destination }}: {{ type_annotation }} = UNSET + {% else %} +{{ destination }} = UNSET + {% endif %} +{% endif %} +if not isinstance({{ source }}, Unset): + {{ destination }} = {{ transformed }} +{%- endif %} +{% endmacro %} + +{% macro multipart(property, source, name) %} +files.append(({{ name }}, (None, str({{ source }}), "text/plain"))) +{% endmacro %} diff --git a/openapi_python_client/templates/pyproject.toml.jinja b/openapi_python_client/templates/pyproject.toml.jinja index 7f68d58e5..9f21f8043 100644 --- a/openapi_python_client/templates/pyproject.toml.jinja +++ b/openapi_python_client/templates/pyproject.toml.jinja @@ -1,49 +1,9 @@ -{% set poetry = meta == "poetry" %} -{% set pdm = meta == "pdm" %} -{% if poetry or pdm %} -{% if poetry %}[tool.poetry] -{% elif pdm %}[project] +{% if meta == "poetry" %} +{% include "pyproject_poetry.toml.jinja" %} +{% elif meta == "pdm" %} +{% include "pyproject_pdm.toml.jinja" %} +{% elif meta == "uv" %} +{% include "pyproject_uv.toml.jinja" %} {% endif %} -name = "{{ project_name }}" -version = "{{ package_version }}" -description = "{{ package_description }}" -authors = [] -readme = "README.md" -{% if pdm %}requires-python = ">=3.8,<4.0"{% endif %} -{% if poetry %} -packages = [ - {include = "{{ package_name }}"}, -] -include = ["CHANGELOG.md", "{{ package_name }}/py.typed"] -{% endif %} - -{% if pdm %} -dependencies = [ - "httpx>=0.20.0,<0.28.0", - "attrs>=21.3.0", - "python-dateutil>=2.8.0", -] - -[tool.pdm] -distribution = true -{% endif %} -{% if poetry %} - -[tool.poetry.dependencies] -python = "^3.8" -httpx = ">=0.20.0,<0.28.0" -attrs = ">=21.3.0" -python-dateutil = "^2.8.0" -{% endif %} - -[build-system] -{% if poetry %} -requires = ["poetry-core>=1.0.0"] -build-backend = "poetry.core.masonry.api" -{% elif pdm %} -requires = ["pdm-backend"] -build-backend = "pdm.backend" -{% endif %} -{% endif %}{# poetry or pdm #} {% include "pyproject_ruff.toml.jinja" %} diff --git a/openapi_python_client/templates/pyproject_pdm.toml.jinja b/openapi_python_client/templates/pyproject_pdm.toml.jinja new file mode 100644 index 000000000..e3f664f08 --- /dev/null +++ b/openapi_python_client/templates/pyproject_pdm.toml.jinja @@ -0,0 +1,18 @@ +[project] +name = "{{ project_name }}" +version = "{{ package_version | in_double_quote_literal }}" +description = "{{ package_description | in_double_quote_literal }}" +authors = [] +readme = "README.md" +requires-python = ">=3.11" +dependencies = [ + "httpx>=0.23.1,<0.29.0", + "attrs>=22.2.0", +] + +[tool.pdm] +distribution = true + +[build-system] +requires = ["pdm-backend"] +build-backend = "pdm.backend" diff --git a/openapi_python_client/templates/pyproject_poetry.toml.jinja b/openapi_python_client/templates/pyproject_poetry.toml.jinja new file mode 100644 index 000000000..8dc24f621 --- /dev/null +++ b/openapi_python_client/templates/pyproject_poetry.toml.jinja @@ -0,0 +1,19 @@ +[tool.poetry] +name = "{{ project_name }}" +version = "{{ package_version | in_double_quote_literal }}" +description = "{{ package_description | in_double_quote_literal }}" +authors = [] +readme = "README.md" +packages = [ + { include = "{{ package_name }}" }, +] +include = ["{{ package_name }}/py.typed"] + +[tool.poetry.dependencies] +python = "^3.11" +httpx = ">=0.23.1,<0.29.0" +attrs = ">=22.2.0" + +[build-system] +requires = ["poetry-core>=2.0.0,<3.0.0"] +build-backend = "poetry.core.masonry.api" diff --git a/openapi_python_client/templates/pyproject_uv.toml.jinja b/openapi_python_client/templates/pyproject_uv.toml.jinja new file mode 100644 index 000000000..c56e203d8 --- /dev/null +++ b/openapi_python_client/templates/pyproject_uv.toml.jinja @@ -0,0 +1,19 @@ +[project] +name = "{{ project_name }}" +version = "{{ package_version | in_double_quote_literal }}" +description = "{{ package_description | in_double_quote_literal }}" +authors = [] +requires-python = ">=3.11" +readme = "README.md" +dependencies = [ + "httpx>=0.23.1,<0.29.0", + "attrs>=22.2.0", +] + +[tool.uv.build-backend] +module-name = "{{ package_name }}" +module-root = "" + +[build-system] +requires = ["uv_build>=0.12.0,<0.13.0"] +build-backend = "uv_build" diff --git a/openapi_python_client/templates/setup.py.jinja b/openapi_python_client/templates/setup.py.jinja index 87c0cc063..c6e355205 100644 --- a/openapi_python_client/templates/setup.py.jinja +++ b/openapi_python_client/templates/setup.py.jinja @@ -7,12 +7,12 @@ long_description = (here / "README.md").read_text(encoding="utf-8") setup( name="{{ project_name }}", - version="{{ package_version }}", - description="{{ package_description }}", + version="{{ package_version | in_double_quote_literal }}", + description="{{ package_description | in_double_quote_literal }}", long_description=long_description, long_description_content_type="text/markdown", packages=find_packages(), - python_requires=">=3.8, <4", - install_requires=["httpx >= 0.20.0, < 0.28.0", "attrs >= 21.3.0", "python-dateutil >= 2.8.0, < 3"], + python_requires=">=3.11, <4", + install_requires=["httpx >= 0.23.1, < 0.29.0", "attrs >= 22.2.0"], package_data={"{{ package_name }}": ["py.typed"]}, ) diff --git a/openapi_python_client/templates/str_enum.py.jinja b/openapi_python_client/templates/str_enum.py.jinja index e0da5ed0f..ba47032a5 100644 --- a/openapi_python_client/templates/str_enum.py.jinja +++ b/openapi_python_client/templates/str_enum.py.jinja @@ -1,6 +1,6 @@ -from enum import Enum +from enum import StrEnum -class {{ enum.class_info.name }}(str, Enum): +class {{ enum.class_info.name }}(StrEnum): {% for key, value in enum.values|dictsort(true) %} {{ key }} = "{{ value }}" {% endfor %} diff --git a/openapi_python_client/templates/types.py.jinja b/openapi_python_client/templates/types.py.jinja index cc151acb3..f74db0ad7 100644 --- a/openapi_python_client/templates/types.py.jinja +++ b/openapi_python_client/templates/types.py.jinja @@ -1,6 +1,8 @@ """ Contains some shared types for properties """ + +from collections.abc import Mapping, MutableMapping from http import HTTPStatus -from typing import Any, BinaryIO, Generic, MutableMapping, Optional, Tuple, TypeVar, Literal +from typing import BinaryIO, Generic, TypeVar, Literal, IO from attrs import define @@ -12,19 +14,25 @@ class Unset: UNSET: Unset = Unset() -{# Used as `FileProperty._json_type_string` #} -FileJsonType = Tuple[Optional[str], BinaryIO, Optional[str]] - +# The types that `httpx.Client(files=)` can accept, copied from that library. +FileContent = IO[bytes] | bytes | str +FileTypes = ( + # (filename, file (or bytes), content_type) + tuple[str | None, FileContent, str | None] + # (filename, file (or bytes), content_type, headers) + | tuple[str | None, FileContent, str | None, Mapping[str, str]] +) +RequestFiles = list[tuple[str, FileTypes]] @define class File: """ Contains information for file uploads """ payload: BinaryIO - file_name: Optional[str] = None - mime_type: Optional[str] = None + file_name: str | None = None + mime_type: str | None = None - def to_tuple(self) -> FileJsonType: + def to_tuple(self) -> FileTypes: """ Return a tuple representation that httpx will accept for multipart/form-data """ return self.file_name, self.payload, self.mime_type @@ -39,7 +47,7 @@ class Response(Generic[T]): status_code: HTTPStatus content: bytes headers: MutableMapping[str, str] - parsed: Optional[T] + parsed: T | None -__all__ = ["File", "Response", "FileJsonType", "Unset", "UNSET"] +__all__ = ["UNSET", "File", "FileTypes", "RequestFiles", "Response", "Unset"] diff --git a/openapi_python_client/utils.py b/openapi_python_client/utils.py deleted file mode 100644 index 22a7bcfa8..000000000 --- a/openapi_python_client/utils.py +++ /dev/null @@ -1,123 +0,0 @@ -from __future__ import annotations - -import builtins -import re -from email.message import Message -from keyword import iskeyword -from typing import Any - -from .config import Config - -DELIMITERS = r"\. _-" - - -class PythonIdentifier(str): - """A snake_case string which has been validated / transformed into a valid identifier for Python""" - - def __new__(cls, value: str, prefix: str, skip_snake_case: bool = False) -> PythonIdentifier: - new_value = sanitize(value) - if not skip_snake_case: - new_value = snake_case(new_value) - new_value = fix_reserved_words(new_value) - - if not new_value.isidentifier() or value.startswith("_"): - new_value = f"{prefix}{new_value}" - return str.__new__(cls, new_value) - - def __deepcopy__(self, _: Any) -> PythonIdentifier: - return self - - -class ClassName(str): - """A PascalCase string which has been validated / transformed into a valid class name for Python""" - - def __new__(cls, value: str, prefix: str) -> ClassName: - new_value = fix_reserved_words(pascal_case(sanitize(value))) - - if not new_value.isidentifier(): - value = f"{prefix}{new_value}" - new_value = fix_reserved_words(pascal_case(sanitize(value))) - return str.__new__(cls, new_value) - - def __deepcopy__(self, _: Any) -> ClassName: - return self - - -def sanitize(value: str) -> str: - """Removes every character that isn't 0-9, A-Z, a-z, or a known delimiter""" - return re.sub(rf"[^\w{DELIMITERS}]+", "", value) - - -def split_words(value: str) -> list[str]: - """Split a string on words and known delimiters""" - # We can't guess words if there is no capital letter - if any(c.isupper() for c in value): - value = " ".join(re.split("([A-Z]?[a-z]+)", value)) - return re.findall(rf"[^{DELIMITERS}]+", value) - - -RESERVED_WORDS = (set(dir(builtins)) | {"self", "true", "false", "datetime"}) - { - "type", - "id", -} - - -def fix_reserved_words(value: str) -> str: - """ - Using reserved Python words as identifiers in generated code causes problems, so this function renames them. - - Args: - value: The identifier to-be that should be renamed if it's a reserved word. - - Returns: - `value` suffixed with `_` if it was a reserved word. - """ - if value in RESERVED_WORDS or iskeyword(value): - return f"{value}_" - return value - - -def snake_case(value: str) -> str: - """Converts to snake_case""" - words = split_words(sanitize(value)) - return "_".join(words).lower() - - -def pascal_case(value: str) -> str: - """Converts to PascalCase""" - words = split_words(sanitize(value)) - capitalized_words = (word.capitalize() if not word.isupper() else word for word in words) - return "".join(capitalized_words) - - -def kebab_case(value: str) -> str: - """Converts to kebab-case""" - words = split_words(sanitize(value)) - return "-".join(words).lower() - - -def remove_string_escapes(value: str) -> str: - """Used when parsing string-literal defaults to prevent escaping the string to write arbitrary Python - - **REMOVING OR CHANGING THE USAGE OF THIS FUNCTION HAS SECURITY IMPLICATIONS** - - See Also: - - https://github.com/openapi-generators/openapi-python-client/security/advisories/GHSA-9x4c-63pf-525f - """ - return value.replace('"', r"\"") - - -def get_content_type(content_type: str, config: Config) -> str | None: - """ - Given a string representing a content type with optional parameters, returns the content type only - """ - content_type = config.content_type_overrides.get(content_type, content_type) - message = Message() - message.add_header("Content-Type", content_type) - - parsed_content_type = message.get_content_type() - if not content_type.startswith(parsed_content_type): - # Always defaults to `text/plain` if it's not recognized. We want to return an error, not default. - return None - - return parsed_content_type diff --git a/pdm.lock b/pdm.lock index 395ecd6c3..4311788d7 100644 --- a/pdm.lock +++ b/pdm.lock @@ -3,239 +3,116 @@ [metadata] groups = ["default", "dev"] -strategy = ["cross_platform", "inherit_metadata"] -lock_version = "4.4.1" -content_hash = "sha256:33fd6653aa69618cd07823ced1ee6f90250d4f22e8fdd90012950d043cbc18bf" +strategy = ["inherit_metadata"] +lock_version = "4.5.0" +content_hash = "sha256:175e4c79af4623cfe2ff416ec1f952a29b9e4dc783133f62fa873455512ea5ca" + +[[metadata.targets]] +requires_python = "~=3.11" + +[[package]] +name = "annotated-doc" +version = "0.0.4" +requires_python = ">=3.8" +summary = "Document parameters, class attributes, return types, and variables inline, with Annotated." +groups = ["default"] +files = [ + {file = "annotated_doc-0.0.4-py3-none-any.whl", hash = "sha256:571ac1dc6991c450b25a9c2d84a3705e2ae7a53467b5d111c24fa8baabbed320"}, + {file = "annotated_doc-0.0.4.tar.gz", hash = "sha256:fbcda96e87e9c92ad167c2e53839e57503ecfda18804ea28102353485033faa4"}, +] [[package]] name = "annotated-types" -version = "0.6.0" +version = "0.7.0" requires_python = ">=3.8" summary = "Reusable constraint types to use with typing.Annotated" -groups = ["default", "dev"] +groups = ["default"] dependencies = [ "typing-extensions>=4.0.0; python_version < \"3.9\"", ] files = [ - {file = "annotated_types-0.6.0-py3-none-any.whl", hash = "sha256:0641064de18ba7a25dee8f96403ebc39113d0cb953a01429249d5c7564666a43"}, - {file = "annotated_types-0.6.0.tar.gz", hash = "sha256:563339e807e53ffd9c267e99fc6d9ea23eb8443c08f112651963e24e22f84a5d"}, + {file = "annotated_types-0.7.0-py3-none-any.whl", hash = "sha256:1f02e8b43a8fbbc3f3e0d4f0f4bfc8131bcb4eebe8849b8e5c773f3a1c582a53"}, + {file = "annotated_types-0.7.0.tar.gz", hash = "sha256:aff07c09a53a08bc8cfccb9c85b05f1aa9a2a6f23728d790723543408344ce89"}, ] [[package]] name = "anyio" -version = "3.7.1" -requires_python = ">=3.7" -summary = "High level compatibility layer for multiple asynchronous event loop implementations" +version = "4.14.0" +requires_python = ">=3.10" +summary = "High-level concurrency and networking framework on top of asyncio or Trio" groups = ["default"] dependencies = [ - "exceptiongroup; python_version < \"3.11\"", + "exceptiongroup>=1.0.2; python_version < \"3.11\"", "idna>=2.8", - "sniffio>=1.1", + "typing-extensions>=4.5; python_version < \"3.13\"", ] files = [ - {file = "anyio-3.7.1-py3-none-any.whl", hash = "sha256:91dee416e570e92c64041bd18b900d1d6fa78dff7048769ce5ac5ddad004fbb5"}, - {file = "anyio-3.7.1.tar.gz", hash = "sha256:44a3c9aba0f5defa43261a8b3efb97891f2bd7d804e0e1f56419befa1adfc780"}, + {file = "anyio-4.14.0-py3-none-any.whl", hash = "sha256:dd9b7a2a9799ed6552fde617b2c5df02b7fdd7d88392fc48101e51bae46164d9"}, + {file = "anyio-4.14.0.tar.gz", hash = "sha256:b47c1f9ccf73e67021df785332508f99379c68fa7d0684e8e3492cb1d4b23f89"}, ] [[package]] -name = "attrs" -version = "23.2.0" +name = "ast-serialize" +version = "0.5.0" requires_python = ">=3.7" -summary = "Classes Without Boilerplate" -groups = ["default"] -files = [ - {file = "attrs-23.2.0-py3-none-any.whl", hash = "sha256:99b87a485a5820b23b879f04c2305b44b951b502fd64be915879d77a7e8fc6f1"}, - {file = "attrs-23.2.0.tar.gz", hash = "sha256:935dc3b529c262f6cf76e50877d35a4bd3c1de194fd41f47a2b7ae8f19971f30"}, -] - -[[package]] -name = "authlib" -version = "1.3.0" -requires_python = ">=3.8" -summary = "The ultimate Python library in building OAuth and OpenID Connect servers and clients." -groups = ["dev"] -dependencies = [ - "cryptography", -] -files = [ - {file = "Authlib-1.3.0-py2.py3-none-any.whl", hash = "sha256:9637e4de1fb498310a56900b3e2043a206b03cb11c05422014b0302cbc814be3"}, - {file = "Authlib-1.3.0.tar.gz", hash = "sha256:959ea62a5b7b5123c5059758296122b57cd2585ae2ed1c0622c21b371ffdae06"}, -] - -[[package]] -name = "certifi" -version = "2023.11.17" -requires_python = ">=3.6" -summary = "Python package for providing Mozilla's CA Bundle." -groups = ["default", "dev"] -files = [ - {file = "certifi-2023.11.17-py3-none-any.whl", hash = "sha256:e036ab49d5b79556f99cfc2d9320b34cfbe5be05c5871b51de9329f0603b0474"}, - {file = "certifi-2023.11.17.tar.gz", hash = "sha256:9b469f3a900bf28dc19b8cfbf8019bf47f7fdd1a65a1d4ffb98fc14166beb4d1"}, -] - -[[package]] -name = "cffi" -version = "1.16.0" -requires_python = ">=3.8" -summary = "Foreign Function Interface for Python calling C code." +summary = "Python bindings for mypy AST serialization" groups = ["dev"] -marker = "platform_python_implementation != \"PyPy\"" -dependencies = [ - "pycparser", -] files = [ - {file = "cffi-1.16.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:6b3d6606d369fc1da4fd8c357d026317fbb9c9b75d36dc16e90e84c26854b088"}, - {file = "cffi-1.16.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:ac0f5edd2360eea2f1daa9e26a41db02dd4b0451b48f7c318e217ee092a213e9"}, - {file = "cffi-1.16.0-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:7e61e3e4fa664a8588aa25c883eab612a188c725755afff6289454d6362b9673"}, - {file = "cffi-1.16.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a72e8961a86d19bdb45851d8f1f08b041ea37d2bd8d4fd19903bc3083d80c896"}, - {file = "cffi-1.16.0-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:5b50bf3f55561dac5438f8e70bfcdfd74543fd60df5fa5f62d94e5867deca684"}, - {file = "cffi-1.16.0-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:7651c50c8c5ef7bdb41108b7b8c5a83013bfaa8a935590c5d74627c047a583c7"}, - {file = "cffi-1.16.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e4108df7fe9b707191e55f33efbcb2d81928e10cea45527879a4749cbe472614"}, - {file = "cffi-1.16.0-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:32c68ef735dbe5857c810328cb2481e24722a59a2003018885514d4c09af9743"}, - {file = "cffi-1.16.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:673739cb539f8cdaa07d92d02efa93c9ccf87e345b9a0b556e3ecc666718468d"}, - {file = "cffi-1.16.0-cp310-cp310-win32.whl", hash = "sha256:9f90389693731ff1f659e55c7d1640e2ec43ff725cc61b04b2f9c6d8d017df6a"}, - {file = "cffi-1.16.0-cp310-cp310-win_amd64.whl", hash = "sha256:e6024675e67af929088fda399b2094574609396b1decb609c55fa58b028a32a1"}, - {file = "cffi-1.16.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:b84834d0cf97e7d27dd5b7f3aca7b6e9263c56308ab9dc8aae9784abb774d404"}, - {file = "cffi-1.16.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:1b8ebc27c014c59692bb2664c7d13ce7a6e9a629be20e54e7271fa696ff2b417"}, - {file = "cffi-1.16.0-cp311-cp311-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:ee07e47c12890ef248766a6e55bd38ebfb2bb8edd4142d56db91b21ea68b7627"}, - {file = "cffi-1.16.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d8a9d3ebe49f084ad71f9269834ceccbf398253c9fac910c4fd7053ff1386936"}, - {file = "cffi-1.16.0-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:e70f54f1796669ef691ca07d046cd81a29cb4deb1e5f942003f401c0c4a2695d"}, - {file = "cffi-1.16.0-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:5bf44d66cdf9e893637896c7faa22298baebcd18d1ddb6d2626a6e39793a1d56"}, - {file = "cffi-1.16.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7b78010e7b97fef4bee1e896df8a4bbb6712b7f05b7ef630f9d1da00f6444d2e"}, - {file = "cffi-1.16.0-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:c6a164aa47843fb1b01e941d385aab7215563bb8816d80ff3a363a9f8448a8dc"}, - {file = "cffi-1.16.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:e09f3ff613345df5e8c3667da1d918f9149bd623cd9070c983c013792a9a62eb"}, - {file = "cffi-1.16.0-cp311-cp311-win32.whl", hash = "sha256:2c56b361916f390cd758a57f2e16233eb4f64bcbeee88a4881ea90fca14dc6ab"}, - {file = "cffi-1.16.0-cp311-cp311-win_amd64.whl", hash = "sha256:db8e577c19c0fda0beb7e0d4e09e0ba74b1e4c092e0e40bfa12fe05b6f6d75ba"}, - {file = "cffi-1.16.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:fa3a0128b152627161ce47201262d3140edb5a5c3da88d73a1b790a959126956"}, - {file = "cffi-1.16.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:68e7c44931cc171c54ccb702482e9fc723192e88d25a0e133edd7aff8fcd1f6e"}, - {file = "cffi-1.16.0-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:abd808f9c129ba2beda4cfc53bde801e5bcf9d6e0f22f095e45327c038bfe68e"}, - {file = "cffi-1.16.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:88e2b3c14bdb32e440be531ade29d3c50a1a59cd4e51b1dd8b0865c54ea5d2e2"}, - {file = "cffi-1.16.0-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:fcc8eb6d5902bb1cf6dc4f187ee3ea80a1eba0a89aba40a5cb20a5087d961357"}, - {file = "cffi-1.16.0-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b7be2d771cdba2942e13215c4e340bfd76398e9227ad10402a8767ab1865d2e6"}, - {file = "cffi-1.16.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e715596e683d2ce000574bae5d07bd522c781a822866c20495e52520564f0969"}, - {file = "cffi-1.16.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:2d92b25dbf6cae33f65005baf472d2c245c050b1ce709cc4588cdcdd5495b520"}, - {file = "cffi-1.16.0-cp312-cp312-win32.whl", hash = "sha256:b2ca4e77f9f47c55c194982e10f058db063937845bb2b7a86c84a6cfe0aefa8b"}, - {file = "cffi-1.16.0-cp312-cp312-win_amd64.whl", hash = "sha256:68678abf380b42ce21a5f2abde8efee05c114c2fdb2e9eef2efdb0257fba1235"}, - {file = "cffi-1.16.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:0c9ef6ff37e974b73c25eecc13952c55bceed9112be2d9d938ded8e856138bcc"}, - {file = "cffi-1.16.0-cp38-cp38-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a09582f178759ee8128d9270cd1344154fd473bb77d94ce0aeb2a93ebf0feaf0"}, - {file = "cffi-1.16.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e760191dd42581e023a68b758769e2da259b5d52e3103c6060ddc02c9edb8d7b"}, - {file = "cffi-1.16.0-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:80876338e19c951fdfed6198e70bc88f1c9758b94578d5a7c4c91a87af3cf31c"}, - {file = "cffi-1.16.0-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:a6a14b17d7e17fa0d207ac08642c8820f84f25ce17a442fd15e27ea18d67c59b"}, - {file = "cffi-1.16.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6602bc8dc6f3a9e02b6c22c4fc1e47aa50f8f8e6d3f78a5e16ac33ef5fefa324"}, - {file = "cffi-1.16.0-cp38-cp38-win32.whl", hash = "sha256:131fd094d1065b19540c3d72594260f118b231090295d8c34e19a7bbcf2e860a"}, - {file = "cffi-1.16.0-cp38-cp38-win_amd64.whl", hash = "sha256:31d13b0f99e0836b7ff893d37af07366ebc90b678b6664c955b54561fc36ef36"}, - {file = "cffi-1.16.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:582215a0e9adbe0e379761260553ba11c58943e4bbe9c36430c4ca6ac74b15ed"}, - {file = "cffi-1.16.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:b29ebffcf550f9da55bec9e02ad430c992a87e5f512cd63388abb76f1036d8d2"}, - {file = "cffi-1.16.0-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:dc9b18bf40cc75f66f40a7379f6a9513244fe33c0e8aa72e2d56b0196a7ef872"}, - {file = "cffi-1.16.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9cb4a35b3642fc5c005a6755a5d17c6c8b6bcb6981baf81cea8bfbc8903e8ba8"}, - {file = "cffi-1.16.0-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:b86851a328eedc692acf81fb05444bdf1891747c25af7529e39ddafaf68a4f3f"}, - {file = "cffi-1.16.0-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:c0f31130ebc2d37cdd8e44605fb5fa7ad59049298b3f745c74fa74c62fbfcfc4"}, - {file = "cffi-1.16.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8f8e709127c6c77446a8c0a8c8bf3c8ee706a06cd44b1e827c3e6a2ee6b8c098"}, - {file = "cffi-1.16.0-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:748dcd1e3d3d7cd5443ef03ce8685043294ad6bd7c02a38d1bd367cfd968e000"}, - {file = "cffi-1.16.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:8895613bcc094d4a1b2dbe179d88d7fb4a15cee43c052e8885783fac397d91fe"}, - {file = "cffi-1.16.0-cp39-cp39-win32.whl", hash = "sha256:ed86a35631f7bfbb28e108dd96773b9d5a6ce4811cf6ea468bb6a359b256b1e4"}, - {file = "cffi-1.16.0-cp39-cp39-win_amd64.whl", hash = "sha256:3686dffb02459559c74dd3d81748269ffb0eb027c39a6fc99502de37d501faa8"}, - {file = "cffi-1.16.0.tar.gz", hash = "sha256:bcb3ef43e58665bbda2fb198698fcae6776483e0c4a631aa5647806c25e02cc0"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-macosx_10_12_x86_64.whl", hash = "sha256:8f5c14f169eb0972c0c21bada5358b23d6047c76583b005234f865b11f1fa00a"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:7d1a2de9de5be04652f0ed60738356ef94f66db37924a9499fffe98dc491aa0b"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:be5173fb66f9b49026d9d5a2ff0fc7c7009077107c0eb285b2d60fdf1fe10bd1"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:f8015cd071ac1339924ee2b8098c93e00e155f30a16f40ec9816fcf84f4753f6"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:5499e8797edff2a9186aa313ed382c6b422e798e9332d9953badcee6e69a88f2"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:6848f2a093fb5548751a9a09bff8fcd229e2bbeb0e3331f391b6ae6d26cd9903"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:832d4c998e0b091fd60a6d6bceee535483c4d490de9ba85003af835225719261"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-manylinux_2_31_riscv64.whl", hash = "sha256:16db7c62ec0b8efe1d7afd283a388d8f74f2605d56032e5a37747d2de8dba027"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:baf5eb061eb5bccade4128ad42da33787d72f6013809cd1b590376ece8b3c937"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:104e4a35bd7c124173c41760ef9aaea17ddb3f86c65cb643671d59afbe3ee94c"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-musllinux_1_2_armv7l.whl", hash = "sha256:36be371028fc1675acb38a331bde160dbab7ff907fdf00b67eb6911aa106951b"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-musllinux_1_2_i686.whl", hash = "sha256:061ee58bdb52341c8201a6df41182a977736bae3b7ded87ca7176ca25a8a47ab"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:b15219e9cdc9f53f6f4cb51c009203507228226148c05c5e8fe451c28b435eb3"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-win32.whl", hash = "sha256:842d1c004bb466c7df036f95fabef789570541922b10976b12f5592a69cf0b38"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-win_amd64.whl", hash = "sha256:b0c06d760909b095cc466356dfccd05a1c7233a6ca191c020dca2c6a6f16c24c"}, + {file = "ast_serialize-0.5.0-cp314-cp314t-win_arm64.whl", hash = "sha256:787baedb0262cc49e8ce37cc15c00ae818e46a165a3b36f5e21ed174998104cb"}, + {file = "ast_serialize-0.5.0-cp39-abi3-macosx_10_12_x86_64.whl", hash = "sha256:0668aa9459cfa8c9c49ddd2163ebcf43088ba045ef7492af6fe22e0098303101"}, + {file = "ast_serialize-0.5.0-cp39-abi3-macosx_11_0_arm64.whl", hash = "sha256:bf683d6363edf2b39eed6b6d4fe22d34b6203867a67e27134d9e2a2680c4bc4a"}, + {file = "ast_serialize-0.5.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9cc22cf0c9be65e71cf88fda130af60d61eb4a79370ad4cfe7900d48a4aa2211"}, + {file = "ast_serialize-0.5.0-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:f66173891548c9f2726bf27957b41cabce12fa679dc6da505ddbde4d4b3b31cf"}, + {file = "ast_serialize-0.5.0-cp39-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:e42d729ef2be96a14efbad355093284739e3670ece3e534f82cc8832790911d9"}, + {file = "ast_serialize-0.5.0-cp39-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b725026bafa801dbd7310eb13a75f0a2e370e7e51b2cb225f9d21fcfadf919ee"}, + {file = "ast_serialize-0.5.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b54f60c1d78767a53b67eaa663f0dfac3afe606aa07f1301572f588b73d64809"}, + {file = "ast_serialize-0.5.0-cp39-abi3-manylinux_2_31_riscv64.whl", hash = "sha256:27d51654fc240a1e87e742d353d98eb45b75f62f129086b3596ab53df2ac2a43"}, + {file = "ast_serialize-0.5.0-cp39-abi3-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:2782c36237c46dd1674542f2109740ea5ea485a169bf1431939ada0434e17934"}, + {file = "ast_serialize-0.5.0-cp39-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:1943db345233cc7194a470f13afa9c59772c0b123dea0c9414c4d4ca54369759"}, + {file = "ast_serialize-0.5.0-cp39-abi3-musllinux_1_2_armv7l.whl", hash = "sha256:df1c00022cbbcb064bfaa505aa9c9295362443ce5dacb459d1331d3da353f887"}, + {file = "ast_serialize-0.5.0-cp39-abi3-musllinux_1_2_i686.whl", hash = "sha256:cae65289fc456fde04af979a2be09302ef5d8ab92ef23e596d6746dc267ada27"}, + {file = "ast_serialize-0.5.0-cp39-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:239a4c354e8d676e9d94631d1d4a64edc6b266f86ff3a5a80aedd344f342c01d"}, + {file = "ast_serialize-0.5.0-cp39-abi3-win32.whl", hash = "sha256:143a4ef63285a075871908fda3672dc21864b83a8ec3ee12304aa3e4c5387b9a"}, + {file = "ast_serialize-0.5.0-cp39-abi3-win_amd64.whl", hash = "sha256:cf25572c526add400f26a4750dc6ce0c3bb93fc1f75e7ae0cad4ce4f2cd5c590"}, + {file = "ast_serialize-0.5.0-cp39-abi3-win_arm64.whl", hash = "sha256:92a31c9c20d25a076edaeec76b128a3535d74a24f340b9a8a7e96c9b86dc9642"}, + {file = "ast_serialize-0.5.0.tar.gz", hash = "sha256:5880091bfe6f4f986f22866375c2e884843e7a0b6343ae41aeea659613d879b6"}, ] [[package]] -name = "charset-normalizer" -version = "3.3.2" -requires_python = ">=3.7.0" -summary = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet." -groups = ["dev"] +name = "attrs" +version = "26.1.0" +requires_python = ">=3.9" +summary = "Classes Without Boilerplate" +groups = ["default"] files = [ - {file = "charset-normalizer-3.3.2.tar.gz", hash = "sha256:f30c3cb33b24454a82faecaf01b19c18562b1e89558fb6c56de4d9118a032fd5"}, - {file = "charset_normalizer-3.3.2-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:25baf083bf6f6b341f4121c2f3c548875ee6f5339300e08be3f2b2ba1721cdd3"}, - {file = "charset_normalizer-3.3.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:06435b539f889b1f6f4ac1758871aae42dc3a8c0e24ac9e60c2384973ad73027"}, - {file = "charset_normalizer-3.3.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:9063e24fdb1e498ab71cb7419e24622516c4a04476b17a2dab57e8baa30d6e03"}, - {file = "charset_normalizer-3.3.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6897af51655e3691ff853668779c7bad41579facacf5fd7253b0133308cf000d"}, - {file = "charset_normalizer-3.3.2-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:1d3193f4a680c64b4b6a9115943538edb896edc190f0b222e73761716519268e"}, - {file = "charset_normalizer-3.3.2-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:cd70574b12bb8a4d2aaa0094515df2463cb429d8536cfb6c7ce983246983e5a6"}, - {file = "charset_normalizer-3.3.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8465322196c8b4d7ab6d1e049e4c5cb460d0394da4a27d23cc242fbf0034b6b5"}, - {file = "charset_normalizer-3.3.2-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a9a8e9031d613fd2009c182b69c7b2c1ef8239a0efb1df3f7c8da66d5dd3d537"}, - {file = "charset_normalizer-3.3.2-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:beb58fe5cdb101e3a055192ac291b7a21e3b7ef4f67fa1d74e331a7f2124341c"}, - {file = "charset_normalizer-3.3.2-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:e06ed3eb3218bc64786f7db41917d4e686cc4856944f53d5bdf83a6884432e12"}, - {file = "charset_normalizer-3.3.2-cp310-cp310-musllinux_1_1_ppc64le.whl", hash = "sha256:2e81c7b9c8979ce92ed306c249d46894776a909505d8f5a4ba55b14206e3222f"}, - {file = "charset_normalizer-3.3.2-cp310-cp310-musllinux_1_1_s390x.whl", hash = "sha256:572c3763a264ba47b3cf708a44ce965d98555f618ca42c926a9c1616d8f34269"}, - {file = "charset_normalizer-3.3.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:fd1abc0d89e30cc4e02e4064dc67fcc51bd941eb395c502aac3ec19fab46b519"}, - {file = "charset_normalizer-3.3.2-cp310-cp310-win32.whl", hash = "sha256:3d47fa203a7bd9c5b6cee4736ee84ca03b8ef23193c0d1ca99b5089f72645c73"}, - {file = "charset_normalizer-3.3.2-cp310-cp310-win_amd64.whl", hash = "sha256:10955842570876604d404661fbccbc9c7e684caf432c09c715ec38fbae45ae09"}, - {file = "charset_normalizer-3.3.2-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:802fe99cca7457642125a8a88a084cef28ff0cf9407060f7b93dca5aa25480db"}, - {file = "charset_normalizer-3.3.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:573f6eac48f4769d667c4442081b1794f52919e7edada77495aaed9236d13a96"}, - {file = "charset_normalizer-3.3.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:549a3a73da901d5bc3ce8d24e0600d1fa85524c10287f6004fbab87672bf3e1e"}, - {file = "charset_normalizer-3.3.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f27273b60488abe721a075bcca6d7f3964f9f6f067c8c4c605743023d7d3944f"}, - {file = "charset_normalizer-3.3.2-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:1ceae2f17a9c33cb48e3263960dc5fc8005351ee19db217e9b1bb15d28c02574"}, - {file = "charset_normalizer-3.3.2-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:65f6f63034100ead094b8744b3b97965785388f308a64cf8d7c34f2f2e5be0c4"}, - {file = "charset_normalizer-3.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:753f10e867343b4511128c6ed8c82f7bec3bd026875576dfd88483c5c73b2fd8"}, - {file = "charset_normalizer-3.3.2-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:4a78b2b446bd7c934f5dcedc588903fb2f5eec172f3d29e52a9096a43722adfc"}, - {file = "charset_normalizer-3.3.2-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:e537484df0d8f426ce2afb2d0f8e1c3d0b114b83f8850e5f2fbea0e797bd82ae"}, - {file = "charset_normalizer-3.3.2-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:eb6904c354526e758fda7167b33005998fb68c46fbc10e013ca97f21ca5c8887"}, - {file = "charset_normalizer-3.3.2-cp311-cp311-musllinux_1_1_ppc64le.whl", hash = "sha256:deb6be0ac38ece9ba87dea880e438f25ca3eddfac8b002a2ec3d9183a454e8ae"}, - {file = "charset_normalizer-3.3.2-cp311-cp311-musllinux_1_1_s390x.whl", hash = "sha256:4ab2fe47fae9e0f9dee8c04187ce5d09f48eabe611be8259444906793ab7cbce"}, - {file = "charset_normalizer-3.3.2-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:80402cd6ee291dcb72644d6eac93785fe2c8b9cb30893c1af5b8fdd753b9d40f"}, - {file = "charset_normalizer-3.3.2-cp311-cp311-win32.whl", hash = "sha256:7cd13a2e3ddeed6913a65e66e94b51d80a041145a026c27e6bb76c31a853c6ab"}, - {file = "charset_normalizer-3.3.2-cp311-cp311-win_amd64.whl", hash = "sha256:663946639d296df6a2bb2aa51b60a2454ca1cb29835324c640dafb5ff2131a77"}, - {file = "charset_normalizer-3.3.2-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:0b2b64d2bb6d3fb9112bafa732def486049e63de9618b5843bcdd081d8144cd8"}, - {file = "charset_normalizer-3.3.2-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:ddbb2551d7e0102e7252db79ba445cdab71b26640817ab1e3e3648dad515003b"}, - {file = "charset_normalizer-3.3.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:55086ee1064215781fff39a1af09518bc9255b50d6333f2e4c74ca09fac6a8f6"}, - {file = "charset_normalizer-3.3.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8f4a014bc36d3c57402e2977dada34f9c12300af536839dc38c0beab8878f38a"}, - {file = "charset_normalizer-3.3.2-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:a10af20b82360ab00827f916a6058451b723b4e65030c5a18577c8b2de5b3389"}, - {file = "charset_normalizer-3.3.2-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:8d756e44e94489e49571086ef83b2bb8ce311e730092d2c34ca8f7d925cb20aa"}, - {file = "charset_normalizer-3.3.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:90d558489962fd4918143277a773316e56c72da56ec7aa3dc3dbbe20fdfed15b"}, - {file = "charset_normalizer-3.3.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6ac7ffc7ad6d040517be39eb591cac5ff87416c2537df6ba3cba3bae290c0fed"}, - {file = "charset_normalizer-3.3.2-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:7ed9e526742851e8d5cc9e6cf41427dfc6068d4f5a3bb03659444b4cabf6bc26"}, - {file = "charset_normalizer-3.3.2-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:8bdb58ff7ba23002a4c5808d608e4e6c687175724f54a5dade5fa8c67b604e4d"}, - {file = "charset_normalizer-3.3.2-cp312-cp312-musllinux_1_1_ppc64le.whl", hash = "sha256:6b3251890fff30ee142c44144871185dbe13b11bab478a88887a639655be1068"}, - {file = "charset_normalizer-3.3.2-cp312-cp312-musllinux_1_1_s390x.whl", hash = "sha256:b4a23f61ce87adf89be746c8a8974fe1c823c891d8f86eb218bb957c924bb143"}, - {file = "charset_normalizer-3.3.2-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:efcb3f6676480691518c177e3b465bcddf57cea040302f9f4e6e191af91174d4"}, - {file = "charset_normalizer-3.3.2-cp312-cp312-win32.whl", hash = "sha256:d965bba47ddeec8cd560687584e88cf699fd28f192ceb452d1d7ee807c5597b7"}, - {file = "charset_normalizer-3.3.2-cp312-cp312-win_amd64.whl", hash = "sha256:96b02a3dc4381e5494fad39be677abcb5e6634bf7b4fa83a6dd3112607547001"}, - {file = "charset_normalizer-3.3.2-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:6463effa3186ea09411d50efc7d85360b38d5f09b870c48e4600f63af490e56a"}, - {file = "charset_normalizer-3.3.2-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:6c4caeef8fa63d06bd437cd4bdcf3ffefe6738fb1b25951440d80dc7df8c03ac"}, - {file = "charset_normalizer-3.3.2-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:37e55c8e51c236f95b033f6fb391d7d7970ba5fe7ff453dad675e88cf303377a"}, - {file = "charset_normalizer-3.3.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:fb69256e180cb6c8a894fee62b3afebae785babc1ee98b81cdf68bbca1987f33"}, - {file = "charset_normalizer-3.3.2-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:ae5f4161f18c61806f411a13b0310bea87f987c7d2ecdbdaad0e94eb2e404238"}, - {file = "charset_normalizer-3.3.2-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b2b0a0c0517616b6869869f8c581d4eb2dd83a4d79e0ebcb7d373ef9956aeb0a"}, - {file = "charset_normalizer-3.3.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:45485e01ff4d3630ec0d9617310448a8702f70e9c01906b0d0118bdf9d124cf2"}, - {file = "charset_normalizer-3.3.2-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:eb00ed941194665c332bf8e078baf037d6c35d7c4f3102ea2d4f16ca94a26dc8"}, - {file = "charset_normalizer-3.3.2-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:2127566c664442652f024c837091890cb1942c30937add288223dc895793f898"}, - {file = "charset_normalizer-3.3.2-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:a50aebfa173e157099939b17f18600f72f84eed3049e743b68ad15bd69b6bf99"}, - {file = "charset_normalizer-3.3.2-cp38-cp38-musllinux_1_1_ppc64le.whl", hash = "sha256:4d0d1650369165a14e14e1e47b372cfcb31d6ab44e6e33cb2d4e57265290044d"}, - {file = "charset_normalizer-3.3.2-cp38-cp38-musllinux_1_1_s390x.whl", hash = "sha256:923c0c831b7cfcb071580d3f46c4baf50f174be571576556269530f4bbd79d04"}, - {file = "charset_normalizer-3.3.2-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:06a81e93cd441c56a9b65d8e1d043daeb97a3d0856d177d5c90ba85acb3db087"}, - {file = "charset_normalizer-3.3.2-cp38-cp38-win32.whl", hash = "sha256:6ef1d82a3af9d3eecdba2321dc1b3c238245d890843e040e41e470ffa64c3e25"}, - {file = "charset_normalizer-3.3.2-cp38-cp38-win_amd64.whl", hash = "sha256:eb8821e09e916165e160797a6c17edda0679379a4be5c716c260e836e122f54b"}, - {file = "charset_normalizer-3.3.2-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:c235ebd9baae02f1b77bcea61bce332cb4331dc3617d254df3323aa01ab47bd4"}, - {file = "charset_normalizer-3.3.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:5b4c145409bef602a690e7cfad0a15a55c13320ff7a3ad7ca59c13bb8ba4d45d"}, - {file = "charset_normalizer-3.3.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:68d1f8a9e9e37c1223b656399be5d6b448dea850bed7d0f87a8311f1ff3dabb0"}, - {file = "charset_normalizer-3.3.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:22afcb9f253dac0696b5a4be4a1c0f8762f8239e21b99680099abd9b2b1b2269"}, - {file = "charset_normalizer-3.3.2-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:e27ad930a842b4c5eb8ac0016b0a54f5aebbe679340c26101df33424142c143c"}, - {file = "charset_normalizer-3.3.2-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:1f79682fbe303db92bc2b1136016a38a42e835d932bab5b3b1bfcfbf0640e519"}, - {file = "charset_normalizer-3.3.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b261ccdec7821281dade748d088bb6e9b69e6d15b30652b74cbbac25e280b796"}, - {file = "charset_normalizer-3.3.2-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:122c7fa62b130ed55f8f285bfd56d5f4b4a5b503609d181f9ad85e55c89f4185"}, - {file = "charset_normalizer-3.3.2-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:d0eccceffcb53201b5bfebb52600a5fb483a20b61da9dbc885f8b103cbe7598c"}, - {file = "charset_normalizer-3.3.2-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:9f96df6923e21816da7e0ad3fd47dd8f94b2a5ce594e00677c0013018b813458"}, - {file = "charset_normalizer-3.3.2-cp39-cp39-musllinux_1_1_ppc64le.whl", hash = "sha256:7f04c839ed0b6b98b1a7501a002144b76c18fb1c1850c8b98d458ac269e26ed2"}, - {file = "charset_normalizer-3.3.2-cp39-cp39-musllinux_1_1_s390x.whl", hash = "sha256:34d1c8da1e78d2e001f363791c98a272bb734000fcef47a491c1e3b0505657a8"}, - {file = "charset_normalizer-3.3.2-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:ff8fa367d09b717b2a17a052544193ad76cd49979c805768879cb63d9ca50561"}, - {file = "charset_normalizer-3.3.2-cp39-cp39-win32.whl", hash = "sha256:aed38f6e4fb3f5d6bf81bfa990a07806be9d83cf7bacef998ab1a9bd660a581f"}, - {file = "charset_normalizer-3.3.2-cp39-cp39-win_amd64.whl", hash = "sha256:b01b88d45a6fcb69667cd6d2f7a9aeb4bf53760d7fc536bf679ec94fe9f3ff3d"}, - {file = "charset_normalizer-3.3.2-py3-none-any.whl", hash = "sha256:3e4d1f6587322d2788836a99c69062fbb091331ec940e02d12d179c1d53e25fc"}, + {file = "attrs-26.1.0-py3-none-any.whl", hash = "sha256:c647aa4a12dfbad9333ca4e71fe62ddc36f4e63b2d260a37a8b83d2f043ac309"}, + {file = "attrs-26.1.0.tar.gz", hash = "sha256:d03ceb89cb322a8fd706d4fb91940737b6642aa36998fe130a9bc96c985eff32"}, ] [[package]] -name = "click" -version = "8.1.7" +name = "certifi" +version = "2026.6.17" requires_python = ">=3.7" -summary = "Composable command line interface toolkit" -groups = ["default", "dev"] -dependencies = [ - "colorama; platform_system == \"Windows\"", -] +summary = "Python package for providing Mozilla's CA Bundle." +groups = ["default"] files = [ - {file = "click-8.1.7-py3-none-any.whl", hash = "sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28"}, - {file = "click-8.1.7.tar.gz", hash = "sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de"}, + {file = "certifi-2026.6.17-py3-none-any.whl", hash = "sha256:2227dcbaafe0d2f59279d1762ddddc37783ed4354594f194ffc31d20f41fc3db"}, + {file = "certifi-2026.6.17.tar.gz", hash = "sha256:024c88eeec92ca068db80f02b8b07c9cef7b9fe261d1d535abfd5abd6f6af432"}, ] [[package]] @@ -244,6 +121,7 @@ version = "0.4.6" requires_python = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" summary = "Cross-platform colored terminal text." groups = ["default", "dev"] +marker = "sys_platform == \"win32\" or platform_system == \"Windows\"" files = [ {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, @@ -251,231 +129,210 @@ files = [ [[package]] name = "coverage" -version = "7.4.0" -requires_python = ">=3.8" +version = "7.14.2" +requires_python = ">=3.10" summary = "Code coverage measurement for Python" groups = ["dev"] files = [ - {file = "coverage-7.4.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:36b0ea8ab20d6a7564e89cb6135920bc9188fb5f1f7152e94e8300b7b189441a"}, - {file = "coverage-7.4.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:0676cd0ba581e514b7f726495ea75aba3eb20899d824636c6f59b0ed2f88c471"}, - {file = "coverage-7.4.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d0ca5c71a5a1765a0f8f88022c52b6b8be740e512980362f7fdbb03725a0d6b9"}, - {file = "coverage-7.4.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a7c97726520f784239f6c62506bc70e48d01ae71e9da128259d61ca5e9788516"}, - {file = "coverage-7.4.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:815ac2d0f3398a14286dc2cea223a6f338109f9ecf39a71160cd1628786bc6f5"}, - {file = "coverage-7.4.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:80b5ee39b7f0131ebec7968baa9b2309eddb35b8403d1869e08f024efd883566"}, - {file = "coverage-7.4.0-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:5b2ccb7548a0b65974860a78c9ffe1173cfb5877460e5a229238d985565574ae"}, - {file = "coverage-7.4.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:995ea5c48c4ebfd898eacb098164b3cc826ba273b3049e4a889658548e321b43"}, - {file = "coverage-7.4.0-cp310-cp310-win32.whl", hash = "sha256:79287fd95585ed36e83182794a57a46aeae0b64ca53929d1176db56aacc83451"}, - {file = "coverage-7.4.0-cp310-cp310-win_amd64.whl", hash = "sha256:5b14b4f8760006bfdb6e08667af7bc2d8d9bfdb648351915315ea17645347137"}, - {file = "coverage-7.4.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:04387a4a6ecb330c1878907ce0dc04078ea72a869263e53c72a1ba5bbdf380ca"}, - {file = "coverage-7.4.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:ea81d8f9691bb53f4fb4db603203029643caffc82bf998ab5b59ca05560f4c06"}, - {file = "coverage-7.4.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:74775198b702868ec2d058cb92720a3c5a9177296f75bd97317c787daf711505"}, - {file = "coverage-7.4.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:76f03940f9973bfaee8cfba70ac991825611b9aac047e5c80d499a44079ec0bc"}, - {file = "coverage-7.4.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:485e9f897cf4856a65a57c7f6ea3dc0d4e6c076c87311d4bc003f82cfe199d25"}, - {file = "coverage-7.4.0-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:6ae8c9d301207e6856865867d762a4b6fd379c714fcc0607a84b92ee63feff70"}, - {file = "coverage-7.4.0-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:bf477c355274a72435ceb140dc42de0dc1e1e0bf6e97195be30487d8eaaf1a09"}, - {file = "coverage-7.4.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:83c2dda2666fe32332f8e87481eed056c8b4d163fe18ecc690b02802d36a4d26"}, - {file = "coverage-7.4.0-cp311-cp311-win32.whl", hash = "sha256:697d1317e5290a313ef0d369650cfee1a114abb6021fa239ca12b4849ebbd614"}, - {file = "coverage-7.4.0-cp311-cp311-win_amd64.whl", hash = "sha256:26776ff6c711d9d835557ee453082025d871e30b3fd6c27fcef14733f67f0590"}, - {file = "coverage-7.4.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:13eaf476ec3e883fe3e5fe3707caeb88268a06284484a3daf8250259ef1ba143"}, - {file = "coverage-7.4.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:846f52f46e212affb5bcf131c952fb4075b55aae6b61adc9856222df89cbe3e2"}, - {file = "coverage-7.4.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:26f66da8695719ccf90e794ed567a1549bb2644a706b41e9f6eae6816b398c4a"}, - {file = "coverage-7.4.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:164fdcc3246c69a6526a59b744b62e303039a81e42cfbbdc171c91a8cc2f9446"}, - {file = "coverage-7.4.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:316543f71025a6565677d84bc4df2114e9b6a615aa39fb165d697dba06a54af9"}, - {file = "coverage-7.4.0-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:bb1de682da0b824411e00a0d4da5a784ec6496b6850fdf8c865c1d68c0e318dd"}, - {file = "coverage-7.4.0-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:0e8d06778e8fbffccfe96331a3946237f87b1e1d359d7fbe8b06b96c95a5407a"}, - {file = "coverage-7.4.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:a56de34db7b7ff77056a37aedded01b2b98b508227d2d0979d373a9b5d353daa"}, - {file = "coverage-7.4.0-cp312-cp312-win32.whl", hash = "sha256:51456e6fa099a8d9d91497202d9563a320513fcf59f33991b0661a4a6f2ad450"}, - {file = "coverage-7.4.0-cp312-cp312-win_amd64.whl", hash = "sha256:cd3c1e4cb2ff0083758f09be0f77402e1bdf704adb7f89108007300a6da587d0"}, - {file = "coverage-7.4.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:e9d1bf53c4c8de58d22e0e956a79a5b37f754ed1ffdbf1a260d9dcfa2d8a325e"}, - {file = "coverage-7.4.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:109f5985182b6b81fe33323ab4707011875198c41964f014579cf82cebf2bb85"}, - {file = "coverage-7.4.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3cc9d4bc55de8003663ec94c2f215d12d42ceea128da8f0f4036235a119c88ac"}, - {file = "coverage-7.4.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:cc6d65b21c219ec2072c1293c505cf36e4e913a3f936d80028993dd73c7906b1"}, - {file = "coverage-7.4.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5a10a4920def78bbfff4eff8a05c51be03e42f1c3735be42d851f199144897ba"}, - {file = "coverage-7.4.0-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:b8e99f06160602bc64da35158bb76c73522a4010f0649be44a4e167ff8555952"}, - {file = "coverage-7.4.0-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:7d360587e64d006402b7116623cebf9d48893329ef035278969fa3bbf75b697e"}, - {file = "coverage-7.4.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:29f3abe810930311c0b5d1a7140f6395369c3db1be68345638c33eec07535105"}, - {file = "coverage-7.4.0-cp38-cp38-win32.whl", hash = "sha256:5040148f4ec43644702e7b16ca864c5314ccb8ee0751ef617d49aa0e2d6bf4f2"}, - {file = "coverage-7.4.0-cp38-cp38-win_amd64.whl", hash = "sha256:9864463c1c2f9cb3b5db2cf1ff475eed2f0b4285c2aaf4d357b69959941aa555"}, - {file = "coverage-7.4.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:936d38794044b26c99d3dd004d8af0035ac535b92090f7f2bb5aa9c8e2f5cd42"}, - {file = "coverage-7.4.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:799c8f873794a08cdf216aa5d0531c6a3747793b70c53f70e98259720a6fe2d7"}, - {file = "coverage-7.4.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e7defbb9737274023e2d7af02cac77043c86ce88a907c58f42b580a97d5bcca9"}, - {file = "coverage-7.4.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a1526d265743fb49363974b7aa8d5899ff64ee07df47dd8d3e37dcc0818f09ed"}, - {file = "coverage-7.4.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bf635a52fc1ea401baf88843ae8708591aa4adff875e5c23220de43b1ccf575c"}, - {file = "coverage-7.4.0-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:756ded44f47f330666843b5781be126ab57bb57c22adbb07d83f6b519783b870"}, - {file = "coverage-7.4.0-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:0eb3c2f32dabe3a4aaf6441dde94f35687224dfd7eb2a7f47f3fd9428e421058"}, - {file = "coverage-7.4.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:bfd5db349d15c08311702611f3dccbef4b4e2ec148fcc636cf8739519b4a5c0f"}, - {file = "coverage-7.4.0-cp39-cp39-win32.whl", hash = "sha256:53d7d9158ee03956e0eadac38dfa1ec8068431ef8058fe6447043db1fb40d932"}, - {file = "coverage-7.4.0-cp39-cp39-win_amd64.whl", hash = "sha256:cfd2a8b6b0d8e66e944d47cdec2f47c48fef2ba2f2dff5a9a75757f64172857e"}, - {file = "coverage-7.4.0-pp38.pp39.pp310-none-any.whl", hash = "sha256:c530833afc4707fe48524a44844493f36d8727f04dcce91fb978c414a8556cc6"}, - {file = "coverage-7.4.0.tar.gz", hash = "sha256:707c0f58cb1712b8809ece32b68996ee1e609f71bd14615bd8f87a1293cb610e"}, + {file = "coverage-7.14.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:909f265c8c41f04c824bf741b2601fdcb56cab4bf56e018996b6494192ba0f58"}, + {file = "coverage-7.14.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:c8102deaf911938233f760426e6a5e287388521de95111d5c8de26c8a1028924"}, + {file = "coverage-7.14.2-cp311-cp311-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:851f49e7bd7d1cdaf328f3133942b252d5e3d3380690131f423cba8e435b87f5"}, + {file = "coverage-7.14.2-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:04cb445bed86aaf00aaa97d41a8b6e30f100f21e81c34caaec4efc684cb57768"}, + {file = "coverage-7.14.2-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:7471bc920d97c51c37ea8127f13b2adca43c3d78c53313b26a1f428e99d2c254"}, + {file = "coverage-7.14.2-cp311-cp311-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:da5057e1bb257c967feee8ba67f3ebf379e801c7717f238b3d8c9caf00fc8f93"}, + {file = "coverage-7.14.2-cp311-cp311-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:33c0da852e8a40246cd8e20cf3b2fc17ca52a45e9b5f7983c93db26f5d24b87b"}, + {file = "coverage-7.14.2-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:f48a85bb437fab7782021c40bfee6b15146928b96960d008ace41b6901a0f21d"}, + {file = "coverage-7.14.2-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:f44e7579a769a21d5b5e3166916bfe30ee175aaffff750324cbb11be2dbec5ad"}, + {file = "coverage-7.14.2-cp311-cp311-musllinux_1_2_ppc64le.whl", hash = "sha256:78853ca3c6ca2f012daa2b07dbabbb8db0f09d4dbe8ee828d294b3445d3f4cd8"}, + {file = "coverage-7.14.2-cp311-cp311-musllinux_1_2_riscv64.whl", hash = "sha256:c9c2795ee3692097ff226ab806005d36bb9691fca9b35353542b57ea749cc830"}, + {file = "coverage-7.14.2-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:2f5cc48a845d755b6db236f8c29c2b54773eb4c7e4ee2ead43812d73718784b0"}, + {file = "coverage-7.14.2-cp311-cp311-win32.whl", hash = "sha256:9c61cb7eaabcfa609c5bc0f5ff5869d72a2f02f17994e5fba5f971de516f3c82"}, + {file = "coverage-7.14.2-cp311-cp311-win_amd64.whl", hash = "sha256:e715909b0966d1774d8a26e14e2f4a3ae75909dca526901c6306286b2dcbfbdc"}, + {file = "coverage-7.14.2-cp311-cp311-win_arm64.whl", hash = "sha256:9193f7150937a4fd836b10eaa123e15d98e961d1fabac07e60adf2d4785f888a"}, + {file = "coverage-7.14.2-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:37c94712e533ea06f0b1e4d934811c520b1914ce0e4da3916220717aa7a86bc6"}, + {file = "coverage-7.14.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:c050bbc7bba94c77e4ed7438f4fda1babe98ab145691d80aa6f60df934a1468b"}, + {file = "coverage-7.14.2-cp312-cp312-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:a7af571767a2ee342a171c16fc1b1a07a0bf511606d381703fb7cf397fe49d46"}, + {file = "coverage-7.14.2-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:8b4910cce599cd2438f8da65f5ef199a70a1cdb6ab314926df78271ca5954240"}, + {file = "coverage-7.14.2-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:c33e9e4878972f430b0cc06de3bf2a28d054a9efb4f8426d27de0d9cb81396ff"}, + {file = "coverage-7.14.2-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:e7967ea55c6dea6becba4d5870e2fa0aa4915a8be7ebff1bb79e6207aa75ce8d"}, + {file = "coverage-7.14.2-cp312-cp312-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:d1322f237c2979b84096f4239c17828ff17fea6b3bbe96c44381c5f587c44c26"}, + {file = "coverage-7.14.2-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:77849525340c99f516d793dddbcee16b18d50af892ac43c8de1a6f343d41e3b5"}, + {file = "coverage-7.14.2-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:ef11695493ec3f06f7b2678ca274bcabb4ca04057317df268ddbfd8b05f661a8"}, + {file = "coverage-7.14.2-cp312-cp312-musllinux_1_2_ppc64le.whl", hash = "sha256:8134f0e0723e080d1c27bbe8fc149f0162e429fa1852482150015d0fce83eaf1"}, + {file = "coverage-7.14.2-cp312-cp312-musllinux_1_2_riscv64.whl", hash = "sha256:914eead2b843fc357f733b3fe39cc94f1b53d466e8cfe03080b1ed9d24ccfc73"}, + {file = "coverage-7.14.2-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:e4b2d5e847fb7958583b74910cc19e5ec4ece514487385677b26433b2546116e"}, + {file = "coverage-7.14.2-cp312-cp312-win32.whl", hash = "sha256:e753db9e40dda7302e0ac3e1e6e1325fb7f7b4694f87a7314ab15dd5d57911a7"}, + {file = "coverage-7.14.2-cp312-cp312-win_amd64.whl", hash = "sha256:d32e5ca5f16dafb269ee50b60d32b00c704b3f6f78e238105f1d94a3a5f24bf5"}, + {file = "coverage-7.14.2-cp312-cp312-win_arm64.whl", hash = "sha256:dc366f158e2fb2add9d4e57338ca48f12611024278688ee657eb0b853fcb5de5"}, + {file = "coverage-7.14.2-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:e5f077641a6713ce9d38df9e85d4fb9e008677fc0775cbaeb32ddfc3b319d4ca"}, + {file = "coverage-7.14.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:0907f39b49ae818fe8af50aaa0f19afbc8ca164aea0865181ca7af17a3ac690b"}, + {file = "coverage-7.14.2-cp313-cp313-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:5734d47669118d75c28981e562d4530ceb77342d31ffef6def5edd5ad4f05d7b"}, + {file = "coverage-7.14.2-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:1d9a1b5813d00ea6151f6ccf64d1fa16892771dfdda12ba87162d15ec4ea3e1e"}, + {file = "coverage-7.14.2-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:9f0a80f4c8ac3f774210b1cc1bc0e31e75502f2818dda9a144ff90e702c4d91d"}, + {file = "coverage-7.14.2-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:c2e66f3f22d6c1515ce70f2e7c3e9c6f3ff0ff33480125c9f9c53e8f6508e30f"}, + {file = "coverage-7.14.2-cp313-cp313-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:6a2c37c3114f87ca7f10113756026eecb49656514debad600dcbec21f355ccea"}, + {file = "coverage-7.14.2-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:3b16a7959d04b1497281c062c180413565c3f3469211d78799ad5b9a75f67796"}, + {file = "coverage-7.14.2-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:6466c6999545cf00c4c142dfcbbf2db396dc735f005dcf8f91d57e351a79472b"}, + {file = "coverage-7.14.2-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:5c60915ebb8f562317ba5ff6b8c32e25c0882289b201a9f2fb2987f91efd95d8"}, + {file = "coverage-7.14.2-cp313-cp313-musllinux_1_2_riscv64.whl", hash = "sha256:33b830850488acbcd358c78a4fecfafe7031667b4da8ddff5546295dc962cdeb"}, + {file = "coverage-7.14.2-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:d0f845539230b8269aec902bc978b0cc403f52f002d18a04492efc943404d0bc"}, + {file = "coverage-7.14.2-cp313-cp313-win32.whl", hash = "sha256:a8ac51a2e441e9119b9395f4d893fbc4934c64c8ba58be9b9eaa85591249e548"}, + {file = "coverage-7.14.2-cp313-cp313-win_amd64.whl", hash = "sha256:039b264cdb31c44b48f9821e2afbf8f37df49e0fb837e24a942918b36c567e31"}, + {file = "coverage-7.14.2-cp313-cp313-win_arm64.whl", hash = "sha256:7f2ef591e381cc36b8e53334e1b842c760c520c8a52d01e8626209400e93fe6a"}, + {file = "coverage-7.14.2-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:7a0d1f026b72d627fa5c8a57cbc86ad209b64aa2a65833c83b290ace5cbee126"}, + {file = "coverage-7.14.2-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:4d2b86f81c1c9310a7e774e3cc9e927a3d0bf583ecbfa01498dd626930025428"}, + {file = "coverage-7.14.2-cp314-cp314-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:d76bdc1f9396ae70a55d050cf9743d88141c62ce0a22a3f627fab1d11c2f8bc6"}, + {file = "coverage-7.14.2-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:cda36d8e7bfd63b3e44e75163265429caa5d935b672b00f71bccc8c010518c64"}, + {file = "coverage-7.14.2-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:0904f3b79d7b845bef0715afe1900da634d12b97f05b9479cb472880ca07cb9c"}, + {file = "coverage-7.14.2-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:b6795ca4198d6cb7fc2c6163214f6555a6bc5f0ae1e268e76139dec4b37c4499"}, + {file = "coverage-7.14.2-cp314-cp314-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:c41e9b60fc0fa57f5d73306417d2f9d668202cca6944f9435878c55a5e7ae213"}, + {file = "coverage-7.14.2-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:419d2aadd5746efc2e9df0f33c05570d8192e6f6a6098ab05acce586f44ce8a5"}, + {file = "coverage-7.14.2-cp314-cp314-musllinux_1_2_i686.whl", hash = "sha256:1c5d273c5f1411c0d26c4f066c398d4a434b1f97bb5fa409189bedce86d4add4"}, + {file = "coverage-7.14.2-cp314-cp314-musllinux_1_2_ppc64le.whl", hash = "sha256:5fe465bc691264adce601527a972990c1174075d86bcbe9968fd20c95e0b1948"}, + {file = "coverage-7.14.2-cp314-cp314-musllinux_1_2_riscv64.whl", hash = "sha256:6fbb61617af1c56f95d53170ae9fa6c9aef6de1abd02fcc50064bfc672efb18d"}, + {file = "coverage-7.14.2-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:e1eff22b831dfd5694989cc1f0789980f18391f614ac67c851af9a8e6d25e9ba"}, + {file = "coverage-7.14.2-cp314-cp314-win32.whl", hash = "sha256:58e91be0a233adef698d3e6be54f10401bb91fd7854c0d4c4d50e0d3711e72f1"}, + {file = "coverage-7.14.2-cp314-cp314-win_amd64.whl", hash = "sha256:d8429bf97906bfe6c61f9dbfb3342e0d88120da61939da8bd04f830cc3eab3b8"}, + {file = "coverage-7.14.2-cp314-cp314-win_arm64.whl", hash = "sha256:13609d9d77249447aa73357b14831b0f3b95f275026c9ff20dd105f981f53a0c"}, + {file = "coverage-7.14.2-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:9818486c2bac88ae931df7e04905ee29bef49fd218c00f5f02bed4855254a101"}, + {file = "coverage-7.14.2-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:58055adffabfa243516a197aa9f85f0dd56d905b0fba1a10193269759c29ccb0"}, + {file = "coverage-7.14.2-cp314-cp314t-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:535747dbc200349d7fb434cffcb28e770f0290f69b225f56dc3803aa7210cdea"}, + {file = "coverage-7.14.2-cp314-cp314t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:420c66e35d85c0ca5dc6a38147d83ef239762542900e5921ebbdb89333c540ea"}, + {file = "coverage-7.14.2-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:f2cf17b33773be446a588551ea6a746b2d70dd0bc90dc31f1dd7648975a63c6b"}, + {file = "coverage-7.14.2-cp314-cp314t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:adb4a5fef041f7179bb264203add873c147d169cf2f8d0adae89ff2e51271bac"}, + {file = "coverage-7.14.2-cp314-cp314t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:9c012ec357dec9408a83dad5541172a63c5cfa1421709f2e5811480d31ae1b28"}, + {file = "coverage-7.14.2-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:dacd0ecd08fda3cb2f85b60cabea7da326dcb2fc15fbb23a88830a80144cc9f2"}, + {file = "coverage-7.14.2-cp314-cp314t-musllinux_1_2_i686.whl", hash = "sha256:f27e980f2feba5dfe7a32b22b125470de69c0bd113c75e16165de909a777f512"}, + {file = "coverage-7.14.2-cp314-cp314t-musllinux_1_2_ppc64le.whl", hash = "sha256:105c00efb65c863630b2b63cbf7b8267e4da2d44b62284efbb19a03b04c337d4"}, + {file = "coverage-7.14.2-cp314-cp314t-musllinux_1_2_riscv64.whl", hash = "sha256:571173fa04c8e8d6235ab32ae67fecca97777e2e1b4a1a30f3022c34e397c1c1"}, + {file = "coverage-7.14.2-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:e532f34d42d1a421fa00ed6b7735d14ac2e340256c1bad26a5e1dc1252b0bed7"}, + {file = "coverage-7.14.2-cp314-cp314t-win32.whl", hash = "sha256:243971550fb46c3039257f75e65610002d84304c505f609bbd9779e20a653a0a"}, + {file = "coverage-7.14.2-cp314-cp314t-win_amd64.whl", hash = "sha256:60fb0ca084a92da96474b8b405a7ea76dfecac3c68db54383e7934b6f3871169"}, + {file = "coverage-7.14.2-cp314-cp314t-win_arm64.whl", hash = "sha256:36a0a3f42ed7dfdbca2a69a541519ffd5064a5692152fc0018109e74370d7345"}, + {file = "coverage-7.14.2-py3-none-any.whl", hash = "sha256:04d92589e481a8b68a005a5a1e0646a91c76f322c397c4635298c57cf63699b5"}, + {file = "coverage-7.14.2.tar.gz", hash = "sha256:7a2da3d81cfe17c18038c6d98e6592aa9147d596d056119b0ee612c3c8bd5230"}, ] [[package]] name = "coverage" -version = "7.4.0" +version = "7.14.2" extras = ["toml"] -requires_python = ">=3.8" +requires_python = ">=3.10" summary = "Code coverage measurement for Python" groups = ["dev"] dependencies = [ - "coverage==7.4.0", + "coverage==7.14.2", "tomli; python_full_version <= \"3.11.0a6\"", ] files = [ - {file = "coverage-7.4.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:36b0ea8ab20d6a7564e89cb6135920bc9188fb5f1f7152e94e8300b7b189441a"}, - {file = "coverage-7.4.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:0676cd0ba581e514b7f726495ea75aba3eb20899d824636c6f59b0ed2f88c471"}, - {file = "coverage-7.4.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d0ca5c71a5a1765a0f8f88022c52b6b8be740e512980362f7fdbb03725a0d6b9"}, - {file = "coverage-7.4.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a7c97726520f784239f6c62506bc70e48d01ae71e9da128259d61ca5e9788516"}, - {file = "coverage-7.4.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:815ac2d0f3398a14286dc2cea223a6f338109f9ecf39a71160cd1628786bc6f5"}, - {file = "coverage-7.4.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:80b5ee39b7f0131ebec7968baa9b2309eddb35b8403d1869e08f024efd883566"}, - {file = "coverage-7.4.0-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:5b2ccb7548a0b65974860a78c9ffe1173cfb5877460e5a229238d985565574ae"}, - {file = "coverage-7.4.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:995ea5c48c4ebfd898eacb098164b3cc826ba273b3049e4a889658548e321b43"}, - {file = "coverage-7.4.0-cp310-cp310-win32.whl", hash = "sha256:79287fd95585ed36e83182794a57a46aeae0b64ca53929d1176db56aacc83451"}, - {file = "coverage-7.4.0-cp310-cp310-win_amd64.whl", hash = "sha256:5b14b4f8760006bfdb6e08667af7bc2d8d9bfdb648351915315ea17645347137"}, - {file = "coverage-7.4.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:04387a4a6ecb330c1878907ce0dc04078ea72a869263e53c72a1ba5bbdf380ca"}, - {file = "coverage-7.4.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:ea81d8f9691bb53f4fb4db603203029643caffc82bf998ab5b59ca05560f4c06"}, - {file = "coverage-7.4.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:74775198b702868ec2d058cb92720a3c5a9177296f75bd97317c787daf711505"}, - {file = "coverage-7.4.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:76f03940f9973bfaee8cfba70ac991825611b9aac047e5c80d499a44079ec0bc"}, - {file = "coverage-7.4.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:485e9f897cf4856a65a57c7f6ea3dc0d4e6c076c87311d4bc003f82cfe199d25"}, - {file = "coverage-7.4.0-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:6ae8c9d301207e6856865867d762a4b6fd379c714fcc0607a84b92ee63feff70"}, - {file = "coverage-7.4.0-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:bf477c355274a72435ceb140dc42de0dc1e1e0bf6e97195be30487d8eaaf1a09"}, - {file = "coverage-7.4.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:83c2dda2666fe32332f8e87481eed056c8b4d163fe18ecc690b02802d36a4d26"}, - {file = "coverage-7.4.0-cp311-cp311-win32.whl", hash = "sha256:697d1317e5290a313ef0d369650cfee1a114abb6021fa239ca12b4849ebbd614"}, - {file = "coverage-7.4.0-cp311-cp311-win_amd64.whl", hash = "sha256:26776ff6c711d9d835557ee453082025d871e30b3fd6c27fcef14733f67f0590"}, - {file = "coverage-7.4.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:13eaf476ec3e883fe3e5fe3707caeb88268a06284484a3daf8250259ef1ba143"}, - {file = "coverage-7.4.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:846f52f46e212affb5bcf131c952fb4075b55aae6b61adc9856222df89cbe3e2"}, - {file = "coverage-7.4.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:26f66da8695719ccf90e794ed567a1549bb2644a706b41e9f6eae6816b398c4a"}, - {file = "coverage-7.4.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:164fdcc3246c69a6526a59b744b62e303039a81e42cfbbdc171c91a8cc2f9446"}, - {file = "coverage-7.4.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:316543f71025a6565677d84bc4df2114e9b6a615aa39fb165d697dba06a54af9"}, - {file = "coverage-7.4.0-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:bb1de682da0b824411e00a0d4da5a784ec6496b6850fdf8c865c1d68c0e318dd"}, - {file = "coverage-7.4.0-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:0e8d06778e8fbffccfe96331a3946237f87b1e1d359d7fbe8b06b96c95a5407a"}, - {file = "coverage-7.4.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:a56de34db7b7ff77056a37aedded01b2b98b508227d2d0979d373a9b5d353daa"}, - {file = "coverage-7.4.0-cp312-cp312-win32.whl", hash = "sha256:51456e6fa099a8d9d91497202d9563a320513fcf59f33991b0661a4a6f2ad450"}, - {file = "coverage-7.4.0-cp312-cp312-win_amd64.whl", hash = "sha256:cd3c1e4cb2ff0083758f09be0f77402e1bdf704adb7f89108007300a6da587d0"}, - {file = "coverage-7.4.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:e9d1bf53c4c8de58d22e0e956a79a5b37f754ed1ffdbf1a260d9dcfa2d8a325e"}, - {file = "coverage-7.4.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:109f5985182b6b81fe33323ab4707011875198c41964f014579cf82cebf2bb85"}, - {file = "coverage-7.4.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3cc9d4bc55de8003663ec94c2f215d12d42ceea128da8f0f4036235a119c88ac"}, - {file = "coverage-7.4.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:cc6d65b21c219ec2072c1293c505cf36e4e913a3f936d80028993dd73c7906b1"}, - {file = "coverage-7.4.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5a10a4920def78bbfff4eff8a05c51be03e42f1c3735be42d851f199144897ba"}, - {file = "coverage-7.4.0-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:b8e99f06160602bc64da35158bb76c73522a4010f0649be44a4e167ff8555952"}, - {file = "coverage-7.4.0-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:7d360587e64d006402b7116623cebf9d48893329ef035278969fa3bbf75b697e"}, - {file = "coverage-7.4.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:29f3abe810930311c0b5d1a7140f6395369c3db1be68345638c33eec07535105"}, - {file = "coverage-7.4.0-cp38-cp38-win32.whl", hash = "sha256:5040148f4ec43644702e7b16ca864c5314ccb8ee0751ef617d49aa0e2d6bf4f2"}, - {file = "coverage-7.4.0-cp38-cp38-win_amd64.whl", hash = "sha256:9864463c1c2f9cb3b5db2cf1ff475eed2f0b4285c2aaf4d357b69959941aa555"}, - {file = "coverage-7.4.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:936d38794044b26c99d3dd004d8af0035ac535b92090f7f2bb5aa9c8e2f5cd42"}, - {file = "coverage-7.4.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:799c8f873794a08cdf216aa5d0531c6a3747793b70c53f70e98259720a6fe2d7"}, - {file = "coverage-7.4.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e7defbb9737274023e2d7af02cac77043c86ce88a907c58f42b580a97d5bcca9"}, - {file = "coverage-7.4.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a1526d265743fb49363974b7aa8d5899ff64ee07df47dd8d3e37dcc0818f09ed"}, - {file = "coverage-7.4.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bf635a52fc1ea401baf88843ae8708591aa4adff875e5c23220de43b1ccf575c"}, - {file = "coverage-7.4.0-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:756ded44f47f330666843b5781be126ab57bb57c22adbb07d83f6b519783b870"}, - {file = "coverage-7.4.0-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:0eb3c2f32dabe3a4aaf6441dde94f35687224dfd7eb2a7f47f3fd9428e421058"}, - {file = "coverage-7.4.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:bfd5db349d15c08311702611f3dccbef4b4e2ec148fcc636cf8739519b4a5c0f"}, - {file = "coverage-7.4.0-cp39-cp39-win32.whl", hash = "sha256:53d7d9158ee03956e0eadac38dfa1ec8068431ef8058fe6447043db1fb40d932"}, - {file = "coverage-7.4.0-cp39-cp39-win_amd64.whl", hash = "sha256:cfd2a8b6b0d8e66e944d47cdec2f47c48fef2ba2f2dff5a9a75757f64172857e"}, - {file = "coverage-7.4.0-pp38.pp39.pp310-none-any.whl", hash = "sha256:c530833afc4707fe48524a44844493f36d8727f04dcce91fb978c414a8556cc6"}, - {file = "coverage-7.4.0.tar.gz", hash = "sha256:707c0f58cb1712b8809ece32b68996ee1e609f71bd14615bd8f87a1293cb610e"}, -] - -[[package]] -name = "cryptography" -version = "42.0.5" -requires_python = ">=3.7" -summary = "cryptography is a package which provides cryptographic recipes and primitives to Python developers." -groups = ["dev"] -dependencies = [ - "cffi>=1.12; platform_python_implementation != \"PyPy\"", -] -files = [ - {file = "cryptography-42.0.5-cp37-abi3-macosx_10_12_universal2.whl", hash = "sha256:a30596bae9403a342c978fb47d9b0ee277699fa53bbafad14706af51fe543d16"}, - {file = "cryptography-42.0.5-cp37-abi3-macosx_10_12_x86_64.whl", hash = "sha256:b7ffe927ee6531c78f81aa17e684e2ff617daeba7f189f911065b2ea2d526dec"}, - {file = "cryptography-42.0.5-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2424ff4c4ac7f6b8177b53c17ed5d8fa74ae5955656867f5a8affaca36a27abb"}, - {file = "cryptography-42.0.5-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:329906dcc7b20ff3cad13c069a78124ed8247adcac44b10bea1130e36caae0b4"}, - {file = "cryptography-42.0.5-cp37-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:b03c2ae5d2f0fc05f9a2c0c997e1bc18c8229f392234e8a0194f202169ccd278"}, - {file = "cryptography-42.0.5-cp37-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:f8837fe1d6ac4a8052a9a8ddab256bc006242696f03368a4009be7ee3075cdb7"}, - {file = "cryptography-42.0.5-cp37-abi3-musllinux_1_1_aarch64.whl", hash = "sha256:0270572b8bd2c833c3981724b8ee9747b3ec96f699a9665470018594301439ee"}, - {file = "cryptography-42.0.5-cp37-abi3-musllinux_1_1_x86_64.whl", hash = "sha256:b8cac287fafc4ad485b8a9b67d0ee80c66bf3574f655d3b97ef2e1082360faf1"}, - {file = "cryptography-42.0.5-cp37-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:16a48c23a62a2f4a285699dba2e4ff2d1cff3115b9df052cdd976a18856d8e3d"}, - {file = "cryptography-42.0.5-cp37-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:2bce03af1ce5a5567ab89bd90d11e7bbdff56b8af3acbbec1faded8f44cb06da"}, - {file = "cryptography-42.0.5-cp37-abi3-win32.whl", hash = "sha256:b6cd2203306b63e41acdf39aa93b86fb566049aeb6dc489b70e34bcd07adca74"}, - {file = "cryptography-42.0.5-cp37-abi3-win_amd64.whl", hash = "sha256:98d8dc6d012b82287f2c3d26ce1d2dd130ec200c8679b6213b3c73c08b2b7940"}, - {file = "cryptography-42.0.5-cp39-abi3-macosx_10_12_universal2.whl", hash = "sha256:5e6275c09d2badf57aea3afa80d975444f4be8d3bc58f7f80d2a484c6f9485c8"}, - {file = "cryptography-42.0.5-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e4985a790f921508f36f81831817cbc03b102d643b5fcb81cd33df3fa291a1a1"}, - {file = "cryptography-42.0.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7cde5f38e614f55e28d831754e8a3bacf9ace5d1566235e39d91b35502d6936e"}, - {file = "cryptography-42.0.5-cp39-abi3-manylinux_2_28_aarch64.whl", hash = "sha256:7367d7b2eca6513681127ebad53b2582911d1736dc2ffc19f2c3ae49997496bc"}, - {file = "cryptography-42.0.5-cp39-abi3-manylinux_2_28_x86_64.whl", hash = "sha256:cd2030f6650c089aeb304cf093f3244d34745ce0cfcc39f20c6fbfe030102e2a"}, - {file = "cryptography-42.0.5-cp39-abi3-musllinux_1_1_aarch64.whl", hash = "sha256:a2913c5375154b6ef2e91c10b5720ea6e21007412f6437504ffea2109b5a33d7"}, - {file = "cryptography-42.0.5-cp39-abi3-musllinux_1_1_x86_64.whl", hash = "sha256:c41fb5e6a5fe9ebcd58ca3abfeb51dffb5d83d6775405305bfa8715b76521922"}, - {file = "cryptography-42.0.5-cp39-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:3eaafe47ec0d0ffcc9349e1708be2aaea4c6dd4978d76bf6eb0cb2c13636c6fc"}, - {file = "cryptography-42.0.5-cp39-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:1b95b98b0d2af784078fa69f637135e3c317091b615cd0905f8b8a087e86fa30"}, - {file = "cryptography-42.0.5-cp39-abi3-win32.whl", hash = "sha256:1f71c10d1e88467126f0efd484bd44bca5e14c664ec2ede64c32f20875c0d413"}, - {file = "cryptography-42.0.5-cp39-abi3-win_amd64.whl", hash = "sha256:a011a644f6d7d03736214d38832e030d8268bcff4a41f728e6030325fea3e400"}, - {file = "cryptography-42.0.5-pp310-pypy310_pp73-macosx_10_12_x86_64.whl", hash = "sha256:9481ffe3cf013b71b2428b905c4f7a9a4f76ec03065b05ff499bb5682a8d9ad8"}, - {file = "cryptography-42.0.5-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:ba334e6e4b1d92442b75ddacc615c5476d4ad55cc29b15d590cc6b86efa487e2"}, - {file = "cryptography-42.0.5-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:ba3e4a42397c25b7ff88cdec6e2a16c2be18720f317506ee25210f6d31925f9c"}, - {file = "cryptography-42.0.5-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:111a0d8553afcf8eb02a4fea6ca4f59d48ddb34497aa8706a6cf536f1a5ec576"}, - {file = "cryptography-42.0.5-pp39-pypy39_pp73-macosx_10_12_x86_64.whl", hash = "sha256:cd65d75953847815962c84a4654a84850b2bb4aed3f26fadcc1c13892e1e29f6"}, - {file = "cryptography-42.0.5-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:e807b3188f9eb0eaa7bbb579b462c5ace579f1cedb28107ce8b48a9f7ad3679e"}, - {file = "cryptography-42.0.5-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:f12764b8fffc7a123f641d7d049d382b73f96a34117e0b637b80643169cec8ac"}, - {file = "cryptography-42.0.5-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:37dd623507659e08be98eec89323469e8c7b4c1407c85112634ae3dbdb926fdd"}, - {file = "cryptography-42.0.5.tar.gz", hash = "sha256:6fe07eec95dfd477eb9530aef5bead34fec819b3aaf6c5bd6d20565da607bfe1"}, -] - -[[package]] -name = "dparse" -version = "0.6.4b0" -requires_python = ">=3.7" -summary = "A parser for Python dependency files" -groups = ["dev"] -dependencies = [ - "packaging", - "tomli; python_version < \"3.11\"", -] -files = [ - {file = "dparse-0.6.4b0-py3-none-any.whl", hash = "sha256:592ff183348b8a5ea0a18442a7965e29445d3a26063654ec2c7e8ef42cd5753c"}, - {file = "dparse-0.6.4b0.tar.gz", hash = "sha256:f8d49b41a527f3d16a269f854e6665245b325e50e41d2c213810cb984553e5c8"}, -] - -[[package]] -name = "exceptiongroup" -version = "1.2.0" -requires_python = ">=3.7" -summary = "Backport of PEP 654 (exception groups)" -groups = ["default", "dev"] -marker = "python_version < \"3.11\"" -files = [ - {file = "exceptiongroup-1.2.0-py3-none-any.whl", hash = "sha256:4bfd3996ac73b41e9b9628b04e079f193850720ea5945fc96a08633c66912f14"}, - {file = "exceptiongroup-1.2.0.tar.gz", hash = "sha256:91f5c769735f051a4290d52edd0858999b57e5876e9f85937691bd4c9fa3ed68"}, + {file = "coverage-7.14.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:909f265c8c41f04c824bf741b2601fdcb56cab4bf56e018996b6494192ba0f58"}, + {file = "coverage-7.14.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:c8102deaf911938233f760426e6a5e287388521de95111d5c8de26c8a1028924"}, + {file = "coverage-7.14.2-cp311-cp311-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:851f49e7bd7d1cdaf328f3133942b252d5e3d3380690131f423cba8e435b87f5"}, + {file = "coverage-7.14.2-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:04cb445bed86aaf00aaa97d41a8b6e30f100f21e81c34caaec4efc684cb57768"}, + {file = "coverage-7.14.2-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:7471bc920d97c51c37ea8127f13b2adca43c3d78c53313b26a1f428e99d2c254"}, + {file = "coverage-7.14.2-cp311-cp311-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:da5057e1bb257c967feee8ba67f3ebf379e801c7717f238b3d8c9caf00fc8f93"}, + {file = "coverage-7.14.2-cp311-cp311-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:33c0da852e8a40246cd8e20cf3b2fc17ca52a45e9b5f7983c93db26f5d24b87b"}, + {file = "coverage-7.14.2-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:f48a85bb437fab7782021c40bfee6b15146928b96960d008ace41b6901a0f21d"}, + {file = "coverage-7.14.2-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:f44e7579a769a21d5b5e3166916bfe30ee175aaffff750324cbb11be2dbec5ad"}, + {file = "coverage-7.14.2-cp311-cp311-musllinux_1_2_ppc64le.whl", hash = "sha256:78853ca3c6ca2f012daa2b07dbabbb8db0f09d4dbe8ee828d294b3445d3f4cd8"}, + {file = "coverage-7.14.2-cp311-cp311-musllinux_1_2_riscv64.whl", hash = "sha256:c9c2795ee3692097ff226ab806005d36bb9691fca9b35353542b57ea749cc830"}, + {file = "coverage-7.14.2-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:2f5cc48a845d755b6db236f8c29c2b54773eb4c7e4ee2ead43812d73718784b0"}, + {file = "coverage-7.14.2-cp311-cp311-win32.whl", hash = "sha256:9c61cb7eaabcfa609c5bc0f5ff5869d72a2f02f17994e5fba5f971de516f3c82"}, + {file = "coverage-7.14.2-cp311-cp311-win_amd64.whl", hash = "sha256:e715909b0966d1774d8a26e14e2f4a3ae75909dca526901c6306286b2dcbfbdc"}, + {file = "coverage-7.14.2-cp311-cp311-win_arm64.whl", hash = "sha256:9193f7150937a4fd836b10eaa123e15d98e961d1fabac07e60adf2d4785f888a"}, + {file = "coverage-7.14.2-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:37c94712e533ea06f0b1e4d934811c520b1914ce0e4da3916220717aa7a86bc6"}, + {file = "coverage-7.14.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:c050bbc7bba94c77e4ed7438f4fda1babe98ab145691d80aa6f60df934a1468b"}, + {file = "coverage-7.14.2-cp312-cp312-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:a7af571767a2ee342a171c16fc1b1a07a0bf511606d381703fb7cf397fe49d46"}, + {file = "coverage-7.14.2-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:8b4910cce599cd2438f8da65f5ef199a70a1cdb6ab314926df78271ca5954240"}, + {file = "coverage-7.14.2-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:c33e9e4878972f430b0cc06de3bf2a28d054a9efb4f8426d27de0d9cb81396ff"}, + {file = "coverage-7.14.2-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:e7967ea55c6dea6becba4d5870e2fa0aa4915a8be7ebff1bb79e6207aa75ce8d"}, + {file = "coverage-7.14.2-cp312-cp312-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:d1322f237c2979b84096f4239c17828ff17fea6b3bbe96c44381c5f587c44c26"}, + {file = "coverage-7.14.2-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:77849525340c99f516d793dddbcee16b18d50af892ac43c8de1a6f343d41e3b5"}, + {file = "coverage-7.14.2-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:ef11695493ec3f06f7b2678ca274bcabb4ca04057317df268ddbfd8b05f661a8"}, + {file = "coverage-7.14.2-cp312-cp312-musllinux_1_2_ppc64le.whl", hash = "sha256:8134f0e0723e080d1c27bbe8fc149f0162e429fa1852482150015d0fce83eaf1"}, + {file = "coverage-7.14.2-cp312-cp312-musllinux_1_2_riscv64.whl", hash = "sha256:914eead2b843fc357f733b3fe39cc94f1b53d466e8cfe03080b1ed9d24ccfc73"}, + {file = "coverage-7.14.2-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:e4b2d5e847fb7958583b74910cc19e5ec4ece514487385677b26433b2546116e"}, + {file = "coverage-7.14.2-cp312-cp312-win32.whl", hash = "sha256:e753db9e40dda7302e0ac3e1e6e1325fb7f7b4694f87a7314ab15dd5d57911a7"}, + {file = "coverage-7.14.2-cp312-cp312-win_amd64.whl", hash = "sha256:d32e5ca5f16dafb269ee50b60d32b00c704b3f6f78e238105f1d94a3a5f24bf5"}, + {file = "coverage-7.14.2-cp312-cp312-win_arm64.whl", hash = "sha256:dc366f158e2fb2add9d4e57338ca48f12611024278688ee657eb0b853fcb5de5"}, + {file = "coverage-7.14.2-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:e5f077641a6713ce9d38df9e85d4fb9e008677fc0775cbaeb32ddfc3b319d4ca"}, + {file = "coverage-7.14.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:0907f39b49ae818fe8af50aaa0f19afbc8ca164aea0865181ca7af17a3ac690b"}, + {file = "coverage-7.14.2-cp313-cp313-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:5734d47669118d75c28981e562d4530ceb77342d31ffef6def5edd5ad4f05d7b"}, + {file = "coverage-7.14.2-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:1d9a1b5813d00ea6151f6ccf64d1fa16892771dfdda12ba87162d15ec4ea3e1e"}, + {file = "coverage-7.14.2-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:9f0a80f4c8ac3f774210b1cc1bc0e31e75502f2818dda9a144ff90e702c4d91d"}, + {file = "coverage-7.14.2-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:c2e66f3f22d6c1515ce70f2e7c3e9c6f3ff0ff33480125c9f9c53e8f6508e30f"}, + {file = "coverage-7.14.2-cp313-cp313-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:6a2c37c3114f87ca7f10113756026eecb49656514debad600dcbec21f355ccea"}, + {file = "coverage-7.14.2-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:3b16a7959d04b1497281c062c180413565c3f3469211d78799ad5b9a75f67796"}, + {file = "coverage-7.14.2-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:6466c6999545cf00c4c142dfcbbf2db396dc735f005dcf8f91d57e351a79472b"}, + {file = "coverage-7.14.2-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:5c60915ebb8f562317ba5ff6b8c32e25c0882289b201a9f2fb2987f91efd95d8"}, + {file = "coverage-7.14.2-cp313-cp313-musllinux_1_2_riscv64.whl", hash = "sha256:33b830850488acbcd358c78a4fecfafe7031667b4da8ddff5546295dc962cdeb"}, + {file = "coverage-7.14.2-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:d0f845539230b8269aec902bc978b0cc403f52f002d18a04492efc943404d0bc"}, + {file = "coverage-7.14.2-cp313-cp313-win32.whl", hash = "sha256:a8ac51a2e441e9119b9395f4d893fbc4934c64c8ba58be9b9eaa85591249e548"}, + {file = "coverage-7.14.2-cp313-cp313-win_amd64.whl", hash = "sha256:039b264cdb31c44b48f9821e2afbf8f37df49e0fb837e24a942918b36c567e31"}, + {file = "coverage-7.14.2-cp313-cp313-win_arm64.whl", hash = "sha256:7f2ef591e381cc36b8e53334e1b842c760c520c8a52d01e8626209400e93fe6a"}, + {file = "coverage-7.14.2-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:7a0d1f026b72d627fa5c8a57cbc86ad209b64aa2a65833c83b290ace5cbee126"}, + {file = "coverage-7.14.2-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:4d2b86f81c1c9310a7e774e3cc9e927a3d0bf583ecbfa01498dd626930025428"}, + {file = "coverage-7.14.2-cp314-cp314-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:d76bdc1f9396ae70a55d050cf9743d88141c62ce0a22a3f627fab1d11c2f8bc6"}, + {file = "coverage-7.14.2-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:cda36d8e7bfd63b3e44e75163265429caa5d935b672b00f71bccc8c010518c64"}, + {file = "coverage-7.14.2-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:0904f3b79d7b845bef0715afe1900da634d12b97f05b9479cb472880ca07cb9c"}, + {file = "coverage-7.14.2-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:b6795ca4198d6cb7fc2c6163214f6555a6bc5f0ae1e268e76139dec4b37c4499"}, + {file = "coverage-7.14.2-cp314-cp314-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:c41e9b60fc0fa57f5d73306417d2f9d668202cca6944f9435878c55a5e7ae213"}, + {file = "coverage-7.14.2-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:419d2aadd5746efc2e9df0f33c05570d8192e6f6a6098ab05acce586f44ce8a5"}, + {file = "coverage-7.14.2-cp314-cp314-musllinux_1_2_i686.whl", hash = "sha256:1c5d273c5f1411c0d26c4f066c398d4a434b1f97bb5fa409189bedce86d4add4"}, + {file = "coverage-7.14.2-cp314-cp314-musllinux_1_2_ppc64le.whl", hash = "sha256:5fe465bc691264adce601527a972990c1174075d86bcbe9968fd20c95e0b1948"}, + {file = "coverage-7.14.2-cp314-cp314-musllinux_1_2_riscv64.whl", hash = "sha256:6fbb61617af1c56f95d53170ae9fa6c9aef6de1abd02fcc50064bfc672efb18d"}, + {file = "coverage-7.14.2-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:e1eff22b831dfd5694989cc1f0789980f18391f614ac67c851af9a8e6d25e9ba"}, + {file = "coverage-7.14.2-cp314-cp314-win32.whl", hash = "sha256:58e91be0a233adef698d3e6be54f10401bb91fd7854c0d4c4d50e0d3711e72f1"}, + {file = "coverage-7.14.2-cp314-cp314-win_amd64.whl", hash = "sha256:d8429bf97906bfe6c61f9dbfb3342e0d88120da61939da8bd04f830cc3eab3b8"}, + {file = "coverage-7.14.2-cp314-cp314-win_arm64.whl", hash = "sha256:13609d9d77249447aa73357b14831b0f3b95f275026c9ff20dd105f981f53a0c"}, + {file = "coverage-7.14.2-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:9818486c2bac88ae931df7e04905ee29bef49fd218c00f5f02bed4855254a101"}, + {file = "coverage-7.14.2-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:58055adffabfa243516a197aa9f85f0dd56d905b0fba1a10193269759c29ccb0"}, + {file = "coverage-7.14.2-cp314-cp314t-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:535747dbc200349d7fb434cffcb28e770f0290f69b225f56dc3803aa7210cdea"}, + {file = "coverage-7.14.2-cp314-cp314t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:420c66e35d85c0ca5dc6a38147d83ef239762542900e5921ebbdb89333c540ea"}, + {file = "coverage-7.14.2-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:f2cf17b33773be446a588551ea6a746b2d70dd0bc90dc31f1dd7648975a63c6b"}, + {file = "coverage-7.14.2-cp314-cp314t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:adb4a5fef041f7179bb264203add873c147d169cf2f8d0adae89ff2e51271bac"}, + {file = "coverage-7.14.2-cp314-cp314t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:9c012ec357dec9408a83dad5541172a63c5cfa1421709f2e5811480d31ae1b28"}, + {file = "coverage-7.14.2-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:dacd0ecd08fda3cb2f85b60cabea7da326dcb2fc15fbb23a88830a80144cc9f2"}, + {file = "coverage-7.14.2-cp314-cp314t-musllinux_1_2_i686.whl", hash = "sha256:f27e980f2feba5dfe7a32b22b125470de69c0bd113c75e16165de909a777f512"}, + {file = "coverage-7.14.2-cp314-cp314t-musllinux_1_2_ppc64le.whl", hash = "sha256:105c00efb65c863630b2b63cbf7b8267e4da2d44b62284efbb19a03b04c337d4"}, + {file = "coverage-7.14.2-cp314-cp314t-musllinux_1_2_riscv64.whl", hash = "sha256:571173fa04c8e8d6235ab32ae67fecca97777e2e1b4a1a30f3022c34e397c1c1"}, + {file = "coverage-7.14.2-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:e532f34d42d1a421fa00ed6b7735d14ac2e340256c1bad26a5e1dc1252b0bed7"}, + {file = "coverage-7.14.2-cp314-cp314t-win32.whl", hash = "sha256:243971550fb46c3039257f75e65610002d84304c505f609bbd9779e20a653a0a"}, + {file = "coverage-7.14.2-cp314-cp314t-win_amd64.whl", hash = "sha256:60fb0ca084a92da96474b8b405a7ea76dfecac3c68db54383e7934b6f3871169"}, + {file = "coverage-7.14.2-cp314-cp314t-win_arm64.whl", hash = "sha256:36a0a3f42ed7dfdbca2a69a541519ffd5064a5692152fc0018109e74370d7345"}, + {file = "coverage-7.14.2-py3-none-any.whl", hash = "sha256:04d92589e481a8b68a005a5a1e0646a91c76f322c397c4635298c57cf63699b5"}, + {file = "coverage-7.14.2.tar.gz", hash = "sha256:7a2da3d81cfe17c18038c6d98e6592aa9147d596d056119b0ee612c3c8bd5230"}, ] [[package]] name = "h11" -version = "0.14.0" -requires_python = ">=3.7" +version = "0.16.0" +requires_python = ">=3.8" summary = "A pure-Python, bring-your-own-I/O implementation of HTTP/1.1" groups = ["default"] files = [ - {file = "h11-0.14.0-py3-none-any.whl", hash = "sha256:e3fe4ac4b851c468cc8363d500db52c2ead036020723024a109d37346efaa761"}, - {file = "h11-0.14.0.tar.gz", hash = "sha256:8f19fbbe99e72420ff35c00b27a34cb9937e902a8b810e2c88300c6f0a3b699d"}, + {file = "h11-0.16.0-py3-none-any.whl", hash = "sha256:63cf8bbe7522de3bf65932fda1d9c2772064ffb3dae62d55932da54b31cb6c86"}, + {file = "h11-0.16.0.tar.gz", hash = "sha256:4e35b956cf45792e4caa5885e69fba00bdbc6ffafbfa020300e549b208ee5ff1"}, ] [[package]] name = "httpcore" -version = "1.0.2" +version = "1.0.9" requires_python = ">=3.8" summary = "A minimal low-level HTTP client." groups = ["default"] dependencies = [ "certifi", - "h11<0.15,>=0.13", + "h11>=0.16", ] files = [ - {file = "httpcore-1.0.2-py3-none-any.whl", hash = "sha256:096cc05bca73b8e459a1fc3dcf585148f63e534eae4339559c9b8a8d6399acc7"}, - {file = "httpcore-1.0.2.tar.gz", hash = "sha256:9fc092e4799b26174648e54b74ed5f683132a464e95643b226e00c2ed2fa6535"}, + {file = "httpcore-1.0.9-py3-none-any.whl", hash = "sha256:2d400746a40668fc9dec9810239072b40b4484b640a8c38fd654a024c7a1bf55"}, + {file = "httpcore-1.0.9.tar.gz", hash = "sha256:6e34463af53fd2ab5d807f399a9b45ea31c3dfa2276f15a2c3f00afff6e176e8"}, ] [[package]] name = "httpx" -version = "0.27.0" +version = "0.28.1" requires_python = ">=3.8" summary = "The next generation HTTP client." groups = ["default"] @@ -484,135 +341,299 @@ dependencies = [ "certifi", "httpcore==1.*", "idna", - "sniffio", ] files = [ - {file = "httpx-0.27.0-py3-none-any.whl", hash = "sha256:71d5465162c13681bff01ad59b2cc68dd838ea1f10e51574bac27103f00c91a5"}, - {file = "httpx-0.27.0.tar.gz", hash = "sha256:a0cb88a46f32dc874e04ee956e4c2764aba2aa228f650b06788ba6bda2962ab5"}, + {file = "httpx-0.28.1-py3-none-any.whl", hash = "sha256:d909fcccc110f8c7faf814ca82a9a4d816bc5a6dbfea25d6591d6985b8ba59ad"}, + {file = "httpx-0.28.1.tar.gz", hash = "sha256:75e98c5f16b0f35b567856f597f06ff2270a374470a5c2392242528e3e3e42fc"}, +] + +[[package]] +name = "hypothesis" +version = "6.165.10" +requires_python = ">=3.10" +summary = "The property-based testing library for Python" +groups = ["dev"] +dependencies = [ + "exceptiongroup>=1.0.0; python_full_version < \"3.11\"", + "sortedcontainers<3.0.0,>=2.1.0", +] +files = [ + {file = "hypothesis-6.165.10-cp310-abi3-macosx_10_12_x86_64.whl", hash = "sha256:f839d29d0cc12048cf073d88ca4fdf94d420bc2b8afd69641ff6d496422ccd4f"}, + {file = "hypothesis-6.165.10-cp310-abi3-macosx_11_0_arm64.whl", hash = "sha256:e10858f57ed0e74baa04393845f469fe8ad502c16ece4499bef7700c575611bd"}, + {file = "hypothesis-6.165.10-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:76a7be86d986223b9f1bdb7e7cbcdb048649901fdb956c598ef73bdab1786cd5"}, + {file = "hypothesis-6.165.10-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:717aea574e0e5edba2868aa66b1caae335d8f1ad3fb29f01dd6502953fa823a1"}, + {file = "hypothesis-6.165.10-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:4334058033e0214475f019e15492a50f3854fe8728cf51fe25c6191a2c3f8e52"}, + {file = "hypothesis-6.165.10-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2abb50cf1cf77d721de0a24c3f99d9c4ffdeb2cbd1e12aebb5a7a93e2b6b6d1f"}, + {file = "hypothesis-6.165.10-cp310-abi3-manylinux_2_31_riscv64.whl", hash = "sha256:3de69aa8b924b400291a3cc42aaf78e6ab65c905a3e7e1a5dc39d95ef1b428cb"}, + {file = "hypothesis-6.165.10-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:5841331c504e02d7c334591681cb8587cdd59dee7e149db6d3db8e3f9e9f02eb"}, + {file = "hypothesis-6.165.10-cp310-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:2d0e0f8263d34dd8fa3b39eaa9a50bba56a8470b3dd9ebf6672d10840abe063e"}, + {file = "hypothesis-6.165.10-cp310-abi3-musllinux_1_2_armv7l.whl", hash = "sha256:0c4e6869817c3cfdf5a2b4d348497b95159bdecb3365be732c9b8570e36a4eef"}, + {file = "hypothesis-6.165.10-cp310-abi3-musllinux_1_2_ppc64le.whl", hash = "sha256:9f07ae36c3b093e13687a894e79fe69e98a94c0b67fef656c575247682218143"}, + {file = "hypothesis-6.165.10-cp310-abi3-musllinux_1_2_riscv64.whl", hash = "sha256:aff1f584c9538e8979cd180b1d70bf99bc16be19d4666414f49e5942b21a4f2c"}, + {file = "hypothesis-6.165.10-cp310-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:1f2c4db25fb8ec1a16a8dba580666337b8ffb1887c4cf1750cc954313897cef7"}, + {file = "hypothesis-6.165.10-cp310-abi3-win32.whl", hash = "sha256:b33dc30170a7402e03c180f2c5ef69dc077152f35b91621e9cebcde9c7d71746"}, + {file = "hypothesis-6.165.10-cp310-abi3-win_amd64.whl", hash = "sha256:e9f924aa610c0618445e1e8738c822c3190ce2a2699a0cb48ec3a351a96761f2"}, + {file = "hypothesis-6.165.10-cp310-abi3-win_arm64.whl", hash = "sha256:1d305448e9bd8e2f4f3cea0eafd809efdaab4e998a0019bc615650c8463e42f1"}, + {file = "hypothesis-6.165.10-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:592107a0faf6c9c3a63a8dbf13dfb1cbda1cf599b0bc11c953221b00204b9ce1"}, + {file = "hypothesis-6.165.10-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:f9180c362bde06fd05380298ded4e234fbc0d6ede0a864835bfd91c1e24283d5"}, + {file = "hypothesis-6.165.10-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d623801ae3dcd97b77b983400ef3d48bf976648e4efff19929175322eaae074d"}, + {file = "hypothesis-6.165.10-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:20f6236cfb90b7817bb1a6a087589ca4aa46d73170f0dd62963952ed5dadc589"}, + {file = "hypothesis-6.165.10-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:ad0764730e8e3421601c2cc7e1f054a9206c60ea0917165d8d9193dc453f34f1"}, + {file = "hypothesis-6.165.10-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:10d9a650a4666b0914831f769703d36140ed8039fd19bf9b71f615b8541eccf2"}, + {file = "hypothesis-6.165.10-cp311-cp311-win_amd64.whl", hash = "sha256:5671d2b2bf83bd4b6f02e55b32d432506eff5358c82f39b460a849ce19a2666e"}, + {file = "hypothesis-6.165.10-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:637445c1593a2a9d1024fda50082f07bb56baedda78d90a25f64b8111727ef94"}, + {file = "hypothesis-6.165.10-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:713f4ce4e82c26b53031f139de959bc9e8b54d3995aa824b89bbdf8229df2a45"}, + {file = "hypothesis-6.165.10-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f9ff356e97e3ab09db07c8b675efa67340103874a0bae7465acb83dad7a35f7f"}, + {file = "hypothesis-6.165.10-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1a380bc99aa3b035e6a95a2201bf792d4082a04ca75babcc21849c2d0914bb28"}, + {file = "hypothesis-6.165.10-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:e9acb2c4d9cb532c3fedea74159f7b923c8c036328c9239b4049e7aa073bdd81"}, + {file = "hypothesis-6.165.10-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:8660572b2d424bf5369ea8990985225f70bd1615b76ecd9c25588a3b9307009f"}, + {file = "hypothesis-6.165.10-cp312-cp312-win_amd64.whl", hash = "sha256:3376f2594763aef14faa519b0fb27cae7ce9eeaab4c69efa07777499110306c9"}, + {file = "hypothesis-6.165.10-cp313-cp313-macosx_10_12_x86_64.whl", hash = "sha256:9d77c3be7b429875036ad0f0597c6e5cc6bb17894a4da005e3807de64d2673ad"}, + {file = "hypothesis-6.165.10-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:490c56b830772b0eca3b4b2cecb3741a1ed26b1d7206a279e1525dbf0aa95ee4"}, + {file = "hypothesis-6.165.10-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ed68e27b8a61e57a3ccdc7c5a14499e00b54dfe223087204d5d40b3b5ef58b6d"}, + {file = "hypothesis-6.165.10-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6caadcd1afb62630ff5c5ff353626eaa616553a5971295ad6dc2b19ca8a39620"}, + {file = "hypothesis-6.165.10-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:d9145fe43ebb22e66672967c3fab411793b226ed776e4fe282271bca6ad3c0bb"}, + {file = "hypothesis-6.165.10-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:79900a9920a0b1d3a626c03a90ac6bf7042e78d46906a565b86a0dbe926f1d96"}, + {file = "hypothesis-6.165.10-cp313-cp313-win_amd64.whl", hash = "sha256:c01dd04044c472e47193b54f68e84e08d6ebf4f29551885aa959b015f7cd9747"}, + {file = "hypothesis-6.165.10-cp314-cp314-macosx_10_12_x86_64.whl", hash = "sha256:9ccac776b2ca93b324806facd526ccb45da0fd035001c899a35b02c44431e209"}, + {file = "hypothesis-6.165.10-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:e5f95f7b622e4171096d92175dda0a560f0955ade9b8a3a07bdcf151f7359611"}, + {file = "hypothesis-6.165.10-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f76d1562643693b8a40066f1f96af795b93fd9bcfc9690a1af2ff4c5867ee29e"}, + {file = "hypothesis-6.165.10-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:60cab3ab4ea468d31a33739ffd7e94ec3e37dea891d65a6582ecc8a477175191"}, + {file = "hypothesis-6.165.10-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:22cf19388f0ff6ced8eb3e49c903d14938e4ed909d93bf28383eef451511e424"}, + {file = "hypothesis-6.165.10-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:057d0232f1224dcd0b7698902551a4341a7399f90670b036db6c4376715fe889"}, + {file = "hypothesis-6.165.10-cp314-cp314-pyemscripten_2026_0_wasm32.whl", hash = "sha256:ab0f2e9d7d7d4db257f7cf53de3706c2baf124269571f20ffc2bcd6781f03063"}, + {file = "hypothesis-6.165.10-cp314-cp314-win_amd64.whl", hash = "sha256:d1ea02fa8ab3d33eb1125eade81f7136341eb429152c6dbe2ae6f8bc33b3fbdd"}, + {file = "hypothesis-6.165.10-cp314-cp314t-macosx_10_12_x86_64.whl", hash = "sha256:ed1a5891e59472884a03cb9875483e8fc131c80a275c60967f8afc5458a0c8ff"}, + {file = "hypothesis-6.165.10-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:09772e328a26e50486ac572be34f9887f9aa185efe7ebb16bde4e8f6038db1f4"}, + {file = "hypothesis-6.165.10-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5cf3b612542ba174c9da4000b59a4f4c81e8d66f87509be85d3a1b71b5c36413"}, + {file = "hypothesis-6.165.10-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f69ec5be85ef508e206153bed8eafd03f7995dc464356c8bbb279a1e2b7d56f3"}, + {file = "hypothesis-6.165.10-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:dd207497bb985918409a1bb5db85d1875f74e1269487332113b73d1ee7c77647"}, + {file = "hypothesis-6.165.10-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:00de0abdcf8c05c9d0eab735a3c49a276376b55151e6fcb903c2b39a90e5e5c3"}, + {file = "hypothesis-6.165.10-cp314-cp314t-win_amd64.whl", hash = "sha256:cc2da5aa4edf14743fa9257e5ba3513963999f01211635702479d8e92b8207c8"}, + {file = "hypothesis-6.165.10-cp315-abi3.abi3t-macosx_10_12_x86_64.whl", hash = "sha256:eeab73050ea58c13dd56e329f594c1dfe32ebd7bb169bbdf4f8ceefbc31ec6b5"}, + {file = "hypothesis-6.165.10-cp315-abi3.abi3t-macosx_11_0_arm64.whl", hash = "sha256:4c68e983d0007d014bb01ad4bcbba78bc432c73a1755ff36d5102ceefa18299a"}, + {file = "hypothesis-6.165.10-cp315-abi3.abi3t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:7730d8197086f65d8969a991d6728a1d420a51b19fea06535c896cb43a1e05d0"}, + {file = "hypothesis-6.165.10-cp315-abi3.abi3t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:7a7980a898a3e6ebe4de1896a0507e3d519edb53fb9b4bda478c9fbeb6514558"}, + {file = "hypothesis-6.165.10-cp315-abi3.abi3t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:b5820d009aedb7ae9cfd32f98b1ab0c0bbd6268379c4fab042218b6b655c63f8"}, + {file = "hypothesis-6.165.10-cp315-abi3.abi3t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:37a7ac3d34220800e1107871cc391bca1b00439875925d7d821878b8b791f245"}, + {file = "hypothesis-6.165.10-cp315-abi3.abi3t-manylinux_2_31_riscv64.whl", hash = "sha256:dafa7c9dbe3d802f9bcdf261b29c8a70700fb22839947f06e471f62c46b6257f"}, + {file = "hypothesis-6.165.10-cp315-abi3.abi3t-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:90915635b9648071129b0f72c0673cf8eac9eb84cfd445c5bedef30c714b1ec2"}, + {file = "hypothesis-6.165.10-cp315-abi3.abi3t-musllinux_1_2_aarch64.whl", hash = "sha256:e1bbeb7c506b07ee0422cf9b2f7212fefa4240957f03526d38d27bc6743a0a48"}, + {file = "hypothesis-6.165.10-cp315-abi3.abi3t-musllinux_1_2_armv7l.whl", hash = "sha256:2b36aaffc88625a44f91074c5bbedfdefb9b376c38d1b3c342edcd2e4c8ed16c"}, + {file = "hypothesis-6.165.10-cp315-abi3.abi3t-musllinux_1_2_ppc64le.whl", hash = "sha256:18a3ea838ddea183388f8788750afa8494d79abb5358823be9782585f34445d3"}, + {file = "hypothesis-6.165.10-cp315-abi3.abi3t-musllinux_1_2_riscv64.whl", hash = "sha256:2a2567b3a03a4a5a7c575c191cfcce321a967df3727803817e75bffbbeaecabe"}, + {file = "hypothesis-6.165.10-cp315-abi3.abi3t-musllinux_1_2_x86_64.whl", hash = "sha256:8001925fa3dde51cb574e4c9de4c7efe77c4e4d64bd2fd2ef61d5651f9d04f3d"}, + {file = "hypothesis-6.165.10-cp315-abi3.abi3t-win32.whl", hash = "sha256:c6559380469295c4009215fe1cab561301591a3bee2e2fb3f4f96d2273a3affc"}, + {file = "hypothesis-6.165.10-cp315-abi3.abi3t-win_amd64.whl", hash = "sha256:30797f20ca45e57f526d2df872f63ba453cb4e1091ad542184a7a951af8da79d"}, + {file = "hypothesis-6.165.10-cp315-abi3.abi3t-win_arm64.whl", hash = "sha256:c53e9b1c36350df9965ec44d6c0d4e0bbbb38f720dd2b0e1256dc6524d411015"}, + {file = "hypothesis-6.165.10-pp311-pypy311_pp73-macosx_10_12_x86_64.whl", hash = "sha256:34ee6402df6f31274d89119f1561b5f7489c97866afc5b7a3ed3a13d7e762802"}, + {file = "hypothesis-6.165.10-pp311-pypy311_pp73-macosx_11_0_arm64.whl", hash = "sha256:277f41801e88dad2eba082f91a75632b7584ff64044ba2cf9dadf511b0d19cd0"}, + {file = "hypothesis-6.165.10-pp311-pypy311_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:72df95fb1db41755b155c5f02106e0036a339250555c8d351d488704fd112cf9"}, + {file = "hypothesis-6.165.10-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6e20a02775eb3cf0ffb4f0219b6d7c1f240336663d4e5d7028675ec247c790c4"}, + {file = "hypothesis-6.165.10-pp311-pypy311_pp73-win_amd64.whl", hash = "sha256:1ec53f08732e3cfd0342cbbd75dbd1b193c8f19390660466e536a748bb81f757"}, + {file = "hypothesis-6.165.10.tar.gz", hash = "sha256:68b45e09834cd80523cb1eb274463073c7a9af4e4ef7cff34d9615f355572d32"}, ] [[package]] name = "idna" -version = "3.6" -requires_python = ">=3.5" +version = "3.18" +requires_python = ">=3.9" summary = "Internationalized Domain Names in Applications (IDNA)" -groups = ["default", "dev"] +groups = ["default"] files = [ - {file = "idna-3.6-py3-none-any.whl", hash = "sha256:c05567e9c24a6b9faaa835c4821bad0590fbb9d5779e7caa6e1cc4978e7eb24f"}, - {file = "idna-3.6.tar.gz", hash = "sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca"}, + {file = "idna-3.18-py3-none-any.whl", hash = "sha256:7f952cbe720b688055e3f87de14f5c3e5fdaa8bc3928985c4077ca689de849a2"}, + {file = "idna-3.18.tar.gz", hash = "sha256:ffb385a7e039654cef1ab9ef32c6fafe283c0c0467bba1d9029738ce4a14a848"}, ] [[package]] name = "iniconfig" -version = "2.0.0" -requires_python = ">=3.7" +version = "2.3.0" +requires_python = ">=3.10" summary = "brain-dead simple config-ini parsing" groups = ["dev"] files = [ - {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"}, - {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, + {file = "iniconfig-2.3.0-py3-none-any.whl", hash = "sha256:f631c04d2c48c52b84d0d0549c99ff3859c98df65b3101406327ecc7d53fbf12"}, + {file = "iniconfig-2.3.0.tar.gz", hash = "sha256:c76315c77db068650d49c5b56314774a7804df16fee4402c1f19d6d15d8c4730"}, ] [[package]] name = "jinja2" -version = "3.1.3" +version = "3.1.6" requires_python = ">=3.7" summary = "A very fast and expressive template engine." -groups = ["default", "dev"] +groups = ["default"] dependencies = [ "MarkupSafe>=2.0", ] files = [ - {file = "Jinja2-3.1.3-py3-none-any.whl", hash = "sha256:7d6d50dd97d52cbc355597bd845fabfbac3f551e1f99619e39a35ce8c370b5fa"}, - {file = "Jinja2-3.1.3.tar.gz", hash = "sha256:ac8bd6544d4bb2c9792bf3a159e80bba8fda7f07e81bc3aed565432d5925ba90"}, + {file = "jinja2-3.1.6-py3-none-any.whl", hash = "sha256:85ece4451f492d0c13c5dd7c13a64681a86afae63a5f347908daf103ce6d2f67"}, + {file = "jinja2-3.1.6.tar.gz", hash = "sha256:0137fb05990d35f1275a587e9aee6d56da821fc83491a0fb838183be43f66d6d"}, +] + +[[package]] +name = "librt" +version = "0.11.0" +requires_python = ">=3.9" +summary = "Mypyc runtime library" +groups = ["dev"] +marker = "platform_python_implementation != \"PyPy\"" +files = [ + {file = "librt-0.11.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:93d95bd45b7d58343d8b90d904450a545144eec19a002511163426f8ab1fae29"}, + {file = "librt-0.11.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:4ee278c769a713638cdacd4c0436d72156e75df3ebc0166ab2b9dc43acc386c9"}, + {file = "librt-0.11.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:f230cb1cbc9faaa616f9a678f530ebcf186e414b6bcbd88b960e4ba1b92428d5"}, + {file = "librt-0.11.0-cp311-cp311-manylinux2014_i686.manylinux_2_17_i686.manylinux_2_28_i686.whl", hash = "sha256:5d63c855d86938d9de93e265c9bd8c705b51ec494de5738340ee93767a686e4b"}, + {file = "librt-0.11.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:993f028be9e96a08d31df3479ac80d99be374d17f3b78e4796b3fd3c913d4e89"}, + {file = "librt-0.11.0-cp311-cp311-manylinux_2_34_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:258d73a0aa66a055e65b2e4d1b8cdb23b9d132c5bb915d9547d804fcaed116cc"}, + {file = "librt-0.11.0-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:0827efe7854718f04aaddf6496e96960a956e676fe1d0f04eb41511fd8ad06d5"}, + {file = "librt-0.11.0-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:7753e57d6e12d019c0d8786f1c09c709f4c3fcc57c3887b24e36e6c06ec938b7"}, + {file = "librt-0.11.0-cp311-cp311-musllinux_1_2_riscv64.whl", hash = "sha256:11bd19822431cc21af9f27374e7ae2e58103c7d98bda823536a6c47f6bb2bb3d"}, + {file = "librt-0.11.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:22bdf239b219d3993761a148ffa134b19e52e9989c84f845d5d7b71d70a17412"}, + {file = "librt-0.11.0-cp311-cp311-win32.whl", hash = "sha256:46c60b61e308eb535fbd6fa622b1ee1bb2815691c1ad9c98bf7b84952ec3bc8d"}, + {file = "librt-0.11.0-cp311-cp311-win_amd64.whl", hash = "sha256:902e546ff044f579ff1c953ff5fce97b636fe9e3943996b2177710c6ef076f73"}, + {file = "librt-0.11.0-cp311-cp311-win_arm64.whl", hash = "sha256:65ac3bc20f78aa0ee5ae84baa68917f89fef4af63e941084dd019a0d0e749f0c"}, + {file = "librt-0.11.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:b87504f1690a23b9a2cca841191a04f83895d4fc2dd04df91d82b1a04ca2ad46"}, + {file = "librt-0.11.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40071fc5fe0ce8daa6de616702314a01e1250711682b0523d6ab8d4525910cb3"}, + {file = "librt-0.11.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:137e79445c896a0ea7b265f52d23954e05b64222ee1af69e2cb34219067cbb67"}, + {file = "librt-0.11.0-cp312-cp312-manylinux2014_i686.manylinux_2_17_i686.manylinux_2_28_i686.whl", hash = "sha256:cca6644054e78746d8d4ef238681f9c34ff8b584fe6b988ecebb8db3b15e622a"}, + {file = "librt-0.11.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:d5b0eea49f5562861ee8d757a32ef7d559c1d35be2aaaa1ec28941d74c9ffc8a"}, + {file = "librt-0.11.0-cp312-cp312-manylinux_2_34_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:0d1029d7e1ae1a7e647ed6fb5df8c4ce2dffefb7a9f5fd1376a4554d96dac09f"}, + {file = "librt-0.11.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:bc3ce6b33c5828d9e80592011a5c584cb2ce86edbc4088405f70da47dc1d1b3b"}, + {file = "librt-0.11.0-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:936c5995f3514a42111f20099397d8177c79b4d7e70961e396c6f5a0a3566766"}, + {file = "librt-0.11.0-cp312-cp312-musllinux_1_2_riscv64.whl", hash = "sha256:9bc0ca6ad9381cbe8e4aa6e5726e4c80c78115a6e9723c599ed1d73e092bc49d"}, + {file = "librt-0.11.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:070aa8c26c0a74774317a72df8851facc7f0f012a5b406557ac56992d92e1ec8"}, + {file = "librt-0.11.0-cp312-cp312-win32.whl", hash = "sha256:6bf14feb84b05ae945277395451998c89c54d0def4070eb5c08de544930b245a"}, + {file = "librt-0.11.0-cp312-cp312-win_amd64.whl", hash = "sha256:75672f0bc524ede266287d532d7923dbce94c7514ad07627bac3d0c6d92cc4d9"}, + {file = "librt-0.11.0-cp312-cp312-win_arm64.whl", hash = "sha256:2f10cf143e4a9bb0f4f5af568a00df94a2d69ef41c2579584454bb0fe5cc642c"}, + {file = "librt-0.11.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:78dc31f7fdfe9c9d0eb0e8f42d139db230e826415bbcabd9f0e9faaaee909894"}, + {file = "librt-0.11.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:fa475675db22290c3158e1d42326d0f5a65f04f44a0e68c3630a25b53560fb9c"}, + {file = "librt-0.11.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:621db29691044bdeda22e789e482e1b0f3a985d90e3426c9c6d17606416205ea"}, + {file = "librt-0.11.0-cp313-cp313-manylinux2014_i686.manylinux_2_17_i686.manylinux_2_28_i686.whl", hash = "sha256:a9010e2ed5b3a9e158c5fd966b3ab7e834bb3d3aacc8f66c91dd4b57a3799230"}, + {file = "librt-0.11.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:7c39513d8b7477a2e1ed8c43fc21c524e8d5a0f8d4e8b7b074dbdbe7820a08e2"}, + {file = "librt-0.11.0-cp313-cp313-manylinux_2_34_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:7aef3cf1d5af86e770ab04bfd993dfc4ae8b8c17f66fb77dd4a7d50de7bbb1a3"}, + {file = "librt-0.11.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:557183ddc36babe46b27dd60facbd5adb4492181a5be887587d57cda6e092f21"}, + {file = "librt-0.11.0-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:83d3e1f72bd42f6c5c0b7daec530c3f829bd02db42c70b8ddf0c2d90a2459930"}, + {file = "librt-0.11.0-cp313-cp313-musllinux_1_2_riscv64.whl", hash = "sha256:4ce1f21fbe589bc1afd7872dece84fb0e1144f794a288e58a10d2c54a55c43be"}, + {file = "librt-0.11.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:970b09f7044ea2b64c9da42fd3d335666518cfd1c6e8a182c95da73d0214b41e"}, + {file = "librt-0.11.0-cp313-cp313-win32.whl", hash = "sha256:78fddc31cd4d3caa897ad5d31f856b1faadc9474021ad6cb182b9018793e254e"}, + {file = "librt-0.11.0-cp313-cp313-win_amd64.whl", hash = "sha256:8ca8aa88751a775870b764e93bad5135385f563cb8dcee399abf034ea4d3cb47"}, + {file = "librt-0.11.0-cp313-cp313-win_arm64.whl", hash = "sha256:96f044bb325fd9cf1a723015638c219e9143f0dfbc0ca54c565df2b7fc748b44"}, + {file = "librt-0.11.0-cp314-cp314-macosx_10_13_x86_64.whl", hash = "sha256:4a017a95e5837dc15a8c5661d60e05daa96b90908b1aa6b7acdf443cd25c8ebd"}, + {file = "librt-0.11.0-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:b1ecbd9819deccc39b7542bf4d2a740d8a620694d39989e58661d3763458f8d4"}, + {file = "librt-0.11.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:7da327dacd7be8f8ec36547373550744a3cc0e536d54665cd83f8bcd961200e8"}, + {file = "librt-0.11.0-cp314-cp314-manylinux2014_i686.manylinux_2_17_i686.manylinux_2_28_i686.whl", hash = "sha256:0dc56b1f8d06e60db362cc3fdae206681817f86ce4725d34511473487f12a34b"}, + {file = "librt-0.11.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:05fb8fb2ab90e21c8d12ea240d744ad514da9baf381ebfa70d91d20d21713175"}, + {file = "librt-0.11.0-cp314-cp314-manylinux_2_34_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:cae74872be221df4374d10fec61f93ed1513b9546ea84f2c0bf73ab3e9bd0b03"}, + {file = "librt-0.11.0-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:32bcc918c0148eb7e3d57385125bac7e5f9e4359d05f07448b09f6f778c2f31c"}, + {file = "librt-0.11.0-cp314-cp314-musllinux_1_2_i686.whl", hash = "sha256:f9743fc99135d5f78d2454435615f6dec0473ca507c26ce9d92b10b562a280d3"}, + {file = "librt-0.11.0-cp314-cp314-musllinux_1_2_riscv64.whl", hash = "sha256:5ba067f4aadae8fda802d91d2124c90c42195ff32d9161d3549e6d05cfe26f96"}, + {file = "librt-0.11.0-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:de3bf945454d032f9e390b85c4072e0a0570bf825421c8be0e71209fa65e1abe"}, + {file = "librt-0.11.0-cp314-cp314-win32.whl", hash = "sha256:d2277a05f6dcb9fd13db9566aac4fabd68c3ea1ea46ee5567d4eef8efa495a2f"}, + {file = "librt-0.11.0-cp314-cp314-win_amd64.whl", hash = "sha256:ab73e8db5e3f564d812c1f5c3a175930a5f9bc96ccb5e3b22a34d7858b401cf7"}, + {file = "librt-0.11.0-cp314-cp314-win_arm64.whl", hash = "sha256:aea3caa317752e3a466fa8af45d91ee0ea8c7fdd96e42b0a8dd9b76a7931eba1"}, + {file = "librt-0.11.0-cp314-cp314t-macosx_10_13_x86_64.whl", hash = "sha256:d1b36540d7aaf9b9101b3a6f376c8d8e9f7a9aec93ed05918f2c69d493ffef72"}, + {file = "librt-0.11.0-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:efbb343ab2ce3540f4ecbe6315d677ed70f37cd9a72b1e58066c918ca83acbaa"}, + {file = "librt-0.11.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:aa0dd688aab3f7914d3e6e5e3554978e0383312fb8e771d84be008a35b9ee548"}, + {file = "librt-0.11.0-cp314-cp314t-manylinux2014_i686.manylinux_2_17_i686.manylinux_2_28_i686.whl", hash = "sha256:f5fb36b8c6c63fdcbb1d526d94c0d1331610d43f4118cc1beb4efef4f3faacb2"}, + {file = "librt-0.11.0-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:4a9a237d13addb93715b6fee74023d5ee3469b53fce527626c0e088aa585805f"}, + {file = "librt-0.11.0-cp314-cp314t-manylinux_2_34_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:5ddd17bd87b2c56ddd60e546a7984a2e64c4e8eab92fb4cf3830a48ad5469d51"}, + {file = "librt-0.11.0-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:bd43992b4473d42f12ff9e68326079f0696d9d4e6000e8f39a0238d482ba6ee2"}, + {file = "librt-0.11.0-cp314-cp314t-musllinux_1_2_i686.whl", hash = "sha256:f8e3e8056dd674e279741485e2e512d6e9a751c7455809d0114e6ebf8d781085"}, + {file = "librt-0.11.0-cp314-cp314t-musllinux_1_2_riscv64.whl", hash = "sha256:c1f708d8ae9c56cf38a903c44297243d2ec83fd82b396b977e0144a3e76217e3"}, + {file = "librt-0.11.0-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:0add982e0e7b9fc14cf4b33789d5f13f66581889b88c2f58099f6ce8f92617bd"}, + {file = "librt-0.11.0-cp314-cp314t-win32.whl", hash = "sha256:2b481d846ac894c4e8403c5fd0e87c5d11d6499e404b474602508a224ff531c8"}, + {file = "librt-0.11.0-cp314-cp314t-win_amd64.whl", hash = "sha256:28edb433edde181112a908c78907af28f964eabc15f4dd16c9d66c834302677c"}, + {file = "librt-0.11.0-cp314-cp314t-win_arm64.whl", hash = "sha256:dee008f20b542e3cd162ba338a7f9ec0f6d23d395f66fe8aeeec3c9d067ea253"}, + {file = "librt-0.11.0.tar.gz", hash = "sha256:075dc3ef4458a278e0195cbf6ac9d38808d9b906c5a6c7f7f79c3888276a3fb1"}, ] [[package]] name = "markdown-it-py" -version = "3.0.0" -requires_python = ">=3.8" +version = "4.2.0" +requires_python = ">=3.10" summary = "Python port of markdown-it. Markdown parsing, done right!" -groups = ["default", "dev"] +groups = ["default"] dependencies = [ "mdurl~=0.1", ] files = [ - {file = "markdown-it-py-3.0.0.tar.gz", hash = "sha256:e3f60a94fa066dc52ec76661e37c851cb232d92f9886b15cb560aaada2df8feb"}, - {file = "markdown_it_py-3.0.0-py3-none-any.whl", hash = "sha256:355216845c60bd96232cd8d8c40e8f9765cc86f46880e43a8fd22dc1a1a8cab1"}, + {file = "markdown_it_py-4.2.0-py3-none-any.whl", hash = "sha256:9f7ebbcd14fe59494226453aed97c1070d83f8d24b6fc3a3bcf9a38092641c4a"}, + {file = "markdown_it_py-4.2.0.tar.gz", hash = "sha256:04a21681d6fbb623de53f6f364d352309d4094dd4194040a10fd51833e418d49"}, ] [[package]] name = "markupsafe" -version = "2.1.3" -requires_python = ">=3.7" +version = "3.0.3" +requires_python = ">=3.9" summary = "Safely add untrusted strings to HTML/XML markup." -groups = ["default", "dev"] -files = [ - {file = "MarkupSafe-2.1.3-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:cd0f502fe016460680cd20aaa5a76d241d6f35a1c3350c474bac1273803893fa"}, - {file = "MarkupSafe-2.1.3-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:e09031c87a1e51556fdcb46e5bd4f59dfb743061cf93c4d6831bf894f125eb57"}, - {file = "MarkupSafe-2.1.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:68e78619a61ecf91e76aa3e6e8e33fc4894a2bebe93410754bd28fce0a8a4f9f"}, - {file = "MarkupSafe-2.1.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:65c1a9bcdadc6c28eecee2c119465aebff8f7a584dd719facdd9e825ec61ab52"}, - {file = "MarkupSafe-2.1.3-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:525808b8019e36eb524b8c68acdd63a37e75714eac50e988180b169d64480a00"}, - {file = "MarkupSafe-2.1.3-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:962f82a3086483f5e5f64dbad880d31038b698494799b097bc59c2edf392fce6"}, - {file = "MarkupSafe-2.1.3-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:aa7bd130efab1c280bed0f45501b7c8795f9fdbeb02e965371bbef3523627779"}, - {file = "MarkupSafe-2.1.3-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:c9c804664ebe8f83a211cace637506669e7890fec1b4195b505c214e50dd4eb7"}, - {file = "MarkupSafe-2.1.3-cp310-cp310-win32.whl", hash = "sha256:10bbfe99883db80bdbaff2dcf681dfc6533a614f700da1287707e8a5d78a8431"}, - {file = "MarkupSafe-2.1.3-cp310-cp310-win_amd64.whl", hash = "sha256:1577735524cdad32f9f694208aa75e422adba74f1baee7551620e43a3141f559"}, - {file = "MarkupSafe-2.1.3-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:ad9e82fb8f09ade1c3e1b996a6337afac2b8b9e365f926f5a61aacc71adc5b3c"}, - {file = "MarkupSafe-2.1.3-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:3c0fae6c3be832a0a0473ac912810b2877c8cb9d76ca48de1ed31e1c68386575"}, - {file = "MarkupSafe-2.1.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b076b6226fb84157e3f7c971a47ff3a679d837cf338547532ab866c57930dbee"}, - {file = "MarkupSafe-2.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bfce63a9e7834b12b87c64d6b155fdd9b3b96191b6bd334bf37db7ff1fe457f2"}, - {file = "MarkupSafe-2.1.3-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:338ae27d6b8745585f87218a3f23f1512dbf52c26c28e322dbe54bcede54ccb9"}, - {file = "MarkupSafe-2.1.3-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:e4dd52d80b8c83fdce44e12478ad2e85c64ea965e75d66dbeafb0a3e77308fcc"}, - {file = "MarkupSafe-2.1.3-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:df0be2b576a7abbf737b1575f048c23fb1d769f267ec4358296f31c2479db8f9"}, - {file = "MarkupSafe-2.1.3-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:5bbe06f8eeafd38e5d0a4894ffec89378b6c6a625ff57e3028921f8ff59318ac"}, - {file = "MarkupSafe-2.1.3-cp311-cp311-win32.whl", hash = "sha256:dd15ff04ffd7e05ffcb7fe79f1b98041b8ea30ae9234aed2a9168b5797c3effb"}, - {file = "MarkupSafe-2.1.3-cp311-cp311-win_amd64.whl", hash = "sha256:134da1eca9ec0ae528110ccc9e48041e0828d79f24121a1a146161103c76e686"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:f698de3fd0c4e6972b92290a45bd9b1536bffe8c6759c62471efaa8acb4c37bc"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:aa57bd9cf8ae831a362185ee444e15a93ecb2e344c8e52e4d721ea3ab6ef1823"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ffcc3f7c66b5f5b7931a5aa68fc9cecc51e685ef90282f4a82f0f5e9b704ad11"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:47d4f1c5f80fc62fdd7777d0d40a2e9dda0a05883ab11374334f6c4de38adffd"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1f67c7038d560d92149c060157d623c542173016c4babc0c1913cca0564b9939"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:9aad3c1755095ce347e26488214ef77e0485a3c34a50c5a5e2471dff60b9dd9c"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:14ff806850827afd6b07a5f32bd917fb7f45b046ba40c57abdb636674a8b559c"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8f9293864fe09b8149f0cc42ce56e3f0e54de883a9de90cd427f191c346eb2e1"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-win32.whl", hash = "sha256:715d3562f79d540f251b99ebd6d8baa547118974341db04f5ad06d5ea3eb8007"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-win_amd64.whl", hash = "sha256:1b8dd8c3fd14349433c79fa8abeb573a55fc0fdd769133baac1f5e07abf54aeb"}, - {file = "MarkupSafe-2.1.3-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:2ef12179d3a291be237280175b542c07a36e7f60718296278d8593d21ca937d4"}, - {file = "MarkupSafe-2.1.3-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:2c1b19b3aaacc6e57b7e25710ff571c24d6c3613a45e905b1fde04d691b98ee0"}, - {file = "MarkupSafe-2.1.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8afafd99945ead6e075b973fefa56379c5b5c53fd8937dad92c662da5d8fd5ee"}, - {file = "MarkupSafe-2.1.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8c41976a29d078bb235fea9b2ecd3da465df42a562910f9022f1a03107bd02be"}, - {file = "MarkupSafe-2.1.3-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d080e0a5eb2529460b30190fcfcc4199bd7f827663f858a226a81bc27beaa97e"}, - {file = "MarkupSafe-2.1.3-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:69c0f17e9f5a7afdf2cc9fb2d1ce6aabdb3bafb7f38017c0b77862bcec2bbad8"}, - {file = "MarkupSafe-2.1.3-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:504b320cd4b7eff6f968eddf81127112db685e81f7e36e75f9f84f0df46041c3"}, - {file = "MarkupSafe-2.1.3-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:42de32b22b6b804f42c5d98be4f7e5e977ecdd9ee9b660fda1a3edf03b11792d"}, - {file = "MarkupSafe-2.1.3-cp38-cp38-win32.whl", hash = "sha256:ceb01949af7121f9fc39f7d27f91be8546f3fb112c608bc4029aef0bab86a2a5"}, - {file = "MarkupSafe-2.1.3-cp38-cp38-win_amd64.whl", hash = "sha256:1b40069d487e7edb2676d3fbdb2b0829ffa2cd63a2ec26c4938b2d34391b4ecc"}, - {file = "MarkupSafe-2.1.3-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:8023faf4e01efadfa183e863fefde0046de576c6f14659e8782065bcece22198"}, - {file = "MarkupSafe-2.1.3-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:6b2b56950d93e41f33b4223ead100ea0fe11f8e6ee5f641eb753ce4b77a7042b"}, - {file = "MarkupSafe-2.1.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9dcdfd0eaf283af041973bff14a2e143b8bd64e069f4c383416ecd79a81aab58"}, - {file = "MarkupSafe-2.1.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:05fb21170423db021895e1ea1e1f3ab3adb85d1c2333cbc2310f2a26bc77272e"}, - {file = "MarkupSafe-2.1.3-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:282c2cb35b5b673bbcadb33a585408104df04f14b2d9b01d4c345a3b92861c2c"}, - {file = "MarkupSafe-2.1.3-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:ab4a0df41e7c16a1392727727e7998a467472d0ad65f3ad5e6e765015df08636"}, - {file = "MarkupSafe-2.1.3-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:7ef3cb2ebbf91e330e3bb937efada0edd9003683db6b57bb108c4001f37a02ea"}, - {file = "MarkupSafe-2.1.3-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:0a4e4a1aff6c7ac4cd55792abf96c915634c2b97e3cc1c7129578aa68ebd754e"}, - {file = "MarkupSafe-2.1.3-cp39-cp39-win32.whl", hash = "sha256:fec21693218efe39aa7f8599346e90c705afa52c5b31ae019b2e57e8f6542bb2"}, - {file = "MarkupSafe-2.1.3-cp39-cp39-win_amd64.whl", hash = "sha256:3fd4abcb888d15a94f32b75d8fd18ee162ca0c064f35b11134be77050296d6ba"}, - {file = "MarkupSafe-2.1.3.tar.gz", hash = "sha256:af598ed32d6ae86f1b747b82783958b1a4ab8f617b06fe68795c7f026abbdcad"}, -] - -[[package]] -name = "marshmallow" -version = "3.21.1" -requires_python = ">=3.8" -summary = "A lightweight library for converting complex datatypes to and from native Python datatypes." -groups = ["dev"] -dependencies = [ - "packaging>=17.0", -] +groups = ["default"] files = [ - {file = "marshmallow-3.21.1-py3-none-any.whl", hash = "sha256:f085493f79efb0644f270a9bf2892843142d80d7174bbbd2f3713f2a589dc633"}, - {file = "marshmallow-3.21.1.tar.gz", hash = "sha256:4e65e9e0d80fc9e609574b9983cf32579f305c718afb30d7233ab818571768c3"}, + {file = "markupsafe-3.0.3-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:1cc7ea17a6824959616c525620e387f6dd30fec8cb44f649e31712db02123dad"}, + {file = "markupsafe-3.0.3-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:4bd4cd07944443f5a265608cc6aab442e4f74dff8088b0dfc8238647b8f6ae9a"}, + {file = "markupsafe-3.0.3-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:6b5420a1d9450023228968e7e6a9ce57f65d148ab56d2313fcd589eee96a7a50"}, + {file = "markupsafe-3.0.3-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:0bf2a864d67e76e5c9a34dc26ec616a66b9888e25e7b9460e1c76d3293bd9dbf"}, + {file = "markupsafe-3.0.3-cp311-cp311-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:bc51efed119bc9cfdf792cdeaa4d67e8f6fcccab66ed4bfdd6bde3e59bfcbb2f"}, + {file = "markupsafe-3.0.3-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:068f375c472b3e7acbe2d5318dea141359e6900156b5b2ba06a30b169086b91a"}, + {file = "markupsafe-3.0.3-cp311-cp311-musllinux_1_2_riscv64.whl", hash = "sha256:7be7b61bb172e1ed687f1754f8e7484f1c8019780f6f6b0786e76bb01c2ae115"}, + {file = "markupsafe-3.0.3-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:f9e130248f4462aaa8e2552d547f36ddadbeaa573879158d721bbd33dfe4743a"}, + {file = "markupsafe-3.0.3-cp311-cp311-win32.whl", hash = "sha256:0db14f5dafddbb6d9208827849fad01f1a2609380add406671a26386cdf15a19"}, + {file = "markupsafe-3.0.3-cp311-cp311-win_amd64.whl", hash = "sha256:de8a88e63464af587c950061a5e6a67d3632e36df62b986892331d4620a35c01"}, + {file = "markupsafe-3.0.3-cp311-cp311-win_arm64.whl", hash = "sha256:3b562dd9e9ea93f13d53989d23a7e775fdfd1066c33494ff43f5418bc8c58a5c"}, + {file = "markupsafe-3.0.3-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:d53197da72cc091b024dd97249dfc7794d6a56530370992a5e1a08983ad9230e"}, + {file = "markupsafe-3.0.3-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:1872df69a4de6aead3491198eaf13810b565bdbeec3ae2dc8780f14458ec73ce"}, + {file = "markupsafe-3.0.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:3a7e8ae81ae39e62a41ec302f972ba6ae23a5c5396c8e60113e9066ef893da0d"}, + {file = "markupsafe-3.0.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:d6dd0be5b5b189d31db7cda48b91d7e0a9795f31430b7f271219ab30f1d3ac9d"}, + {file = "markupsafe-3.0.3-cp312-cp312-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:94c6f0bb423f739146aec64595853541634bde58b2135f27f61c1ffd1cd4d16a"}, + {file = "markupsafe-3.0.3-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:be8813b57049a7dc738189df53d69395eba14fb99345e0a5994914a3864c8a4b"}, + {file = "markupsafe-3.0.3-cp312-cp312-musllinux_1_2_riscv64.whl", hash = "sha256:83891d0e9fb81a825d9a6d61e3f07550ca70a076484292a70fde82c4b807286f"}, + {file = "markupsafe-3.0.3-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:77f0643abe7495da77fb436f50f8dab76dbc6e5fd25d39589a0f1fe6548bfa2b"}, + {file = "markupsafe-3.0.3-cp312-cp312-win32.whl", hash = "sha256:d88b440e37a16e651bda4c7c2b930eb586fd15ca7406cb39e211fcff3bf3017d"}, + {file = "markupsafe-3.0.3-cp312-cp312-win_amd64.whl", hash = "sha256:26a5784ded40c9e318cfc2bdb30fe164bdb8665ded9cd64d500a34fb42067b1c"}, + {file = "markupsafe-3.0.3-cp312-cp312-win_arm64.whl", hash = "sha256:35add3b638a5d900e807944a078b51922212fb3dedb01633a8defc4b01a3c85f"}, + {file = "markupsafe-3.0.3-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:e1cf1972137e83c5d4c136c43ced9ac51d0e124706ee1c8aa8532c1287fa8795"}, + {file = "markupsafe-3.0.3-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:116bb52f642a37c115f517494ea5feb03889e04df47eeff5b130b1808ce7c219"}, + {file = "markupsafe-3.0.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:133a43e73a802c5562be9bbcd03d090aa5a1fe899db609c29e8c8d815c5f6de6"}, + {file = "markupsafe-3.0.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:ccfcd093f13f0f0b7fdd0f198b90053bf7b2f02a3927a30e63f3ccc9df56b676"}, + {file = "markupsafe-3.0.3-cp313-cp313-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:509fa21c6deb7a7a273d629cf5ec029bc209d1a51178615ddf718f5918992ab9"}, + {file = "markupsafe-3.0.3-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:a4afe79fb3de0b7097d81da19090f4df4f8d3a2b3adaa8764138aac2e44f3af1"}, + {file = "markupsafe-3.0.3-cp313-cp313-musllinux_1_2_riscv64.whl", hash = "sha256:795e7751525cae078558e679d646ae45574b47ed6e7771863fcc079a6171a0fc"}, + {file = "markupsafe-3.0.3-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:8485f406a96febb5140bfeca44a73e3ce5116b2501ac54fe953e488fb1d03b12"}, + {file = "markupsafe-3.0.3-cp313-cp313-win32.whl", hash = "sha256:bdd37121970bfd8be76c5fb069c7751683bdf373db1ed6c010162b2a130248ed"}, + {file = "markupsafe-3.0.3-cp313-cp313-win_amd64.whl", hash = "sha256:9a1abfdc021a164803f4d485104931fb8f8c1efd55bc6b748d2f5774e78b62c5"}, + {file = "markupsafe-3.0.3-cp313-cp313-win_arm64.whl", hash = "sha256:7e68f88e5b8799aa49c85cd116c932a1ac15caaa3f5db09087854d218359e485"}, + {file = "markupsafe-3.0.3-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:218551f6df4868a8d527e3062d0fb968682fe92054e89978594c28e642c43a73"}, + {file = "markupsafe-3.0.3-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:3524b778fe5cfb3452a09d31e7b5adefeea8c5be1d43c4f810ba09f2ceb29d37"}, + {file = "markupsafe-3.0.3-cp313-cp313t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:4e885a3d1efa2eadc93c894a21770e4bc67899e3543680313b09f139e149ab19"}, + {file = "markupsafe-3.0.3-cp313-cp313t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:8709b08f4a89aa7586de0aadc8da56180242ee0ada3999749b183aa23df95025"}, + {file = "markupsafe-3.0.3-cp313-cp313t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:b8512a91625c9b3da6f127803b166b629725e68af71f8184ae7e7d54686a56d6"}, + {file = "markupsafe-3.0.3-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:9b79b7a16f7fedff2495d684f2b59b0457c3b493778c9eed31111be64d58279f"}, + {file = "markupsafe-3.0.3-cp313-cp313t-musllinux_1_2_riscv64.whl", hash = "sha256:12c63dfb4a98206f045aa9563db46507995f7ef6d83b2f68eda65c307c6829eb"}, + {file = "markupsafe-3.0.3-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:8f71bc33915be5186016f675cd83a1e08523649b0e33efdb898db577ef5bb009"}, + {file = "markupsafe-3.0.3-cp313-cp313t-win32.whl", hash = "sha256:69c0b73548bc525c8cb9a251cddf1931d1db4d2258e9599c28c07ef3580ef354"}, + {file = "markupsafe-3.0.3-cp313-cp313t-win_amd64.whl", hash = "sha256:1b4b79e8ebf6b55351f0d91fe80f893b4743f104bff22e90697db1590e47a218"}, + {file = "markupsafe-3.0.3-cp313-cp313t-win_arm64.whl", hash = "sha256:ad2cf8aa28b8c020ab2fc8287b0f823d0a7d8630784c31e9ee5edea20f406287"}, + {file = "markupsafe-3.0.3-cp314-cp314-macosx_10_13_x86_64.whl", hash = "sha256:eaa9599de571d72e2daf60164784109f19978b327a3910d3e9de8c97b5b70cfe"}, + {file = "markupsafe-3.0.3-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:c47a551199eb8eb2121d4f0f15ae0f923d31350ab9280078d1e5f12b249e0026"}, + {file = "markupsafe-3.0.3-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:f34c41761022dd093b4b6896d4810782ffbabe30f2d443ff5f083e0cbbb8c737"}, + {file = "markupsafe-3.0.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:457a69a9577064c05a97c41f4e65148652db078a3a509039e64d3467b9e7ef97"}, + {file = "markupsafe-3.0.3-cp314-cp314-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:e8afc3f2ccfa24215f8cb28dcf43f0113ac3c37c2f0f0806d8c70e4228c5cf4d"}, + {file = "markupsafe-3.0.3-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:ec15a59cf5af7be74194f7ab02d0f59a62bdcf1a537677ce67a2537c9b87fcda"}, + {file = "markupsafe-3.0.3-cp314-cp314-musllinux_1_2_riscv64.whl", hash = "sha256:0eb9ff8191e8498cca014656ae6b8d61f39da5f95b488805da4bb029cccbfbaf"}, + {file = "markupsafe-3.0.3-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:2713baf880df847f2bece4230d4d094280f4e67b1e813eec43b4c0e144a34ffe"}, + {file = "markupsafe-3.0.3-cp314-cp314-win32.whl", hash = "sha256:729586769a26dbceff69f7a7dbbf59ab6572b99d94576a5592625d5b411576b9"}, + {file = "markupsafe-3.0.3-cp314-cp314-win_amd64.whl", hash = "sha256:bdc919ead48f234740ad807933cdf545180bfbe9342c2bb451556db2ed958581"}, + {file = "markupsafe-3.0.3-cp314-cp314-win_arm64.whl", hash = "sha256:5a7d5dc5140555cf21a6fefbdbf8723f06fcd2f63ef108f2854de715e4422cb4"}, + {file = "markupsafe-3.0.3-cp314-cp314t-macosx_10_13_x86_64.whl", hash = "sha256:1353ef0c1b138e1907ae78e2f6c63ff67501122006b0f9abad68fda5f4ffc6ab"}, + {file = "markupsafe-3.0.3-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:1085e7fbddd3be5f89cc898938f42c0b3c711fdcb37d75221de2666af647c175"}, + {file = "markupsafe-3.0.3-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:1b52b4fb9df4eb9ae465f8d0c228a00624de2334f216f178a995ccdcf82c4634"}, + {file = "markupsafe-3.0.3-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:fed51ac40f757d41b7c48425901843666a6677e3e8eb0abcff09e4ba6e664f50"}, + {file = "markupsafe-3.0.3-cp314-cp314t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:f190daf01f13c72eac4efd5c430a8de82489d9cff23c364c3ea822545032993e"}, + {file = "markupsafe-3.0.3-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:e56b7d45a839a697b5eb268c82a71bd8c7f6c94d6fd50c3d577fa39a9f1409f5"}, + {file = "markupsafe-3.0.3-cp314-cp314t-musllinux_1_2_riscv64.whl", hash = "sha256:f3e98bb3798ead92273dc0e5fd0f31ade220f59a266ffd8a4f6065e0a3ce0523"}, + {file = "markupsafe-3.0.3-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:5678211cb9333a6468fb8d8be0305520aa073f50d17f089b5b4b477ea6e67fdc"}, + {file = "markupsafe-3.0.3-cp314-cp314t-win32.whl", hash = "sha256:915c04ba3851909ce68ccc2b8e2cd691618c4dc4c4232fb7982bca3f41fd8c3d"}, + {file = "markupsafe-3.0.3-cp314-cp314t-win_amd64.whl", hash = "sha256:4faffd047e07c38848ce017e8725090413cd80cbc23d86e55c587bf979e579c9"}, + {file = "markupsafe-3.0.3-cp314-cp314t-win_arm64.whl", hash = "sha256:32001d6a8fc98c8cb5c947787c5d08b0a50663d139f1305bac5885d98d9b40fa"}, + {file = "markupsafe-3.0.3.tar.gz", hash = "sha256:722695808f4b6457b320fdc131280796bdceb04ab50fe1795cd540799ebe1698"}, ] [[package]] @@ -620,558 +641,347 @@ name = "mdurl" version = "0.1.2" requires_python = ">=3.7" summary = "Markdown URL utilities" -groups = ["default", "dev"] +groups = ["default"] files = [ {file = "mdurl-0.1.2-py3-none-any.whl", hash = "sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8"}, {file = "mdurl-0.1.2.tar.gz", hash = "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba"}, ] -[[package]] -name = "mslex" -version = "1.1.0" -requires_python = ">=3.5" -summary = "shlex for windows" -groups = ["dev"] -marker = "sys_platform == \"win32\"" -files = [ - {file = "mslex-1.1.0-py2.py3-none-any.whl", hash = "sha256:8826f4bb8d8c63402203d921dc8c2df0c7fec0d9c91d020ddf02fc9d0dce81bd"}, - {file = "mslex-1.1.0.tar.gz", hash = "sha256:7fe305fbdc9721283875e0b737fdb344374b761338a7f41af91875de278568e4"}, -] - [[package]] name = "mypy" -version = "1.9.0" -requires_python = ">=3.8" +version = "2.1.0" +requires_python = ">=3.10" summary = "Optional static typing for Python" groups = ["dev"] dependencies = [ + "ast-serialize<1.0.0,>=0.3.0", + "librt>=0.11.0; platform_python_implementation != \"PyPy\"", "mypy-extensions>=1.0.0", + "pathspec>=1.0.0", "tomli>=1.1.0; python_version < \"3.11\"", - "typing-extensions>=4.1.0", + "typing-extensions>=4.14.0; python_version >= \"3.15\"", + "typing-extensions>=4.6.0; python_version < \"3.15\"", ] files = [ - {file = "mypy-1.9.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:f8a67616990062232ee4c3952f41c779afac41405806042a8126fe96e098419f"}, - {file = "mypy-1.9.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:d357423fa57a489e8c47b7c85dfb96698caba13d66e086b412298a1a0ea3b0ed"}, - {file = "mypy-1.9.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:49c87c15aed320de9b438ae7b00c1ac91cd393c1b854c2ce538e2a72d55df150"}, - {file = "mypy-1.9.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:48533cdd345c3c2e5ef48ba3b0d3880b257b423e7995dada04248725c6f77374"}, - {file = "mypy-1.9.0-cp310-cp310-win_amd64.whl", hash = "sha256:4d3dbd346cfec7cb98e6cbb6e0f3c23618af826316188d587d1c1bc34f0ede03"}, - {file = "mypy-1.9.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:653265f9a2784db65bfca694d1edd23093ce49740b2244cde583aeb134c008f3"}, - {file = "mypy-1.9.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:3a3c007ff3ee90f69cf0a15cbcdf0995749569b86b6d2f327af01fd1b8aee9dc"}, - {file = "mypy-1.9.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2418488264eb41f69cc64a69a745fad4a8f86649af4b1041a4c64ee61fc61129"}, - {file = "mypy-1.9.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:68edad3dc7d70f2f17ae4c6c1b9471a56138ca22722487eebacfd1eb5321d612"}, - {file = "mypy-1.9.0-cp311-cp311-win_amd64.whl", hash = "sha256:85ca5fcc24f0b4aeedc1d02f93707bccc04733f21d41c88334c5482219b1ccb3"}, - {file = "mypy-1.9.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:aceb1db093b04db5cd390821464504111b8ec3e351eb85afd1433490163d60cd"}, - {file = "mypy-1.9.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:0235391f1c6f6ce487b23b9dbd1327b4ec33bb93934aa986efe8a9563d9349e6"}, - {file = "mypy-1.9.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d4d5ddc13421ba3e2e082a6c2d74c2ddb3979c39b582dacd53dd5d9431237185"}, - {file = "mypy-1.9.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:190da1ee69b427d7efa8aa0d5e5ccd67a4fb04038c380237a0d96829cb157913"}, - {file = "mypy-1.9.0-cp312-cp312-win_amd64.whl", hash = "sha256:fe28657de3bfec596bbeef01cb219833ad9d38dd5393fc649f4b366840baefe6"}, - {file = "mypy-1.9.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:e54396d70be04b34f31d2edf3362c1edd023246c82f1730bbf8768c28db5361b"}, - {file = "mypy-1.9.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:5e6061f44f2313b94f920e91b204ec600982961e07a17e0f6cd83371cb23f5c2"}, - {file = "mypy-1.9.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:81a10926e5473c5fc3da8abb04119a1f5811a236dc3a38d92015cb1e6ba4cb9e"}, - {file = "mypy-1.9.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:b685154e22e4e9199fc95f298661deea28aaede5ae16ccc8cbb1045e716b3e04"}, - {file = "mypy-1.9.0-cp38-cp38-win_amd64.whl", hash = "sha256:5d741d3fc7c4da608764073089e5f58ef6352bedc223ff58f2f038c2c4698a89"}, - {file = "mypy-1.9.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:587ce887f75dd9700252a3abbc9c97bbe165a4a630597845c61279cf32dfbf02"}, - {file = "mypy-1.9.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:f88566144752999351725ac623471661c9d1cd8caa0134ff98cceeea181789f4"}, - {file = "mypy-1.9.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:61758fabd58ce4b0720ae1e2fea5cfd4431591d6d590b197775329264f86311d"}, - {file = "mypy-1.9.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:e49499be624dead83927e70c756970a0bc8240e9f769389cdf5714b0784ca6bf"}, - {file = "mypy-1.9.0-cp39-cp39-win_amd64.whl", hash = "sha256:571741dc4194b4f82d344b15e8837e8c5fcc462d66d076748142327626a1b6e9"}, - {file = "mypy-1.9.0-py3-none-any.whl", hash = "sha256:a260627a570559181a9ea5de61ac6297aa5af202f06fd7ab093ce74e7181e43e"}, - {file = "mypy-1.9.0.tar.gz", hash = "sha256:3cc5da0127e6a478cddd906068496a97a7618a21ce9b54bde5bf7e539c7af974"}, + {file = "mypy-2.1.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:a683016b16fe2f572dc04c72be7ee0504ac1605a265d0200f5cea695fb788f41"}, + {file = "mypy-2.1.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:1a293c534adb55271fef24a26da04b855540a8c13cc07bc5917b9fd2c394f2ca"}, + {file = "mypy-2.1.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:7406f4d048e71e576f5356d317e5b0a9e666dfd966bd99f9d14ca06e1a341538"}, + {file = "mypy-2.1.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:e0210d626fc8b31ccc90233754c7bc90e1f43205e85d96387f7db1285b55c398"}, + {file = "mypy-2.1.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:3712c20deed54e814eaaa825603bada8ea1c390670a397c95b98405347acc563"}, + {file = "mypy-2.1.0-cp311-cp311-win_amd64.whl", hash = "sha256:fcaa0e479066e31f7cceb6a3bea39cb22b2ff51a6b2f24f193d19179ba17c389"}, + {file = "mypy-2.1.0-cp311-cp311-win_arm64.whl", hash = "sha256:0b1a5260c95aa443083f9ed3592662941951bca3d4ca224a5dc517c38b7cf666"}, + {file = "mypy-2.1.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:244358bf1c0da7722230bce60683d52e8e9fd030554926f15b747a84efb5b3af"}, + {file = "mypy-2.1.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:4ec7c57657493c7a75534df2751c8ae2cda383c16ecc55d2106c54476b1b16f6"}, + {file = "mypy-2.1.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:d8161b6ff4392410023224f0969d17db93e1e154bc3e4ba62598e720723ae211"}, + {file = "mypy-2.1.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:bf03e12003084a67395184d3eb8cbd6a489dc3655b5664b28c210a9e2403ab0b"}, + {file = "mypy-2.1.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:20509760fd791c51579d573153407d226385ec1f8bcce55d730b354f3336bc22"}, + {file = "mypy-2.1.0-cp312-cp312-win_amd64.whl", hash = "sha256:6753d0c1fdd6b1a23b9e4f283ce80b2153b724adcb2653b20b85a8a28ac6436b"}, + {file = "mypy-2.1.0-cp312-cp312-win_arm64.whl", hash = "sha256:98ebb6589bb3b6d0c6f0c459d53ca55b8091fbc13d277c4041c885392e8195e8"}, + {file = "mypy-2.1.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:35aac3bb114e03888f535d5eb51b8bafbb3266586b599da1940f9b1be3ec5bd5"}, + {file = "mypy-2.1.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:8de55a8c861f2a49331f807be98d90caeceeef520bde13d43a160207f8af613e"}, + {file = "mypy-2.1.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:5fdf2941a07434af755837d9880f7d7d25f1dacb1af9dcd4b9b66f2220a3024e"}, + {file = "mypy-2.1.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:e195b817c13f02352a9c124301f9f30f078405444679b6753c1b96b6eed37285"}, + {file = "mypy-2.1.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:5431d42af987ebd92ba2f71d45c85ed41d8e6ca9f5fd209a69f68f707d2469e5"}, + {file = "mypy-2.1.0-cp313-cp313-win_amd64.whl", hash = "sha256:767fe8c66dc3e01e19e1737d4c38ebefead16125e1b8e58ad421903b376f5c65"}, + {file = "mypy-2.1.0-cp313-cp313-win_arm64.whl", hash = "sha256:ecfe70d43775ab99562ab128ce49854a362044c9f894961f68f898c23cb7429d"}, + {file = "mypy-2.1.0-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:7354c5a7f69d9345c3d6e69921d57088eea3ddeeb6b20d34c1b3855b02c36ec2"}, + {file = "mypy-2.1.0-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:49890d4f76ac9e06ec117f9e09f3174da70a620a0c300953d8595c926e80947f"}, + {file = "mypy-2.1.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:761be68e023ef5d94678772396a8af1220030f80837a3afd8d0aef3b419666f4"}, + {file = "mypy-2.1.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:c90345fc182dc363b891350457ec69c35140858538f38b4540845afcc32b1aef"}, + {file = "mypy-2.1.0-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:b84802e7b5a6daf1f5e15bc9fcd7ddae77be13981ffab037f1c67bb84d67d135"}, + {file = "mypy-2.1.0-cp314-cp314-win_amd64.whl", hash = "sha256:022c771234936ceac541ebaf836fe9e2abeb3f5e09aff21588fe543ff006fe21"}, + {file = "mypy-2.1.0-cp314-cp314-win_arm64.whl", hash = "sha256:498207db725cec88829a6a5c2fc771205fd043719ef98bc49aba8fb9fc4e6d57"}, + {file = "mypy-2.1.0-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:7d5e5cad0efeba72b93cd17490cc0d69c5ac9ca132994fe3fb0314808aeeb83e"}, + {file = "mypy-2.1.0-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:ff715050c127d724fd260a2e666e7747fdd83511c0c47d449d98238970aef780"}, + {file = "mypy-2.1.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:82208da9e09414d520e912d3e462d454854bed0810b71540bb016dcbca7308fd"}, + {file = "mypy-2.1.0-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:e79ebc1b904b84f0310dff7469655a9c36c7a68bddb37bdd42b67a332df61d08"}, + {file = "mypy-2.1.0-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:e583edc957cfb0deb142079162ae826f58449b116c1d442f2d91c69d9fced081"}, + {file = "mypy-2.1.0-cp314-cp314t-win_amd64.whl", hash = "sha256:b33b6cd332695bba180d55e717a79d3038e479a2c49cc5eb3d53603409b9a5d7"}, + {file = "mypy-2.1.0-cp314-cp314t-win_arm64.whl", hash = "sha256:4f910fe825376a7b66ef7ca8c98e5a149e8cd64c19ae71d84047a74ee060d4e6"}, + {file = "mypy-2.1.0-py3-none-any.whl", hash = "sha256:a663814603a5c563fb87a4f96fb473eeb30d1f5a4885afcf44f9db000a366289"}, + {file = "mypy-2.1.0.tar.gz", hash = "sha256:81e76ad12c2d804512e9b13240d1588316531bfba07558286078bfbce9613633"}, ] [[package]] name = "mypy-extensions" -version = "1.0.0" -requires_python = ">=3.5" +version = "1.1.0" +requires_python = ">=3.8" summary = "Type system extensions for programs checked with the mypy type checker." groups = ["dev"] files = [ - {file = "mypy_extensions-1.0.0-py3-none-any.whl", hash = "sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d"}, - {file = "mypy_extensions-1.0.0.tar.gz", hash = "sha256:75dbf8955dc00442a438fc4d0666508a9a97b6bd41aa2f0ffe9d2f2725af0782"}, + {file = "mypy_extensions-1.1.0-py3-none-any.whl", hash = "sha256:1be4cccdb0f2482337c4743e60421de3a356cd97508abadd57d47403e94f5505"}, + {file = "mypy_extensions-1.1.0.tar.gz", hash = "sha256:52e68efc3284861e772bbcd66823fde5ae21fd2fdb51c62a211403730b916558"}, ] [[package]] name = "packaging" -version = "21.3" -requires_python = ">=3.6" -summary = "Core utilities for Python packages" -groups = ["dev"] -dependencies = [ - "pyparsing!=3.0.5,>=2.0.2", -] -files = [ - {file = "packaging-21.3-py3-none-any.whl", hash = "sha256:ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522"}, - {file = "packaging-21.3.tar.gz", hash = "sha256:dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb"}, -] - -[[package]] -name = "pluggy" -version = "1.4.0" +version = "26.2" requires_python = ">=3.8" -summary = "plugin and hook calling mechanisms for python" +summary = "Core utilities for Python packages" groups = ["dev"] files = [ - {file = "pluggy-1.4.0-py3-none-any.whl", hash = "sha256:7db9f7b503d67d1c5b95f59773ebb58a8c1c288129a88665838012cfb07b8981"}, - {file = "pluggy-1.4.0.tar.gz", hash = "sha256:8c85c2876142a764e5b7548e7d9a0e0ddb46f5185161049a79b7e974454223be"}, + {file = "packaging-26.2-py3-none-any.whl", hash = "sha256:5fc45236b9446107ff2415ce77c807cee2862cb6fac22b8a73826d0693b0980e"}, + {file = "packaging-26.2.tar.gz", hash = "sha256:ff452ff5a3e828ce110190feff1178bb1f2ea2281fa2075aadb987c2fb221661"}, ] [[package]] -name = "psutil" -version = "5.9.7" -requires_python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*" -summary = "Cross-platform lib for process and system monitoring in Python." +name = "pathspec" +version = "1.1.1" +requires_python = ">=3.9" +summary = "Utility library for gitignore style pattern matching of file paths." groups = ["dev"] files = [ - {file = "psutil-5.9.7-cp36-abi3-macosx_10_9_x86_64.whl", hash = "sha256:ea36cc62e69a13ec52b2f625c27527f6e4479bca2b340b7a452af55b34fcbe2e"}, - {file = "psutil-5.9.7-cp36-abi3-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1132704b876e58d277168cd729d64750633d5ff0183acf5b3c986b8466cd0284"}, - {file = "psutil-5.9.7-cp36-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fe8b7f07948f1304497ce4f4684881250cd859b16d06a1dc4d7941eeb6233bfe"}, - {file = "psutil-5.9.7-cp37-abi3-win32.whl", hash = "sha256:c727ca5a9b2dd5193b8644b9f0c883d54f1248310023b5ad3e92036c5e2ada68"}, - {file = "psutil-5.9.7-cp37-abi3-win_amd64.whl", hash = "sha256:f37f87e4d73b79e6c5e749440c3113b81d1ee7d26f21c19c47371ddea834f414"}, - {file = "psutil-5.9.7-cp38-abi3-macosx_11_0_arm64.whl", hash = "sha256:032f4f2c909818c86cea4fe2cc407f1c0f0cde8e6c6d702b28b8ce0c0d143340"}, - {file = "psutil-5.9.7.tar.gz", hash = "sha256:3f02134e82cfb5d089fddf20bb2e03fd5cd52395321d1c8458a9e58500ff417c"}, + {file = "pathspec-1.1.1-py3-none-any.whl", hash = "sha256:a00ce642f577bf7f473932318056212bc4f8bfdf53128c78bbd5af0b9b20b189"}, + {file = "pathspec-1.1.1.tar.gz", hash = "sha256:17db5ecd524104a120e173814c90367a96a98d07c45b2e10c2f3919fff91bf5a"}, ] [[package]] -name = "pycparser" -version = "2.21" -requires_python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" -summary = "C parser in Python" +name = "pluggy" +version = "1.6.0" +requires_python = ">=3.9" +summary = "plugin and hook calling mechanisms for python" groups = ["dev"] -marker = "platform_python_implementation != \"PyPy\"" files = [ - {file = "pycparser-2.21-py2.py3-none-any.whl", hash = "sha256:8ee45429555515e1f6b185e78100aea234072576aa43ab53aefcae078162fca9"}, - {file = "pycparser-2.21.tar.gz", hash = "sha256:e644fdec12f7872f86c58ff790da456218b10f863970249516d60a5eaca77206"}, + {file = "pluggy-1.6.0-py3-none-any.whl", hash = "sha256:e920276dd6813095e9377c0bc5566d94c932c33b27a3e3945d8389c374dd4746"}, + {file = "pluggy-1.6.0.tar.gz", hash = "sha256:7dcc130b76258d33b90f61b658791dede3486c3e6bfb003ee5c9bfb396dd22f3"}, ] [[package]] name = "pydantic" -version = "2.7.0" -requires_python = ">=3.8" +version = "2.13.4" +requires_python = ">=3.9" summary = "Data validation using Python type hints" -groups = ["default", "dev"] +groups = ["default"] dependencies = [ - "annotated-types>=0.4.0", - "pydantic-core==2.18.1", - "typing-extensions>=4.6.1", + "annotated-types>=0.6.0", + "pydantic-core==2.46.4", + "typing-extensions>=4.14.1", + "typing-inspection>=0.4.2", ] files = [ - {file = "pydantic-2.7.0-py3-none-any.whl", hash = "sha256:9dee74a271705f14f9a1567671d144a851c675b072736f0a7b2608fd9e495352"}, - {file = "pydantic-2.7.0.tar.gz", hash = "sha256:b5ecdd42262ca2462e2624793551e80911a1e989f462910bb81aef974b4bb383"}, + {file = "pydantic-2.13.4-py3-none-any.whl", hash = "sha256:45a282cde31d808236fd7ea9d919b128653c8b38b393d1c4ab335c62924d9aba"}, + {file = "pydantic-2.13.4.tar.gz", hash = "sha256:c40756b57adaa8b1efeeced5c196f3f3b7c435f90e84ea7f443901bec8099ef6"}, ] [[package]] name = "pydantic-core" -version = "2.18.1" -requires_python = ">=3.8" +version = "2.46.4" +requires_python = ">=3.9" summary = "Core functionality for Pydantic validation and serialization" -groups = ["default", "dev"] +groups = ["default"] dependencies = [ - "typing-extensions!=4.7.0,>=4.6.0", + "typing-extensions>=4.14.1", ] files = [ - {file = "pydantic_core-2.18.1-cp310-cp310-macosx_10_12_x86_64.whl", hash = "sha256:ee9cf33e7fe14243f5ca6977658eb7d1042caaa66847daacbd2117adb258b226"}, - {file = "pydantic_core-2.18.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:6b7bbb97d82659ac8b37450c60ff2e9f97e4eb0f8a8a3645a5568b9334b08b50"}, - {file = "pydantic_core-2.18.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:df4249b579e75094f7e9bb4bd28231acf55e308bf686b952f43100a5a0be394c"}, - {file = "pydantic_core-2.18.1-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:d0491006a6ad20507aec2be72e7831a42efc93193d2402018007ff827dc62926"}, - {file = "pydantic_core-2.18.1-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:2ae80f72bb7a3e397ab37b53a2b49c62cc5496412e71bc4f1277620a7ce3f52b"}, - {file = "pydantic_core-2.18.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:58aca931bef83217fca7a390e0486ae327c4af9c3e941adb75f8772f8eeb03a1"}, - {file = "pydantic_core-2.18.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1be91ad664fc9245404a789d60cba1e91c26b1454ba136d2a1bf0c2ac0c0505a"}, - {file = "pydantic_core-2.18.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:667880321e916a8920ef49f5d50e7983792cf59f3b6079f3c9dac2b88a311d17"}, - {file = "pydantic_core-2.18.1-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:f7054fdc556f5421f01e39cbb767d5ec5c1139ea98c3e5b350e02e62201740c7"}, - {file = "pydantic_core-2.18.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:030e4f9516f9947f38179249778709a460a3adb516bf39b5eb9066fcfe43d0e6"}, - {file = "pydantic_core-2.18.1-cp310-none-win32.whl", hash = "sha256:2e91711e36e229978d92642bfc3546333a9127ecebb3f2761372e096395fc649"}, - {file = "pydantic_core-2.18.1-cp310-none-win_amd64.whl", hash = "sha256:9a29726f91c6cb390b3c2338f0df5cd3e216ad7a938762d11c994bb37552edb0"}, - {file = "pydantic_core-2.18.1-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:9ece8a49696669d483d206b4474c367852c44815fca23ac4e48b72b339807f80"}, - {file = "pydantic_core-2.18.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:7a5d83efc109ceddb99abd2c1316298ced2adb4570410defe766851a804fcd5b"}, - {file = "pydantic_core-2.18.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5f7973c381283783cd1043a8c8f61ea5ce7a3a58b0369f0ee0ee975eaf2f2a1b"}, - {file = "pydantic_core-2.18.1-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:54c7375c62190a7845091f521add19b0f026bcf6ae674bdb89f296972272e86d"}, - {file = "pydantic_core-2.18.1-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:dd63cec4e26e790b70544ae5cc48d11b515b09e05fdd5eff12e3195f54b8a586"}, - {file = "pydantic_core-2.18.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:561cf62c8a3498406495cfc49eee086ed2bb186d08bcc65812b75fda42c38294"}, - {file = "pydantic_core-2.18.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:68717c38a68e37af87c4da20e08f3e27d7e4212e99e96c3d875fbf3f4812abfc"}, - {file = "pydantic_core-2.18.1-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:2d5728e93d28a3c63ee513d9ffbac9c5989de8c76e049dbcb5bfe4b923a9739d"}, - {file = "pydantic_core-2.18.1-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:f0f17814c505f07806e22b28856c59ac80cee7dd0fbb152aed273e116378f519"}, - {file = "pydantic_core-2.18.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:d816f44a51ba5175394bc6c7879ca0bd2be560b2c9e9f3411ef3a4cbe644c2e9"}, - {file = "pydantic_core-2.18.1-cp311-none-win32.whl", hash = "sha256:09f03dfc0ef8c22622eaa8608caa4a1e189cfb83ce847045eca34f690895eccb"}, - {file = "pydantic_core-2.18.1-cp311-none-win_amd64.whl", hash = "sha256:27f1009dc292f3b7ca77feb3571c537276b9aad5dd4efb471ac88a8bd09024e9"}, - {file = "pydantic_core-2.18.1-cp311-none-win_arm64.whl", hash = "sha256:48dd883db92e92519201f2b01cafa881e5f7125666141a49ffba8b9facc072b0"}, - {file = "pydantic_core-2.18.1-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:b6b0e4912030c6f28bcb72b9ebe4989d6dc2eebcd2a9cdc35fefc38052dd4fe8"}, - {file = "pydantic_core-2.18.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:f3202a429fe825b699c57892d4371c74cc3456d8d71b7f35d6028c96dfecad31"}, - {file = "pydantic_core-2.18.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a3982b0a32d0a88b3907e4b0dc36809fda477f0757c59a505d4e9b455f384b8b"}, - {file = "pydantic_core-2.18.1-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:25595ac311f20e5324d1941909b0d12933f1fd2171075fcff763e90f43e92a0d"}, - {file = "pydantic_core-2.18.1-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:14fe73881cf8e4cbdaded8ca0aa671635b597e42447fec7060d0868b52d074e6"}, - {file = "pydantic_core-2.18.1-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:ca976884ce34070799e4dfc6fbd68cb1d181db1eefe4a3a94798ddfb34b8867f"}, - {file = "pydantic_core-2.18.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:684d840d2c9ec5de9cb397fcb3f36d5ebb6fa0d94734f9886032dd796c1ead06"}, - {file = "pydantic_core-2.18.1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:54764c083bbe0264f0f746cefcded6cb08fbbaaf1ad1d78fb8a4c30cff999a90"}, - {file = "pydantic_core-2.18.1-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:201713f2f462e5c015b343e86e68bd8a530a4f76609b33d8f0ec65d2b921712a"}, - {file = "pydantic_core-2.18.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:fd1a9edb9dd9d79fbeac1ea1f9a8dd527a6113b18d2e9bcc0d541d308dae639b"}, - {file = "pydantic_core-2.18.1-cp312-none-win32.whl", hash = "sha256:d5e6b7155b8197b329dc787356cfd2684c9d6a6b1a197f6bbf45f5555a98d411"}, - {file = "pydantic_core-2.18.1-cp312-none-win_amd64.whl", hash = "sha256:9376d83d686ec62e8b19c0ac3bf8d28d8a5981d0df290196fb6ef24d8a26f0d6"}, - {file = "pydantic_core-2.18.1-cp312-none-win_arm64.whl", hash = "sha256:c562b49c96906b4029b5685075fe1ebd3b5cc2601dfa0b9e16c2c09d6cbce048"}, - {file = "pydantic_core-2.18.1-cp38-cp38-macosx_10_12_x86_64.whl", hash = "sha256:3e352f0191d99fe617371096845070dee295444979efb8f27ad941227de6ad09"}, - {file = "pydantic_core-2.18.1-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:c0295d52b012cbe0d3059b1dba99159c3be55e632aae1999ab74ae2bd86a33d7"}, - {file = "pydantic_core-2.18.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:56823a92075780582d1ffd4489a2e61d56fd3ebb4b40b713d63f96dd92d28144"}, - {file = "pydantic_core-2.18.1-cp38-cp38-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:dd3f79e17b56741b5177bcc36307750d50ea0698df6aa82f69c7db32d968c1c2"}, - {file = "pydantic_core-2.18.1-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:38a5024de321d672a132b1834a66eeb7931959c59964b777e8f32dbe9523f6b1"}, - {file = "pydantic_core-2.18.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:d2ce426ee691319d4767748c8e0895cfc56593d725594e415f274059bcf3cb76"}, - {file = "pydantic_core-2.18.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2adaeea59849ec0939af5c5d476935f2bab4b7f0335b0110f0f069a41024278e"}, - {file = "pydantic_core-2.18.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:9b6431559676a1079eac0f52d6d0721fb8e3c5ba43c37bc537c8c83724031feb"}, - {file = "pydantic_core-2.18.1-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:85233abb44bc18d16e72dc05bf13848a36f363f83757541f1a97db2f8d58cfd9"}, - {file = "pydantic_core-2.18.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:641a018af4fe48be57a2b3d7a1f0f5dbca07c1d00951d3d7463f0ac9dac66622"}, - {file = "pydantic_core-2.18.1-cp38-none-win32.whl", hash = "sha256:63d7523cd95d2fde0d28dc42968ac731b5bb1e516cc56b93a50ab293f4daeaad"}, - {file = "pydantic_core-2.18.1-cp38-none-win_amd64.whl", hash = "sha256:907a4d7720abfcb1c81619863efd47c8a85d26a257a2dbebdb87c3b847df0278"}, - {file = "pydantic_core-2.18.1-cp39-cp39-macosx_10_12_x86_64.whl", hash = "sha256:aad17e462f42ddbef5984d70c40bfc4146c322a2da79715932cd8976317054de"}, - {file = "pydantic_core-2.18.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:94b9769ba435b598b547c762184bcfc4783d0d4c7771b04a3b45775c3589ca44"}, - {file = "pydantic_core-2.18.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:80e0e57cc704a52fb1b48f16d5b2c8818da087dbee6f98d9bf19546930dc64b5"}, - {file = "pydantic_core-2.18.1-cp39-cp39-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:76b86e24039c35280ceee6dce7e62945eb93a5175d43689ba98360ab31eebc4a"}, - {file = "pydantic_core-2.18.1-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:12a05db5013ec0ca4a32cc6433f53faa2a014ec364031408540ba858c2172bb0"}, - {file = "pydantic_core-2.18.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:250ae39445cb5475e483a36b1061af1bc233de3e9ad0f4f76a71b66231b07f88"}, - {file = "pydantic_core-2.18.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a32204489259786a923e02990249c65b0f17235073149d0033efcebe80095570"}, - {file = "pydantic_core-2.18.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:6395a4435fa26519fd96fdccb77e9d00ddae9dd6c742309bd0b5610609ad7fb2"}, - {file = "pydantic_core-2.18.1-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:2533ad2883f001efa72f3d0e733fb846710c3af6dcdd544fe5bf14fa5fe2d7db"}, - {file = "pydantic_core-2.18.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:b560b72ed4816aee52783c66854d96157fd8175631f01ef58e894cc57c84f0f6"}, - {file = "pydantic_core-2.18.1-cp39-none-win32.whl", hash = "sha256:582cf2cead97c9e382a7f4d3b744cf0ef1a6e815e44d3aa81af3ad98762f5a9b"}, - {file = "pydantic_core-2.18.1-cp39-none-win_amd64.whl", hash = "sha256:ca71d501629d1fa50ea7fa3b08ba884fe10cefc559f5c6c8dfe9036c16e8ae89"}, - {file = "pydantic_core-2.18.1-pp310-pypy310_pp73-macosx_10_12_x86_64.whl", hash = "sha256:e178e5b66a06ec5bf51668ec0d4ac8cfb2bdcb553b2c207d58148340efd00143"}, - {file = "pydantic_core-2.18.1-pp310-pypy310_pp73-macosx_11_0_arm64.whl", hash = "sha256:72722ce529a76a4637a60be18bd789d8fb871e84472490ed7ddff62d5fed620d"}, - {file = "pydantic_core-2.18.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2fe0c1ce5b129455e43f941f7a46f61f3d3861e571f2905d55cdbb8b5c6f5e2c"}, - {file = "pydantic_core-2.18.1-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d4284c621f06a72ce2cb55f74ea3150113d926a6eb78ab38340c08f770eb9b4d"}, - {file = "pydantic_core-2.18.1-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:1a0c3e718f4e064efde68092d9d974e39572c14e56726ecfaeebbe6544521f47"}, - {file = "pydantic_core-2.18.1-pp310-pypy310_pp73-musllinux_1_1_aarch64.whl", hash = "sha256:2027493cc44c23b598cfaf200936110433d9caa84e2c6cf487a83999638a96ac"}, - {file = "pydantic_core-2.18.1-pp310-pypy310_pp73-musllinux_1_1_x86_64.whl", hash = "sha256:76909849d1a6bffa5a07742294f3fa1d357dc917cb1fe7b470afbc3a7579d539"}, - {file = "pydantic_core-2.18.1-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:ee7ccc7fb7e921d767f853b47814c3048c7de536663e82fbc37f5eb0d532224b"}, - {file = "pydantic_core-2.18.1-pp39-pypy39_pp73-macosx_10_12_x86_64.whl", hash = "sha256:ee2794111c188548a4547eccc73a6a8527fe2af6cf25e1a4ebda2fd01cdd2e60"}, - {file = "pydantic_core-2.18.1-pp39-pypy39_pp73-macosx_11_0_arm64.whl", hash = "sha256:a139fe9f298dc097349fb4f28c8b81cc7a202dbfba66af0e14be5cfca4ef7ce5"}, - {file = "pydantic_core-2.18.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d074b07a10c391fc5bbdcb37b2f16f20fcd9e51e10d01652ab298c0d07908ee2"}, - {file = "pydantic_core-2.18.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c69567ddbac186e8c0aadc1f324a60a564cfe25e43ef2ce81bcc4b8c3abffbae"}, - {file = "pydantic_core-2.18.1-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:baf1c7b78cddb5af00971ad5294a4583188bda1495b13760d9f03c9483bb6203"}, - {file = "pydantic_core-2.18.1-pp39-pypy39_pp73-musllinux_1_1_aarch64.whl", hash = "sha256:2684a94fdfd1b146ff10689c6e4e815f6a01141781c493b97342cdc5b06f4d5d"}, - {file = "pydantic_core-2.18.1-pp39-pypy39_pp73-musllinux_1_1_x86_64.whl", hash = "sha256:73c1bc8a86a5c9e8721a088df234265317692d0b5cd9e86e975ce3bc3db62a59"}, - {file = "pydantic_core-2.18.1-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:e60defc3c15defb70bb38dd605ff7e0fae5f6c9c7cbfe0ad7868582cb7e844a6"}, - {file = "pydantic_core-2.18.1.tar.gz", hash = "sha256:de9d3e8717560eb05e28739d1b35e4eac2e458553a52a301e51352a7ffc86a35"}, + {file = "pydantic_core-2.46.4-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:0e96592440881c74a213e5ad528e2b24d3d4f940de2766bed9010ab1d9e51594"}, + {file = "pydantic_core-2.46.4-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:e0d65b8c354be7fb5f720c3caa8bc940bc2d20ce749c8e06135f07f8ed95dd7c"}, + {file = "pydantic_core-2.46.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:7bfb192b3f4b9e8a89b6277b6ce787564f62cfd272055f6e685726b111dc7826"}, + {file = "pydantic_core-2.46.4-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:9037063db01f09b09e237c282b6792bd4da634b5402c4e7f0c61effed7701a04"}, + {file = "pydantic_core-2.46.4-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:fc010ab034c8c7452522748bf937df58020d256ccae0874463d1f4d01758af8e"}, + {file = "pydantic_core-2.46.4-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:8c5dac79fa1614d1e06ca695109c6105923bd9c7d1d6c918d4e637b7e6b32fd3"}, + {file = "pydantic_core-2.46.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f9fa868638bf362d3d138ea55829cefb3d5f4b0d7f142234382a15e2485dbec4"}, + {file = "pydantic_core-2.46.4-cp311-cp311-manylinux_2_31_riscv64.whl", hash = "sha256:17299feefe090f2caa5b8e37222bb5f663e4935a8bfa6931d4102e5df1a9f398"}, + {file = "pydantic_core-2.46.4-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:4c63ebc82684aa89d9a3bcbd13d515b3be44250dc68dd3bd81526c1cb31286c3"}, + {file = "pydantic_core-2.46.4-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:aaa2a54443eff1950ba5ddc6b6ccda0d9c84a364276a62f969bdf2a390650848"}, + {file = "pydantic_core-2.46.4-cp311-cp311-musllinux_1_1_armv7l.whl", hash = "sha256:18e5ceec2ab67e6d5f1a9085e5a24c9c4e2ac4545730bfe668680bca05e555f3"}, + {file = "pydantic_core-2.46.4-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:a0f62d0a58f4e7da165457e995725421e0064f2255d8eccebc49f41bbc23b109"}, + {file = "pydantic_core-2.46.4-cp311-cp311-win32.whl", hash = "sha256:041bde0a48fd37cf71cab1c9d56d3e8625a3793fef1f7dd232b3ff37e978ecda"}, + {file = "pydantic_core-2.46.4-cp311-cp311-win_amd64.whl", hash = "sha256:6f2eeda33a839975441c86a4119e1383c50b47faf0cbb5176985565c6bb02c33"}, + {file = "pydantic_core-2.46.4-cp311-cp311-win_arm64.whl", hash = "sha256:14f4c5d6db102bd796a627bbb3a17b4cf4574b9ae861d8b7c9a9661c6dd3362d"}, + {file = "pydantic_core-2.46.4-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:3245406455a5d98187ec35530fd772b1d799b26667980872c8d4614991e2c4a2"}, + {file = "pydantic_core-2.46.4-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:962ccbab7b642487b1d8b7df90ef677e03134cf1fd8880bf698649b22a69371f"}, + {file = "pydantic_core-2.46.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8233f2947cf85404441fd7e0085f53b10c93e0ee78611099b5c7237e36aacbf7"}, + {file = "pydantic_core-2.46.4-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:3a233125ac121aa3ffba9a2b59edfc4a985a76092dc8279586ab4b71390875e7"}, + {file = "pydantic_core-2.46.4-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:5b712b53160b79a5850310b912a5ef8e57e56947c8ad690c227f5c9d7e561712"}, + {file = "pydantic_core-2.46.4-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:9401557acd873c3a7f3eb9383edef8ac4968f9510e340f4808d427e75667e7b4"}, + {file = "pydantic_core-2.46.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:926c9541b14b12b1681dca8a0b75feb510b06c6341b70a8e500c2fdcff837cce"}, + {file = "pydantic_core-2.46.4-cp312-cp312-manylinux_2_31_riscv64.whl", hash = "sha256:56cb4851bcaf3d117eddcef4fe66afd750a50274b0da8e22be256d10e5611987"}, + {file = "pydantic_core-2.46.4-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:c68fcd102d71ea85c5b2dfac3f4f8476eff42a9e078fd5faefff6d145063536b"}, + {file = "pydantic_core-2.46.4-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:b2f69dec1725e79a012d920df1707de5caf7ed5e08f3be4435e25803efc47458"}, + {file = "pydantic_core-2.46.4-cp312-cp312-musllinux_1_1_armv7l.whl", hash = "sha256:8d0820e8192167f80d88d64038e609c31452eeca865b4e1d9950a27a4609b00b"}, + {file = "pydantic_core-2.46.4-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:fbdb89b3e1c94a30cc5edfce477c6e6a5dc4d8f84665b455c27582f211a1c72c"}, + {file = "pydantic_core-2.46.4-cp312-cp312-win32.whl", hash = "sha256:9aa768456404a8bf48a4406685ac2bec8e72b62c69313734fa3b73cf33b3a894"}, + {file = "pydantic_core-2.46.4-cp312-cp312-win_amd64.whl", hash = "sha256:e9c26f834c65f5752f3f06cb08cb86a913ceb7274d0db6e267808a708b46bc89"}, + {file = "pydantic_core-2.46.4-cp312-cp312-win_arm64.whl", hash = "sha256:4fc73cb559bdb54b1134a706a2802a4cddd27a0633f5abb7e53056268751ac6a"}, + {file = "pydantic_core-2.46.4-cp313-cp313-macosx_10_12_x86_64.whl", hash = "sha256:5d5902252db0d3cedf8d4a1bc68f70eeb430f7e4c7104c8c476753519b423008"}, + {file = "pydantic_core-2.46.4-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:c94f0688e7b8d0a67abf40e57a7eaaecd17cc9586706a31b76c031f63df052b4"}, + {file = "pydantic_core-2.46.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f027324c56cd5406ca49c124b0db10e56c69064fec039acc571c29020cc87c76"}, + {file = "pydantic_core-2.46.4-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:e739fee756ba1010f8bcccb534252e85a35fe45ae92c295a06059ce58b74ccd3"}, + {file = "pydantic_core-2.46.4-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:9d56801be94b86a9da183e5f3766e6310752b99ff647e38b09a9500d88e46e76"}, + {file = "pydantic_core-2.46.4-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:2412e734dcb48da14d4e4006b82b46b74f2518b8a26ee7e58c6844a6cd6d03c4"}, + {file = "pydantic_core-2.46.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9551187363ffc0de2a00b2e47c25aeaeb1020b69b668762966df15fc5659dd5a"}, + {file = "pydantic_core-2.46.4-cp313-cp313-manylinux_2_31_riscv64.whl", hash = "sha256:0186750b482eefa11d7f435892b09c5c606193ef3375bcf94aa00ae6bfb66262"}, + {file = "pydantic_core-2.46.4-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:5855698a4856556d86e8e6cd8434bc3ac0314ee8e12089ae0e143f64c6256e4e"}, + {file = "pydantic_core-2.46.4-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:cbaf13819775b7f769bf4a1f066cb6df7a28d4480081a589828ef190226881cd"}, + {file = "pydantic_core-2.46.4-cp313-cp313-musllinux_1_1_armv7l.whl", hash = "sha256:633147d34cf4550417f12e2b1a0383973bdf5cdfde212cb09e9a581cf10820be"}, + {file = "pydantic_core-2.46.4-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:82cf5301172168103724d49a1444d3378cb20cdee30b116a1bd6031236298a5d"}, + {file = "pydantic_core-2.46.4-cp313-cp313-win32.whl", hash = "sha256:9fa8ae11da9e2b3126c6426f147e0fba88d96d65921799bb30c6abd1cb2c97fb"}, + {file = "pydantic_core-2.46.4-cp313-cp313-win_amd64.whl", hash = "sha256:6b3ace8194b0e5204818c92802dcdca7fc6d88aabbb799d7c795540d9cd6d292"}, + {file = "pydantic_core-2.46.4-cp313-cp313-win_arm64.whl", hash = "sha256:184c081504d17f1c1066e430e117142b2c77d9448a97f7b65c6ac9fd9aee238d"}, + {file = "pydantic_core-2.46.4-cp314-cp314-macosx_10_12_x86_64.whl", hash = "sha256:428e04521a40150c85216fc8b85e8d39fece235a9cf5e383761238c7fa9b96fb"}, + {file = "pydantic_core-2.46.4-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:23ace664830ee0bfe014a0c7bc248b1f7f25ed7ad103852c317624a1083af462"}, + {file = "pydantic_core-2.46.4-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ce5c1d2a8b27468f433ca974829c44060b8097eedc39933e3c206a90ee49c4a9"}, + {file = "pydantic_core-2.46.4-cp314-cp314-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:7283d57845ecf5a163403eb0702dfc220cc4fbdd18919cb5ccea4f95ee1cdab4"}, + {file = "pydantic_core-2.46.4-cp314-cp314-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:8daafc69c93ee8a0204506a3b6b30f586ef54028f52aeeeb5c4cfc5184fd5914"}, + {file = "pydantic_core-2.46.4-cp314-cp314-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:cd2213145bcc2ba85884d0ac63d222fece9209678f77b9b4d76f054c561adb28"}, + {file = "pydantic_core-2.46.4-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7a5f930472650a82629163023e630d160863fce524c616f4e5186e5de9d9a49b"}, + {file = "pydantic_core-2.46.4-cp314-cp314-manylinux_2_31_riscv64.whl", hash = "sha256:c1b3f518abeca3aa13c712fd202306e145abf59a18b094a6bafb2d2bbf59192c"}, + {file = "pydantic_core-2.46.4-cp314-cp314-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:1a7dd0b3ee80d90150e3495a3a13ac34dbcbfd4f012996a6a1d8900e91b5c0fb"}, + {file = "pydantic_core-2.46.4-cp314-cp314-musllinux_1_1_aarch64.whl", hash = "sha256:3fb702cd90b0446a3a1c5e470bfa0dd23c0233b676a9099ddcc964fa6ca13898"}, + {file = "pydantic_core-2.46.4-cp314-cp314-musllinux_1_1_armv7l.whl", hash = "sha256:b8458003118a712e66286df6a707db01c52c0f52f7db8e4a38f0da1d3b94fc4e"}, + {file = "pydantic_core-2.46.4-cp314-cp314-musllinux_1_1_x86_64.whl", hash = "sha256:372429a130e469c9cd698925ce5fc50940b7a1336b0d82038e63d5bbc4edc519"}, + {file = "pydantic_core-2.46.4-cp314-cp314-win32.whl", hash = "sha256:85bb3611ff1802f3ee7fdd7dbff26b56f343fb432d57a4728fdd49b6ef35e2f4"}, + {file = "pydantic_core-2.46.4-cp314-cp314-win_amd64.whl", hash = "sha256:811ff8e9c313ab425368bcbb36e5c4ebd7108c2bbf4e4089cfbb0b01eff63fac"}, + {file = "pydantic_core-2.46.4-cp314-cp314-win_arm64.whl", hash = "sha256:bfec22eab3c8cc2ceec0248aec886624116dc079afa027ecc8ad4a7e62010f8a"}, + {file = "pydantic_core-2.46.4-cp314-cp314t-macosx_10_12_x86_64.whl", hash = "sha256:af8244b2bef6aaad6d92cda81372de7f8c8d36c9f0c3ea36e827c60e7d9467a0"}, + {file = "pydantic_core-2.46.4-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:5a4330cdbc57162e4b3aa303f588ba752257694c9c9be3e7ebb11b4aca659b5d"}, + {file = "pydantic_core-2.46.4-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:29c61fc04a3d840155ff08e475a04809278972fe6aef51e2720554e96367e34b"}, + {file = "pydantic_core-2.46.4-cp314-cp314t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:c50f2528cf200c5eed56faf3f4e22fcd5f38c157a8b78576e6ba3168ec35f000"}, + {file = "pydantic_core-2.46.4-cp314-cp314t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:0cbe8b01f948de4286c74cdd6c667aceb38f5c1e26f0693b3983d9d74887c65e"}, + {file = "pydantic_core-2.46.4-cp314-cp314t-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:617d7e2ca7dcb8c5cf6bcb8c59b8832c94b36196bbf1cbd1bfb56ed341905edd"}, + {file = "pydantic_core-2.46.4-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7027560ee92211647d0d34e3f7cd6f50da56399d26a9c8ad0da286d3869a53f3"}, + {file = "pydantic_core-2.46.4-cp314-cp314t-manylinux_2_31_riscv64.whl", hash = "sha256:f99626688942fb746e545232e7726926f3be91b5975f8b55327665fafda991c7"}, + {file = "pydantic_core-2.46.4-cp314-cp314t-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:fc3e9034a63de20e15e8ade85358bc6efc614008cab72898b4b4952bea0509ff"}, + {file = "pydantic_core-2.46.4-cp314-cp314t-musllinux_1_1_aarch64.whl", hash = "sha256:97e7cf2be5c77b7d1a9713a05605d49460d02c6078d38d8bef3cbe323c548424"}, + {file = "pydantic_core-2.46.4-cp314-cp314t-musllinux_1_1_armv7l.whl", hash = "sha256:3bf92c5d0e00fefaab325a4d27828fe6b6e2a21848686b5b60d2d9eeb09d76c6"}, + {file = "pydantic_core-2.46.4-cp314-cp314t-musllinux_1_1_x86_64.whl", hash = "sha256:3ecbc122d18468d06ca279dc26a8c2e2d5acb10943bb35e36ae92096dc3b5565"}, + {file = "pydantic_core-2.46.4-cp314-cp314t-win32.whl", hash = "sha256:e846ae7835bf0703ae43f534ab79a867146dadd59dc9ca5c8b53d5c8f7c9ef02"}, + {file = "pydantic_core-2.46.4-cp314-cp314t-win_amd64.whl", hash = "sha256:2108ba5c1c1eca18030634489dc544844144ee36357f2f9f780b93e7ddbb44b5"}, + {file = "pydantic_core-2.46.4-cp314-cp314t-win_arm64.whl", hash = "sha256:4fcbe087dbc2068af7eda3aa87634eba216dbda64d1ae73c8684b621d33f6596"}, + {file = "pydantic_core-2.46.4-pp311-pypy311_pp73-macosx_10_12_x86_64.whl", hash = "sha256:0c563b08bca408dc7f65f700633d8442fffb2421fc47b8101377e9fd65051ff0"}, + {file = "pydantic_core-2.46.4-pp311-pypy311_pp73-macosx_11_0_arm64.whl", hash = "sha256:db06ffe51636ffe9ca531fe9023dd64bdd794be8754cb5df57c5498ae5b518a7"}, + {file = "pydantic_core-2.46.4-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:133878133d271ade3d41d1bfb2a45ec38dbdbda40bc065921c6b04e4630127e2"}, + {file = "pydantic_core-2.46.4-pp311-pypy311_pp73-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:9bc519fbf2b7578398853d815009ae5e4d4603d12f4e3f91da8c06852d3da3e9"}, + {file = "pydantic_core-2.46.4-pp311-pypy311_pp73-musllinux_1_1_aarch64.whl", hash = "sha256:c7a7bd4e39e8e4c12c39cd480356842b6a8a06e41b23a55a5e3e191718838ddf"}, + {file = "pydantic_core-2.46.4-pp311-pypy311_pp73-musllinux_1_1_armv7l.whl", hash = "sha256:d396ec2b979760aaf3218e76c24e65bd0aca24983298653b3a9d7a45f9e47b30"}, + {file = "pydantic_core-2.46.4-pp311-pypy311_pp73-musllinux_1_1_x86_64.whl", hash = "sha256:86e1a4418c6cd97d60c95c71164158eaf7324fae7b0923264016baa993eba6fc"}, + {file = "pydantic_core-2.46.4-pp311-pypy311_pp73-win_amd64.whl", hash = "sha256:d51026d73fcfd93610abc7b27789c26b313920fcfb20e27462d74a7f8b06e983"}, + {file = "pydantic_core-2.46.4.tar.gz", hash = "sha256:62f875393d7f270851f20523dd2e29f082bcc82292d66db2b64ea71f64b6e1c1"}, ] [[package]] name = "pygments" -version = "2.17.2" -requires_python = ">=3.7" +version = "2.20.0" +requires_python = ">=3.9" summary = "Pygments is a syntax highlighting package written in Python." groups = ["default", "dev"] files = [ - {file = "pygments-2.17.2-py3-none-any.whl", hash = "sha256:b27c2826c47d0f3219f29554824c30c5e8945175d888647acd804ddd04af846c"}, - {file = "pygments-2.17.2.tar.gz", hash = "sha256:da46cec9fd2de5be3a8a784f434e4c4ab670b4ff54d605c4c2717e9d49c4c367"}, -] - -[[package]] -name = "pyparsing" -version = "3.1.1" -requires_python = ">=3.6.8" -summary = "pyparsing module - Classes and methods to define and execute parsing grammars" -groups = ["dev"] -files = [ - {file = "pyparsing-3.1.1-py3-none-any.whl", hash = "sha256:32c7c0b711493c72ff18a981d24f28aaf9c1fb7ed5e9667c9e84e3db623bdbfb"}, - {file = "pyparsing-3.1.1.tar.gz", hash = "sha256:ede28a1a32462f5a9705e07aea48001a08f7cf81a021585011deba701581a0db"}, + {file = "pygments-2.20.0-py3-none-any.whl", hash = "sha256:81a9e26dd42fd28a23a2d169d86d7ac03b46e2f8b59ed4698fb4785f946d0176"}, + {file = "pygments-2.20.0.tar.gz", hash = "sha256:6757cd03768053ff99f3039c1a36d6c0aa0b263438fcab17520b30a303a82b5f"}, ] [[package]] name = "pytest" -version = "8.1.1" -requires_python = ">=3.8" +version = "9.1.1" +requires_python = ">=3.10" summary = "pytest: simple powerful testing with Python" groups = ["dev"] dependencies = [ - "colorama; sys_platform == \"win32\"", - "exceptiongroup>=1.0.0rc8; python_version < \"3.11\"", - "iniconfig", - "packaging", - "pluggy<2.0,>=1.4", + "colorama>=0.4; sys_platform == \"win32\"", + "exceptiongroup>=1; python_version < \"3.11\"", + "iniconfig>=1.0.1", + "packaging>=22", + "pluggy<2,>=1.5", + "pygments>=2.7.2", "tomli>=1; python_version < \"3.11\"", ] files = [ - {file = "pytest-8.1.1-py3-none-any.whl", hash = "sha256:2a8386cfc11fa9d2c50ee7b2a57e7d898ef90470a7a34c4b949ff59662bb78b7"}, - {file = "pytest-8.1.1.tar.gz", hash = "sha256:ac978141a75948948817d360297b7aae0fcb9d6ff6bc9ec6d514b85d5a65c044"}, + {file = "pytest-9.1.1-py3-none-any.whl", hash = "sha256:37a86b45efb9a47a61a36449063e8e18d0cab3161329fc099eb21783169c4f0c"}, + {file = "pytest-9.1.1.tar.gz", hash = "sha256:1088fbde8f2b49d95a549a195707afa7a76a3ce9bcadc26b6d71f0ffda5fe313"}, ] [[package]] name = "pytest-cov" -version = "5.0.0" -requires_python = ">=3.8" +version = "7.1.0" +requires_python = ">=3.9" summary = "Pytest plugin for measuring coverage." groups = ["dev"] dependencies = [ - "coverage[toml]>=5.2.1", - "pytest>=4.6", + "coverage[toml]>=7.10.6", + "pluggy>=1.2", + "pytest>=7", ] files = [ - {file = "pytest-cov-5.0.0.tar.gz", hash = "sha256:5837b58e9f6ebd335b0f8060eecce69b662415b16dc503883a02f45dfeb14857"}, - {file = "pytest_cov-5.0.0-py3-none-any.whl", hash = "sha256:4f0764a1219df53214206bf1feea4633c3b558a2925c8b59f144f682861ce652"}, + {file = "pytest_cov-7.1.0-py3-none-any.whl", hash = "sha256:a0461110b7865f9a271aa1b51e516c9a95de9d696734a2f71e3e78f46e1d4678"}, + {file = "pytest_cov-7.1.0.tar.gz", hash = "sha256:30674f2b5f6351aa09702a9c8c364f6a01c27aae0c1366ae8016160d1efc56b2"}, ] [[package]] name = "pytest-mock" -version = "3.14.0" -requires_python = ">=3.8" +version = "3.15.1" +requires_python = ">=3.9" summary = "Thin-wrapper around the mock package for easier use with pytest" groups = ["dev"] dependencies = [ "pytest>=6.2.5", ] files = [ - {file = "pytest-mock-3.14.0.tar.gz", hash = "sha256:2719255a1efeceadbc056d6bf3df3d1c5015530fb40cf347c0f9afac88410bd0"}, - {file = "pytest_mock-3.14.0-py3-none-any.whl", hash = "sha256:0b72c38033392a5f4621342fe11e9219ac11ec9d375f8e2a0c164539e0d70f6f"}, -] - -[[package]] -name = "python-dateutil" -version = "2.9.0.post0" -requires_python = "!=3.0.*,!=3.1.*,!=3.2.*,>=2.7" -summary = "Extensions to the standard Python datetime module" -groups = ["default"] -dependencies = [ - "six>=1.5", -] -files = [ - {file = "python-dateutil-2.9.0.post0.tar.gz", hash = "sha256:37dd54208da7e1cd875388217d5e00ebd4179249f90fb72437e91a35459a0ad3"}, - {file = "python_dateutil-2.9.0.post0-py2.py3-none-any.whl", hash = "sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427"}, + {file = "pytest_mock-3.15.1-py3-none-any.whl", hash = "sha256:0a25e2eb88fe5168d535041d09a4529a188176ae608a6d249ee65abc0949630d"}, + {file = "pytest_mock-3.15.1.tar.gz", hash = "sha256:1849a238f6f396da19762269de72cb1814ab44416fa73a8686deac10b0d87a0f"}, ] [[package]] name = "python-multipart" -version = "0.0.9" -requires_python = ">=3.8" +version = "0.0.32" +requires_python = ">=3.10" summary = "A streaming multipart parser for Python" groups = ["dev"] files = [ - {file = "python_multipart-0.0.9-py3-none-any.whl", hash = "sha256:97ca7b8ea7b05f977dc3849c3ba99d51689822fab725c3703af7c866a0c2b215"}, - {file = "python_multipart-0.0.9.tar.gz", hash = "sha256:03f54688c663f1b7977105f021043b0793151e4cb1c1a9d4a11fc13d622c4026"}, -] - -[[package]] -name = "pyyaml" -version = "6.0.1" -requires_python = ">=3.6" -summary = "YAML parser and emitter for Python" -groups = ["default"] -files = [ - {file = "PyYAML-6.0.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:d858aa552c999bc8a8d57426ed01e40bef403cd8ccdd0fc5f6f04a00414cac2a"}, - {file = "PyYAML-6.0.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:fd66fc5d0da6d9815ba2cebeb4205f95818ff4b79c3ebe268e75d961704af52f"}, - {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938"}, - {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d"}, - {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ba336e390cd8e4d1739f42dfe9bb83a3cc2e80f567d8805e11b46f4a943f5515"}, - {file = "PyYAML-6.0.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:326c013efe8048858a6d312ddd31d56e468118ad4cdeda36c719bf5bb6192290"}, - {file = "PyYAML-6.0.1-cp310-cp310-win32.whl", hash = "sha256:bd4af7373a854424dabd882decdc5579653d7868b8fb26dc7d0e99f823aa5924"}, - {file = "PyYAML-6.0.1-cp310-cp310-win_amd64.whl", hash = "sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d"}, - {file = "PyYAML-6.0.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007"}, - {file = "PyYAML-6.0.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:f003ed9ad21d6a4713f0a9b5a7a0a79e08dd0f221aff4525a2be4c346ee60aab"}, - {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d"}, - {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc"}, - {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673"}, - {file = "PyYAML-6.0.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:e7d73685e87afe9f3b36c799222440d6cf362062f78be1013661b00c5c6f678b"}, - {file = "PyYAML-6.0.1-cp311-cp311-win32.whl", hash = "sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741"}, - {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, - {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, - {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, - {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"}, - {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, - {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, - {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, - {file = "PyYAML-6.0.1-cp312-cp312-win_amd64.whl", hash = "sha256:0d3304d8c0adc42be59c5f8a4d9e3d7379e6955ad754aa9d6ab7a398b59dd1df"}, - {file = "PyYAML-6.0.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:1d4c7e777c441b20e32f52bd377e0c409713e8bb1386e1099c2415f26e479595"}, - {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5"}, - {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696"}, - {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735"}, - {file = "PyYAML-6.0.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:49a183be227561de579b4a36efbb21b3eab9651dd81b1858589f796549873dd6"}, - {file = "PyYAML-6.0.1-cp38-cp38-win32.whl", hash = "sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206"}, - {file = "PyYAML-6.0.1-cp38-cp38-win_amd64.whl", hash = "sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62"}, - {file = "PyYAML-6.0.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8"}, - {file = "PyYAML-6.0.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:c8098ddcc2a85b61647b2590f825f3db38891662cfc2fc776415143f599bb859"}, - {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6"}, - {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b786eecbdf8499b9ca1d697215862083bd6d2a99965554781d0d8d1ad31e13a0"}, - {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bc1bf2925a1ecd43da378f4db9e4f799775d6367bdb94671027b73b393a7c42c"}, - {file = "PyYAML-6.0.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:04ac92ad1925b2cff1db0cfebffb6ffc43457495c9b3c39d3fcae417d7125dc5"}, - {file = "PyYAML-6.0.1-cp39-cp39-win32.whl", hash = "sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c"}, - {file = "PyYAML-6.0.1-cp39-cp39-win_amd64.whl", hash = "sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486"}, - {file = "PyYAML-6.0.1.tar.gz", hash = "sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43"}, -] - -[[package]] -name = "requests" -version = "2.31.0" -requires_python = ">=3.7" -summary = "Python HTTP for Humans." -groups = ["dev"] -dependencies = [ - "certifi>=2017.4.17", - "charset-normalizer<4,>=2", - "idna<4,>=2.5", - "urllib3<3,>=1.21.1", -] -files = [ - {file = "requests-2.31.0-py3-none-any.whl", hash = "sha256:58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f"}, - {file = "requests-2.31.0.tar.gz", hash = "sha256:942c5a758f98d790eaed1a29cb6eefc7ffb0d1cf7af05c3d2791656dbd6ad1e1"}, + {file = "python_multipart-0.0.32-py3-none-any.whl", hash = "sha256:ff6d3f776f16878c894e52e107296ffc890e913c611b1a4ec6c44e2821fe2e23"}, + {file = "python_multipart-0.0.32.tar.gz", hash = "sha256:be54b7f3fa167bb83e4fcd936b887b708f4e57fe75911c02aebf53efaf8d938e"}, ] [[package]] name = "rich" -version = "13.7.1" -requires_python = ">=3.7.0" +version = "15.0.0" +requires_python = ">=3.9.0" summary = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal" -groups = ["default", "dev"] +groups = ["default"] dependencies = [ "markdown-it-py>=2.2.0", "pygments<3.0.0,>=2.13.0", - "typing-extensions<5.0,>=4.0.0; python_version < \"3.9\"", ] files = [ - {file = "rich-13.7.1-py3-none-any.whl", hash = "sha256:4edbae314f59eb482f54e9e30bf00d33350aaa94f4bfcd4e9e3110e64d0d7222"}, - {file = "rich-13.7.1.tar.gz", hash = "sha256:9be308cb1fe2f1f57d67ce99e95af38a1e2bc71ad9813b0e247cf7ffbcc3a432"}, + {file = "rich-15.0.0-py3-none-any.whl", hash = "sha256:33bd4ef74232fb73fe9279a257718407f169c09b78a87ad3d296f548e27de0bb"}, + {file = "rich-15.0.0.tar.gz", hash = "sha256:edd07a4824c6b40189fb7ac9bc4c52536e9780fbbfbddf6f1e2502c31b068c36"}, ] [[package]] name = "ruamel-yaml" -version = "0.18.5" -requires_python = ">=3.7" +version = "0.19.1" +requires_python = ">=3.9" summary = "ruamel.yaml is a YAML parser/emitter that supports roundtrip preservation of comments, seq/map flow style, and map key order" -groups = ["dev"] -dependencies = [ - "ruamel-yaml-clib>=0.2.7; platform_python_implementation == \"CPython\" and python_version < \"3.13\"", -] -files = [ - {file = "ruamel.yaml-0.18.5-py3-none-any.whl", hash = "sha256:a013ac02f99a69cdd6277d9664689eb1acba07069f912823177c5eced21a6ada"}, - {file = "ruamel.yaml-0.18.5.tar.gz", hash = "sha256:61917e3a35a569c1133a8f772e1226961bf5a1198bea7e23f06a0841dea1ab0e"}, -] - -[[package]] -name = "ruamel-yaml-clib" -version = "0.2.8" -requires_python = ">=3.6" -summary = "C version of reader, parser and emitter for ruamel.yaml derived from libyaml" -groups = ["dev"] -marker = "platform_python_implementation == \"CPython\" and python_version < \"3.13\"" +groups = ["default"] files = [ - {file = "ruamel.yaml.clib-0.2.8-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:b42169467c42b692c19cf539c38d4602069d8c1505e97b86387fcf7afb766e1d"}, - {file = "ruamel.yaml.clib-0.2.8-cp310-cp310-macosx_13_0_arm64.whl", hash = "sha256:07238db9cbdf8fc1e9de2489a4f68474e70dffcb32232db7c08fa61ca0c7c462"}, - {file = "ruamel.yaml.clib-0.2.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl", hash = "sha256:fff3573c2db359f091e1589c3d7c5fc2f86f5bdb6f24252c2d8e539d4e45f412"}, - {file = "ruamel.yaml.clib-0.2.8-cp310-cp310-manylinux_2_24_aarch64.whl", hash = "sha256:aa2267c6a303eb483de8d02db2871afb5c5fc15618d894300b88958f729ad74f"}, - {file = "ruamel.yaml.clib-0.2.8-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:840f0c7f194986a63d2c2465ca63af8ccbbc90ab1c6001b1978f05119b5e7334"}, - {file = "ruamel.yaml.clib-0.2.8-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:024cfe1fc7c7f4e1aff4a81e718109e13409767e4f871443cbff3dba3578203d"}, - {file = "ruamel.yaml.clib-0.2.8-cp310-cp310-win32.whl", hash = "sha256:c69212f63169ec1cfc9bb44723bf2917cbbd8f6191a00ef3410f5a7fe300722d"}, - {file = "ruamel.yaml.clib-0.2.8-cp310-cp310-win_amd64.whl", hash = "sha256:cabddb8d8ead485e255fe80429f833172b4cadf99274db39abc080e068cbcc31"}, - {file = "ruamel.yaml.clib-0.2.8-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:bef08cd86169d9eafb3ccb0a39edb11d8e25f3dae2b28f5c52fd997521133069"}, - {file = "ruamel.yaml.clib-0.2.8-cp311-cp311-macosx_13_0_arm64.whl", hash = "sha256:b16420e621d26fdfa949a8b4b47ade8810c56002f5389970db4ddda51dbff248"}, - {file = "ruamel.yaml.clib-0.2.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl", hash = "sha256:25c515e350e5b739842fc3228d662413ef28f295791af5e5110b543cf0b57d9b"}, - {file = "ruamel.yaml.clib-0.2.8-cp311-cp311-manylinux_2_24_aarch64.whl", hash = "sha256:1707814f0d9791df063f8c19bb51b0d1278b8e9a2353abbb676c2f685dee6afe"}, - {file = "ruamel.yaml.clib-0.2.8-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:46d378daaac94f454b3a0e3d8d78cafd78a026b1d71443f4966c696b48a6d899"}, - {file = "ruamel.yaml.clib-0.2.8-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:09b055c05697b38ecacb7ac50bdab2240bfca1a0c4872b0fd309bb07dc9aa3a9"}, - {file = "ruamel.yaml.clib-0.2.8-cp311-cp311-win32.whl", hash = "sha256:53a300ed9cea38cf5a2a9b069058137c2ca1ce658a874b79baceb8f892f915a7"}, - {file = "ruamel.yaml.clib-0.2.8-cp311-cp311-win_amd64.whl", hash = "sha256:c2a72e9109ea74e511e29032f3b670835f8a59bbdc9ce692c5b4ed91ccf1eedb"}, - {file = "ruamel.yaml.clib-0.2.8-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:ebc06178e8821efc9692ea7544aa5644217358490145629914d8020042c24aa1"}, - {file = "ruamel.yaml.clib-0.2.8-cp312-cp312-macosx_13_0_arm64.whl", hash = "sha256:edaef1c1200c4b4cb914583150dcaa3bc30e592e907c01117c08b13a07255ec2"}, - {file = "ruamel.yaml.clib-0.2.8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:d176b57452ab5b7028ac47e7b3cf644bcfdc8cacfecf7e71759f7f51a59e5c92"}, - {file = "ruamel.yaml.clib-0.2.8-cp312-cp312-manylinux_2_24_aarch64.whl", hash = "sha256:1dc67314e7e1086c9fdf2680b7b6c2be1c0d8e3a8279f2e993ca2a7545fecf62"}, - {file = "ruamel.yaml.clib-0.2.8-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:3213ece08ea033eb159ac52ae052a4899b56ecc124bb80020d9bbceeb50258e9"}, - {file = "ruamel.yaml.clib-0.2.8-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:aab7fd643f71d7946f2ee58cc88c9b7bfc97debd71dcc93e03e2d174628e7e2d"}, - {file = "ruamel.yaml.clib-0.2.8-cp312-cp312-win32.whl", hash = "sha256:5c365d91c88390c8d0a8545df0b5857172824b1c604e867161e6b3d59a827eaa"}, - {file = "ruamel.yaml.clib-0.2.8-cp312-cp312-win_amd64.whl", hash = "sha256:1758ce7d8e1a29d23de54a16ae867abd370f01b5a69e1a3ba75223eaa3ca1a1b"}, - {file = "ruamel.yaml.clib-0.2.8-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:1b617618914cb00bf5c34d4357c37aa15183fa229b24767259657746c9077615"}, - {file = "ruamel.yaml.clib-0.2.8-cp38-cp38-macosx_12_0_arm64.whl", hash = "sha256:a6a9ffd280b71ad062eae53ac1659ad86a17f59a0fdc7699fd9be40525153337"}, - {file = "ruamel.yaml.clib-0.2.8-cp38-cp38-manylinux_2_24_aarch64.whl", hash = "sha256:305889baa4043a09e5b76f8e2a51d4ffba44259f6b4c72dec8ca56207d9c6fe1"}, - {file = "ruamel.yaml.clib-0.2.8-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl", hash = "sha256:700e4ebb569e59e16a976857c8798aee258dceac7c7d6b50cab63e080058df91"}, - {file = "ruamel.yaml.clib-0.2.8-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:e2b4c44b60eadec492926a7270abb100ef9f72798e18743939bdbf037aab8c28"}, - {file = "ruamel.yaml.clib-0.2.8-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:e79e5db08739731b0ce4850bed599235d601701d5694c36570a99a0c5ca41a9d"}, - {file = "ruamel.yaml.clib-0.2.8-cp38-cp38-win32.whl", hash = "sha256:955eae71ac26c1ab35924203fda6220f84dce57d6d7884f189743e2abe3a9fbe"}, - {file = "ruamel.yaml.clib-0.2.8-cp38-cp38-win_amd64.whl", hash = "sha256:56f4252222c067b4ce51ae12cbac231bce32aee1d33fbfc9d17e5b8d6966c312"}, - {file = "ruamel.yaml.clib-0.2.8-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:03d1162b6d1df1caa3a4bd27aa51ce17c9afc2046c31b0ad60a0a96ec22f8001"}, - {file = "ruamel.yaml.clib-0.2.8-cp39-cp39-macosx_12_0_arm64.whl", hash = "sha256:bba64af9fa9cebe325a62fa398760f5c7206b215201b0ec825005f1b18b9bccf"}, - {file = "ruamel.yaml.clib-0.2.8-cp39-cp39-manylinux_2_24_aarch64.whl", hash = "sha256:a1a45e0bb052edf6a1d3a93baef85319733a888363938e1fc9924cb00c8df24c"}, - {file = "ruamel.yaml.clib-0.2.8-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl", hash = "sha256:da09ad1c359a728e112d60116f626cc9f29730ff3e0e7db72b9a2dbc2e4beed5"}, - {file = "ruamel.yaml.clib-0.2.8-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:184565012b60405d93838167f425713180b949e9d8dd0bbc7b49f074407c5a8b"}, - {file = "ruamel.yaml.clib-0.2.8-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:a75879bacf2c987c003368cf14bed0ffe99e8e85acfa6c0bfffc21a090f16880"}, - {file = "ruamel.yaml.clib-0.2.8-cp39-cp39-win32.whl", hash = "sha256:84b554931e932c46f94ab306913ad7e11bba988104c5cff26d90d03f68258cd5"}, - {file = "ruamel.yaml.clib-0.2.8-cp39-cp39-win_amd64.whl", hash = "sha256:25ac8c08322002b06fa1d49d1646181f0b2c72f5cbc15a85e80b4c30a544bb15"}, - {file = "ruamel.yaml.clib-0.2.8.tar.gz", hash = "sha256:beb2e0404003de9a4cab9753a8805a8fe9320ee6673136ed7f04255fe60bb512"}, + {file = "ruamel_yaml-0.19.1-py3-none-any.whl", hash = "sha256:27592957fedf6e0b62f281e96effd28043345e0e66001f97683aa9a40c667c93"}, + {file = "ruamel_yaml-0.19.1.tar.gz", hash = "sha256:53eb66cd27849eff968ebf8f0bf61f46cdac2da1d1f3576dd4ccee9b25c31993"}, ] [[package]] name = "ruff" -version = "0.4.1" +version = "0.15.18" requires_python = ">=3.7" summary = "An extremely fast Python linter and code formatter, written in Rust." groups = ["default"] files = [ - {file = "ruff-0.4.1-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:2d9ef6231e3fbdc0b8c72404a1a0c46fd0dcea84efca83beb4681c318ea6a953"}, - {file = "ruff-0.4.1-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:9485f54a7189e6f7433e0058cf8581bee45c31a25cd69009d2a040d1bd4bfaef"}, - {file = "ruff-0.4.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d2921ac03ce1383e360e8a95442ffb0d757a6a7ddd9a5be68561a671e0e5807e"}, - {file = "ruff-0.4.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:eec8d185fe193ad053eda3a6be23069e0c8ba8c5d20bc5ace6e3b9e37d246d3f"}, - {file = "ruff-0.4.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:baa27d9d72a94574d250f42b7640b3bd2edc4c58ac8ac2778a8c82374bb27984"}, - {file = "ruff-0.4.1-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:f1ee41580bff1a651339eb3337c20c12f4037f6110a36ae4a2d864c52e5ef954"}, - {file = "ruff-0.4.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:0926cefb57fc5fced629603fbd1a23d458b25418681d96823992ba975f050c2b"}, - {file = "ruff-0.4.1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:2c6e37f2e3cd74496a74af9a4fa67b547ab3ca137688c484749189bf3a686ceb"}, - {file = "ruff-0.4.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:efd703a5975ac1998c2cc5e9494e13b28f31e66c616b0a76e206de2562e0843c"}, - {file = "ruff-0.4.1-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:b92f03b4aa9fa23e1799b40f15f8b95cdc418782a567d6c43def65e1bbb7f1cf"}, - {file = "ruff-0.4.1-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:1c859f294f8633889e7d77de228b203eb0e9a03071b72b5989d89a0cf98ee262"}, - {file = "ruff-0.4.1-py3-none-musllinux_1_2_i686.whl", hash = "sha256:b34510141e393519a47f2d7b8216fec747ea1f2c81e85f076e9f2910588d4b64"}, - {file = "ruff-0.4.1-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:6e68d248ed688b9d69fd4d18737edcbb79c98b251bba5a2b031ce2470224bdf9"}, - {file = "ruff-0.4.1-py3-none-win32.whl", hash = "sha256:b90506f3d6d1f41f43f9b7b5ff845aeefabed6d2494307bc7b178360a8805252"}, - {file = "ruff-0.4.1-py3-none-win_amd64.whl", hash = "sha256:c7d391e5936af5c9e252743d767c564670dc3889aff460d35c518ee76e4b26d7"}, - {file = "ruff-0.4.1-py3-none-win_arm64.whl", hash = "sha256:a1eaf03d87e6a7cd5e661d36d8c6e874693cb9bc3049d110bc9a97b350680c43"}, - {file = "ruff-0.4.1.tar.gz", hash = "sha256:d592116cdbb65f8b1b7e2a2b48297eb865f6bdc20641879aa9d7b9c11d86db79"}, -] - -[[package]] -name = "safety" -version = "3.1.0" -requires_python = ">=3.7" -summary = "Checks installed dependencies for known vulnerabilities and licenses." -groups = ["dev"] -dependencies = [ - "Authlib>=1.2.0", - "Click>=8.0.2", - "dparse>=0.6.4b0", - "jinja2>=3.1.0", - "marshmallow>=3.15.0", - "packaging>=21.0", - "pydantic>=1.10.12", - "requests", - "rich", - "ruamel-yaml>=0.17.21", - "safety-schemas>=0.0.2", - "setuptools>=65.5.1", - "typer", - "typing-extensions>=4.7.1", - "urllib3>=1.26.5", -] -files = [ - {file = "safety-3.1.0-py3-none-any.whl", hash = "sha256:f2ba2d36f15ac1e24751547a73b854509a7d6db31efd30b57f64ffdf9d021934"}, - {file = "safety-3.1.0.tar.gz", hash = "sha256:71f47b82ece153ec2f240e277f7cbfa70d5da2e0d143162c67f63b2f7459a1aa"}, -] - -[[package]] -name = "safety-schemas" -version = "0.0.2" -requires_python = ">=3.7" -summary = "Schemas for Safety tools" -groups = ["dev"] -dependencies = [ - "dparse>=0.6.4b0", - "packaging>=21.0", - "pydantic", - "ruamel-yaml>=0.17.21", - "typing-extensions>=4.7.1", -] -files = [ - {file = "safety_schemas-0.0.2-py3-none-any.whl", hash = "sha256:277c077ce6e53221874a87c29515ffdd2f3773a6db4d035a9f67cc98db3b8c7f"}, - {file = "safety_schemas-0.0.2.tar.gz", hash = "sha256:7d1b040ec06480f05cff6b45ea7a93e09c8942df864fb0d01ddeb67c323cfa8c"}, -] - -[[package]] -name = "setuptools" -version = "69.0.3" -requires_python = ">=3.8" -summary = "Easily download, build, install, upgrade, and uninstall Python packages" -groups = ["dev"] -files = [ - {file = "setuptools-69.0.3-py3-none-any.whl", hash = "sha256:385eb4edd9c9d5c17540511303e39a147ce2fc04bc55289c322b9e5904fe2c05"}, - {file = "setuptools-69.0.3.tar.gz", hash = "sha256:be1af57fc409f93647f2e8e4573a142ed38724b8cdd389706a867bb4efcf1e78"}, + {file = "ruff-0.15.18-py3-none-linux_armv6l.whl", hash = "sha256:8b6850172348c8381b8b3084c5915a4393c2373b9b54cd5b5e1ea15812bc10df"}, + {file = "ruff-0.15.18-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:3fccc153a85417dcd976883160cacce486997b0a0058dd18f54b8aaaac7d1ce2"}, + {file = "ruff-0.15.18-py3-none-macosx_11_0_arm64.whl", hash = "sha256:08d4c86a68f2c3ec2c9d56380a71fb4a4f65373055cbb8caabd645e9102f38d4"}, + {file = "ruff-0.15.18-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:37e5108745c2c0705da916d7d4de533ddf547051ef45f62888c31bae73f66318"}, + {file = "ruff-0.15.18-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:56949a6ce8b3abde54c0bcb22cebfe57e8771cadc84b407ae8b8eaf67ebdcd43"}, + {file = "ruff-0.15.18-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:01a754cd6a1b630d3f97e33eb452cf7a98040482318e870f8bc52a5a30e62657"}, + {file = "ruff-0.15.18-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:6ba7a07e03a44dbf10bb086ee06705b173625014ec99f73a7e6836a5e5590a0c"}, + {file = "ruff-0.15.18-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:5a2c40a41a4cadbcf5897b548ab29dfe248b20c540961c0247d98a3973c70403"}, + {file = "ruff-0.15.18-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5f0480ce690cbb6c4db6e5d08f19fce98e10ba131a8b60c1bcdac42771e3ae2d"}, + {file = "ruff-0.15.18-py3-none-manylinux_2_31_riscv64.whl", hash = "sha256:2330215f1f393fa8733f55edce04fcf94c36a2c460fcde31f78cc84e4951e9b1"}, + {file = "ruff-0.15.18-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:a6aa6a3d979e48ae617578183674bf264fbe7d0114a796a26bd678d67963c7ff"}, + {file = "ruff-0.15.18-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:a81beadbbff2c9c245561ae3f77b16709d87f35eec650d0501679239d3449b22"}, + {file = "ruff-0.15.18-py3-none-musllinux_1_2_i686.whl", hash = "sha256:2186d9e940ae332ab293623a75b5f4fe49565f449954d50a72a046683aa6b809"}, + {file = "ruff-0.15.18-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:5c2abf140438032bc77b2284a6c9944ecd8a19e5f1c7b52b1b8e4a0a80d19a7a"}, + {file = "ruff-0.15.18-py3-none-win32.whl", hash = "sha256:02299e6e9fa5b297a3f6d5d10d7bcd655c925b028bb8b9d4588214549c6b9ec4"}, + {file = "ruff-0.15.18-py3-none-win_amd64.whl", hash = "sha256:dac80dc8d26b2257dbefabed62f5d255c3937b4ccb122da1fc634794fa3578b3"}, + {file = "ruff-0.15.18-py3-none-win_arm64.whl", hash = "sha256:b2c9257fcbd4a3e5b977a1904e6facca016bafe2edc17df24db67cfaee03b4e4"}, + {file = "ruff-0.15.18.tar.gz", hash = "sha256:2698a964c70e8bf402dcb99c8810472d270d141e7aa8c4e13599fd52033a2f33"}, ] [[package]] @@ -1179,78 +989,51 @@ name = "shellingham" version = "1.5.4" requires_python = ">=3.7" summary = "Tool to Detect Surrounding Shell" -groups = ["default", "dev"] +groups = ["default"] files = [ {file = "shellingham-1.5.4-py2.py3-none-any.whl", hash = "sha256:7ecfff8f2fd72616f7481040475a65b2bf8af90a56c89140852d1120324e8686"}, {file = "shellingham-1.5.4.tar.gz", hash = "sha256:8dbca0739d487e5bd35ab3ca4b36e11c4078f3a234bfce294b0a0291363404de"}, ] [[package]] -name = "six" -version = "1.16.0" -requires_python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" -summary = "Python 2 and 3 compatibility utilities" -groups = ["default"] -files = [ - {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"}, - {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"}, -] - -[[package]] -name = "sniffio" -version = "1.3.0" -requires_python = ">=3.7" -summary = "Sniff out which async library your code is running under" -groups = ["default"] +name = "sortedcontainers" +version = "2.4.0" +summary = "Sorted Containers -- Sorted List, Sorted Dict, Sorted Set" +groups = ["dev"] files = [ - {file = "sniffio-1.3.0-py3-none-any.whl", hash = "sha256:eecefdce1e5bbfb7ad2eeaabf7c1eeb404d7757c379bd1f7e5cce9d8bf425384"}, - {file = "sniffio-1.3.0.tar.gz", hash = "sha256:e60305c5e5d314f5389259b7f22aaa33d8f7dee49763119234af3755c55b9101"}, + {file = "sortedcontainers-2.4.0-py2.py3-none-any.whl", hash = "sha256:a163dcaede0f1c021485e957a39245190e74249897e2ae4b2aa38595db237ee0"}, + {file = "sortedcontainers-2.4.0.tar.gz", hash = "sha256:25caa5a06cc30b6b83d11423433f65d1f9d76c4c6a0c90e3379eaa43b9bfdb88"}, ] [[package]] -name = "taskipy" -version = "1.12.2" -requires_python = ">=3.6,<4.0" -summary = "tasks runner for python projects" +name = "syrupy" +version = "5.3.2" +requires_python = ">=3.10" +summary = "Pytest Snapshot Test Utility" groups = ["dev"] dependencies = [ - "colorama<0.5.0,>=0.4.4", - "mslex<2.0.0,>=1.1.0; sys_platform == \"win32\"", - "psutil<6.0.0,>=5.7.2", - "tomli<3.0.0,>=2.0.1; python_version ~= \"3.7\"", + "pytest>=8.0.0", ] files = [ - {file = "taskipy-1.12.2-py3-none-any.whl", hash = "sha256:ffdbb0bb0db54c0ec5c424610a3a087eea22706d4d1f6e3e8b4f12ebba05f98f"}, - {file = "taskipy-1.12.2.tar.gz", hash = "sha256:eadfdc20d6bb94d8018eda32f1dbf584cf4aa6cffb71ba5cc2de20d344f8c4fb"}, -] - -[[package]] -name = "tomli" -version = "2.0.1" -requires_python = ">=3.7" -summary = "A lil' TOML parser" -groups = ["dev"] -marker = "python_version < \"4.0\"" -files = [ - {file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, - {file = "tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, + {file = "syrupy-5.3.2-py3-none-any.whl", hash = "sha256:a4cb08f07342655816c16b6b3aef5f6af8859ef5fbad6a57d0e2c20c0f8be54c"}, + {file = "syrupy-5.3.2.tar.gz", hash = "sha256:d4c9d4badb165a5694dcd869812717d899a8aa0b6f14f842437cb57c4ce09b3a"}, ] [[package]] name = "typer" -version = "0.12.3" -requires_python = ">=3.7" +version = "0.27.0" +requires_python = ">=3.10" summary = "Typer, build great CLIs. Easy to code. Based on Python type hints." -groups = ["default", "dev"] +groups = ["default"] dependencies = [ - "click>=8.0.0", - "rich>=10.11.0", + "annotated-doc>=0.0.2", + "colorama; platform_system == \"Windows\"", + "rich>=13.8.0", "shellingham>=1.3.0", - "typing-extensions>=3.7.4.3", ] files = [ - {file = "typer-0.12.3-py3-none-any.whl", hash = "sha256:070d7ca53f785acbccba8e7d28b08dcd88f79f1fbda035ade0aecec71ca5c914"}, - {file = "typer-0.12.3.tar.gz", hash = "sha256:49e73131481d804288ef62598d97a1ceef3058905aa536a1134f90891ba35482"}, + {file = "typer-0.27.0-py3-none-any.whl", hash = "sha256:6f4b27631e47f077871b7dc30e933ec0131c1390fbe0e387ea5574b5bac9ccf1"}, + {file = "typer-0.27.0.tar.gz", hash = "sha256:629bd12ea5d13a17148125d9a264f949eb171fb3f120f9b04d85873cab054fa5"}, ] [[package]] @@ -1263,46 +1046,38 @@ files = [ {file = "types_certifi-2021.10.8.3-py3-none-any.whl", hash = "sha256:b2d1e325e69f71f7c78e5943d410e650b4707bb0ef32e4ddf3da37f54176e88a"}, ] -[[package]] -name = "types-python-dateutil" -version = "2.9.0.20240316" -requires_python = ">=3.8" -summary = "Typing stubs for python-dateutil" -groups = ["dev"] -files = [ - {file = "types-python-dateutil-2.9.0.20240316.tar.gz", hash = "sha256:5d2f2e240b86905e40944dd787db6da9263f0deabef1076ddaed797351ec0202"}, - {file = "types_python_dateutil-2.9.0.20240316-py3-none-any.whl", hash = "sha256:6b8cb66d960771ce5ff974e9dd45e38facb81718cc1e208b10b1baccbfdbee3b"}, -] - [[package]] name = "types-pyyaml" -version = "6.0.12.20240311" -requires_python = ">=3.8" +version = "6.0.12.20260518" +requires_python = ">=3.10" summary = "Typing stubs for PyYAML" groups = ["dev"] files = [ - {file = "types-PyYAML-6.0.12.20240311.tar.gz", hash = "sha256:a9e0f0f88dc835739b0c1ca51ee90d04ca2a897a71af79de9aec5f38cb0a5342"}, - {file = "types_PyYAML-6.0.12.20240311-py3-none-any.whl", hash = "sha256:b845b06a1c7e54b8e5b4c683043de0d9caf205e7434b3edc678ff2411979b8f6"}, + {file = "types_pyyaml-6.0.12.20260518-py3-none-any.whl", hash = "sha256:d2150f75a231c9fe9c7463bd29487d93e60bac90400287351384bc2284eba7cd"}, + {file = "types_pyyaml-6.0.12.20260518.tar.gz", hash = "sha256:d917f83fb38462550338c1297faedd860b3ec83912b96b1e3d73255f7473e466"}, ] [[package]] name = "typing-extensions" -version = "4.11.0" -requires_python = ">=3.8" -summary = "Backported and Experimental Type Hints for Python 3.8+" +version = "4.15.0" +requires_python = ">=3.9" +summary = "Backported and Experimental Type Hints for Python 3.9+" groups = ["default", "dev"] files = [ - {file = "typing_extensions-4.11.0-py3-none-any.whl", hash = "sha256:c1f94d72897edaf4ce775bb7558d5b79d8126906a14ea5ed1635921406c0387a"}, - {file = "typing_extensions-4.11.0.tar.gz", hash = "sha256:83f085bd5ca59c80295fc2a82ab5dac679cbe02b9f33f7d83af68e241bea51b0"}, + {file = "typing_extensions-4.15.0-py3-none-any.whl", hash = "sha256:f0fa19c6845758ab08074a0cfa8b7aecb71c999ca73d62883bc25cc018c4e548"}, + {file = "typing_extensions-4.15.0.tar.gz", hash = "sha256:0cea48d173cc12fa28ecabc3b837ea3cf6f38c6d1136f85cbaaf598984861466"}, ] [[package]] -name = "urllib3" -version = "2.1.0" -requires_python = ">=3.8" -summary = "HTTP library with thread-safe connection pooling, file post, and more." -groups = ["dev"] +name = "typing-inspection" +version = "0.4.2" +requires_python = ">=3.9" +summary = "Runtime typing introspection tools" +groups = ["default"] +dependencies = [ + "typing-extensions>=4.12.0", +] files = [ - {file = "urllib3-2.1.0-py3-none-any.whl", hash = "sha256:55901e917a5896a349ff771be919f8bd99aff50b79fe58fec595eb37bbc56bb3"}, - {file = "urllib3-2.1.0.tar.gz", hash = "sha256:df7aa8afb0148fa78488e7899b2c59b5f4ffcfa82e6c54ccb9dd37c1d7b52d54"}, + {file = "typing_inspection-0.4.2-py3-none-any.whl", hash = "sha256:4ed1cacbdc298c220f1bd249ed5287caa16f34d44ef4e9c3d0cbad5b521545e7"}, + {file = "typing_inspection-0.4.2.tar.gz", hash = "sha256:ba561c48a67c5958007083d386c3295464928b01faa735ab8547c5692e87f464"}, ] diff --git a/pdm.minimal.lock b/pdm.minimal.lock new file mode 100644 index 000000000..ee5d2ee21 --- /dev/null +++ b/pdm.minimal.lock @@ -0,0 +1,867 @@ +# This file is @generated by PDM. +# It is not intended for manual editing. + +[metadata] +groups = ["default", "dev"] +strategy = ["direct_minimal_versions", "inherit_metadata"] +lock_version = "4.5.0" +content_hash = "sha256:175e4c79af4623cfe2ff416ec1f952a29b9e4dc783133f62fa873455512ea5ca" + +[[metadata.targets]] +requires_python = "~=3.11" + +[[package]] +name = "annotated-types" +version = "0.8.0" +requires_python = ">=3.10" +summary = "Reusable constraint types to use with typing.Annotated" +groups = ["default"] +files = [ + {file = "annotated_types-0.8.0-py3-none-any.whl", hash = "sha256:f072f4d804ea359e4eaf198b1af7a8b0943881a87f31bb764f8bf219bb9419e0"}, + {file = "annotated_types-0.8.0.tar.gz", hash = "sha256:13b2beaad985e05e2d6407ee4c4f35590b11f8d693a258a561055cac8f64cab7"}, +] + +[[package]] +name = "anyio" +version = "4.14.2" +requires_python = ">=3.10" +summary = "High-level concurrency and networking framework on top of asyncio or Trio" +groups = ["default"] +dependencies = [ + "exceptiongroup>=1.0.2; python_version < \"3.11\"", + "idna>=2.8", + "typing-extensions>=4.5; python_version < \"3.13\"", +] +files = [ + {file = "anyio-4.14.2-py3-none-any.whl", hash = "sha256:9f505dda5ac9f0c8309b5e8bd445a8c2bf7246f3ce950121e45ea15bc41d1494"}, + {file = "anyio-4.14.2.tar.gz", hash = "sha256:cfa139f3ed1a23ee8f88a145ddb5ac7605b8bbfd8592baacd7ce3d8bb4313c7f"}, +] + +[[package]] +name = "attrs" +version = "22.2.0" +requires_python = ">=3.6" +summary = "Classes Without Boilerplate" +groups = ["default", "dev"] +files = [ + {file = "attrs-22.2.0-py3-none-any.whl", hash = "sha256:29e95c7f6778868dbd49170f98f8818f78f3dc5e0e37c0b1f474e3561b240836"}, + {file = "attrs-22.2.0.tar.gz", hash = "sha256:c9227bfc2f01993c03f68db37d1d15c9690188323c067c641f1a35ca58185f99"}, +] + +[[package]] +name = "certifi" +version = "2026.7.22" +requires_python = ">=3.7" +summary = "Python package for providing Mozilla's CA Bundle." +groups = ["default"] +files = [ + {file = "certifi-2026.7.22-py3-none-any.whl", hash = "sha256:62f22742b58a1a33014a2b6b706588a8d7e2a88ae7bd1a6ebe8c992928483775"}, + {file = "certifi-2026.7.22.tar.gz", hash = "sha256:741e2c3b351ddf169a738da9f2c048608ff7f2c5cc02f1ebc6b118bb090d5d55"}, +] + +[[package]] +name = "click" +version = "8.4.2" +requires_python = ">=3.10" +summary = "Composable command line interface toolkit" +groups = ["default"] +dependencies = [ + "colorama; platform_system == \"Windows\"", +] +files = [ + {file = "click-8.4.2-py3-none-any.whl", hash = "sha256:e6f9f66136c816745b9d65817da91d61d957fb16e02e4dcd0552553c5a197b76"}, + {file = "click-8.4.2.tar.gz", hash = "sha256:9a6cea6e60b17ebe0a44c5cc636d94f09bd66142c1cd7d8b4cd731c4917a15f6"}, +] + +[[package]] +name = "colorama" +version = "0.4.3" +requires_python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +summary = "Cross-platform colored terminal text." +groups = ["default", "dev"] +marker = "sys_platform == \"win32\" or platform_system == \"Windows\"" +files = [ + {file = "colorama-0.4.3-py2.py3-none-any.whl", hash = "sha256:7d73d2a99753107a36ac6b455ee49046802e59d9d076ef8e47b61499fa29afff"}, + {file = "colorama-0.4.3.tar.gz", hash = "sha256:e96da0d330793e2cb9485e9ddfd918d456036c7149416295932478192f4436a1"}, +] + +[[package]] +name = "coverage" +version = "7.15.4" +requires_python = ">=3.10" +summary = "Code coverage measurement for Python" +groups = ["dev"] +files = [ + {file = "coverage-7.15.4-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:bbac5abad70df71019988f83f26ac7092ff2642975def4429e98dc7585ef3490"}, + {file = "coverage-7.15.4-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:357a173465c7ce028d07a95cc2b63b5bf59f50ecdd5ad75c5cbb78ada984048e"}, + {file = "coverage-7.15.4-cp311-cp311-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:21b803935e2efc3acebe9697197a294fccf5dc4e5382bd6369542ff7a7d2a1d7"}, + {file = "coverage-7.15.4-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:7a2b580774a4786c1053157c0165e04476e03ff293993d7c148eee784a94bae6"}, + {file = "coverage-7.15.4-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:a9464451c4efffe8d47ace5a540b10b0dc10e879066290f8600872b7f54a419d"}, + {file = "coverage-7.15.4-cp311-cp311-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:de602f34123c2f4af1c1869c6dbbbd60da6d5983bf01937367295d135cccbfce"}, + {file = "coverage-7.15.4-cp311-cp311-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:6879ded16a27f3eeca19b900c147e81616e7054db451471a611b2755ee5249f7"}, + {file = "coverage-7.15.4-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:986be58c3ab54aae8d3496a6225eea74f760fdbe739b38bd442c7e8d133aa53b"}, + {file = "coverage-7.15.4-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:c6103639613fe6c1e989082948419bc77a2d26b6c825c99d7fad25f7d3d87afc"}, + {file = "coverage-7.15.4-cp311-cp311-musllinux_1_2_ppc64le.whl", hash = "sha256:d3af93dddb5659276c63bc16ac6466ac2033a70ca816097bbc06345b8ccdf571"}, + {file = "coverage-7.15.4-cp311-cp311-musllinux_1_2_riscv64.whl", hash = "sha256:b10075e5421d04265766a6d1dac809bbeb8a946fbb23c8f82c227409b2190719"}, + {file = "coverage-7.15.4-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:a67a9f78b2942d87ba8ce3059c642164d2aedd65337377fb52fe9803656bc5c7"}, + {file = "coverage-7.15.4-cp311-cp311-win32.whl", hash = "sha256:69484d1aca26e322e1c3ce03f09341e84524ababad2d7202161738d83cc9f82e"}, + {file = "coverage-7.15.4-cp311-cp311-win_amd64.whl", hash = "sha256:63fd6fcd1dd6e158f7eb78606e72933b3f6d01e7b747f99c6c12d764307a0fdc"}, + {file = "coverage-7.15.4-cp311-cp311-win_arm64.whl", hash = "sha256:ea82116c9893fa89e929b7f197ee5a1950a76e91cc5c85ba503fc02379d04890"}, + {file = "coverage-7.15.4-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:d4fedd1f7f428f9fe83b1ead5e7cc87a43427be31aadafbac3ac0636dc7abb22"}, + {file = "coverage-7.15.4-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:37e2f0cdf58e2e1fed4e4d5a8f8786ae2f7eb80b478016876667dc4a01d60a97"}, + {file = "coverage-7.15.4-cp312-cp312-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:fb55d0e70bb15f2e81477613627286581414693d74ac7963c93a790dd453ca9d"}, + {file = "coverage-7.15.4-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:899b9da30f3c6c336566e3707495bb23e8302d39d862f01fa78c48b99b9437e2"}, + {file = "coverage-7.15.4-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:d15715e8c46552827e5e4f30a35575a2dbcad14454cf3284c54483946bd16931"}, + {file = "coverage-7.15.4-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:002a438859f7b430bc99afeaf01a6d187dad1d0dc907b64cdeffc632a5db8fd8"}, + {file = "coverage-7.15.4-cp312-cp312-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:e4193a04b518f7968f3099755f5509ee7cccc6dc2b92a6b14841934d22e222c9"}, + {file = "coverage-7.15.4-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:e98dcc55d572b38e69d117da7e8e8efb8500f1f5eaf81ecd460a63220790b839"}, + {file = "coverage-7.15.4-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:af6c538498ce66c10d3fd541c2a8d5b03da5850355add34e6cba564210cb9e72"}, + {file = "coverage-7.15.4-cp312-cp312-musllinux_1_2_ppc64le.whl", hash = "sha256:1d10025d96ea89fc2f73714dbc4cbd433fe012c1ac9e23f895d7728b238b6e52"}, + {file = "coverage-7.15.4-cp312-cp312-musllinux_1_2_riscv64.whl", hash = "sha256:d802e1947603162ded419bff83ac7489820355d2b856dfb09206574e3a37ac0c"}, + {file = "coverage-7.15.4-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:c2de40895718f91951b86712b4c5b694acaf9a0a49be13874896f599a1eed3f4"}, + {file = "coverage-7.15.4-cp312-cp312-win32.whl", hash = "sha256:5c3431b2161279b7db5c2a1aa58ae02e5cb8c3c42d93a5094be3f5537bd5b11b"}, + {file = "coverage-7.15.4-cp312-cp312-win_amd64.whl", hash = "sha256:6befeab5fb2b51c958ca4ac6c5d141a1e8240f4f76e46350f1911963deda49cd"}, + {file = "coverage-7.15.4-cp312-cp312-win_arm64.whl", hash = "sha256:67bc345491ab55b837277d76f5775d057e8c7f1ac44d890d8c2c82adde258c6f"}, + {file = "coverage-7.15.4-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:c705b28feb2775dc82a25f1d473a370bc37ff93f5177f4e29ce2425f560f6921"}, + {file = "coverage-7.15.4-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:3ff205ab5e3ecc670f6a4dd19d9cbf12ede53dd41cfc1e15716ec961ea6d314e"}, + {file = "coverage-7.15.4-cp313-cp313-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:5172326e861a38b48b48befca15e0f477a26b283337a33a739c8fed229934e36"}, + {file = "coverage-7.15.4-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:12b59c90084e3234fb11184886bf4a40f4f16a8c8f867be2e087b81f8e8868d4"}, + {file = "coverage-7.15.4-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:349062d66f00b40fa2c1c222438bad25fabf755631b5d82937fe985c8008615c"}, + {file = "coverage-7.15.4-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:4256ced708e598e05209bc1a8ab4074e04a51dba4c62fb45926a229af675ace7"}, + {file = "coverage-7.15.4-cp313-cp313-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:d80f974b20782d9612c8b4c9beeca867074c7cf4079d1419843fa25a26428b25"}, + {file = "coverage-7.15.4-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:2e179f19bfe1d31f8eeeaa12990194d761c4f62f0759661000bca6cd8729f40b"}, + {file = "coverage-7.15.4-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:8bc16bb47b7679670eceff71d78bfb7d6e5b143f6c2cd117487ec7c75e0d4b78"}, + {file = "coverage-7.15.4-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:1cd685005cd2c4200adfc14cf39a603b9320efab3f18a8f7f156d20c9cc3345f"}, + {file = "coverage-7.15.4-cp313-cp313-musllinux_1_2_riscv64.whl", hash = "sha256:337399ad2c93b3acd2a937627dae8b3e86b66707cd3d3e856347999aadf1ef8d"}, + {file = "coverage-7.15.4-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:96e257121228ec5cd2bb919276e94ac11074471bc37d68dbae0e8308cce15fff"}, + {file = "coverage-7.15.4-cp313-cp313-win32.whl", hash = "sha256:c65a9e0dfc6143491879da4e13b5e30f8be192055de508d737fb14601edbd22c"}, + {file = "coverage-7.15.4-cp313-cp313-win_amd64.whl", hash = "sha256:2ff8f5e9b8f7a94f0c11c45631eee103dbcb7d63274edd12c56efe1be690b3b4"}, + {file = "coverage-7.15.4-cp313-cp313-win_arm64.whl", hash = "sha256:6e0a8a5083b096487d6cfced94cdd514d8f5db6f113610fb36c0620edb1028cf"}, + {file = "coverage-7.15.4-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:770e9325ab5ea6d56f77e59b29ecfe0ac20b57a82a601876f90494a4dda0386f"}, + {file = "coverage-7.15.4-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:d12b33a3a50a1676b7784dc8d00a0c6d66a9f2add4b85a041c19b6a7e53ef23c"}, + {file = "coverage-7.15.4-cp314-cp314-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:5669c8378ebde86f5def7a25d29586631b58acc27ffde04399f678f3dfc6e082"}, + {file = "coverage-7.15.4-cp314-cp314-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:ff97a14362eef486483ed44042ca2027ea257df6ff768e62358ee0c9776925ac"}, + {file = "coverage-7.15.4-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:5a325e815318638aed1655d9c06e6d7c2d3d46c09231ce988070428a8762d734"}, + {file = "coverage-7.15.4-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:474223409d88eb20d2d6a0d37ea60e8647a65a90cc008dc1f0410af5f64f1e0d"}, + {file = "coverage-7.15.4-cp314-cp314-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:7f2f62ae3cd189dd2e13aece758c57b3eecbd27be070dbd4cbd10936049e5dbf"}, + {file = "coverage-7.15.4-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:39ece820e29e0a2ba34b3ecb3be83c27e997eed8926f2ba6fe7ce7a0bda5843b"}, + {file = "coverage-7.15.4-cp314-cp314-musllinux_1_2_i686.whl", hash = "sha256:f21b56dcace11dfe013014201f577dcd592b2a9b72182d930361b47cf6f73f25"}, + {file = "coverage-7.15.4-cp314-cp314-musllinux_1_2_ppc64le.whl", hash = "sha256:93a3a0b662abcc10c73a47cbc72cd60f63618d6989fb2d1286e50eacd974f303"}, + {file = "coverage-7.15.4-cp314-cp314-musllinux_1_2_riscv64.whl", hash = "sha256:141fae2cabf5569b782c10afc4c850ce10f618c13f8db54765cba99cc839da1f"}, + {file = "coverage-7.15.4-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:81294c7e6ab30c5f74c0353b11b2fd6320e72d9bee6ac73b357caa8b916323a5"}, + {file = "coverage-7.15.4-cp314-cp314-win32.whl", hash = "sha256:7bbd7d6418e0dab31a206af5203bd43ae36edb8e7fba1940b055d3e9249290d7"}, + {file = "coverage-7.15.4-cp314-cp314-win_amd64.whl", hash = "sha256:f0204ed122758782970526057093f448051a39db9d810d4e344bb87a3546f425"}, + {file = "coverage-7.15.4-cp314-cp314-win_arm64.whl", hash = "sha256:9e71e7bc71c686a123347ae47a0de33a175e797a85bb57b791492adf4eec8ed8"}, + {file = "coverage-7.15.4-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:7c922735321eef3f87c280a3d39afff6b646723a2880b862cda4ac7a093b8aa8"}, + {file = "coverage-7.15.4-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:f41c17c4668a655ce96d090d8d5ffdc24ef64b5a02f9753884d08483e8a4a41a"}, + {file = "coverage-7.15.4-cp314-cp314t-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:46822e9b6ff1c6a72b518c162c44a8f45a61a1d609c51084bf5b16c023c5037b"}, + {file = "coverage-7.15.4-cp314-cp314t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:3d6f4955b73b5445271379a59e3792b0d978f42d4a01e0cf7a67d9c33a3bb0a5"}, + {file = "coverage-7.15.4-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:3fc9e047706fb4a9abb54f719d3aa643e80e5bb3818182c40aee01ac0f0247ba"}, + {file = "coverage-7.15.4-cp314-cp314t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:05e491d4f3165d62d4f5c8fd48dfeabf2ae8f42cbbd484319af33ea851b78982"}, + {file = "coverage-7.15.4-cp314-cp314t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:226c66e80ec0598d3b9b4874123df167ccca342aca8714f77cac6829688ee09c"}, + {file = "coverage-7.15.4-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:ac41cc14bebda0dbfb0628036b7f75706935c95bcc07fefe9a0f93614aa60a57"}, + {file = "coverage-7.15.4-cp314-cp314t-musllinux_1_2_i686.whl", hash = "sha256:8af623e5cd92080acddd02b38f2f406a2c3a0893c38950b211890361448fbf26"}, + {file = "coverage-7.15.4-cp314-cp314t-musllinux_1_2_ppc64le.whl", hash = "sha256:07545711d4f0f32852a18f18ad11f76f0109909d09e78b9008b4cfc67e829429"}, + {file = "coverage-7.15.4-cp314-cp314t-musllinux_1_2_riscv64.whl", hash = "sha256:a0865421cfdc53654b342d515e5a233187590882d20b95752150e53f65460017"}, + {file = "coverage-7.15.4-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:460115e32ee40566476db5048f9bec1e842c127ad8e6f8be745aad3ac9cbc839"}, + {file = "coverage-7.15.4-cp314-cp314t-win32.whl", hash = "sha256:cbde877ef9dd7baf272b9bfef2b8a25edd45d9170fc326951dd20eb480335e85"}, + {file = "coverage-7.15.4-cp314-cp314t-win_amd64.whl", hash = "sha256:3da9e92d1c551fd7563833e9ade686efb0c4b7363ab7681a94283958c950bf5e"}, + {file = "coverage-7.15.4-cp314-cp314t-win_arm64.whl", hash = "sha256:3a54f5a0d85050c73a38f6793090ee83974531e67fe5e57a1da9bee11398aa5e"}, + {file = "coverage-7.15.4-cp315-cp315-macosx_10_15_x86_64.whl", hash = "sha256:2c9872e4d9dc5d3cf616bf4b382f5a00359305a5be666a3dd0b5cdb4e49597f9"}, + {file = "coverage-7.15.4-cp315-cp315-macosx_11_0_arm64.whl", hash = "sha256:e101dbb4b9b72f0cddd8cdc8c9c5b47f456766f5e0ac82dbfb75e5c55409b78a"}, + {file = "coverage-7.15.4-cp315-cp315-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:7d1abebdb047729e852b9c77a00497dfbeb11eb3a117e037d7dbc3ac8e5f5c54"}, + {file = "coverage-7.15.4-cp315-cp315-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:d28a4a899354d0ea6214cc59b4fa19eefbce1b9ff1688ab579acf49e894bd3fb"}, + {file = "coverage-7.15.4-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:ffb3c2aacea411cc7e1d27712490c11108e2de1d39019ae32915493a59a8b9ed"}, + {file = "coverage-7.15.4-cp315-cp315-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:a9447978a92f405d301123cfd39ff49895490efb769a758fe2734c7f631bf8ce"}, + {file = "coverage-7.15.4-cp315-cp315-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:050467a7983b8e2fe7dd41a78bb30c3e7f8c0b8cafda14b1c46f8b5e3cf2dd3c"}, + {file = "coverage-7.15.4-cp315-cp315-musllinux_1_2_aarch64.whl", hash = "sha256:d003b7a5708ddad5c206c79607a6b92abb6fc13c57d99d8a4468cc03a2941ced"}, + {file = "coverage-7.15.4-cp315-cp315-musllinux_1_2_i686.whl", hash = "sha256:c38efe30fd74e5c19e9433f11fb1f5dc9c6522770971b7c6145bbaa413dc8800"}, + {file = "coverage-7.15.4-cp315-cp315-musllinux_1_2_ppc64le.whl", hash = "sha256:1f4f826d70f772ab8b0c052329580d7fe8b8abd191e4ce0c8f81aec6614665d3"}, + {file = "coverage-7.15.4-cp315-cp315-musllinux_1_2_riscv64.whl", hash = "sha256:4a4bf917c9953f57c957be31c1cd504e3bd2f34d4a352b9d391a3025336f6768"}, + {file = "coverage-7.15.4-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:1c9bf40ebef178a45192c75c4964760bb261b0e6ad725da5fc4c93f674f19753"}, + {file = "coverage-7.15.4-cp315-cp315-win32.whl", hash = "sha256:43619d04c3671792d2c4706ae8bf45e265dc87bbd4078189ef8b847ea1e74be2"}, + {file = "coverage-7.15.4-cp315-cp315-win_amd64.whl", hash = "sha256:be619439dbcd31a2eab10b32de9fff62c26ed4bab69dc32b8363fdaaa0882809"}, + {file = "coverage-7.15.4-cp315-cp315-win_arm64.whl", hash = "sha256:def597967dafc2e8d97c9097ea453c464e0bb8ed38f193a43070f10dc623bb6d"}, + {file = "coverage-7.15.4-cp315-cp315t-macosx_10_15_x86_64.whl", hash = "sha256:c7dbc748ac8a1e3e59a2b28bea47675e6e778081dbbf081bde0d75def2fcbe1d"}, + {file = "coverage-7.15.4-cp315-cp315t-macosx_11_0_arm64.whl", hash = "sha256:2413074a5ecbb61a01a7888fc72db0ca324d13588c5b38bc0dd8564cdcdfea26"}, + {file = "coverage-7.15.4-cp315-cp315t-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:4e6f6f632b7b2f714bf7a1346e8f97b650ee71f3c298aaad42a2ab60f0f07645"}, + {file = "coverage-7.15.4-cp315-cp315t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:8df457da2249d3c75ca2e5e835d59c725abfe92d27fdff6cd99eed85b51d5e9a"}, + {file = "coverage-7.15.4-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:050f66a08805acb5b8a23c6d4a517b1ecf82c08e81ed0e4bd727df065e5c6624"}, + {file = "coverage-7.15.4-cp315-cp315t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:1587fb771d1ccceef708fdde1e5af8c7ed24b486b61d13a321acb7d8145390aa"}, + {file = "coverage-7.15.4-cp315-cp315t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:8b4f1c3a69ca580f3fbd6b2046915f536d7f586874f25c1bb23add2a3c88d50f"}, + {file = "coverage-7.15.4-cp315-cp315t-musllinux_1_2_aarch64.whl", hash = "sha256:ffb58d7eff5b7f6ecc6fa21d6288ab7f968a212cb67d682c269c09b9eba3b66f"}, + {file = "coverage-7.15.4-cp315-cp315t-musllinux_1_2_i686.whl", hash = "sha256:d9df165544774574ee004b953023d1bebada1894a80b1052a43d798b0f676e67"}, + {file = "coverage-7.15.4-cp315-cp315t-musllinux_1_2_ppc64le.whl", hash = "sha256:f9de0a24a4079b53e523b5c5e2c5945ec251ab486652659955187cf255a259bc"}, + {file = "coverage-7.15.4-cp315-cp315t-musllinux_1_2_riscv64.whl", hash = "sha256:150089274bdc9f940628552cb92844e0223c987f1902ab8efe9f45a2ec758d88"}, + {file = "coverage-7.15.4-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:a58a94fed5da6997d258e8f7668c1e195fbd04a691d781b7558f1e468f9e68bc"}, + {file = "coverage-7.15.4-cp315-cp315t-win32.whl", hash = "sha256:ebd5a6d8466ff30836572f3ba2cae8a5e8f85029b1c6d5e2ed338dc472a5166a"}, + {file = "coverage-7.15.4-cp315-cp315t-win_amd64.whl", hash = "sha256:288bde2a2d7ab6b6c2d7252fcde8b524387f2d970bdba9658fc6f8bbcaef0f9b"}, + {file = "coverage-7.15.4-cp315-cp315t-win_arm64.whl", hash = "sha256:68be5e1de60ff13c9095bbec0e5a7fa45b33b101752215b91345ea1f61c4a278"}, + {file = "coverage-7.15.4-py3-none-any.whl", hash = "sha256:964730a1e9de9c0cf11be6a1a3c79ce419c34882842abd256086ba4698705e84"}, + {file = "coverage-7.15.4.tar.gz", hash = "sha256:0548198fff07ccf4faf469520bce1c2eceb1ce3e62891921138dec10907f9d00"}, +] + +[[package]] +name = "execnet" +version = "2.1.2" +requires_python = ">=3.8" +summary = "execnet: rapid multi-Python deployment" +groups = ["dev"] +files = [ + {file = "execnet-2.1.2-py3-none-any.whl", hash = "sha256:67fba928dd5a544b783f6056f449e5e3931a5c378b128bc18501f7ea79e296ec"}, + {file = "execnet-2.1.2.tar.gz", hash = "sha256:63d83bfdd9a23e35b9c6a3261412324f964c2ec8dcd8d3c6916ee9373e0befcd"}, +] + +[[package]] +name = "h11" +version = "0.14.0" +requires_python = ">=3.7" +summary = "A pure-Python, bring-your-own-I/O implementation of HTTP/1.1" +groups = ["default"] +dependencies = [ + "typing-extensions; python_version < \"3.8\"", +] +files = [ + {file = "h11-0.14.0-py3-none-any.whl", hash = "sha256:e3fe4ac4b851c468cc8363d500db52c2ead036020723024a109d37346efaa761"}, + {file = "h11-0.14.0.tar.gz", hash = "sha256:8f19fbbe99e72420ff35c00b27a34cb9937e902a8b810e2c88300c6f0a3b699d"}, +] + +[[package]] +name = "httpcore" +version = "0.16.3" +requires_python = ">=3.7" +summary = "A minimal low-level HTTP client." +groups = ["default"] +dependencies = [ + "anyio<5.0,>=3.0", + "certifi", + "h11<0.15,>=0.13", + "sniffio==1.*", +] +files = [ + {file = "httpcore-0.16.3-py3-none-any.whl", hash = "sha256:da1fb708784a938aa084bde4feb8317056c55037247c787bd7e19eb2c2949dc0"}, + {file = "httpcore-0.16.3.tar.gz", hash = "sha256:c5d6f04e2fc530f39e0c077e6a30caa53f1451096120f1f38b954afd0b17c0cb"}, +] + +[[package]] +name = "httpx" +version = "0.23.1" +requires_python = ">=3.7" +summary = "The next generation HTTP client." +groups = ["default"] +dependencies = [ + "certifi", + "httpcore<0.17.0,>=0.15.0", + "rfc3986[idna2008]<2,>=1.3", + "sniffio", +] +files = [ + {file = "httpx-0.23.1-py3-none-any.whl", hash = "sha256:0b9b1f0ee18b9978d637b0776bfd7f54e2ca278e063e3586d8f01cda89e042a8"}, + {file = "httpx-0.23.1.tar.gz", hash = "sha256:202ae15319be24efe9a8bd4ed4360e68fde7b38bcc2ce87088d416f026667d19"}, +] + +[[package]] +name = "hypothesis" +version = "6.100.0" +requires_python = ">=3.8" +summary = "A library for property-based testing" +groups = ["dev"] +dependencies = [ + "attrs>=22.2.0", + "exceptiongroup>=1.0.0; python_version < \"3.11\"", + "sortedcontainers<3.0.0,>=2.1.0", +] +files = [ + {file = "hypothesis-6.100.0-py3-none-any.whl", hash = "sha256:ceaeb7c051085dbec37f2fc4dca524b6304472ff1887fed53b3d84705507c10e"}, + {file = "hypothesis-6.100.0.tar.gz", hash = "sha256:1841f6b5083844cd4b66965e44a17c0dc8fe8e9c6370c1f7b8d50647fcb2efd3"}, +] + +[[package]] +name = "idna" +version = "3.19" +requires_python = ">=3.9" +summary = "Internationalized Domain Names in Applications (IDNA)" +groups = ["default"] +files = [ + {file = "idna-3.19-py3-none-any.whl", hash = "sha256:815e7be7a7806d54abb586dc943addc79e8b2ee16915059658cbeff4b1b43bf4"}, + {file = "idna-3.19.tar.gz", hash = "sha256:5e0811a4383b21dc5838069f801c4fb62113b7447663d2530d2bd6e77b49bf15"}, +] + +[[package]] +name = "iniconfig" +version = "2.3.0" +requires_python = ">=3.10" +summary = "brain-dead simple config-ini parsing" +groups = ["dev"] +files = [ + {file = "iniconfig-2.3.0-py3-none-any.whl", hash = "sha256:f631c04d2c48c52b84d0d0549c99ff3859c98df65b3101406327ecc7d53fbf12"}, + {file = "iniconfig-2.3.0.tar.gz", hash = "sha256:c76315c77db068650d49c5b56314774a7804df16fee4402c1f19d6d15d8c4730"}, +] + +[[package]] +name = "jinja2" +version = "3.0.0" +requires_python = ">=3.6" +summary = "A very fast and expressive template engine." +groups = ["default"] +dependencies = [ + "MarkupSafe>=2.0.0rc2", +] +files = [ + {file = "Jinja2-3.0.0-py3-none-any.whl", hash = "sha256:2f2de5285cf37f33d33ecd4a9080b75c87cd0c1994d5a9c6df17131ea1f049c6"}, + {file = "Jinja2-3.0.0.tar.gz", hash = "sha256:ea8d7dd814ce9df6de6a761ec7f1cac98afe305b8cdc4aaae4e114b8d8ce24c5"}, +] + +[[package]] +name = "markdown-it-py" +version = "4.2.0" +requires_python = ">=3.10" +summary = "Python port of markdown-it. Markdown parsing, done right!" +groups = ["default"] +dependencies = [ + "mdurl~=0.1", +] +files = [ + {file = "markdown_it_py-4.2.0-py3-none-any.whl", hash = "sha256:9f7ebbcd14fe59494226453aed97c1070d83f8d24b6fc3a3bcf9a38092641c4a"}, + {file = "markdown_it_py-4.2.0.tar.gz", hash = "sha256:04a21681d6fbb623de53f6f364d352309d4094dd4194040a10fd51833e418d49"}, +] + +[[package]] +name = "markupsafe" +version = "3.0.3" +requires_python = ">=3.9" +summary = "Safely add untrusted strings to HTML/XML markup." +groups = ["default"] +files = [ + {file = "markupsafe-3.0.3-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:1cc7ea17a6824959616c525620e387f6dd30fec8cb44f649e31712db02123dad"}, + {file = "markupsafe-3.0.3-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:4bd4cd07944443f5a265608cc6aab442e4f74dff8088b0dfc8238647b8f6ae9a"}, + {file = "markupsafe-3.0.3-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:6b5420a1d9450023228968e7e6a9ce57f65d148ab56d2313fcd589eee96a7a50"}, + {file = "markupsafe-3.0.3-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:0bf2a864d67e76e5c9a34dc26ec616a66b9888e25e7b9460e1c76d3293bd9dbf"}, + {file = "markupsafe-3.0.3-cp311-cp311-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:bc51efed119bc9cfdf792cdeaa4d67e8f6fcccab66ed4bfdd6bde3e59bfcbb2f"}, + {file = "markupsafe-3.0.3-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:068f375c472b3e7acbe2d5318dea141359e6900156b5b2ba06a30b169086b91a"}, + {file = "markupsafe-3.0.3-cp311-cp311-musllinux_1_2_riscv64.whl", hash = "sha256:7be7b61bb172e1ed687f1754f8e7484f1c8019780f6f6b0786e76bb01c2ae115"}, + {file = "markupsafe-3.0.3-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:f9e130248f4462aaa8e2552d547f36ddadbeaa573879158d721bbd33dfe4743a"}, + {file = "markupsafe-3.0.3-cp311-cp311-win32.whl", hash = "sha256:0db14f5dafddbb6d9208827849fad01f1a2609380add406671a26386cdf15a19"}, + {file = "markupsafe-3.0.3-cp311-cp311-win_amd64.whl", hash = "sha256:de8a88e63464af587c950061a5e6a67d3632e36df62b986892331d4620a35c01"}, + {file = "markupsafe-3.0.3-cp311-cp311-win_arm64.whl", hash = "sha256:3b562dd9e9ea93f13d53989d23a7e775fdfd1066c33494ff43f5418bc8c58a5c"}, + {file = "markupsafe-3.0.3-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:d53197da72cc091b024dd97249dfc7794d6a56530370992a5e1a08983ad9230e"}, + {file = "markupsafe-3.0.3-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:1872df69a4de6aead3491198eaf13810b565bdbeec3ae2dc8780f14458ec73ce"}, + {file = "markupsafe-3.0.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:3a7e8ae81ae39e62a41ec302f972ba6ae23a5c5396c8e60113e9066ef893da0d"}, + {file = "markupsafe-3.0.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:d6dd0be5b5b189d31db7cda48b91d7e0a9795f31430b7f271219ab30f1d3ac9d"}, + {file = "markupsafe-3.0.3-cp312-cp312-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:94c6f0bb423f739146aec64595853541634bde58b2135f27f61c1ffd1cd4d16a"}, + {file = "markupsafe-3.0.3-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:be8813b57049a7dc738189df53d69395eba14fb99345e0a5994914a3864c8a4b"}, + {file = "markupsafe-3.0.3-cp312-cp312-musllinux_1_2_riscv64.whl", hash = "sha256:83891d0e9fb81a825d9a6d61e3f07550ca70a076484292a70fde82c4b807286f"}, + {file = "markupsafe-3.0.3-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:77f0643abe7495da77fb436f50f8dab76dbc6e5fd25d39589a0f1fe6548bfa2b"}, + {file = "markupsafe-3.0.3-cp312-cp312-win32.whl", hash = "sha256:d88b440e37a16e651bda4c7c2b930eb586fd15ca7406cb39e211fcff3bf3017d"}, + {file = "markupsafe-3.0.3-cp312-cp312-win_amd64.whl", hash = "sha256:26a5784ded40c9e318cfc2bdb30fe164bdb8665ded9cd64d500a34fb42067b1c"}, + {file = "markupsafe-3.0.3-cp312-cp312-win_arm64.whl", hash = "sha256:35add3b638a5d900e807944a078b51922212fb3dedb01633a8defc4b01a3c85f"}, + {file = "markupsafe-3.0.3-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:e1cf1972137e83c5d4c136c43ced9ac51d0e124706ee1c8aa8532c1287fa8795"}, + {file = "markupsafe-3.0.3-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:116bb52f642a37c115f517494ea5feb03889e04df47eeff5b130b1808ce7c219"}, + {file = "markupsafe-3.0.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:133a43e73a802c5562be9bbcd03d090aa5a1fe899db609c29e8c8d815c5f6de6"}, + {file = "markupsafe-3.0.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:ccfcd093f13f0f0b7fdd0f198b90053bf7b2f02a3927a30e63f3ccc9df56b676"}, + {file = "markupsafe-3.0.3-cp313-cp313-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:509fa21c6deb7a7a273d629cf5ec029bc209d1a51178615ddf718f5918992ab9"}, + {file = "markupsafe-3.0.3-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:a4afe79fb3de0b7097d81da19090f4df4f8d3a2b3adaa8764138aac2e44f3af1"}, + {file = "markupsafe-3.0.3-cp313-cp313-musllinux_1_2_riscv64.whl", hash = "sha256:795e7751525cae078558e679d646ae45574b47ed6e7771863fcc079a6171a0fc"}, + {file = "markupsafe-3.0.3-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:8485f406a96febb5140bfeca44a73e3ce5116b2501ac54fe953e488fb1d03b12"}, + {file = "markupsafe-3.0.3-cp313-cp313-win32.whl", hash = "sha256:bdd37121970bfd8be76c5fb069c7751683bdf373db1ed6c010162b2a130248ed"}, + {file = "markupsafe-3.0.3-cp313-cp313-win_amd64.whl", hash = "sha256:9a1abfdc021a164803f4d485104931fb8f8c1efd55bc6b748d2f5774e78b62c5"}, + {file = "markupsafe-3.0.3-cp313-cp313-win_arm64.whl", hash = "sha256:7e68f88e5b8799aa49c85cd116c932a1ac15caaa3f5db09087854d218359e485"}, + {file = "markupsafe-3.0.3-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:218551f6df4868a8d527e3062d0fb968682fe92054e89978594c28e642c43a73"}, + {file = "markupsafe-3.0.3-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:3524b778fe5cfb3452a09d31e7b5adefeea8c5be1d43c4f810ba09f2ceb29d37"}, + {file = "markupsafe-3.0.3-cp313-cp313t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:4e885a3d1efa2eadc93c894a21770e4bc67899e3543680313b09f139e149ab19"}, + {file = "markupsafe-3.0.3-cp313-cp313t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:8709b08f4a89aa7586de0aadc8da56180242ee0ada3999749b183aa23df95025"}, + {file = "markupsafe-3.0.3-cp313-cp313t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:b8512a91625c9b3da6f127803b166b629725e68af71f8184ae7e7d54686a56d6"}, + {file = "markupsafe-3.0.3-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:9b79b7a16f7fedff2495d684f2b59b0457c3b493778c9eed31111be64d58279f"}, + {file = "markupsafe-3.0.3-cp313-cp313t-musllinux_1_2_riscv64.whl", hash = "sha256:12c63dfb4a98206f045aa9563db46507995f7ef6d83b2f68eda65c307c6829eb"}, + {file = "markupsafe-3.0.3-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:8f71bc33915be5186016f675cd83a1e08523649b0e33efdb898db577ef5bb009"}, + {file = "markupsafe-3.0.3-cp313-cp313t-win32.whl", hash = "sha256:69c0b73548bc525c8cb9a251cddf1931d1db4d2258e9599c28c07ef3580ef354"}, + {file = "markupsafe-3.0.3-cp313-cp313t-win_amd64.whl", hash = "sha256:1b4b79e8ebf6b55351f0d91fe80f893b4743f104bff22e90697db1590e47a218"}, + {file = "markupsafe-3.0.3-cp313-cp313t-win_arm64.whl", hash = "sha256:ad2cf8aa28b8c020ab2fc8287b0f823d0a7d8630784c31e9ee5edea20f406287"}, + {file = "markupsafe-3.0.3-cp314-cp314-macosx_10_13_x86_64.whl", hash = "sha256:eaa9599de571d72e2daf60164784109f19978b327a3910d3e9de8c97b5b70cfe"}, + {file = "markupsafe-3.0.3-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:c47a551199eb8eb2121d4f0f15ae0f923d31350ab9280078d1e5f12b249e0026"}, + {file = "markupsafe-3.0.3-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:f34c41761022dd093b4b6896d4810782ffbabe30f2d443ff5f083e0cbbb8c737"}, + {file = "markupsafe-3.0.3-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:457a69a9577064c05a97c41f4e65148652db078a3a509039e64d3467b9e7ef97"}, + {file = "markupsafe-3.0.3-cp314-cp314-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:e8afc3f2ccfa24215f8cb28dcf43f0113ac3c37c2f0f0806d8c70e4228c5cf4d"}, + {file = "markupsafe-3.0.3-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:ec15a59cf5af7be74194f7ab02d0f59a62bdcf1a537677ce67a2537c9b87fcda"}, + {file = "markupsafe-3.0.3-cp314-cp314-musllinux_1_2_riscv64.whl", hash = "sha256:0eb9ff8191e8498cca014656ae6b8d61f39da5f95b488805da4bb029cccbfbaf"}, + {file = "markupsafe-3.0.3-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:2713baf880df847f2bece4230d4d094280f4e67b1e813eec43b4c0e144a34ffe"}, + {file = "markupsafe-3.0.3-cp314-cp314-win32.whl", hash = "sha256:729586769a26dbceff69f7a7dbbf59ab6572b99d94576a5592625d5b411576b9"}, + {file = "markupsafe-3.0.3-cp314-cp314-win_amd64.whl", hash = "sha256:bdc919ead48f234740ad807933cdf545180bfbe9342c2bb451556db2ed958581"}, + {file = "markupsafe-3.0.3-cp314-cp314-win_arm64.whl", hash = "sha256:5a7d5dc5140555cf21a6fefbdbf8723f06fcd2f63ef108f2854de715e4422cb4"}, + {file = "markupsafe-3.0.3-cp314-cp314t-macosx_10_13_x86_64.whl", hash = "sha256:1353ef0c1b138e1907ae78e2f6c63ff67501122006b0f9abad68fda5f4ffc6ab"}, + {file = "markupsafe-3.0.3-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:1085e7fbddd3be5f89cc898938f42c0b3c711fdcb37d75221de2666af647c175"}, + {file = "markupsafe-3.0.3-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:1b52b4fb9df4eb9ae465f8d0c228a00624de2334f216f178a995ccdcf82c4634"}, + {file = "markupsafe-3.0.3-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:fed51ac40f757d41b7c48425901843666a6677e3e8eb0abcff09e4ba6e664f50"}, + {file = "markupsafe-3.0.3-cp314-cp314t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:f190daf01f13c72eac4efd5c430a8de82489d9cff23c364c3ea822545032993e"}, + {file = "markupsafe-3.0.3-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:e56b7d45a839a697b5eb268c82a71bd8c7f6c94d6fd50c3d577fa39a9f1409f5"}, + {file = "markupsafe-3.0.3-cp314-cp314t-musllinux_1_2_riscv64.whl", hash = "sha256:f3e98bb3798ead92273dc0e5fd0f31ade220f59a266ffd8a4f6065e0a3ce0523"}, + {file = "markupsafe-3.0.3-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:5678211cb9333a6468fb8d8be0305520aa073f50d17f089b5b4b477ea6e67fdc"}, + {file = "markupsafe-3.0.3-cp314-cp314t-win32.whl", hash = "sha256:915c04ba3851909ce68ccc2b8e2cd691618c4dc4c4232fb7982bca3f41fd8c3d"}, + {file = "markupsafe-3.0.3-cp314-cp314t-win_amd64.whl", hash = "sha256:4faffd047e07c38848ce017e8725090413cd80cbc23d86e55c587bf979e579c9"}, + {file = "markupsafe-3.0.3-cp314-cp314t-win_arm64.whl", hash = "sha256:32001d6a8fc98c8cb5c947787c5d08b0a50663d139f1305bac5885d98d9b40fa"}, + {file = "markupsafe-3.0.3.tar.gz", hash = "sha256:722695808f4b6457b320fdc131280796bdceb04ab50fe1795cd540799ebe1698"}, +] + +[[package]] +name = "mdurl" +version = "0.1.2" +requires_python = ">=3.7" +summary = "Markdown URL utilities" +groups = ["default"] +files = [ + {file = "mdurl-0.1.2-py3-none-any.whl", hash = "sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8"}, + {file = "mdurl-0.1.2.tar.gz", hash = "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba"}, +] + +[[package]] +name = "mypy" +version = "1.13.0" +requires_python = ">=3.8" +summary = "Optional static typing for Python" +groups = ["dev"] +dependencies = [ + "mypy-extensions>=1.0.0", + "tomli>=1.1.0; python_version < \"3.11\"", + "typing-extensions>=4.6.0", +] +files = [ + {file = "mypy-1.13.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:581665e6f3a8a9078f28d5502f4c334c0c8d802ef55ea0e7276a6e409bc0d82d"}, + {file = "mypy-1.13.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:3ddb5b9bf82e05cc9a627e84707b528e5c7caaa1c55c69e175abb15a761cec2d"}, + {file = "mypy-1.13.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:20c7ee0bc0d5a9595c46f38beb04201f2620065a93755704e141fcac9f59db2b"}, + {file = "mypy-1.13.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:3790ded76f0b34bc9c8ba4def8f919dd6a46db0f5a6610fb994fe8efdd447f73"}, + {file = "mypy-1.13.0-cp311-cp311-win_amd64.whl", hash = "sha256:51f869f4b6b538229c1d1bcc1dd7d119817206e2bc54e8e374b3dfa202defcca"}, + {file = "mypy-1.13.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:5c7051a3461ae84dfb5dd15eff5094640c61c5f22257c8b766794e6dd85e72d5"}, + {file = "mypy-1.13.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:39bb21c69a5d6342f4ce526e4584bc5c197fd20a60d14a8624d8743fffb9472e"}, + {file = "mypy-1.13.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:164f28cb9d6367439031f4c81e84d3ccaa1e19232d9d05d37cb0bd880d3f93c2"}, + {file = "mypy-1.13.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:a4c1bfcdbce96ff5d96fc9b08e3831acb30dc44ab02671eca5953eadad07d6d0"}, + {file = "mypy-1.13.0-cp312-cp312-win_amd64.whl", hash = "sha256:a0affb3a79a256b4183ba09811e3577c5163ed06685e4d4b46429a271ba174d2"}, + {file = "mypy-1.13.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:a7b44178c9760ce1a43f544e595d35ed61ac2c3de306599fa59b38a6048e1aa7"}, + {file = "mypy-1.13.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:5d5092efb8516d08440e36626f0153b5006d4088c1d663d88bf79625af3d1d62"}, + {file = "mypy-1.13.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:de2904956dac40ced10931ac967ae63c5089bd498542194b436eb097a9f77bc8"}, + {file = "mypy-1.13.0-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:7bfd8836970d33c2105562650656b6846149374dc8ed77d98424b40b09340ba7"}, + {file = "mypy-1.13.0-cp313-cp313-win_amd64.whl", hash = "sha256:9f73dba9ec77acb86457a8fc04b5239822df0c14a082564737833d2963677dbc"}, + {file = "mypy-1.13.0-py3-none-any.whl", hash = "sha256:9c250883f9fd81d212e0952c92dbfcc96fc237f4b7c92f56ac81fd48460b3e5a"}, + {file = "mypy-1.13.0.tar.gz", hash = "sha256:0291a61b6fbf3e6673e3405cfcc0e7650bebc7939659fdca2702958038bd835e"}, +] + +[[package]] +name = "mypy-extensions" +version = "1.1.0" +requires_python = ">=3.8" +summary = "Type system extensions for programs checked with the mypy type checker." +groups = ["dev"] +files = [ + {file = "mypy_extensions-1.1.0-py3-none-any.whl", hash = "sha256:1be4cccdb0f2482337c4743e60421de3a356cd97508abadd57d47403e94f5505"}, + {file = "mypy_extensions-1.1.0.tar.gz", hash = "sha256:52e68efc3284861e772bbcd66823fde5ae21fd2fdb51c62a211403730b916558"}, +] + +[[package]] +name = "packaging" +version = "26.3" +requires_python = ">=3.9" +summary = "Core utilities for Python packages" +groups = ["dev"] +files = [ + {file = "packaging-26.3-py3-none-any.whl", hash = "sha256:d7193f7c8e4e93f444fde0262bf90af30e16fa0ad0ad44cb553c87339b23cd1c"}, + {file = "packaging-26.3.tar.gz", hash = "sha256:94edc256424af38762eb31306eed28beb9f0efc50a8837492c9d6fd6004aed79"}, +] + +[[package]] +name = "pluggy" +version = "1.6.0" +requires_python = ">=3.9" +summary = "plugin and hook calling mechanisms for python" +groups = ["dev"] +files = [ + {file = "pluggy-1.6.0-py3-none-any.whl", hash = "sha256:e920276dd6813095e9377c0bc5566d94c932c33b27a3e3945d8389c374dd4746"}, + {file = "pluggy-1.6.0.tar.gz", hash = "sha256:7dcc130b76258d33b90f61b658791dede3486c3e6bfb003ee5c9bfb396dd22f3"}, +] + +[[package]] +name = "py" +version = "1.11.0" +requires_python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +summary = "library with cross-python path, ini-parsing, io, code, log facilities" +groups = ["dev"] +files = [ + {file = "py-1.11.0-py2.py3-none-any.whl", hash = "sha256:607c53218732647dff4acdfcd50cb62615cedf612e72d1724fb1a0cc6405b378"}, + {file = "py-1.11.0.tar.gz", hash = "sha256:51c75c4126074b472f746a24399ad32f6053d1b34b68d2fa41e558e6f4a98719"}, +] + +[[package]] +name = "pydantic" +version = "2.10.0" +requires_python = ">=3.8" +summary = "Data validation using Python type hints" +groups = ["default"] +dependencies = [ + "annotated-types>=0.6.0", + "pydantic-core==2.27.0", + "typing-extensions>=4.12.2", +] +files = [ + {file = "pydantic-2.10.0-py3-none-any.whl", hash = "sha256:5e7807ba9201bdf61b1b58aa6eb690916c40a47acfb114b1b4fef3e7fd5b30fc"}, + {file = "pydantic-2.10.0.tar.gz", hash = "sha256:0aca0f045ff6e2f097f1fe89521115335f15049eeb8a7bef3dafe4b19a74e289"}, +] + +[[package]] +name = "pydantic-core" +version = "2.27.0" +requires_python = ">=3.8" +summary = "Core functionality for Pydantic validation and serialization" +groups = ["default"] +dependencies = [ + "typing-extensions!=4.7.0,>=4.6.0", +] +files = [ + {file = "pydantic_core-2.27.0-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:4523c4009c3f39d948e01962223c9f5538602e7087a628479b723c939fab262d"}, + {file = "pydantic_core-2.27.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:84af1cf7bfdcbc6fcf5a5f70cc9896205e0350306e4dd73d54b6a18894f79386"}, + {file = "pydantic_core-2.27.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e65466b31be1070b4a5b7dbfbd14b247884cb8e8b79c64fb0f36b472912dbaea"}, + {file = "pydantic_core-2.27.0-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:a5c022bb0d453192426221605efc865373dde43b17822a264671c53b068ac20c"}, + {file = "pydantic_core-2.27.0-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:6bb69bf3b6500f195c3deb69c1205ba8fc3cb21d1915f1f158a10d6b1ef29b6a"}, + {file = "pydantic_core-2.27.0-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:0aa4d1b2eba9a325897308b3124014a142cdccb9f3e016f31d3ebee6b5ea5e75"}, + {file = "pydantic_core-2.27.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8e96ca781e0c01e32115912ebdf7b3fb0780ce748b80d7d28a0802fa9fbaf44e"}, + {file = "pydantic_core-2.27.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:b872c86d8d71827235c7077461c502feb2db3f87d9d6d5a9daa64287d75e4fa0"}, + {file = "pydantic_core-2.27.0-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:82e1ad4ca170e8af4c928b67cff731b6296e6a0a0981b97b2eb7c275cc4e15bd"}, + {file = "pydantic_core-2.27.0-cp311-cp311-musllinux_1_1_armv7l.whl", hash = "sha256:eb40f828bc2f73f777d1eb8fee2e86cd9692a4518b63b6b5aa8af915dfd3207b"}, + {file = "pydantic_core-2.27.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:9a8fbf506fde1529a1e3698198fe64bfbe2e0c09557bc6a7dcf872e7c01fec40"}, + {file = "pydantic_core-2.27.0-cp311-none-win32.whl", hash = "sha256:24f984fc7762ed5f806d9e8c4c77ea69fdb2afd987b4fd319ef06c87595a8c55"}, + {file = "pydantic_core-2.27.0-cp311-none-win_amd64.whl", hash = "sha256:68950bc08f9735306322bfc16a18391fcaac99ded2509e1cc41d03ccb6013cfe"}, + {file = "pydantic_core-2.27.0-cp311-none-win_arm64.whl", hash = "sha256:3eb8849445c26b41c5a474061032c53e14fe92a11a5db969f722a2716cd12206"}, + {file = "pydantic_core-2.27.0-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:8117839a9bdbba86e7f9df57018fe3b96cec934c3940b591b0fd3fbfb485864a"}, + {file = "pydantic_core-2.27.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:a291d0b4243a259c8ea7e2b84eb9ccb76370e569298875a7c5e3e71baf49057a"}, + {file = "pydantic_core-2.27.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:84e35afd9e10b2698e6f2f32256678cb23ca6c1568d02628033a837638b3ed12"}, + {file = "pydantic_core-2.27.0-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:58ab0d979c969983cdb97374698d847a4acffb217d543e172838864636ef10d9"}, + {file = "pydantic_core-2.27.0-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:0d06b667e53320332be2bf6f9461f4a9b78092a079b8ce8634c9afaa7e10cd9f"}, + {file = "pydantic_core-2.27.0-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:78f841523729e43e3928a364ec46e2e3f80e6625a4f62aca5c345f3f626c6e8a"}, + {file = "pydantic_core-2.27.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:400bf470e4327e920883b51e255617dfe4496d4e80c3fea0b5a5d0bf2c404dd4"}, + {file = "pydantic_core-2.27.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:951e71da6c89d354572098bada5ba5b5dc3a9390c933af8a614e37755d3d1840"}, + {file = "pydantic_core-2.27.0-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:2a51ce96224eadd1845150b204389623c8e129fde5a67a84b972bd83a85c6c40"}, + {file = "pydantic_core-2.27.0-cp312-cp312-musllinux_1_1_armv7l.whl", hash = "sha256:483c2213a609e7db2c592bbc015da58b6c75af7360ca3c981f178110d9787bcf"}, + {file = "pydantic_core-2.27.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:359e7951f04ad35111b5ddce184db3391442345d0ab073aa63a95eb8af25a5ef"}, + {file = "pydantic_core-2.27.0-cp312-none-win32.whl", hash = "sha256:ee7d9d5537daf6d5c74a83b38a638cc001b648096c1cae8ef695b0c919d9d379"}, + {file = "pydantic_core-2.27.0-cp312-none-win_amd64.whl", hash = "sha256:2be0ad541bb9f059954ccf8877a49ed73877f862529575ff3d54bf4223e4dd61"}, + {file = "pydantic_core-2.27.0-cp312-none-win_arm64.whl", hash = "sha256:6e19401742ed7b69e51d8e4df3c03ad5ec65a83b36244479fd70edde2828a5d9"}, + {file = "pydantic_core-2.27.0-cp313-cp313-macosx_10_12_x86_64.whl", hash = "sha256:5f2b19b8d6fca432cb3acf48cf5243a7bf512988029b6e6fd27e9e8c0a204d85"}, + {file = "pydantic_core-2.27.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:c86679f443e7085ea55a7376462553996c688395d18ef3f0d3dbad7838f857a2"}, + {file = "pydantic_core-2.27.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:510b11e9c3b1a852876d1ccd8d5903684336d635214148637ceb27366c75a467"}, + {file = "pydantic_core-2.27.0-cp313-cp313-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:eb704155e73b833801c247f39d562229c0303f54770ca14fb1c053acb376cf10"}, + {file = "pydantic_core-2.27.0-cp313-cp313-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:9ce048deb1e033e7a865ca384770bccc11d44179cf09e5193a535c4c2f497bdc"}, + {file = "pydantic_core-2.27.0-cp313-cp313-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:58560828ee0951bb125c6f2862fbc37f039996d19ceb6d8ff1905abf7da0bf3d"}, + {file = "pydantic_core-2.27.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:abb4785894936d7682635726613c44578c420a096729f1978cd061a7e72d5275"}, + {file = "pydantic_core-2.27.0-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:2883b260f7a93235488699d39cbbd94fa7b175d3a8063fbfddd3e81ad9988cb2"}, + {file = "pydantic_core-2.27.0-cp313-cp313-musllinux_1_1_aarch64.whl", hash = "sha256:c6fcb3fa3855d583aa57b94cf146f7781d5d5bc06cb95cb3afece33d31aac39b"}, + {file = "pydantic_core-2.27.0-cp313-cp313-musllinux_1_1_armv7l.whl", hash = "sha256:e851a051f7260e6d688267eb039c81f05f23a19431bd7dfa4bf5e3cb34c108cd"}, + {file = "pydantic_core-2.27.0-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:edb1bfd45227dec8d50bc7c7d86463cd8728bcc574f9b07de7369880de4626a3"}, + {file = "pydantic_core-2.27.0-cp313-none-win32.whl", hash = "sha256:678f66462058dd978702db17eb6a3633d634f7aa0deaea61e0a674152766d3fc"}, + {file = "pydantic_core-2.27.0-cp313-none-win_amd64.whl", hash = "sha256:d28ca7066d6cdd347a50d8b725dc10d9a1d6a1cce09836cf071ea6a2d4908be0"}, + {file = "pydantic_core-2.27.0-cp313-none-win_arm64.whl", hash = "sha256:6f4a53af9e81d757756508b57cae1cf28293f0f31b9fa2bfcb416cc7fb230f9d"}, + {file = "pydantic_core-2.27.0.tar.gz", hash = "sha256:f57783fbaf648205ac50ae7d646f27582fc706be3977e87c3c124e7a92407b10"}, +] + +[[package]] +name = "pygments" +version = "2.21.0" +requires_python = ">=3.9" +summary = "Pygments is a syntax highlighting package written in Python." +groups = ["default"] +files = [ + {file = "pygments-2.21.0-py3-none-any.whl", hash = "sha256:2363c69b61c4a97c838da3b130dcd6468f4848992b21a82f2a63ec34377137d9"}, + {file = "pygments-2.21.0.tar.gz", hash = "sha256:610ca751c9bc2492b38eb9a38a7fbc93edbbb2d7182edaf34e66ae493dee5c8c"}, +] + +[[package]] +name = "pytest" +version = "8.0.1" +requires_python = ">=3.8" +summary = "pytest: simple powerful testing with Python" +groups = ["dev"] +dependencies = [ + "colorama; sys_platform == \"win32\"", + "exceptiongroup>=1.0.0rc8; python_version < \"3.11\"", + "iniconfig", + "packaging", + "pluggy<2.0,>=1.3.0", + "tomli>=1.0.0; python_version < \"3.11\"", +] +files = [ + {file = "pytest-8.0.1-py3-none-any.whl", hash = "sha256:3e4f16fe1c0a9dc9d9389161c127c3edc5d810c38d6793042fb81d9f48a59fca"}, + {file = "pytest-8.0.1.tar.gz", hash = "sha256:267f6563751877d772019b13aacbe4e860d73fe8f651f28112e9ac37de7513ae"}, +] + +[[package]] +name = "pytest-cov" +version = "0.6" +summary = "py.test plugin for coverage reporting with support for both centralised and distributed testing" +groups = ["dev"] +dependencies = [ + "coverage>=3.3.1", + "py>=1.2.2", + "pytest-xdist>=1.2", +] +files = [ + {file = "pytest-cov-0.6.tar.gz", hash = "sha256:ab095420d1845bfb8998e6aa3072141da3b0c97a34475574752bbcf04edbac85"}, +] + +[[package]] +name = "pytest-mock" +version = "3.1.0" +requires_python = ">=3.5" +summary = "Thin-wrapper around the mock package for easier use with pytest" +groups = ["dev"] +dependencies = [ + "pytest>=2.7", +] +files = [ + {file = "pytest-mock-3.1.0.tar.gz", hash = "sha256:ce610831cedeff5331f4e2fc453a5dd65384303f680ab34bee2c6533855b431c"}, + {file = "pytest_mock-3.1.0-py2.py3-none-any.whl", hash = "sha256:997729451dfc36b851a9accf675488c7020beccda15e11c75632ee3d1b1ccd71"}, +] + +[[package]] +name = "pytest-xdist" +version = "3.8.0" +requires_python = ">=3.9" +summary = "pytest xdist plugin for distributed testing, most importantly across multiple CPUs" +groups = ["dev"] +dependencies = [ + "execnet>=2.1", + "pytest>=7.0.0", +] +files = [ + {file = "pytest_xdist-3.8.0-py3-none-any.whl", hash = "sha256:202ca578cfeb7370784a8c33d6d05bc6e13b4f25b5053c30a152269fd10f0b88"}, + {file = "pytest_xdist-3.8.0.tar.gz", hash = "sha256:7e578125ec9bc6050861aa93f2d59f1d8d085595d6551c2c90b6f4fad8d3a9f1"}, +] + +[[package]] +name = "python-multipart" +version = "0.0.1" +summary = "A streaming multipart parser for Python" +groups = ["dev"] +files = [ + {file = "python-multipart-0.0.1.tar.gz", hash = "sha256:ae940d053341378e53937d6e7f2081d26b4435dbd53dcd901be73ef3d6ff70be"}, +] + +[[package]] +name = "rfc3986" +version = "1.5.0" +summary = "Validating URI References per RFC 3986" +groups = ["default"] +files = [ + {file = "rfc3986-1.5.0-py2.py3-none-any.whl", hash = "sha256:a86d6e1f5b1dc238b218b012df0aa79409667bb209e58da56d0b94704e712a97"}, + {file = "rfc3986-1.5.0.tar.gz", hash = "sha256:270aaf10d87d0d4e095063c65bf3ddbc6ee3d0b226328ce21e036f946e421835"}, +] + +[[package]] +name = "rfc3986" +version = "1.5.0" +extras = ["idna2008"] +summary = "Validating URI References per RFC 3986" +groups = ["default"] +dependencies = [ + "idna", + "rfc3986==1.5.0", +] +files = [ + {file = "rfc3986-1.5.0-py2.py3-none-any.whl", hash = "sha256:a86d6e1f5b1dc238b218b012df0aa79409667bb209e58da56d0b94704e712a97"}, + {file = "rfc3986-1.5.0.tar.gz", hash = "sha256:270aaf10d87d0d4e095063c65bf3ddbc6ee3d0b226328ce21e036f946e421835"}, +] + +[[package]] +name = "rich" +version = "15.0.0" +requires_python = ">=3.9.0" +summary = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal" +groups = ["default"] +dependencies = [ + "markdown-it-py>=2.2.0", + "pygments<3.0.0,>=2.13.0", +] +files = [ + {file = "rich-15.0.0-py3-none-any.whl", hash = "sha256:33bd4ef74232fb73fe9279a257718407f169c09b78a87ad3d296f548e27de0bb"}, + {file = "rich-15.0.0.tar.gz", hash = "sha256:edd07a4824c6b40189fb7ac9bc4c52536e9780fbbfbddf6f1e2502c31b068c36"}, +] + +[[package]] +name = "ruamel-yaml" +version = "0.18.6" +requires_python = ">=3.7" +summary = "ruamel.yaml is a YAML parser/emitter that supports roundtrip preservation of comments, seq/map flow style, and map key order" +groups = ["default"] +dependencies = [ + "ruamel-yaml-clib>=0.2.7; platform_python_implementation == \"CPython\" and python_version < \"3.13\"", +] +files = [ + {file = "ruamel.yaml-0.18.6-py3-none-any.whl", hash = "sha256:57b53ba33def16c4f3d807c0ccbc00f8a6081827e81ba2491691b76882d0c636"}, + {file = "ruamel.yaml-0.18.6.tar.gz", hash = "sha256:8b27e6a217e786c6fbe5634d8f3f11bc63e0f80f6a5890f28863d9c45aac311b"}, +] + +[[package]] +name = "ruamel-yaml-clib" +version = "0.2.15" +requires_python = ">=3.9" +summary = "C version of reader, parser and emitter for ruamel.yaml derived from libyaml" +groups = ["default"] +marker = "platform_python_implementation == \"CPython\" and python_version < \"3.13\"" +files = [ + {file = "ruamel_yaml_clib-0.2.15-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:c583229f336682b7212a43d2fa32c30e643d3076178fb9f7a6a14dde85a2d8bd"}, + {file = "ruamel_yaml_clib-0.2.15-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:56ea19c157ed8c74b6be51b5fa1c3aff6e289a041575f0556f66e5fb848bb137"}, + {file = "ruamel_yaml_clib-0.2.15-cp311-cp311-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:5fea0932358e18293407feb921d4f4457db837b67ec1837f87074667449f9401"}, + {file = "ruamel_yaml_clib-0.2.15-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:ef71831bd61fbdb7aa0399d5c4da06bea37107ab5c79ff884cc07f2450910262"}, + {file = "ruamel_yaml_clib-0.2.15-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:617d35dc765715fa86f8c3ccdae1e4229055832c452d4ec20856136acc75053f"}, + {file = "ruamel_yaml_clib-0.2.15-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:1b45498cc81a4724a2d42273d6cfc243c0547ad7c6b87b4f774cb7bcc131c98d"}, + {file = "ruamel_yaml_clib-0.2.15-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:def5663361f6771b18646620fca12968aae730132e104688766cf8a3b1d65922"}, + {file = "ruamel_yaml_clib-0.2.15-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:014181cdec565c8745b7cbc4de3bf2cc8ced05183d986e6d1200168e5bb59490"}, + {file = "ruamel_yaml_clib-0.2.15-cp311-cp311-win32.whl", hash = "sha256:d290eda8f6ada19e1771b54e5706b8f9807e6bb08e873900d5ba114ced13e02c"}, + {file = "ruamel_yaml_clib-0.2.15-cp311-cp311-win_amd64.whl", hash = "sha256:bdc06ad71173b915167702f55d0f3f027fc61abd975bd308a0968c02db4a4c3e"}, + {file = "ruamel_yaml_clib-0.2.15-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:cb15a2e2a90c8475df45c0949793af1ff413acfb0a716b8b94e488ea95ce7cff"}, + {file = "ruamel_yaml_clib-0.2.15-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:64da03cbe93c1e91af133f5bec37fd24d0d4ba2418eaf970d7166b0a26a148a2"}, + {file = "ruamel_yaml_clib-0.2.15-cp312-cp312-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:f6d3655e95a80325b84c4e14c080b2470fe4f33b6846f288379ce36154993fb1"}, + {file = "ruamel_yaml_clib-0.2.15-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:71845d377c7a47afc6592aacfea738cc8a7e876d586dfba814501d8c53c1ba60"}, + {file = "ruamel_yaml_clib-0.2.15-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:11e5499db1ccbc7f4b41f0565e4f799d863ea720e01d3e99fa0b7b5fcd7802c9"}, + {file = "ruamel_yaml_clib-0.2.15-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:4b293a37dc97e2b1e8a1aec62792d1e52027087c8eea4fc7b5abd2bdafdd6642"}, + {file = "ruamel_yaml_clib-0.2.15-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:512571ad41bba04eac7268fe33f7f4742210ca26a81fe0c75357fa682636c690"}, + {file = "ruamel_yaml_clib-0.2.15-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:e5e9f630c73a490b758bf14d859a39f375e6999aea5ddd2e2e9da89b9953486a"}, + {file = "ruamel_yaml_clib-0.2.15-cp312-cp312-win32.whl", hash = "sha256:f4421ab780c37210a07d138e56dd4b51f8642187cdfb433eb687fe8c11de0144"}, + {file = "ruamel_yaml_clib-0.2.15-cp312-cp312-win_amd64.whl", hash = "sha256:2b216904750889133d9222b7b873c199d48ecbb12912aca78970f84a5aa1a4bc"}, + {file = "ruamel_yaml_clib-0.2.15-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:4dcec721fddbb62e60c2801ba08c87010bd6b700054a09998c4d09c08147b8fb"}, + {file = "ruamel_yaml_clib-0.2.15-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:65f48245279f9bb301d1276f9679b82e4c080a1ae25e679f682ac62446fac471"}, + {file = "ruamel_yaml_clib-0.2.15-cp313-cp313-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:46895c17ead5e22bea5e576f1db7e41cb273e8d062c04a6a49013d9f60996c25"}, + {file = "ruamel_yaml_clib-0.2.15-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:3eb199178b08956e5be6288ee0b05b2fb0b5c1f309725ad25d9c6ea7e27f962a"}, + {file = "ruamel_yaml_clib-0.2.15-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:4d1032919280ebc04a80e4fb1e93f7a738129857eaec9448310e638c8bccefcf"}, + {file = "ruamel_yaml_clib-0.2.15-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:ab0df0648d86a7ecbd9c632e8f8d6b21bb21b5fc9d9e095c796cacf32a728d2d"}, + {file = "ruamel_yaml_clib-0.2.15-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:331fb180858dd8534f0e61aa243b944f25e73a4dae9962bd44c46d1761126bbf"}, + {file = "ruamel_yaml_clib-0.2.15-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:fd4c928ddf6bce586285daa6d90680b9c291cfd045fc40aad34e445d57b1bf51"}, + {file = "ruamel_yaml_clib-0.2.15-cp313-cp313-win32.whl", hash = "sha256:bf0846d629e160223805db9fe8cc7aec16aaa11a07310c50c8c7164efa440aec"}, + {file = "ruamel_yaml_clib-0.2.15-cp313-cp313-win_amd64.whl", hash = "sha256:45702dfbea1420ba3450bb3dd9a80b33f0badd57539c6aac09f42584303e0db6"}, + {file = "ruamel_yaml_clib-0.2.15-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:753faf20b3a5906faf1fc50e4ddb8c074cb9b251e00b14c18b28492f933ac8ef"}, + {file = "ruamel_yaml_clib-0.2.15-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:480894aee0b29752560a9de46c0e5f84a82602f2bc5c6cde8db9a345319acfdf"}, + {file = "ruamel_yaml_clib-0.2.15-cp314-cp314-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:4d3b58ab2454b4747442ac76fab66739c72b1e2bb9bd173d7694b9f9dbc9c000"}, + {file = "ruamel_yaml_clib-0.2.15-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:bfd309b316228acecfa30670c3887dcedf9b7a44ea39e2101e75d2654522acd4"}, + {file = "ruamel_yaml_clib-0.2.15-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:2812ff359ec1f30129b62372e5f22a52936fac13d5d21e70373dbca5d64bb97c"}, + {file = "ruamel_yaml_clib-0.2.15-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:7e74ea87307303ba91073b63e67f2c667e93f05a8c63079ee5b7a5c8d0d7b043"}, + {file = "ruamel_yaml_clib-0.2.15-cp314-cp314-musllinux_1_2_i686.whl", hash = "sha256:713cd68af9dfbe0bb588e144a61aad8dcc00ef92a82d2e87183ca662d242f524"}, + {file = "ruamel_yaml_clib-0.2.15-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:542d77b72786a35563f97069b9379ce762944e67055bea293480f7734b2c7e5e"}, + {file = "ruamel_yaml_clib-0.2.15-cp314-cp314-win32.whl", hash = "sha256:424ead8cef3939d690c4b5c85ef5b52155a231ff8b252961b6516ed7cf05f6aa"}, + {file = "ruamel_yaml_clib-0.2.15-cp314-cp314-win_amd64.whl", hash = "sha256:ac9b8d5fa4bb7fd2917ab5027f60d4234345fd366fe39aa711d5dca090aa1467"}, + {file = "ruamel_yaml_clib-0.2.15.tar.gz", hash = "sha256:46e4cc8c43ef6a94885f72512094e482114a8a706d3c555a34ed4b0d20200600"}, +] + +[[package]] +name = "ruff" +version = "0.2.0" +requires_python = ">=3.7" +summary = "An extremely fast Python linter and code formatter, written in Rust." +groups = ["default"] +files = [ + {file = "ruff-0.2.0-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:638ea3294f800d18bae84a492cb5a245c8d29c90d19a91d8e338937a4c27fca0"}, + {file = "ruff-0.2.0-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:3ff35433fcf4dff6d610738712152df6b7d92351a1bde8e00bd405b08b3d5759"}, + {file = "ruff-0.2.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:bf9faafbdcf4f53917019f2c230766da437d4fd5caecd12ddb68bb6a17d74399"}, + {file = "ruff-0.2.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:8153a3e4128ed770871c47545f1ae7b055023e0c222ff72a759f5a341ee06483"}, + {file = "ruff-0.2.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e8a75a98ae989a27090e9c51f763990ad5bbc92d20626d54e9701c7fe597f399"}, + {file = "ruff-0.2.0-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:87057dd2fdde297130ff99553be8549ca38a2965871462a97394c22ed2dfc19d"}, + {file = "ruff-0.2.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:6d232f99d3ab00094ebaf88e0fb7a8ccacaa54cc7fa3b8993d9627a11e6aed7a"}, + {file = "ruff-0.2.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:3d3c641f95f435fc6754b05591774a17df41648f0daf3de0d75ad3d9f099ab92"}, + {file = "ruff-0.2.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3826fb34c144ef1e171b323ed6ae9146ab76d109960addca730756dc19dc7b22"}, + {file = "ruff-0.2.0-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:eceab7d85d09321b4de18b62d38710cf296cb49e98979960a59c6b9307c18cfe"}, + {file = "ruff-0.2.0-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:30ad74687e1f4a9ff8e513b20b82ccadb6bd796fe5697f1e417189c5cde6be3e"}, + {file = "ruff-0.2.0-py3-none-musllinux_1_2_i686.whl", hash = "sha256:a7e3818698f8460bd0f8d4322bbe99db8327e9bc2c93c789d3159f5b335f47da"}, + {file = "ruff-0.2.0-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:edf23041242c48b0d8295214783ef543847ef29e8226d9f69bf96592dba82a83"}, + {file = "ruff-0.2.0-py3-none-win32.whl", hash = "sha256:e155147199c2714ff52385b760fe242bb99ea64b240a9ffbd6a5918eb1268843"}, + {file = "ruff-0.2.0-py3-none-win_amd64.whl", hash = "sha256:ba918e01cdd21e81b07555564f40d307b0caafa9a7a65742e98ff244f5035c59"}, + {file = "ruff-0.2.0-py3-none-win_arm64.whl", hash = "sha256:3fbaff1ba9564a2c5943f8f38bc221f04bac687cc7485e45237579fee7ccda79"}, + {file = "ruff-0.2.0.tar.gz", hash = "sha256:63856b91837606c673537d2889989733d7dffde553828d3b0f0bacfa6def54be"}, +] + +[[package]] +name = "shellingham" +version = "1.3.2" +requires_python = "!=3.0,!=3.1,!=3.2,!=3.3,>=2.6" +summary = "Tool to Detect Surrounding Shell" +groups = ["default"] +files = [ + {file = "shellingham-1.3.2-py2.py3-none-any.whl", hash = "sha256:7f6206ae169dc1a03af8a138681b3f962ae61cc93ade84d0585cca3aaf770044"}, + {file = "shellingham-1.3.2.tar.gz", hash = "sha256:576c1982bea0ba82fb46c36feb951319d7f42214a82634233f58b40d858a751e"}, +] + +[[package]] +name = "sniffio" +version = "1.3.1" +requires_python = ">=3.7" +summary = "Sniff out which async library your code is running under" +groups = ["default"] +files = [ + {file = "sniffio-1.3.1-py3-none-any.whl", hash = "sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2"}, + {file = "sniffio-1.3.1.tar.gz", hash = "sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc"}, +] + +[[package]] +name = "sortedcontainers" +version = "2.4.0" +summary = "Sorted Containers -- Sorted List, Sorted Dict, Sorted Set" +groups = ["dev"] +files = [ + {file = "sortedcontainers-2.4.0-py2.py3-none-any.whl", hash = "sha256:a163dcaede0f1c021485e957a39245190e74249897e2ae4b2aa38595db237ee0"}, + {file = "sortedcontainers-2.4.0.tar.gz", hash = "sha256:25caa5a06cc30b6b83d11423433f65d1f9d76c4c6a0c90e3379eaa43b9bfdb88"}, +] + +[[package]] +name = "syrupy" +version = "4.6.1" +requires_python = ">=3.8.1,<4" +summary = "Pytest Snapshot Test Utility" +groups = ["dev"] +dependencies = [ + "pytest<9.0.0,>=7.0.0", +] +files = [ + {file = "syrupy-4.6.1-py3-none-any.whl", hash = "sha256:203e52f9cb9fa749cf683f29bd68f02c16c3bc7e7e5fe8f2fc59bdfe488ce133"}, + {file = "syrupy-4.6.1.tar.gz", hash = "sha256:37a835c9ce7857eeef86d62145885e10b3cb9615bc6abeb4ce404b3f18e1bb36"}, +] + +[[package]] +name = "typer" +version = "0.16.1" +requires_python = ">=3.7" +summary = "Typer, build great CLIs. Easy to code. Based on Python type hints." +groups = ["default"] +dependencies = [ + "click>=8.0.0", + "rich>=10.11.0", + "shellingham>=1.3.0", + "typing-extensions>=3.7.4.3", +] +files = [ + {file = "typer-0.16.1-py3-none-any.whl", hash = "sha256:90ee01cb02d9b8395ae21ee3368421faf21fa138cb2a541ed369c08cec5237c9"}, + {file = "typer-0.16.1.tar.gz", hash = "sha256:d358c65a464a7a90f338e3bb7ff0c74ac081449e53884b12ba658cbd72990614"}, +] + +[[package]] +name = "types-certifi" +version = "2020.4.0" +summary = "Typing stubs for certifi" +groups = ["dev"] +files = [ + {file = "types-certifi-2020.4.0.tar.gz", hash = "sha256:787d1a0c7897a1c658f8f7958ae57141b3fff13acb866e5bcd31cfb45037546f"}, + {file = "types_certifi-2020.4.0-py3-none-any.whl", hash = "sha256:0ffdbe451d3b02f6d2cfd87bcfb2f086a4ff1fa76a35d51cfc3771e261d7a8fd"}, +] + +[[package]] +name = "types-pyyaml" +version = "6.0.3" +summary = "Typing stubs for PyYAML" +groups = ["dev"] +files = [ + {file = "types-PyYAML-6.0.3.tar.gz", hash = "sha256:6ea4eefa8579e0ce022f785a62de2bcd647fad4a81df5cf946fd67e4b059920b"}, + {file = "types_PyYAML-6.0.3-py3-none-any.whl", hash = "sha256:8b50294b55a9db89498cdc5a65b1b4545112b6cd1cf4465bd693d828b0282a17"}, +] + +[[package]] +name = "typing-extensions" +version = "4.16.0" +requires_python = ">=3.9" +summary = "Backported and Experimental Type Hints for Python 3.9+" +groups = ["default", "dev"] +files = [ + {file = "typing_extensions-4.16.0-py3-none-any.whl", hash = "sha256:481caa481374e813c1b176ada14e97f1f67a4539ce9cfeb3f350d78d6370c2e8"}, + {file = "typing_extensions-4.16.0.tar.gz", hash = "sha256:dc983d19a509c94dba722ee6abd33940f7c05a89e243c47e907eb4db6f1a43e5"}, +] diff --git a/pyproject.toml b/pyproject.toml index c828b564e..91d4bf1fb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,23 +2,21 @@ authors = [ { name = "Dylan Anthony", email = "contact@dylananthony.com" }, ] -license = { text = "MIT" } -requires-python = ">=3.8,<4.0" +license = "MIT" +requires-python = ">=3.11,<4.0" dependencies = [ "jinja2>=3.0.0,<4.0.0", - "typer>0.6,<0.13", + "typer>0.16,<0.28", "colorama>=0.4.3; sys_platform == \"win32\"", "shellingham>=1.3.2,<2.0.0", - "pydantic>=2.1.1,<3.0.0", - "attrs>=21.3.0", - "python-dateutil>=2.8.1,<3.0.0", - "httpx>=0.20.0,<0.28.0", - "PyYAML>=6.0,<7.0", - "ruff>=0.2,<0.5", - "typing-extensions>=4.8.0,<5.0.0", + "pydantic>=2.10,<3.0.0", + "attrs>=22.2.0", + "httpx>=0.23.1,<0.29.0", + "ruamel.yaml>=0.18.6,<0.20.0", + "ruff>=0.2", ] name = "openapi-python-client" -version = "0.19.1" +version = "0.29.1" description = "Generate modern Python clients from OpenAPI" keywords = [ "OpenAPI", @@ -27,14 +25,12 @@ keywords = [ ] classifiers = [ "Development Status :: 4 - Beta", - "License :: OSI Approved :: MIT License", "Intended Audience :: Developers", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", "Topic :: Software Development :: Code Generators", "Typing :: Typed", ] @@ -46,6 +42,19 @@ repository = "https://github.com/openapi-generators/openapi-python-client" [project.scripts] openapi-python-client = "openapi_python_client.cli:app" +[dependency-groups] +dev = [ + "pytest>8", + "pytest-mock>3", + "mypy>=1.13", + "pytest-cov", + "python-multipart", + "types-PyYAML<7.0.0,>=6.0.3", + "types-certifi<2021.10.9,>=2020.0.0", + "syrupy>=4", + "hypothesis>=6.100", +] + [tool.ruff] line-length = 120 exclude = [ @@ -53,19 +62,21 @@ exclude = [ ".mypy_cache", ".venv", "openapi_python_client/templates/*", - "end_to_end_tests/*", + "end_to_end_tests/golden-records/*", + "end_to_end_tests/__snapshots__/*", "tests/test_templates/*", ] [tool.ruff.lint] select = ["E", "F", "I", "UP", "B", "PL", "RUF"] -ignore = ["E501", "PLR0913"] +ignore = ["E501", "PLR0913", "PLR2004"] [tool.ruff.lint.per-file-ignores] "openapi_python_client/cli.py" = ["B008"] +"tests/*" = ["PLR2004"] [tool.coverage.run] -omit = ["openapi_python_client/templates/*"] +omit = ["openapi_python_client/__main__.py", "openapi_python_client/templates/*", "end_to_end_tests/*", "integration_tests/*", "tests/*"] [tool.mypy] plugins = ["pydantic.mypy"] @@ -84,21 +95,6 @@ ignore_missing_imports = true [tool.pytest.ini_options] junit_family = "xunit2" - -[tool.pdm.dev-dependencies] -dev = [ - "pytest", - "pytest-mock", - "mypy", - "taskipy", - "safety", - "pytest-cov", - "python-multipart", - "types-PyYAML<7.0.0,>=6.0.3", - "types-certifi<2021.10.9,>=2020.0.0", - "types-python-dateutil<3.0.0,>=2.0.0", -] - [tool.pdm.build] includes = [ "openapi_python_client", @@ -107,18 +103,19 @@ includes = [ ] [tool.pdm.scripts] -lint = "ruff check --fix ." +lint = "ruff check ." format = "ruff format ." -safety_check = { shell = "pdm export -o requirements.txt && safety check -r requirements.txt --bare && rm requirements.txt" } -mypy = "mypy openapi_python_client" -check = { composite = ["lint", "format", "safety_check", "mypy", "test"] } -regen = {composite = ["regen_e2e", "regen_integration"]} +mypy = "mypy openapi_python_client fuzz" +check = { composite = ["lint", "format", "mypy", "test"] } +regen = { composite = ["regen_e2e", "regen_integration"] } e2e = "pytest openapi_python_client end_to_end_tests/test_end_to_end.py" -re = {composite = ["regen_e2e", "e2e"]} +re = { composite = ["regen_e2e", "e2e --snapshot-update"] } regen_e2e = "python -m end_to_end_tests.regen_golden_record" +unit_test = "pytest tests" +fuzz = "pytest fuzz --hypothesis-show-statistics" [tool.pdm.scripts.test] -cmd = "pytest tests end_to_end_tests/test_end_to_end.py --basetemp=tests/tmp" +cmd = "pytest tests end_to_end_tests/test_end_to_end.py end_to_end_tests/functional_tests --basetemp=tests/tmp" [tool.pdm.scripts.test.env] "TEST_RELATIVE" = "true" @@ -130,7 +127,7 @@ composite = ["test --cov openapi_python_client tests --cov-report=term-missing"] [tool.pdm.scripts.regen_integration] shell = """ -openapi-python-client update --url https://raw.githubusercontent.com/openapi-generators/openapi-test-server/main/openapi.json --config integration-tests/config.yaml --meta pdm \ +openapi-python-client generate --overwrite --url https://raw.githubusercontent.com/openapi-generators/openapi-test-server/refs/tags/v0.2.1/openapi.yaml --config integration-tests/config.yaml --meta none --output-path integration-tests/integration_tests \ """ [build-system] diff --git a/tests/conftest.py b/tests/conftest.py index 44fbe717c..97d59898b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,51 +1,71 @@ +from __future__ import annotations + +from collections.abc import Callable from pathlib import Path -from typing import Any, Callable, Dict +from typing import Any import pytest +from mypy.semanal_shared import Protocol -from openapi_python_client import Config, MetaType +from openapi_python_client import Config, MetaType, strings from openapi_python_client import schema as oai from openapi_python_client.config import ConfigFile from openapi_python_client.parser.properties import ( AnyProperty, BooleanProperty, + Class, DateProperty, DateTimeProperty, EnumProperty, FileProperty, IntProperty, ListProperty, + LiteralEnumProperty, ModelProperty, NoneProperty, StringProperty, UnionProperty, ) +from openapi_python_client.parser.properties.float import FloatProperty +from openapi_python_client.parser.properties.protocol import PropertyType, Value from openapi_python_client.schema.openapi_schema_pydantic import Parameter from openapi_python_client.schema.parameter_location import ParameterLocation +from openapi_python_client.schema.untrusted_string import UntrustedString +from openapi_python_client.strings import ClassName, PythonIdentifier @pytest.fixture(scope="session") def config() -> Config: """Create a default config for when it doesn't matter""" return Config.from_sources( - ConfigFile(), MetaType.POETRY, document_source=Path("openapi.yaml"), file_encoding="utf-8" + ConfigFile(), + MetaType.POETRY, + document_source=Path("openapi.yaml"), + file_encoding="utf-8", + overwrite=False, + output_path=None, ) +class ModelFactory(Protocol): + def __call__(self, *args, **kwargs): ... + + @pytest.fixture -def model_property_factory() -> Callable[..., ModelProperty]: +def model_property_factory() -> ModelFactory: """ This fixture surfaces in the test as a function which manufactures ModelProperties with defaults. You can pass the same params into this as the ModelProperty constructor to override defaults. """ - from openapi_python_client.parser.properties import Class def _factory(**kwargs): kwargs = _common_kwargs(kwargs) kwargs = { "description": "", - "class_info": Class(name="MyClass", module_name="my_module"), + "class_info": Class( + name=ClassName(UntrustedString("MyClass"), ""), module_name=PythonIdentifier("my_module", "") + ), "data": oai.Schema.model_construct(), "roots": set(), "required_properties": None, @@ -62,180 +82,218 @@ def _factory(**kwargs): return _factory +def _simple_factory( + cls: type[PropertyType], default_kwargs: dict | Callable[[dict], dict] | None = None +) -> Callable[..., PropertyType]: + def _factory(**kwargs): + kwargs = _common_kwargs(kwargs) + defaults = default_kwargs + if defaults: + if callable(defaults): + defaults = defaults(kwargs) + kwargs = {**defaults, **kwargs} + rv = cls(**kwargs) + return rv + + return _factory + + +class SimpleFactory(Protocol[PropertyType]): + def __call__( + self, + *, + default: Value | None = None, + name: str | None = None, + required: bool | None = None, + description: str | None = None, + example: str | None = None, + ) -> PropertyType: ... + + +class EnumFactory(Protocol[PropertyType]): + def __call__( + self, + *, + default: Value | None = None, + name: str | None = None, + required: bool | None = None, + values: dict[str, str | int] | None = None, + class_info: Class | None = None, + value_type: type | None = None, + python_name: PythonIdentifier | None = None, + description: str | None = None, + example: str | None = None, + ) -> PropertyType: ... + + @pytest.fixture -def enum_property_factory() -> Callable[..., EnumProperty]: +def enum_property_factory() -> EnumFactory[EnumProperty]: """ This fixture surfaces in the test as a function which manufactures EnumProperties with defaults. You can pass the same params into this as the EnumProerty constructor to override defaults. """ - from openapi_python_client.parser.properties import Class - def _factory(**kwargs): - kwargs = _common_kwargs(kwargs) - kwargs = { - "class_info": Class(name=kwargs["name"], module_name=kwargs["name"]), + return _simple_factory( + EnumProperty, + lambda kwargs: { + "class_info": Class(name=ClassName(kwargs["name"], prefix=""), module_name=kwargs["name"]), "values": {}, "value_type": str, - **kwargs, - } - return EnumProperty(**kwargs) + }, + ) - return _factory + +@pytest.fixture +def literal_enum_property_factory() -> EnumFactory[LiteralEnumProperty]: + """ + This fixture surfaces in the test as a function which manufactures LiteralEnumProperties with defaults. + + You can pass the same params into this as the LiteralEnumProerty constructor to override defaults. + """ + + return _simple_factory( + LiteralEnumProperty, + lambda kwargs: { + "class_info": Class(name=UntrustedString(kwargs["name"]), module_name=kwargs["name"]), + "values": set(), + "value_type": str, + }, + ) @pytest.fixture -def any_property_factory() -> Callable[..., AnyProperty]: +def any_property_factory() -> SimpleFactory[AnyProperty]: """ This fixture surfaces in the test as a function which manufactures AnyProperty with defaults. You can pass the same params into this as the AnyProperty constructor to override defaults. """ - def _factory(**kwargs): - kwargs = _common_kwargs(kwargs) - return AnyProperty(**kwargs) - - return _factory + return _simple_factory(AnyProperty) @pytest.fixture -def string_property_factory() -> Callable[..., StringProperty]: +def string_property_factory() -> SimpleFactory[StringProperty]: """ This fixture surfaces in the test as a function which manufactures StringProperties with defaults. You can pass the same params into this as the StringProperty constructor to override defaults. """ - def _factory(**kwargs): - kwargs = _common_kwargs(kwargs) - return StringProperty(**kwargs) - - return _factory + return _simple_factory(StringProperty) @pytest.fixture -def int_property_factory() -> Callable[..., IntProperty]: +def int_property_factory() -> SimpleFactory[IntProperty]: """ - This fixture surfaces in the test as a function which manufactures StringProperties with defaults. + This fixture surfaces in the test as a function which manufactures IntProperties with defaults. - You can pass the same params into this as the StringProperty constructor to override defaults. + You can pass the same params into this as the IntProperty constructor to override defaults. """ - def _factory(**kwargs): - kwargs = _common_kwargs(kwargs) - return IntProperty(**kwargs) - - return _factory + return _simple_factory(IntProperty) @pytest.fixture -def none_property_factory() -> Callable[..., NoneProperty]: +def float_property_factory() -> SimpleFactory[FloatProperty]: """ - This fixture surfaces in the test as a function which manufactures StringProperties with defaults. + This fixture surfaces in the test as a function which manufactures FloatProperties with defaults. - You can pass the same params into this as the StringProperty constructor to override defaults. + You can pass the same params into this as the FloatProperty constructor to override defaults. """ - def _factory(**kwargs): - kwargs = _common_kwargs(kwargs) - return NoneProperty(**kwargs) - - return _factory + return _simple_factory(FloatProperty) @pytest.fixture -def boolean_property_factory() -> Callable[..., BooleanProperty]: +def none_property_factory() -> SimpleFactory[NoneProperty]: """ - This fixture surfaces in the test as a function which manufactures StringProperties with defaults. + This fixture surfaces in the test as a function which manufactures NoneProperties with defaults. - You can pass the same params into this as the StringProperty constructor to override defaults. + You can pass the same params into this as the NoneProperty constructor to override defaults. """ - def _factory(**kwargs): - kwargs = _common_kwargs(kwargs) - return BooleanProperty(**kwargs) + return _simple_factory(NoneProperty) - return _factory + +@pytest.fixture +def boolean_property_factory() -> SimpleFactory[BooleanProperty]: + """ + This fixture surfaces in the test as a function which manufactures BooleanProperties with defaults. + + You can pass the same params into this as the BooleanProperty constructor to override defaults. + """ + + return _simple_factory(BooleanProperty) @pytest.fixture -def date_time_property_factory() -> Callable[..., DateTimeProperty]: +def date_time_property_factory() -> SimpleFactory[DateTimeProperty]: """ This fixture surfaces in the test as a function which manufactures DateTimeProperties with defaults. You can pass the same params into this as the DateTimeProperty constructor to override defaults. """ - def _factory(**kwargs): - kwargs = _common_kwargs(kwargs) - return DateTimeProperty(**kwargs) - - return _factory + return _simple_factory(DateTimeProperty) @pytest.fixture -def date_property_factory() -> Callable[..., DateProperty]: +def date_property_factory() -> SimpleFactory[DateProperty]: """ This fixture surfaces in the test as a function which manufactures DateProperties with defaults. You can pass the same params into this as the DateProperty constructor to override defaults. """ - def _factory(**kwargs): - kwargs = _common_kwargs(kwargs) - return DateProperty(**kwargs) - - return _factory + return _simple_factory(DateProperty) @pytest.fixture -def file_property_factory() -> Callable[..., FileProperty]: +def file_property_factory() -> SimpleFactory[FileProperty]: """ This fixture surfaces in the test as a function which manufactures FileProperties with defaults. You can pass the same params into this as the FileProperty constructor to override defaults. """ - def _factory(**kwargs): - kwargs = _common_kwargs(kwargs) - return FileProperty(**kwargs) - - return _factory + return _simple_factory(FileProperty) @pytest.fixture -def list_property_factory(string_property_factory) -> Callable[..., ListProperty]: +def list_property_factory(string_property_factory) -> SimpleFactory[ListProperty]: """ This fixture surfaces in the test as a function which manufactures ListProperties with defaults. You can pass the same params into this as the ListProperty constructor to override defaults. """ - def _factory(**kwargs): - kwargs = _common_kwargs(kwargs) - if "inner_property" not in kwargs: - kwargs["inner_property"] = string_property_factory() - return ListProperty(**kwargs) + return _simple_factory(ListProperty, {"inner_property": string_property_factory()}) - return _factory + +class UnionFactory(SimpleFactory): + def __call__( + self, + *, + default: Value | None = None, + name: str | None = None, + required: bool | None = None, + inner_properties: list[PropertyType] | None = None, + ) -> UnionProperty: ... @pytest.fixture -def union_property_factory(date_time_property_factory, string_property_factory) -> Callable[..., UnionProperty]: +def union_property_factory(date_time_property_factory, string_property_factory) -> UnionFactory: """ This fixture surfaces in the test as a function which manufactures UnionProperties with defaults. You can pass the same params into this as the UnionProperty constructor to override defaults. """ - def _factory(**kwargs): - kwargs = _common_kwargs(kwargs) - if "inner_properties" not in kwargs: - kwargs["inner_properties"] = [date_time_property_factory(), string_property_factory()] - return UnionProperty(**kwargs) - - return _factory + return _simple_factory( + UnionProperty, {"inner_properties": [date_time_property_factory(), string_property_factory()]} + ) @pytest.fixture @@ -257,7 +315,7 @@ def _factory(**kwargs): return _factory -def _common_kwargs(kwargs: Dict[str, Any]) -> Dict[str, Any]: +def _common_kwargs(kwargs: dict[str, Any]) -> dict[str, Any]: kwargs = { "name": "test", "required": True, @@ -266,6 +324,7 @@ def _common_kwargs(kwargs: Dict[str, Any]) -> Dict[str, Any]: "example": None, **kwargs, } + kwargs["name"] = UntrustedString(kwargs["name"]) if not kwargs.get("python_name"): - kwargs["python_name"] = kwargs["name"] + kwargs["python_name"] = strings.PythonIdentifier(value=kwargs["name"], prefix="") return kwargs diff --git a/tests/test___init__.py b/tests/test___init__.py index c419fdf32..5c2bd8678 100644 --- a/tests/test___init__.py +++ b/tests/test___init__.py @@ -1,17 +1,27 @@ +from pathlib import Path + import pytest -from openapi_python_client import Config, ErrorLevel, Project +from openapi_python_client import Config, ErrorLevel, GeneratorData, MetaType, Project from openapi_python_client.config import ConfigFile +from openapi_python_client.schema.untrusted_string import UntrustedString default_http_timeout = ConfigFile.model_json_schema()["properties"]["http_timeout"]["default"] def make_project(config: Config) -> Project: - from unittest.mock import MagicMock - - from openapi_python_client import Project - - return Project(openapi=MagicMock(title="My Test API"), config=config) + return Project( + openapi=GeneratorData( + title=UntrustedString("My API Client"), + description=None, + models=[], + version="", + errors=[], + endpoint_collections_by_tag={}, + enums=[], + ), + config=config, + ) @pytest.fixture @@ -29,9 +39,6 @@ class TestProject: def test__run_post_hooks_reports_missing_commands(self, project_with_dir: Project) -> None: fake_command_name = "blahblahdoesntexist" project_with_dir.config.post_hooks = [fake_command_name] - need_to_make_cwd = not project_with_dir.project_dir.exists() - if need_to_make_cwd: - project_with_dir.project_dir.mkdir() project_with_dir._run_post_hooks() @@ -42,23 +49,42 @@ def test__run_post_hooks_reports_missing_commands(self, project_with_dir: Projec assert fake_command_name in error.detail def test__run_post_hooks_reports_stdout_of_commands_that_error_with_no_stderr(self, project_with_dir): - failing_command = "python -c \"print('a message'); exit(1)\"" + failing_command = "python3 -c \"print('a message'); exit(1)\"" project_with_dir.config.post_hooks = [failing_command] project_with_dir._run_post_hooks() assert len(project_with_dir.errors) == 1 error = project_with_dir.errors[0] assert error.level == ErrorLevel.ERROR - assert error.header == "python failed" + assert error.header == "python3 failed" assert "a message" in error.detail def test__run_post_hooks_reports_stderr_of_commands_that_error(self, project_with_dir): - failing_command = "python -c \"print('a message'); raise Exception('some exception')\"" + failing_command = "python3 -c \"print('a message'); raise Exception('some exception')\"" project_with_dir.config.post_hooks = [failing_command] project_with_dir._run_post_hooks() assert len(project_with_dir.errors) == 1 error = project_with_dir.errors[0] assert error.level == ErrorLevel.ERROR - assert error.header == "python failed" + assert error.header == "python3 failed" assert "some exception" in error.detail + + def test_build_creates_parent_directories(self, tmp_path): + fresh_config = Config.from_sources( + ConfigFile(), + MetaType.POETRY, + document_source=Path("openapi.yaml"), + file_encoding="utf-8", + overwrite=False, + output_path=None, + ) + project = make_project(fresh_config) + project.project_dir = tmp_path / "nested" / "dir" / "my-api-client" + project.package_dir = project.project_dir / project.package_name + + errors = project.build() + + assert errors == [] + assert project.project_dir.exists() + assert project.project_dir.is_dir() diff --git a/tests/test___main__.py b/tests/test___main__.py deleted file mode 100644 index 0673c2062..000000000 --- a/tests/test___main__.py +++ /dev/null @@ -1,6 +0,0 @@ -def test_main(mocker): - app = mocker.patch("openapi_python_client.cli.app") - - from openapi_python_client import __main__ # noqa: F401 - - app.assert_called_once() diff --git a/tests/test_cli.py b/tests/test_cli.py index 1b3c21501..9712b2a04 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,157 +1,43 @@ -from unittest.mock import MagicMock - -import pytest from typer.testing import CliRunner -from openapi_python_client.parser.errors import GeneratorError, ParseError +from openapi_python_client.cli import app runner = CliRunner() -def test_version(mocker): - generate = mocker.patch("openapi_python_client.cli.generate") - from openapi_python_client.cli import app - +def test_version() -> None: result = runner.invoke(app, ["--version", "generate"]) - generate.assert_not_called() assert result.exit_code == 0 assert "openapi-python-client version: " in result.stdout -@pytest.fixture -def _create_new_client(mocker) -> MagicMock: - return mocker.patch("openapi_python_client.create_new_client", return_value=[]) - - -def test_bad_config(_create_new_client): - from openapi_python_client.cli import app - +def test_bad_config() -> None: config_path = "config/path" path = "cool/path" result = runner.invoke(app, ["generate", f"--config={config_path}", f"--path={path}"]) - assert result.exit_code == 2 # noqa: PLR2004 - assert "Unable to parse config" in result.stdout + assert result.exit_code == 2 + assert "Unable to parse config" in result.output class TestGenerate: - def test_generate_no_params(self, _create_new_client): - from openapi_python_client.cli import app - + def test_generate_no_params(self) -> None: result = runner.invoke(app, ["generate"]) assert result.exit_code == 1, result.output - _create_new_client.assert_not_called() - - def test_generate_url_and_path(self, _create_new_client): - from openapi_python_client.cli import app + def test_generate_url_and_path(self) -> None: result = runner.invoke(app, ["generate", "--path=blah", "--url=otherblah"]) assert result.exit_code == 1 - _create_new_client.assert_not_called() + assert result.output == "Provide either --url or --path, not both\n" - def test_generate_encoding_errors(self, _create_new_client): + def test_generate_encoding_errors(self) -> None: path = "cool/path" file_encoding = "error-file-encoding" - from openapi_python_client.cli import app - result = runner.invoke(app, ["generate", f"--path={path}", f"--file-encoding={file_encoding}"]) assert result.exit_code == 1 assert result.output == f"Unknown encoding : {file_encoding}\n" - - def test_generate_handle_errors(self, _create_new_client): - _create_new_client.return_value = [GeneratorError(detail="this is a message")] - path = "cool/path" - from openapi_python_client.cli import app - - result = runner.invoke(app, ["generate", f"--path={path}"]) - - assert result.exit_code == 1 - assert result.output == ( - "Error(s) encountered while generating, client was not created\n\n" - "Unable to generate the client\n\n" - "this is a message\n\n\n" - "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\n" - ) - - def test_generate_handle_multiple_warnings(self, _create_new_client): - error_1 = ParseError(data={"test": "data"}, detail="this is a message") - error_2 = ParseError(data={"other": "data"}, detail="this is another message", header="Custom Header") - _create_new_client.return_value = [error_1, error_2] - path = "cool/path" - from openapi_python_client.cli import app - - result = runner.invoke(app, ["generate", f"--path={path}"]) - - assert result.exit_code == 0 - assert result.output == ( - "Warning(s) encountered while generating. Client was generated, but some pieces may be missing\n\n" - "Unable to parse this part of your OpenAPI document: \n\n" - "this is a message\n\n" - "{'test': 'data'}\n\n" - "Custom Header\n\n" - "this is another message\n\n" - "{'other': 'data'}\n\n" - "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\n" - ) - - def test_generate_fail_on_warning(self, _create_new_client): - error_1 = ParseError(data={"test": "data"}, detail="this is a message") - error_2 = ParseError(data={"other": "data"}, detail="this is another message", header="Custom Header") - _create_new_client.return_value = [error_1, error_2] - path = "cool/path" - from openapi_python_client.cli import app - - result = runner.invoke(app, ["generate", f"--path={path}", "--fail-on-warning"]) - - assert result.exit_code == 1 - assert result.output == ( - "Warning(s) encountered while generating. Client was generated, but some pieces may be missing\n\n" - "Unable to parse this part of your OpenAPI document: \n\n" - "this is a message\n\n" - "{'test': 'data'}\n\n" - "Custom Header\n\n" - "this is another message\n\n" - "{'other': 'data'}\n\n" - "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\n" - ) - - -@pytest.fixture -def _update_existing_client(mocker): - return mocker.patch("openapi_python_client.update_existing_client") - - -class TestUpdate: - def test_update_no_params(self, _update_existing_client): - from openapi_python_client.cli import app - - result = runner.invoke(app, ["update"]) - - assert result.exit_code == 1 - _update_existing_client.assert_not_called() - - def test_update_url_and_path(self, _update_existing_client): - from openapi_python_client.cli import app - - result = runner.invoke(app, ["update", "--path=blah", "--url=otherblah"]) - - assert result.exit_code == 1 - _update_existing_client.assert_not_called() - - def test_update_encoding_errors(self, _update_existing_client): - path = "cool/path" - file_encoding = "error-file-encoding" - from openapi_python_client.cli import app - - result = runner.invoke(app, ["update", f"--path={path}", f"--file-encoding={file_encoding}"]) - - assert result.exit_code == 1 - assert result.output == f"Unknown encoding : {file_encoding}\n" diff --git a/tests/test_config.py b/tests/test_config.py index ea03dda47..36cd55ca0 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,28 +1,40 @@ import json import os +from io import StringIO from pathlib import Path +from typing import Any import pytest -import yaml +from ruamel.yaml import YAML as _YAML -from openapi_python_client.config import ConfigFile +from openapi_python_client.config import ClassOverride, ConfigFile -def json_with_tabs(d): +class YAML(_YAML): + def dump_to_string(self, data: Any, **kwargs: Any) -> str: + stream = StringIO() + self.dump(data=data, stream=stream, **kwargs) + return stream.getvalue() + + +yaml = YAML(typ=["safe", "string"]) + + +def json_with_tabs(d: dict) -> str: return json.dumps(d, indent=4).replace(" ", "\t") @pytest.mark.parametrize( "filename,dump", [ - ("example.yml", yaml.dump), + ("example.yml", yaml.dump_to_string), ("example.json", json.dumps), - ("example.yaml", yaml.dump), + ("example.yaml", yaml.dump_to_string), ("example.json", json_with_tabs), ], ) @pytest.mark.parametrize("relative", (True, False), ids=("relative", "absolute")) -def test_load_from_path(tmp_path: Path, filename, dump, relative): +def test_load_from_path(tmp_path: Path, filename, dump, relative) -> None: yml_file = tmp_path.joinpath(filename) if relative: if not os.getenv("TEST_RELATIVE"): @@ -42,8 +54,8 @@ def test_load_from_path(tmp_path: Path, filename, dump, relative): config = ConfigFile.load_from_path(yml_file) assert config.field_prefix == "blah" - assert config.class_overrides["Class1"].model_dump() == override1 - assert config.class_overrides["Class2"].model_dump() == override2 + assert config.class_overrides["Class1"] == ClassOverride.model_validate(override1) + assert config.class_overrides["Class2"] == ClassOverride.model_validate(override2) assert config.project_name_override == "project-name" assert config.package_name_override == "package_name" assert config.package_version_override == "package_version" diff --git a/tests/test_parser/test_bodies.py b/tests/test_parser/test_bodies.py index 699ed00cf..a18eddb04 100644 --- a/tests/test_parser/test_bodies.py +++ b/tests/test_parser/test_bodies.py @@ -1,7 +1,8 @@ from openapi_python_client import schema as oai -from openapi_python_client.parser.bodies import body_from_data +from openapi_python_client.parser.bodies import Body, body_from_data from openapi_python_client.parser.errors import ParseError from openapi_python_client.parser.properties import Schemas +from openapi_python_client.schema import UntrustedString def test_errors(config): @@ -32,7 +33,33 @@ def test_errors(config): responses={}, ) - errs, _ = body_from_data(data=operation, schemas=Schemas(), config=config, endpoint_name="this will not succeed") + errs, _ = body_from_data( + data=operation, schemas=Schemas(), config=config, endpoint_name="this will not succeed", request_bodies={} + ) assert len(errs) == len(operation.request_body.content) assert all(isinstance(err, ParseError) for err in errs) + + +def test_content_type_with_special_characters(config): + """Content types containing quotes or other special characters must stay wrapped for safe template rendering""" + operation = oai.Operation( + requestBody=oai.RequestBody( + content={ + 'application/json; profile="https://example.com"': oai.MediaType( + media_type_schema=oai.Schema(type=oai.DataType.STRING) + ) + } + ), + responses={}, + ) + + bodies, _ = body_from_data( + data=operation, schemas=Schemas(), config=config, endpoint_name="endpoint", request_bodies={} + ) + + assert len(bodies) == 1 + body = bodies[0] + assert isinstance(body, Body) + assert isinstance(body.content_type, UntrustedString) + assert body.content_type == 'application/json; profile="https://example.com"' diff --git a/tests/test_parser/test_openapi.py b/tests/test_parser/test_openapi.py index 43a9e8c42..535a04ffa 100644 --- a/tests/test_parser/test_openapi.py +++ b/tests/test_parser/test_openapi.py @@ -4,192 +4,31 @@ import pytest import openapi_python_client.schema as oai -from openapi_python_client import GeneratorError from openapi_python_client.parser.errors import ParseError -from openapi_python_client.parser.openapi import Endpoint, EndpointCollection -from openapi_python_client.parser.properties import IntProperty, Parameters, Schemas +from openapi_python_client.parser.openapi import Endpoint, EndpointCollection, import_string_from_class +from openapi_python_client.parser.properties import Class, IntProperty, Parameters, Schemas from openapi_python_client.schema import DataType +from openapi_python_client.schema.ref import Ref +from openapi_python_client.schema.untrusted_string import UntrustedString +from openapi_python_client.strings import PythonCode, PythonIdentifier MODULE_NAME = "openapi_python_client.parser.openapi" -class TestGeneratorData: - def test_from_dict(self, mocker, model_property_factory, enum_property_factory): - from openapi_python_client.parser.properties import Schemas - - build_schemas = mocker.patch(f"{MODULE_NAME}.build_schemas") - build_parameters = mocker.patch(f"{MODULE_NAME}.build_parameters") - EndpointCollection = mocker.patch(f"{MODULE_NAME}.EndpointCollection") - schemas = mocker.MagicMock() - schemas.classes_by_name = { - "Model": model_property_factory(), - "Enum": enum_property_factory(), - } - parameters = Parameters() - - endpoints_collections_by_tag = mocker.MagicMock() - EndpointCollection.from_data.return_value = (endpoints_collections_by_tag, schemas, parameters) - OpenAPI = mocker.patch(f"{MODULE_NAME}.oai.OpenAPI") - openapi = OpenAPI.model_validate.return_value - openapi.openapi = mocker.MagicMock(major=3) - config = mocker.MagicMock() - in_dict = mocker.MagicMock() - - from openapi_python_client.parser.openapi import GeneratorData - - generator_data = GeneratorData.from_dict(in_dict, config=config) - - OpenAPI.model_validate.assert_called_once_with(in_dict) - build_schemas.assert_called_once_with(components=openapi.components.schemas, config=config, schemas=Schemas()) - build_parameters.assert_called_once_with( - components=openapi.components.parameters, - parameters=parameters, - config=config, - ) - EndpointCollection.from_data.assert_called_once_with( - data=openapi.paths, - schemas=build_schemas.return_value, - parameters=build_parameters.return_value, - config=config, - ) - assert generator_data.title == openapi.info.title - assert generator_data.description == openapi.info.description - assert generator_data.version == openapi.info.version - assert generator_data.endpoint_collections_by_tag == endpoints_collections_by_tag - assert generator_data.errors == schemas.errors + parameters.errors - assert list(generator_data.models) == [schemas.classes_by_name["Model"]] - assert list(generator_data.enums) == [schemas.classes_by_name["Enum"]] - - # Test no components - openapi.components = None - build_schemas.reset_mock() - build_parameters.reset_mock() - - GeneratorData.from_dict(in_dict, config=config) - - build_schemas.assert_not_called() - build_parameters.assert_not_called() - - def test_from_dict_invalid_schema(self, mocker): - Schemas = mocker.patch(f"{MODULE_NAME}.Schemas") - config = mocker.MagicMock() - - in_dict = {} - - from openapi_python_client.parser.openapi import GeneratorData - - generator_data = GeneratorData.from_dict(in_dict, config=config) - - assert isinstance(generator_data, GeneratorError) - assert generator_data.header == "Failed to parse OpenAPI document" - keywords = ["3 validation errors for OpenAPI", "info", "paths", "openapi", "Field required"] - assert generator_data.detail and all(keyword in generator_data.detail for keyword in keywords) - - Schemas.build.assert_not_called() - Schemas.assert_not_called() - - def test_swagger_document_invalid_schema(self, mocker): - Schemas = mocker.patch(f"{MODULE_NAME}.Schemas") - config = mocker.MagicMock() - - in_dict = {"swagger": "2.0"} - - from openapi_python_client.parser.openapi import GeneratorData - - generator_data = GeneratorData.from_dict(in_dict, config=config) - - assert isinstance(generator_data, GeneratorError) - assert generator_data.header == "Failed to parse OpenAPI document" - keywords = [ - "You may be trying to use a Swagger document; this is not supported by this project.", - "info", - "paths", - "openapi", - "Field required", - ] - assert generator_data.detail and all(keyword in generator_data.detail for keyword in keywords) - - Schemas.build.assert_not_called() - Schemas.assert_not_called() - - class TestEndpoint: def make_endpoint(self): - from openapi_python_client.parser.openapi import Endpoint - return Endpoint( - path="path", + path=UntrustedString("path"), method="method", - description=None, - name="name", + description=UntrustedString(""), + name=PythonIdentifier("name", prefix=""), requires_security=False, - tag="tag", + tags=[PythonIdentifier("tag", prefix="")], relative_imports={"import_3"}, + summary=UntrustedString("summary"), ) - @pytest.mark.parametrize("response_status_code", ["not_a_number", 499]) - def test__add_responses_status_code_error(self, response_status_code, mocker): - from openapi_python_client.parser.openapi import Endpoint, Schemas - - schemas = Schemas() - response_1_data = mocker.MagicMock() - data = { - response_status_code: response_1_data, - } - endpoint = self.make_endpoint() - parse_error = ParseError(data=mocker.MagicMock()) - response_from_data = mocker.patch(f"{MODULE_NAME}.response_from_data", return_value=(parse_error, schemas)) - config = MagicMock() - - response, schemas = Endpoint._add_responses(endpoint=endpoint, data=data, schemas=schemas, config=config) - - assert response.errors == [ - ParseError( - detail=f"Invalid response status code {response_status_code} (not a valid HTTP status code), " - "response will be ommitted from generated client" - ) - ] - response_from_data.assert_not_called() - - def test__add_responses_error(self, mocker): - from openapi_python_client.parser.openapi import Endpoint, Schemas - - schemas = Schemas() - response_1_data = mocker.MagicMock() - response_2_data = mocker.MagicMock() - data = { - "200": response_1_data, - "404": response_2_data, - } - endpoint = self.make_endpoint() - parse_error = ParseError(data=mocker.MagicMock(), detail="some problem") - response_from_data = mocker.patch(f"{MODULE_NAME}.response_from_data", return_value=(parse_error, schemas)) - config = MagicMock() - - response, schemas = Endpoint._add_responses(endpoint=endpoint, data=data, schemas=schemas, config=config) - - response_from_data.assert_has_calls( - [ - mocker.call(status_code=200, data=response_1_data, schemas=schemas, parent_name="name", config=config), - mocker.call(status_code=404, data=response_2_data, schemas=schemas, parent_name="name", config=config), - ] - ) - assert response.errors == [ - ParseError( - detail="Cannot parse response for status code 200 (some problem), " - "response will be ommitted from generated client", - data=parse_error.data, - ), - ParseError( - detail="Cannot parse response for status code 404 (some problem), " - "response will be ommitted from generated client", - data=parse_error.data, - ), - ] - def test_add_parameters_handles_no_params(self): - from openapi_python_client.parser.openapi import Endpoint, Schemas - endpoint = self.make_endpoint() schemas = Schemas() parameters = Parameters() @@ -204,36 +43,6 @@ def test_add_parameters_handles_no_params(self): config=config, ) == (endpoint, schemas, parameters) - def test_add_parameters_parse_error(self, mocker): - from openapi_python_client.parser.openapi import Endpoint - - endpoint = self.make_endpoint() - initial_schemas = mocker.MagicMock() - initial_parameters = mocker.MagicMock() - parse_error = ParseError(data=mocker.MagicMock()) - property_schemas = mocker.MagicMock() - mocker.patch(f"{MODULE_NAME}.property_from_data", return_value=(parse_error, property_schemas)) - param = oai.Parameter.model_construct( - name="test", required=True, param_schema=mocker.MagicMock(), param_in="cookie" - ) - config = MagicMock() - - result, schemas, parameters = Endpoint.add_parameters( - endpoint=endpoint, - data=oai.Operation.model_construct(parameters=[param]), - schemas=initial_schemas, - parameters=initial_parameters, - config=config, - ) - assert (result, schemas, parameters) == ( - ParseError( - data=parse_error.data, - detail=f"cannot parse parameter of endpoint {endpoint.name}: {parse_error.detail}", - ), - initial_schemas, - initial_parameters, - ) - @pytest.mark.parametrize( "data_type, allowed", [ @@ -246,13 +55,14 @@ def test_add_parameters_parse_error(self, mocker): ], ) def test_add_parameters_header_types(self, data_type, allowed, config): - from openapi_python_client.parser.openapi import Endpoint - endpoint = self.make_endpoint() initial_schemas = Schemas() parameters = Parameters() param = oai.Parameter.model_construct( - name="test", required=True, param_schema=oai.Schema(type=data_type), param_in=oai.ParameterLocation.HEADER + name=UntrustedString("test"), + required=True, + param_schema=oai.Schema(type=data_type), + param_in=oai.ParameterLocation.HEADER, ) result = Endpoint.add_parameters( @@ -270,7 +80,7 @@ def test_add_parameters_header_types(self, data_type, allowed, config): def test__add_parameters_parse_error_on_non_required_path_param(self, config): endpoint = self.make_endpoint() param = oai.Parameter.model_construct( - name="test", + name=UntrustedString("test"), required=False, param_schema=oai.Schema.model_construct(type="string"), param_in=oai.ParameterLocation.PATH, @@ -298,7 +108,7 @@ def test__add_parameters_handles_invalid_references(self, config): endpoint = self.make_endpoint() data = oai.Operation.model_construct( parameters=[ - oai.Reference.model_construct(ref="blah"), + oai.Reference.model_construct(ref=Ref("blah")), ] ) @@ -310,29 +120,6 @@ def test__add_parameters_handles_invalid_references(self, config): assert isinstance(error, ParseError) assert parameters == return_parameters - def test__add_parameters_resolves_references(self, mocker, param_factory, config): - """References are not supported as direct params yet""" - endpoint = self.make_endpoint() - data = oai.Operation.model_construct( - parameters=[ - oai.Reference.model_construct(ref="#components/parameters/blah"), - ] - ) - - parameters = mocker.MagicMock() - new_param = param_factory(name="blah", schema=oai.Schema.model_construct(type="string")) - parameters.classes_by_name = { - "blah": new_param, - } - parameters.classes_by_reference = {"components/parameters/blah": new_param} - - (endpoint, _, return_parameters) = endpoint.add_parameters( - endpoint=endpoint, data=data, schemas=Schemas(), parameters=parameters, config=config - ) - - assert isinstance(endpoint, Endpoint) - assert parameters == return_parameters - def test__add_parameters_skips_params_without_schemas(self, config): """Params without schemas are allowed per spec, but the any type doesn't make sense as a parameter""" endpoint = self.make_endpoint() @@ -357,19 +144,19 @@ def test__add_parameters_same_identifier_conflict(self, config): data = oai.Operation.model_construct( parameters=[ oai.Parameter.model_construct( - name="param", + name=UntrustedString("param"), param_in="path", param_schema=oai.Schema.model_construct(type="string"), required=True, ), oai.Parameter.model_construct( - name="param_path", + name=UntrustedString("param_path"), param_in="path", param_schema=oai.Schema.model_construct(type="string"), required=True, ), oai.Parameter.model_construct( - name="param", + name=UntrustedString("param"), param_in="query", param_schema=oai.Schema.model_construct(type="string"), ), @@ -388,13 +175,13 @@ def test__add_parameters_query_optionality(self, config): data = oai.Operation.model_construct( parameters=[ oai.Parameter.model_construct( - name="not_required", + name=UntrustedString("not_required"), required=False, param_schema=oai.Schema.model_construct(type="string"), param_in="query", ), oai.Parameter.model_construct( - name="required", + name=UntrustedString("required"), required=True, param_schema=oai.Schema.model_construct(type="string"), param_in="query", @@ -406,7 +193,7 @@ def test__add_parameters_query_optionality(self, config): endpoint=endpoint, data=data, schemas=Schemas(), parameters=Parameters(), config=config ) - assert len(endpoint.query_parameters) == 2, "Not all query params were added" # noqa: PLR2004 + assert len(endpoint.query_parameters) == 2, "Not all query params were added" for param in endpoint.query_parameters: if param.name == "required": assert param.required @@ -414,11 +201,12 @@ def test__add_parameters_query_optionality(self, config): assert not param.required def test_add_parameters_duplicate_properties(self, config): - from openapi_python_client.parser.openapi import Endpoint, Schemas - endpoint = self.make_endpoint() param = oai.Parameter.model_construct( - name="test", required=True, param_schema=oai.Schema.model_construct(type="string"), param_in="path" + name=UntrustedString("test"), + required=True, + param_schema=oai.Schema.model_construct(type="string"), + param_in="path", ) data = oai.Operation.model_construct(parameters=[param, param]) schemas = Schemas() @@ -439,14 +227,18 @@ def test_add_parameters_duplicate_properties(self, config): ) def test_add_parameters_duplicate_properties_different_location(self, config): - from openapi_python_client.parser.openapi import Endpoint, Schemas - endpoint = self.make_endpoint() path_param = oai.Parameter.model_construct( - name="test", required=True, param_schema=oai.Schema.model_construct(type="string"), param_in="path" + name=UntrustedString("test"), + required=True, + param_schema=oai.Schema.model_construct(type="string"), + param_in="path", ) query_param = oai.Parameter.model_construct( - name="test", required=True, param_schema=oai.Schema.model_construct(type="string"), param_in="query" + name=UntrustedString("test"), + required=True, + param_schema=oai.Schema.model_construct(type="string"), + param_in="query", ) schemas = Schemas() parameters = Parameters() @@ -463,10 +255,8 @@ def test_add_parameters_duplicate_properties_different_location(self, config): assert result.query_parameters[0].name == "test" def test_sort_parameters(self, string_property_factory): - from openapi_python_client.parser.openapi import Endpoint - endpoint = self.make_endpoint() - endpoint.path = "/multiple-path-parameters/{param4}/{param2}/{param1}/{param3}" + endpoint.path = UntrustedString("/multiple-path-parameters/{param4}/{param2}/{param1}/{param3}") for i in range(1, 5): prop = string_property_factory(name=f"param{i}") @@ -479,10 +269,8 @@ def test_sort_parameters(self, string_property_factory): assert result_names == expected_names def test_sort_parameters_missing_param(self, string_property_factory): - from openapi_python_client.parser.openapi import Endpoint - endpoint = self.make_endpoint() - endpoint.path = "/multiple-path-parameters/{param1}/{param2}" + endpoint.path = UntrustedString("/multiple-path-parameters/{param1}/{param2}") param = string_property_factory(name="param1") endpoint.path_parameters.append(param) @@ -490,13 +278,11 @@ def test_sort_parameters_missing_param(self, string_property_factory): assert isinstance(result, ParseError) assert "Incorrect path templating" in result.detail - assert endpoint.path in result.detail + assert endpoint.path.get_untrusted_value() in result.detail def test_sort_parameters_extra_param(self, string_property_factory): - from openapi_python_client.parser.openapi import Endpoint - endpoint = self.make_endpoint() - endpoint.path = "/multiple-path-parameters" + endpoint.path = UntrustedString("/multiple-path-parameters") param = string_property_factory(name="param1") endpoint.path_parameters.append(param) @@ -504,221 +290,7 @@ def test_sort_parameters_extra_param(self, string_property_factory): assert isinstance(result, ParseError) assert "Incorrect path templating" in result.detail - assert endpoint.path in result.detail - - def test_from_data_bad_params(self, mocker, config): - from openapi_python_client.parser.openapi import Endpoint - - path = mocker.MagicMock() - method = mocker.MagicMock() - parse_error = ParseError(data=mocker.MagicMock()) - return_schemas = mocker.MagicMock() - return_parameters = mocker.MagicMock() - mocker.patch.object(Endpoint, "add_parameters", return_value=(parse_error, return_schemas, return_parameters)) - data = oai.Operation.model_construct( - description=mocker.MagicMock(), - operationId=mocker.MagicMock(), - security={"blah": "bloo"}, - responses=mocker.MagicMock(), - ) - initial_schemas = mocker.MagicMock() - parameters = Parameters() - - result = Endpoint.from_data( - data=data, - path=path, - method=method, - tag="default", - schemas=initial_schemas, - parameters=parameters, - config=config, - ) - - assert result == (parse_error, return_schemas, return_parameters) - - def test_from_data_bad_responses(self, mocker, config): - from openapi_python_client.parser.openapi import Endpoint - - path = mocker.MagicMock() - method = mocker.MagicMock() - parse_error = ParseError(data=mocker.MagicMock()) - param_schemas = mocker.MagicMock() - return_parameters = mocker.MagicMock() - mocker.patch.object( - Endpoint, "add_parameters", return_value=(mocker.MagicMock(), param_schemas, return_parameters) - ) - response_schemas = mocker.MagicMock() - _add_responses = mocker.patch.object(Endpoint, "_add_responses", return_value=(parse_error, response_schemas)) - data = oai.Operation.model_construct( - description=mocker.MagicMock(), - operationId=mocker.MagicMock(), - security={"blah": "bloo"}, - responses=mocker.MagicMock(), - ) - initial_schemas = mocker.MagicMock() - initial_parameters = mocker.MagicMock() - - result = Endpoint.from_data( - data=data, - path=path, - method=method, - tag="default", - schemas=initial_schemas, - parameters=initial_parameters, - config=config, - ) - - assert result == (parse_error, response_schemas, return_parameters) - - def test_from_data_standard(self, mocker, config): - from openapi_python_client.parser.openapi import Endpoint - - path = mocker.MagicMock() - method = mocker.MagicMock() - param_schemas = mocker.MagicMock() - param_endpoint = mocker.MagicMock() - return_parameters = mocker.MagicMock() - add_parameters = mocker.patch.object( - Endpoint, "add_parameters", return_value=(param_endpoint, param_schemas, return_parameters) - ) - response_schemas = mocker.MagicMock() - response_endpoint = mocker.MagicMock() - _add_responses = mocker.patch.object( - Endpoint, "_add_responses", return_value=(response_endpoint, response_schemas) - ) - data = oai.Operation.model_construct( - description=mocker.MagicMock(), - operationId=mocker.MagicMock(), - security={"blah": "bloo"}, - responses=mocker.MagicMock(), - ) - initial_schemas = mocker.MagicMock() - initial_parameters = mocker.MagicMock() - - mocker.patch("openapi_python_client.utils.remove_string_escapes", return_value=data.description) - - Endpoint.from_data( - data=data, - path=path, - method=method, - tag="default", - schemas=initial_schemas, - parameters=initial_parameters, - config=config, - ) - - add_parameters.assert_called_once_with( - endpoint=Endpoint( - path=path, - method=method, - description=data.description, - summary="", - name=data.operationId, - requires_security=True, - tag="default", - ), - data=data, - schemas=initial_schemas, - parameters=initial_parameters, - config=config, - ) - _add_responses.assert_called_once_with( - endpoint=param_endpoint, data=data.responses, schemas=param_schemas, config=config - ) - - def test_from_data_no_operation_id(self, mocker, config): - from openapi_python_client.parser.openapi import Endpoint - - path = "/path/with/{param}/" - method = "get" - add_parameters = mocker.patch.object( - Endpoint, "add_parameters", return_value=(mocker.MagicMock(), mocker.MagicMock(), mocker.MagicMock()) - ) - _add_responses = mocker.patch.object( - Endpoint, "_add_responses", return_value=(mocker.MagicMock(), mocker.MagicMock()) - ) - data = oai.Operation.model_construct( - description=mocker.MagicMock(), - operationId=None, - security={"blah": "bloo"}, - responses=mocker.MagicMock(), - ) - schemas = mocker.MagicMock() - mocker.patch("openapi_python_client.utils.remove_string_escapes", return_value=data.description) - parameters = mocker.MagicMock() - - endpoint, return_schemas, return_params = Endpoint.from_data( - data=data, path=path, method=method, tag="default", schemas=schemas, parameters=parameters, config=config - ) - - add_parameters.assert_called_once_with( - endpoint=Endpoint( - path=path, - method=method, - description=data.description, - summary="", - name="get_path_with_param", - requires_security=True, - tag="default", - ), - data=data, - schemas=schemas, - config=config, - parameters=parameters, - ) - _add_responses.assert_called_once_with( - endpoint=add_parameters.return_value[0], - data=data.responses, - schemas=add_parameters.return_value[1], - config=config, - ) - - def test_from_data_no_security(self, mocker, config): - from openapi_python_client.parser.openapi import Endpoint - - data = oai.Operation.model_construct( - description=mocker.MagicMock(), - operationId=mocker.MagicMock(), - security=None, - responses=mocker.MagicMock(), - ) - add_parameters = mocker.patch.object( - Endpoint, "add_parameters", return_value=(mocker.MagicMock(), mocker.MagicMock(), mocker.MagicMock()) - ) - _add_responses = mocker.patch.object( - Endpoint, "_add_responses", return_value=(mocker.MagicMock(), mocker.MagicMock()) - ) - path = mocker.MagicMock() - method = mocker.MagicMock() - mocker.patch("openapi_python_client.utils.remove_string_escapes", return_value=data.description) - schemas = mocker.MagicMock() - parameters = mocker.MagicMock() - - Endpoint.from_data( - data=data, path=path, method=method, tag="a", schemas=schemas, parameters=parameters, config=config - ) - - add_parameters.assert_called_once_with( - endpoint=Endpoint( - path=path, - method=method, - description=data.description, - summary="", - name=data.operationId, - requires_security=False, - tag="a", - ), - data=data, - parameters=parameters, - schemas=schemas, - config=config, - ) - _add_responses.assert_called_once_with( - endpoint=add_parameters.return_value[0], - data=data.responses, - schemas=add_parameters.return_value[1], - config=config, - ) + assert endpoint.path.get_untrusted_value() in result.detail def test_from_data_some_bad_bodies(self, config): endpoint, _, _ = Endpoint.from_data( @@ -732,11 +304,13 @@ def test_from_data_some_bad_bodies(self, config): ), ), schemas=Schemas(), + responses={}, config=config, parameters=Parameters(), - tag="tag", - path="/", + tags=["tag"], + path=UntrustedString("/"), method="get", + request_bodies={}, ) assert isinstance(endpoint, Endpoint) @@ -754,43 +328,39 @@ def test_from_data_all_bodies_bad(self, config): ), ), schemas=Schemas(), + responses={}, config=config, parameters=Parameters(), - tag="tag", - path="/", + tags=["tag"], + path=UntrustedString("/"), method="get", + request_bodies={}, ) assert isinstance(endpoint, ParseError) @pytest.mark.parametrize( "response_types, expected", - (([], "Any"), (["Something"], "Something"), (["First", "Second", "Second"], "Union[First, Second]")), + (([], "Any"), (["Something"], "Something"), (["First", "Second", "Second"], "First | Second")), ) def test_response_type(self, response_types, expected): endpoint = self.make_endpoint() for response_type in response_types: mock_response = MagicMock() - mock_response.prop.get_type_string.return_value = response_type - endpoint.responses.append(mock_response) + mock_response.prop.get_type_string.return_value = PythonCode(response_type) + endpoint.responses.patterns.append(mock_response) - assert endpoint.response_type() == expected + assert endpoint.response_type() == PythonCode(expected) class TestImportStringFromReference: def test_import_string_from_reference_no_prefix(self, mocker): - from openapi_python_client.parser.openapi import import_string_from_class - from openapi_python_client.parser.properties import Class - class_ = mocker.MagicMock(autospec=Class) result = import_string_from_class(class_) assert result == f"from .{class_.module_name} import {class_.name}" def test_import_string_from_reference_with_prefix(self, mocker): - from openapi_python_client.parser.openapi import import_string_from_class - from openapi_python_client.parser.properties import Class - prefix = mocker.MagicMock(autospec=str) class_ = mocker.MagicMock(autospec=Class) result = import_string_from_class(class_=class_, prefix=prefix) @@ -799,249 +369,36 @@ def test_import_string_from_reference_with_prefix(self, mocker): class TestEndpointCollection: - def test_from_data(self, mocker, config): - from openapi_python_client.parser.openapi import Endpoint, EndpointCollection - - path_1_put = oai.Operation.model_construct() - path_1_post = oai.Operation.model_construct(tags=["tag_2", "tag_3"]) - path_2_get = oai.Operation.model_construct() - data = { - "path_1": oai.PathItem.model_construct(post=path_1_post, put=path_1_put), - "path_2": oai.PathItem.model_construct(get=path_2_get), - } - endpoint_1 = mocker.MagicMock(autospec=Endpoint, tag="default", relative_imports={"1", "2"}, path="path_1") - endpoint_2 = mocker.MagicMock(autospec=Endpoint, tag="tag_2", relative_imports={"2"}, path="path_1") - endpoint_3 = mocker.MagicMock(autospec=Endpoint, tag="default", relative_imports={"2", "3"}, path="path_2") - schemas_1 = mocker.MagicMock() - schemas_2 = mocker.MagicMock() - schemas_3 = mocker.MagicMock() - parameters_1 = mocker.MagicMock() - parameters_2 = mocker.MagicMock() - parameters_3 = mocker.MagicMock() - endpoint_from_data = mocker.patch.object( - Endpoint, - "from_data", - side_effect=[ - (endpoint_1, schemas_1, parameters_1), - (endpoint_2, schemas_2, parameters_2), - (endpoint_3, schemas_3, parameters_3), - ], - ) - schemas = mocker.MagicMock() - parameters = mocker.MagicMock() - - result = EndpointCollection.from_data(data=data, schemas=schemas, parameters=parameters, config=config) - - endpoint_from_data.assert_has_calls( - [ - mocker.call( - data=path_1_put, - path="path_1", - method="put", - tag="default", - schemas=schemas, - parameters=parameters, - config=config, - ), - mocker.call( - data=path_1_post, - path="path_1", - method="post", - tag="tag_2", - schemas=schemas_1, - parameters=parameters_1, - config=config, - ), - mocker.call( - data=path_2_get, - path="path_2", - method="get", - tag="default", - schemas=schemas_2, - parameters=parameters_2, - config=config, - ), - ], - ) - assert result == ( - { - "default": EndpointCollection("default", endpoints=[endpoint_1, endpoint_3]), - "tag_2": EndpointCollection("tag_2", endpoints=[endpoint_2]), - }, - schemas_3, - parameters_3, - ) - def test_from_data_overrides_path_item_params_with_operation_params(self, config): data = { - "/": oai.PathItem.model_construct( + UntrustedString("/"): oai.PathItem.model_construct( parameters=[ oai.Parameter.model_construct( - name="param", param_in="query", param_schema=oai.Schema.model_construct(type="string") + name=UntrustedString("param"), + param_in="query", + param_schema=oai.Schema.model_construct(type="string"), ), ], get=oai.Operation.model_construct( parameters=[ oai.Parameter.model_construct( - name="param", param_in="query", param_schema=oai.Schema.model_construct(type="integer") + name=UntrustedString("param"), + param_in="query", + param_schema=oai.Schema.model_construct(type="integer"), ) ], - responses={"200": oai.Response.model_construct(description="blah")}, + responses={UntrustedString("200"): oai.Response.model_construct(description="blah")}, ), ) } - collections, schemas, parameters = EndpointCollection.from_data( + collections, _schemas, _parameters = EndpointCollection.from_data( data=data, schemas=Schemas(), parameters=Parameters(), config=config, + request_bodies={}, + responses={}, ) collection: EndpointCollection = collections["default"] assert isinstance(collection.endpoints[0].query_parameters[0], IntProperty) - - def test_from_data_errors(self, mocker, config): - from openapi_python_client.parser.openapi import ParseError - - path_1_put = oai.Operation.model_construct() - path_1_post = oai.Operation.model_construct(tags=["tag_2", "tag_3"]) - path_2_get = oai.Operation.model_construct() - data = { - "path_1": oai.PathItem.model_construct(post=path_1_post, put=path_1_put), - "path_2": oai.PathItem.model_construct(get=path_2_get), - } - schemas_1 = mocker.MagicMock() - schemas_2 = mocker.MagicMock() - schemas_3 = mocker.MagicMock() - parameters_1 = mocker.MagicMock() - parameters_2 = mocker.MagicMock() - parameters_3 = mocker.MagicMock() - endpoint_from_data = mocker.patch.object( - Endpoint, - "from_data", - side_effect=[ - (ParseError(data="1"), schemas_1, parameters_1), - (ParseError(data="2"), schemas_2, parameters_2), - (mocker.MagicMock(errors=[ParseError(data="3")], path="path_2"), schemas_3, parameters_3), - ], - ) - schemas = mocker.MagicMock() - parameters = mocker.MagicMock() - - result, result_schemas, result_parameters = EndpointCollection.from_data( - data=data, schemas=schemas, config=config, parameters=parameters - ) - - endpoint_from_data.assert_has_calls( - [ - mocker.call( - data=path_1_put, - path="path_1", - method="put", - tag="default", - schemas=schemas, - parameters=parameters, - config=config, - ), - mocker.call( - data=path_1_post, - path="path_1", - method="post", - tag="tag_2", - schemas=schemas_1, - parameters=parameters_1, - config=config, - ), - mocker.call( - data=path_2_get, - path="path_2", - method="get", - tag="default", - schemas=schemas_2, - parameters=parameters_2, - config=config, - ), - ], - ) - assert result["default"].parse_errors[0].data == "1" - assert result["default"].parse_errors[1].data == "3" - assert result["tag_2"].parse_errors[0].data == "2" - assert result_schemas == schemas_3 - - def test_from_data_tags_snake_case_sanitizer(self, mocker, config): - from openapi_python_client.parser.openapi import Endpoint, EndpointCollection - - path_1_put = oai.Operation.model_construct() - path_1_post = oai.Operation.model_construct(tags=["AMF Subscription Info (Document)", "tag_3"]) - path_2_get = oai.Operation.model_construct(tags=["3. ABC"]) - data = { - "path_1": oai.PathItem.model_construct(post=path_1_post, put=path_1_put), - "path_2": oai.PathItem.model_construct(get=path_2_get), - } - endpoint_1 = mocker.MagicMock(autospec=Endpoint, tag="default", relative_imports={"1", "2"}, path="path_1") - endpoint_2 = mocker.MagicMock( - autospec=Endpoint, tag="AMFSubscriptionInfo (Document)", relative_imports={"2"}, path="path_1" - ) - endpoint_3 = mocker.MagicMock(autospec=Endpoint, tag="default", relative_imports={"2", "3"}, path="path_2") - schemas_1 = mocker.MagicMock() - schemas_2 = mocker.MagicMock() - schemas_3 = mocker.MagicMock() - parameters_1 = mocker.MagicMock() - parameters_2 = mocker.MagicMock() - parameters_3 = mocker.MagicMock() - endpoint_from_data = mocker.patch.object( - Endpoint, - "from_data", - side_effect=[ - (endpoint_1, schemas_1, parameters_1), - (endpoint_2, schemas_2, parameters_2), - (endpoint_3, schemas_3, parameters_3), - ], - ) - schemas = mocker.MagicMock() - parameters = mocker.MagicMock() - - result = EndpointCollection.from_data(data=data, schemas=schemas, parameters=parameters, config=config) - - endpoint_from_data.assert_has_calls( - [ - mocker.call( - data=path_1_put, - path="path_1", - method="put", - tag="default", - schemas=schemas, - parameters=parameters, - config=config, - ), - mocker.call( - data=path_1_post, - path="path_1", - method="post", - tag="amf_subscription_info_document", - schemas=schemas_1, - parameters=parameters_1, - config=config, - ), - mocker.call( - data=path_2_get, - path="path_2", - method="get", - tag="tag3_abc", - schemas=schemas_2, - parameters=parameters_2, - config=config, - ), - ], - ) - assert result == ( - { - "default": EndpointCollection("default", endpoints=[endpoint_1]), - "amf_subscription_info_document": EndpointCollection( - "amf_subscription_info_document", endpoints=[endpoint_2] - ), - "tag3_abc": EndpointCollection("tag3_abc", endpoints=[endpoint_3]), - }, - schemas_3, - parameters_3, - ) diff --git a/tests/test_parser/test_properties/test_any.py b/tests/test_parser/test_properties/test_any.py deleted file mode 100644 index 7738a24f9..000000000 --- a/tests/test_parser/test_properties/test_any.py +++ /dev/null @@ -1,12 +0,0 @@ -from openapi_python_client.parser.properties import AnyProperty - - -def test_default(): - AnyProperty.build( - name="test", - required=True, - default=42, - python_name="test", - description="test", - example="test", - ) diff --git a/tests/test_parser/test_properties/test_boolean.py b/tests/test_parser/test_properties/test_boolean.py deleted file mode 100644 index 0c4abf0f3..000000000 --- a/tests/test_parser/test_properties/test_boolean.py +++ /dev/null @@ -1,54 +0,0 @@ -import pytest - -from openapi_python_client.parser.errors import PropertyError -from openapi_python_client.parser.properties import BooleanProperty - - -def test_invalid_default_value(): - err = BooleanProperty.build( - default="not a boolean", - description=None, - example=None, - required=False, - python_name="not_a_boolean", - name="not_a_boolean", - ) - - assert isinstance(err, PropertyError) - - -@pytest.mark.parametrize( - ("value", "expected"), - ( - ("true", "True"), - ("True", "True"), - ("false", "False"), - ("False", "False"), - ), -) -def test_string_default(value, expected): - prop = BooleanProperty.build( - default=value, - description=None, - example=None, - required=False, - python_name="not_a_boolean", - name="not_a_boolean", - ) - - assert isinstance(prop, BooleanProperty) - assert prop.default == expected - - -def test_bool_default(): - prop = BooleanProperty.build( - default=True, - description=None, - example=None, - required=False, - python_name="not_a_boolean", - name="not_a_boolean", - ) - - assert isinstance(prop, BooleanProperty) - assert prop.default == "True" diff --git a/tests/test_parser/test_properties/test_const.py b/tests/test_parser/test_properties/test_const.py deleted file mode 100644 index 6d2ad0bfe..000000000 --- a/tests/test_parser/test_properties/test_const.py +++ /dev/null @@ -1,55 +0,0 @@ -from openapi_python_client.parser.errors import PropertyError -from openapi_python_client.parser.properties import ConstProperty -from openapi_python_client.parser.properties.protocol import Value - - -def test_default_doesnt_match_const(): - err = ConstProperty.build( - name="test", - required=True, - default="not the value", - python_name="test", - description=None, - const="the value", - ) - - assert isinstance(err, PropertyError) - - -def test_non_string_const(): - prop = ConstProperty.build( - name="test", - required=True, - default=123, - python_name="test", - description=None, - const=123, - ) - - assert isinstance(prop, ConstProperty) - - -def test_const_already_converted(): - prop = ConstProperty.build( - name="test", - required=True, - default=123, - python_name="test", - description=None, - const=Value("123"), - ) - - assert isinstance(prop, ConstProperty) - - -def test_default_already_converted(): - prop = ConstProperty.build( - name="test", - required=True, - default=Value("123"), - python_name="test", - description=None, - const=123, - ) - - assert isinstance(prop, ConstProperty) diff --git a/tests/test_parser/test_properties/test_date.py b/tests/test_parser/test_properties/test_date.py deleted file mode 100644 index 0c70b5c30..000000000 --- a/tests/test_parser/test_properties/test_date.py +++ /dev/null @@ -1,33 +0,0 @@ -from openapi_python_client.parser.errors import PropertyError -from openapi_python_client.parser.properties import DateProperty -from openapi_python_client.parser.properties.protocol import Value - - -def test_invalid_default_value(): - err = DateProperty.build( - default="not a date", - description=None, - example=None, - required=False, - python_name="not_a_date", - name="not_a_date", - ) - - assert isinstance(err, PropertyError) - - -def test_default_with_bad_type(): - err = DateProperty.build( - default=123, - description=None, - example=None, - required=False, - python_name="not_a_date", - name="not_a_date", - ) - - assert isinstance(err, PropertyError) - - -def test_dont_recheck_value(): - DateProperty.convert_value(Value("not a date but trust me")) diff --git a/tests/test_parser/test_properties/test_datetime.py b/tests/test_parser/test_properties/test_datetime.py deleted file mode 100644 index 7853208d7..000000000 --- a/tests/test_parser/test_properties/test_datetime.py +++ /dev/null @@ -1,33 +0,0 @@ -from openapi_python_client.parser.errors import PropertyError -from openapi_python_client.parser.properties import DateTimeProperty -from openapi_python_client.parser.properties.protocol import Value - - -def test_invalid_default_value(): - err = DateTimeProperty.build( - default="not a date", - description=None, - example=None, - required=False, - python_name="not_a_date", - name="not_a_date", - ) - - assert isinstance(err, PropertyError) - - -def test_default_with_bad_type(): - err = DateTimeProperty.build( - default=123, - description=None, - example=None, - required=False, - python_name="not_a_date", - name="not_a_date", - ) - - assert isinstance(err, PropertyError) - - -def test_dont_recheck_value(): - DateTimeProperty.convert_value(Value("not a date but trust me")) diff --git a/tests/test_parser/test_properties/test_enum_property.py b/tests/test_parser/test_properties/test_enum_property.py index 704f48b3b..afa9dc843 100644 --- a/tests/test_parser/test_properties/test_enum_property.py +++ b/tests/test_parser/test_properties/test_enum_property.py @@ -1,68 +1,27 @@ -import openapi_python_client.schema as oai -from openapi_python_client.parser.errors import PropertyError -from openapi_python_client.parser.properties import EnumProperty, Schemas +from openapi_python_client.parser.properties import EnumProperty +from openapi_python_client.parser.properties.schemas import Class +from openapi_python_client.schema.untrusted_string import UntrustedString +from openapi_python_client.strings import ClassName, PythonIdentifier -def test_conflict(config): - schemas = Schemas() +def _class_info() -> Class: + return Class(name=ClassName(UntrustedString("MyEnum"), ""), module_name=PythonIdentifier("my_enum", "")) - _, schemas = EnumProperty.build( - data=oai.Schema(enum=["a"]), name="Existing", required=True, schemas=schemas, parent_name="", config=config - ) - err, new_schemas = EnumProperty.build( - data=oai.Schema(enum=["a", "b"]), - name="Existing", - required=True, - schemas=schemas, - parent_name="", - config=config, - ) - assert schemas == new_schemas - assert err.detail == "Found conflicting enums named Existing with incompatible values." +def test_values_from_list_escapes_or_strips_control_characters(): + """Values are embedded in double-quoted string literals; newlines and control characters must be escaped""" + values = EnumProperty.values_from_list(["line\nbreak", "tab\there", "nul\x00byte"], _class_info(), []) + assert values["LINEBREAK"] == "linebreak" + assert values["TABHERE"] == "tab\\there" + assert values["NULBYTE"] == "nulbyte" + # Every value must be safe inside a "..." literal in generated source + for value in values.values(): + assert all(ord(c) >= 0x20 for c in value), value -def test_bad_default_value(config): - data = oai.Schema(default="B", enum=["A"]) - schemas = Schemas() - err, new_schemas = EnumProperty.build( - data=data, name="Existing", required=True, schemas=schemas, parent_name="parent", config=config - ) +def test_values_from_list_sanitizes_keys_with_backslash(): + """A backslash in a value must not survive into the generated identifier""" + values = EnumProperty.values_from_list(["one\\two"], _class_info(), []) - assert schemas == new_schemas - assert err == PropertyError(detail="Value B is not valid for enum Existing", data=data) - - -def test_bad_default_type(config): - data = oai.Schema(default=123, enum=["A"]) - schemas = Schemas() - - err, new_schemas = EnumProperty.build( - data=data, name="Existing", required=True, schemas=schemas, parent_name="parent", config=config - ) - - assert schemas == new_schemas - assert isinstance(err, PropertyError) - - -def test_mixed_types(config): - data = oai.Schema(enum=["A", 1]) - schemas = Schemas() - - err, _ = EnumProperty.build( - data=data, name="Enum", required=True, schemas=schemas, parent_name="parent", config=config - ) - - assert isinstance(err, PropertyError) - - -def test_unsupported_type(config): - data = oai.Schema(enum=[1.4, 1.5]) - schemas = Schemas() - - err, _ = EnumProperty.build( - data=data, name="Enum", required=True, schemas=schemas, parent_name="parent", config=config - ) - - assert isinstance(err, PropertyError) + assert list(values) == ["ONE_TWO"] diff --git a/tests/test_parser/test_properties/test_file.py b/tests/test_parser/test_properties/test_file.py index 87298ba03..f399e8278 100644 --- a/tests/test_parser/test_properties/test_file.py +++ b/tests/test_parser/test_properties/test_file.py @@ -3,6 +3,8 @@ def test_no_default_allowed(): + # currently this is testing an unused code path: + # https://github.com/openapi-generators/openapi-python-client/issues/1162 err = FileProperty.build( default="not none", description=None, diff --git a/tests/test_parser/test_properties/test_float.py b/tests/test_parser/test_properties/test_float.py deleted file mode 100644 index 9d1159409..000000000 --- a/tests/test_parser/test_properties/test_float.py +++ /dev/null @@ -1,43 +0,0 @@ -from openapi_python_client.parser.errors import PropertyError -from openapi_python_client.parser.properties import FloatProperty -from openapi_python_client.parser.properties.protocol import Value - - -def test_invalid_default(): - err = FloatProperty.build( - default="not a float", - description=None, - example=None, - required=False, - python_name="not_a_float", - name="not_a_float", - ) - - assert isinstance(err, PropertyError) - - -def test_convert_from_string(): - val = FloatProperty.convert_value("1.0") - assert isinstance(val, Value) - assert val == "1.0" - assert FloatProperty.convert_value("1") == "1.0" - - -def test_convert_from_float(): - val = FloatProperty.convert_value(1.0) - assert isinstance(val, Value) - assert val == "1.0" - assert FloatProperty.convert_value(1) == "1.0" - - -def test_invalid_type_default(): - err = FloatProperty.build( - default=True, - description=None, - example=None, - required=False, - python_name="not_a_float", - name="not_a_float", - ) - - assert isinstance(err, PropertyError) diff --git a/tests/test_parser/test_properties/test_init.py b/tests/test_parser/test_properties/test_init.py index 3290dcd39..09446414f 100644 --- a/tests/test_parser/test_properties/test_init.py +++ b/tests/test_parser/test_properties/test_init.py @@ -1,210 +1,33 @@ -from unittest.mock import MagicMock, call - -import attr import pytest import openapi_python_client.schema as oai -from openapi_python_client.parser.errors import ParameterError, PropertyError +from openapi_python_client.parser.errors import PropertyError from openapi_python_client.parser.properties import ( - ListProperty, + Class, + ReferencePath, Schemas, - StringProperty, - UnionProperty, + _propogate_removal, + build_schemas, + property_from_data, ) -from openapi_python_client.parser.properties.protocol import ModelProperty -from openapi_python_client.schema import DataType -from openapi_python_client.utils import ClassName, PythonIdentifier +from openapi_python_client.schema.ref import Ref +from openapi_python_client.schema.untrusted_string import UntrustedString +from openapi_python_client.strings import ClassName, PythonCode, PythonIdentifier MODULE_NAME = "openapi_python_client.parser.properties" -class TestStringProperty: - def test_is_base_type(self, string_property_factory): - assert string_property_factory().is_base_type is True - - @pytest.mark.parametrize( - "required, expected", - ( - (True, "str"), - (False, "Union[Unset, str]"), - ), - ) - def test_get_type_string(self, string_property_factory, required, expected): - p = string_property_factory(required=required) - - assert p.get_type_string() == expected - - -class TestDateTimeProperty: - def test_is_base_type(self, date_time_property_factory): - assert date_time_property_factory().is_base_type is True - - @pytest.mark.parametrize("required", (True, False)) - def test_get_imports(self, date_time_property_factory, required): - p = date_time_property_factory(required=required) - - expected = { - "import datetime", - "from typing import cast", - "from dateutil.parser import isoparse", - } - if not required: - expected |= { - "from typing import Union", - "from ...types import UNSET, Unset", - } - - assert p.get_imports(prefix="...") == expected - - -class TestDateProperty: - def test_is_base_type(self, date_property_factory): - assert date_property_factory().is_base_type is True - - @pytest.mark.parametrize("required", (True, False)) - def test_get_imports(self, date_property_factory, required): - p = date_property_factory(required=required) - - expected = { - "import datetime", - "from typing import cast", - "from dateutil.parser import isoparse", - } - if not required: - expected |= { - "from typing import Union", - "from ...types import UNSET, Unset", - } - - assert p.get_imports(prefix="...") == expected - - class TestFileProperty: - def test_is_base_type(self, file_property_factory): - assert file_property_factory().is_base_type is True - @pytest.mark.parametrize("required", (True, False)) def test_get_imports(self, file_property_factory, required): p = file_property_factory(required=required) expected = { "from io import BytesIO", - "from ...types import File, FileJsonType", + "from ...types import File, FileTypes", } if not required: expected |= { - "from typing import Union", - "from ...types import UNSET, Unset", - } - - assert p.get_imports(prefix="...") == expected - - -class TestNoneProperty: - def test_is_base_type(self, none_property_factory): - assert none_property_factory().is_base_type is True - - -class TestBooleanProperty: - def test_is_base_type(self, boolean_property_factory): - assert boolean_property_factory().is_base_type is True - - -class TestAnyProperty: - def test_is_base_type(self, any_property_factory): - assert any_property_factory().is_base_type is True - - -class TestIntProperty: - def test_is_base_type(self, int_property_factory): - assert int_property_factory().is_base_type is True - - -class TestListProperty: - def test_is_base_type(self, list_property_factory): - assert list_property_factory().is_base_type is False - - @pytest.mark.parametrize("quoted", (True, False)) - def test_get_base_json_type_string_base_inner(self, list_property_factory, quoted): - p = list_property_factory() - assert p.get_base_json_type_string(quoted=quoted) == "List[str]" - - @pytest.mark.parametrize("quoted", (True, False)) - def test_get_base_json_type_string_model_inner(self, list_property_factory, model_property_factory, quoted): - m = model_property_factory() - p = list_property_factory(inner_property=m) - assert p.get_base_json_type_string(quoted=quoted) == "List[Dict[str, Any]]" - - def test_get_lazy_import_base_inner(self, list_property_factory): - p = list_property_factory() - assert p.get_lazy_imports(prefix="..") == set() - - def test_get_lazy_import_model_inner(self, list_property_factory, model_property_factory): - m = model_property_factory() - p = list_property_factory(inner_property=m) - assert p.get_lazy_imports(prefix="..") == {"from ..models.my_module import MyClass"} - - @pytest.mark.parametrize( - "required, expected", - ( - (True, "List[str]"), - (False, "Union[Unset, List[str]]"), - ), - ) - def test_get_type_string_base_inner(self, list_property_factory, required, expected): - p = list_property_factory(required=required) - - assert p.get_type_string() == expected - - @pytest.mark.parametrize( - "required, expected", - ( - (True, "List['MyClass']"), - (False, "Union[Unset, List['MyClass']]"), - ), - ) - def test_get_type_string_model_inner(self, list_property_factory, model_property_factory, required, expected): - m = model_property_factory() - p = list_property_factory(required=required, inner_property=m) - - assert p.get_type_string() == expected - - @pytest.mark.parametrize( - "quoted,expected", - [ - (False, "List[str]"), - (True, "List[str]"), - ], - ) - def test_get_base_type_string_base_inner(self, list_property_factory, quoted, expected): - p = list_property_factory() - assert p.get_base_type_string(quoted=quoted) == expected - - @pytest.mark.parametrize( - "quoted,expected", - [ - (False, "List['MyClass']"), - (True, "List['MyClass']"), - ], - ) - def test_get_base_type_string_model_inner(self, list_property_factory, model_property_factory, quoted, expected): - m = model_property_factory() - p = list_property_factory(inner_property=m) - assert p.get_base_type_string(quoted=quoted) == expected - - @pytest.mark.parametrize("required", (True, False)) - def test_get_type_imports(self, list_property_factory, date_time_property_factory, required): - inner_property = date_time_property_factory() - p = list_property_factory(inner_property=inner_property, required=required) - expected = { - "import datetime", - "from typing import cast", - "from dateutil.parser import isoparse", - "from typing import cast, List", - } - if not required: - expected |= { - "from typing import Union", "from ...types import UNSET, Unset", } @@ -212,9 +35,6 @@ def test_get_type_imports(self, list_property_factory, date_time_property_factor class TestUnionProperty: - def test_is_base_type(self, union_property_factory): - assert union_property_factory().is_base_type is False - def test_get_lazy_import_base_inner(self, union_property_factory): p = union_property_factory() assert p.get_lazy_imports(prefix="..") == set() @@ -227,11 +47,11 @@ def test_get_lazy_import_model_inner(self, union_property_factory, model_propert @pytest.mark.parametrize( "required,no_optional,json,expected", [ - (False, False, False, "Union[Unset, datetime.datetime, str]"), - (False, True, False, "Union[datetime.datetime, str]"), - (True, False, False, "Union[datetime.datetime, str]"), - (True, True, False, "Union[datetime.datetime, str]"), - (False, False, True, "Union[Unset, str]"), + (False, False, False, "datetime.datetime | str | Unset"), + (False, True, False, "datetime.datetime | str"), + (True, False, False, "datetime.datetime | str"), + (True, True, False, "datetime.datetime | str"), + (False, False, True, "str | Unset"), (False, True, True, "str"), (True, False, True, "str"), (True, True, True, "str"), @@ -252,44 +72,44 @@ def test_get_type_string( inner_properties=[date_time_property_factory(), string_property_factory()], ) - assert p.get_base_type_string() == "Union[datetime.datetime, str]" + assert p.get_base_type_string() == PythonCode("datetime.datetime | str") - assert p.get_type_string(no_optional=no_optional, json=json) == expected + assert p.get_type_string(no_optional=no_optional, json=json) == PythonCode(expected) def test_get_base_type_string_base_inners( self, union_property_factory, date_time_property_factory, string_property_factory ): p = union_property_factory(inner_properties=[date_time_property_factory(), string_property_factory()]) - assert p.get_base_type_string() == "Union[datetime.datetime, str]" + assert p.get_base_type_string() == PythonCode("datetime.datetime | str") def test_get_base_type_string_one_base_inner(self, union_property_factory, date_time_property_factory): p = union_property_factory( inner_properties=[date_time_property_factory()], ) - assert p.get_base_type_string() == "datetime.datetime" + assert p.get_base_type_string() == PythonCode("datetime.datetime") def test_get_base_type_string_one_model_inner(self, union_property_factory, model_property_factory): p = union_property_factory( inner_properties=[model_property_factory()], ) - assert p.get_base_type_string() == "'MyClass'" + assert p.get_base_type_string() == PythonCode("MyClass") def test_get_base_type_string_model_inners( self, union_property_factory, date_time_property_factory, model_property_factory ): p = union_property_factory(inner_properties=[date_time_property_factory(), model_property_factory()]) - assert p.get_base_type_string() == "Union['MyClass', datetime.datetime]" + assert p.get_base_type_string() == PythonCode("datetime.datetime | MyClass") def test_get_base_json_type_string(self, union_property_factory, date_time_property_factory): p = union_property_factory( inner_properties=[date_time_property_factory()], ) - assert p.get_base_json_type_string() == "str" + assert p.get_base_json_type_string() == PythonCode("str") @pytest.mark.parametrize("required", (True, False)) def test_get_type_imports(self, union_property_factory, date_time_property_factory, required): @@ -300,283 +120,30 @@ def test_get_type_imports(self, union_property_factory, date_time_property_facto expected = { "import datetime", "from typing import cast", - "from dateutil.parser import isoparse", - "from typing import cast, Union", } if not required: expected |= { - "from typing import Union", "from ...types import UNSET, Unset", } assert p.get_imports(prefix="...") == expected -class TestEnumProperty: - def test_is_base_type(self, enum_property_factory): - assert enum_property_factory().is_base_type is True - - @pytest.mark.parametrize( - "required, expected", - ( - (False, "Union[Unset, {}]"), - (True, "{}"), - ), - ) - def test_get_type_string(self, mocker, enum_property_factory, required, expected): - fake_class = mocker.MagicMock() - fake_class.name = "MyTestEnum" - - p = enum_property_factory(class_info=fake_class, required=required) - - assert p.get_type_string() == expected.format(fake_class.name) - assert p.get_type_string(no_optional=True) == fake_class.name - assert p.get_type_string(json=True) == expected.format("str") - - def test_get_imports(self, mocker, enum_property_factory): - fake_class = mocker.MagicMock(module_name="my_test_enum") - fake_class.name = "MyTestEnum" - prefix = "..." - - enum_property = enum_property_factory(class_info=fake_class, required=False) - - assert enum_property.get_imports(prefix=prefix) == { - f"from {prefix}models.{fake_class.module_name} import {fake_class.name}", - "from typing import Union", # Makes sure unset is handled via base class - "from ...types import UNSET, Unset", - } - - def test_values_from_list(self): - from openapi_python_client.parser.properties import EnumProperty - - data = ["abc", "123", "a23", "1bc", 4, -3, "a Thing WIth spaces", ""] - - result = EnumProperty.values_from_list(data) - - assert result == { - "ABC": "abc", - "VALUE_1": "123", - "A23": "a23", - "VALUE_3": "1bc", - "VALUE_4": 4, - "VALUE_NEGATIVE_3": -3, - "A_THING_WITH_SPACES": "a Thing WIth spaces", - "VALUE_7": "", - } - - def test_values_from_list_duplicate(self): - from openapi_python_client.parser.properties import EnumProperty - - data = ["abc", "123", "a23", "abc"] - - with pytest.raises(ValueError): - EnumProperty.values_from_list(data) - - class TestPropertyFromData: - def test_property_from_data_str_enum(self, enum_property_factory, config): - from openapi_python_client.parser.properties import Class, Schemas, property_from_data - from openapi_python_client.schema import Schema - - existing = enum_property_factory() - data = Schema(title="AnEnum", enum=["A", "B", "C"], default="B") - name = "my_enum" - required = True - - schemas = Schemas(classes_by_name={"AnEnum": existing}) - - prop, new_schemas = property_from_data( - name=name, required=required, data=data, schemas=schemas, parent_name="parent", config=config - ) - - assert prop == enum_property_factory( - name=name, - required=required, - values={"A": "A", "B": "B", "C": "C"}, - class_info=Class(name="ParentAnEnum", module_name="parent_an_enum"), - value_type=str, - default="ParentAnEnum.B", - ) - assert schemas != new_schemas, "Provided Schemas was mutated" - assert new_schemas.classes_by_name == { - "AnEnum": existing, - "ParentAnEnum": prop, - } - - def test_property_from_data_str_enum_with_null( - self, enum_property_factory, union_property_factory, none_property_factory, config - ): - from openapi_python_client.parser.properties import Class, Schemas, property_from_data - from openapi_python_client.schema import Schema - - existing = enum_property_factory() - data = Schema(title="AnEnum", enum=["A", "B", "C", None], default="B") - name = "my_enum" - required = True - - schemas = Schemas(classes_by_name={"AnEnum": existing}) - - prop, new_schemas = property_from_data( - name=name, required=required, data=data, schemas=schemas, parent_name="parent", config=config - ) - - # None / null is removed from enum, and property is now nullable - assert isinstance(prop, UnionProperty), "Enums with None should be converted to UnionProperties" - enum_prop = enum_property_factory( - name="my_enum_type_1", - required=required, - values={"A": "A", "B": "B", "C": "C"}, - class_info=Class(name="ParentAnEnum", module_name="parent_an_enum"), - value_type=str, - default="ParentAnEnum.B", - ) - none_property = none_property_factory(name="my_enum_type_0", required=required) - assert prop == union_property_factory( - name=name, default="ParentAnEnum.B", inner_properties=[none_property, enum_prop] - ) - assert schemas != new_schemas, "Provided Schemas was mutated" - assert new_schemas.classes_by_name == { - "AnEnum": existing, - "ParentAnEnum": enum_prop, - } - - def test_property_from_data_null_enum(self, enum_property_factory, none_property_factory, config): - from openapi_python_client.parser.properties import Schemas, property_from_data - from openapi_python_client.schema import Schema - - data = Schema(title="AnEnumWithOnlyNull", enum=[None], default=None) - name = "my_enum" - required = True - - schemas = Schemas() - - prop, new_schemas = property_from_data( - name=name, required=required, data=data, schemas=schemas, parent_name="parent", config=config - ) - - assert prop == none_property_factory(name="my_enum", required=required, default="None") - - def test_property_from_data_int_enum(self, enum_property_factory, config): - from openapi_python_client.parser.properties import Class, Schemas, property_from_data - from openapi_python_client.schema import Schema - - name = "my_enum" - required = True - data = Schema.model_construct(title="anEnum", enum=[1, 2, 3], default=3) - - existing = enum_property_factory() - schemas = Schemas(classes_by_name={"AnEnum": existing}) - - prop, new_schemas = property_from_data( - name=name, required=required, data=data, schemas=schemas, parent_name="parent", config=config - ) - - assert prop == enum_property_factory( - name=name, - required=required, - values={"VALUE_1": 1, "VALUE_2": 2, "VALUE_3": 3}, - class_info=Class(name="ParentAnEnum", module_name="parent_an_enum"), - value_type=int, - default="ParentAnEnum.VALUE_3", - ) - assert schemas != new_schemas, "Provided Schemas was mutated" - assert new_schemas.classes_by_name == { - "AnEnum": existing, - "ParentAnEnum": prop, - } - - def test_property_from_data_ref_enum(self, enum_property_factory, config): - from openapi_python_client.parser.properties import Class, Schemas, property_from_data - - name = "some_enum" - data = oai.Reference.model_construct(ref="#/components/schemas/MyEnum") - existing_enum = enum_property_factory( - name="an_enum", - required=False, - values={"A": "a"}, - class_info=Class(name="MyEnum", module_name="my_enum"), - ) - schemas = Schemas(classes_by_reference={"/components/schemas/MyEnum": existing_enum}) - - prop, new_schemas = property_from_data( - name=name, required=False, data=data, schemas=schemas, parent_name="", config=config - ) - - assert prop == enum_property_factory( - name="some_enum", - required=False, - values={"A": "a"}, - class_info=Class(name="MyEnum", module_name="my_enum"), - ) - assert schemas == new_schemas - - def test_property_from_data_ref_enum_with_overridden_default(self, enum_property_factory, config): - from openapi_python_client.parser.properties import Class, Schemas, property_from_data - - name = "some_enum" - required = False - data = oai.Schema.model_construct( - default="b", allOf=[oai.Reference.model_construct(ref="#/components/schemas/MyEnum")] - ) - existing_enum = enum_property_factory( - name="an_enum", - default="MyEnum.A", - required=required, - values={"A": "a", "B": "b"}, - class_info=Class(name="MyEnum", module_name="my_enum"), - ) - schemas = Schemas(classes_by_reference={"/components/schemas/MyEnum": existing_enum}) - - prop, new_schemas = property_from_data( - name=name, required=required, data=data, schemas=schemas, parent_name="", config=config - ) - - assert prop == enum_property_factory( - name="some_enum", - default="MyEnum.B", - required=required, - values={"A": "a", "B": "b"}, - class_info=Class(name="MyEnum", module_name="my_enum"), - ) - assert schemas == new_schemas - - def test_property_from_data_ref_enum_with_invalid_default(self, enum_property_factory, config): - from openapi_python_client.parser.properties import Class, Schemas, property_from_data - - name = "some_enum" - data = oai.Schema.model_construct( - default="x", allOf=[oai.Reference.model_construct(ref="#/components/schemas/MyEnum")] - ) - existing_enum = enum_property_factory( - name="an_enum", - default="MyEnum.A", - values={"A": "a", "B": "b"}, - class_info=Class(name="MyEnum", module_name="my_enum"), - python_name="an_enum", - ) - schemas = Schemas(classes_by_reference={"/components/schemas/MyEnum": existing_enum}) - - prop, new_schemas = property_from_data( - name=name, required=False, data=data, schemas=schemas, parent_name="", config=config - ) - - assert schemas == new_schemas - assert prop == PropertyError(data=data, detail="Value x is not valid for enum an_enum") - def test_property_from_data_ref_model(self, model_property_factory, config): - from openapi_python_client.parser.properties import Class, Schemas, property_from_data - name = "new_name" required = False - class_name = "MyModel" - data = oai.Reference.model_construct(ref=f"#/components/schemas/{class_name}") - class_info = Class(name=class_name, module_name="my_model") + class_name = ClassName(UntrustedString("MyModel"), "") + data = oai.Reference.model_construct(ref=Ref(f"#/components/schemas/{class_name}")) + class_info = Class(name=class_name, module_name=PythonIdentifier("my_model", "")) existing_model = model_property_factory( name="old_name", class_info=class_info, ) - schemas = Schemas(classes_by_reference={f"/components/schemas/{class_name}": existing_model}) + schemas = Schemas( + classes_by_reference={ReferencePath(UntrustedString(f"/components/schemas/{class_name}")): existing_model} + ) prop, new_schemas = property_from_data( name=name, required=required, data=data, schemas=schemas, parent_name="", config=config @@ -590,8 +157,6 @@ def test_property_from_data_ref_model(self, model_property_factory, config): assert schemas == new_schemas def test_property_from_data_ref_not_found(self, mocker): - from openapi_python_client.parser.properties import PropertyError, Schemas, property_from_data - data = oai.Reference.model_construct(ref="a/b/c") parse_reference_path = mocker.patch(f"{MODULE_NAME}.parse_reference_path") schemas = Schemas() @@ -607,12 +172,10 @@ def test_property_from_data_ref_not_found(self, mocker): @pytest.mark.parametrize("references_exist", (True, False)) def test_property_from_data_ref(self, any_property_factory, references_exist, config): - from openapi_python_client.parser.properties import Schemas, property_from_data - name = "new_name" required = False - ref_path = "/components/schemas/RefName" - data = oai.Reference.model_construct(ref=f"#{ref_path}") + ref_path = ReferencePath(UntrustedString("/components/schemas/RefName")) + data = oai.Reference.model_construct(ref=Ref(f"#{ref_path.get_untrusted_value()}")) roots = {"new_root"} existing_property = any_property_factory(name="old_name") @@ -627,194 +190,9 @@ def test_property_from_data_ref(self, any_property_factory, references_exist, co assert schemas == new_schemas assert schemas.dependencies == {ref_path: {*roots, *references.get(ref_path, set())}} - def test_property_from_data_invalid_ref(self, mocker): - from openapi_python_client.parser.properties import PropertyError, Schemas, property_from_data - - name = mocker.MagicMock() - required = mocker.MagicMock() - data = oai.Reference.model_construct(ref=mocker.MagicMock()) - parse_reference_path = mocker.patch( - f"{MODULE_NAME}.parse_reference_path", return_value=PropertyError(detail="bad stuff") - ) - schemas = Schemas() - - prop, new_schemas = property_from_data( - name=name, required=required, data=data, schemas=schemas, parent_name="parent", config=mocker.MagicMock() - ) - - parse_reference_path.assert_called_once_with(data.ref) - assert prop == PropertyError(data=data, detail="bad stuff") - assert schemas == new_schemas - - def test_property_from_data_array(self, config): - from openapi_python_client.parser.properties import Schemas, property_from_data - - name = "a_list_prop" - required = True - data = oai.Schema( - type=DataType.ARRAY, - items=oai.Schema(type=DataType.STRING), - ) - schemas = Schemas() - - response = property_from_data( - name=name, - required=required, - data=data, - schemas=schemas, - parent_name="parent", - config=config, - )[0] - - assert isinstance(response, ListProperty) - assert isinstance(response.inner_property, StringProperty) - - def test_property_from_data_union(self, config): - from openapi_python_client.parser.properties import Schemas, property_from_data - - name = "union_prop" - required = True - data = oai.Schema( - anyOf=[oai.Schema(type=DataType.NUMBER)], - oneOf=[ - oai.Schema(type=DataType.INTEGER), - ], - ) - schemas = Schemas() - - response = property_from_data( - name=name, required=required, data=data, schemas=schemas, parent_name="parent", config=config - )[0] - - assert isinstance(response, UnionProperty) - assert len(response.inner_properties) == 2 # noqa: PLR2004 - - def test_property_from_data_list_of_types(self, config): - from openapi_python_client.parser.properties import Schemas, property_from_data - - name = "union_prop" - required = True - data = oai.Schema( - type=[DataType.NUMBER, DataType.NULL], - ) - schemas = Schemas() - - response = property_from_data( - name=name, required=required, data=data, schemas=schemas, parent_name="parent", config=config - )[0] - - assert isinstance(response, UnionProperty) - assert len(response.inner_properties) == 2 # noqa: PLR2004 - - def test_property_from_data_union_of_one_element(self, model_property_factory, config): - from openapi_python_client.parser.properties import Schemas, property_from_data - - name = "new_name" - required = False - class_name = "MyModel" - existing_model: ModelProperty = model_property_factory() - schemas = Schemas(classes_by_reference={f"/{class_name}": existing_model}) - - data = oai.Schema.model_construct( - allOf=[oai.Reference.model_construct(ref=f"#/{class_name}")], - ) - - prop, schemas = property_from_data( - name=name, required=required, data=data, schemas=schemas, parent_name="parent", config=config - ) - - assert prop == attr.evolve(existing_model, name=name, required=required, python_name=PythonIdentifier(name, "")) - - def test_property_from_data_no_valid_props_in_data(self, any_property_factory): - from openapi_python_client.parser.properties import Schemas, property_from_data - - schemas = Schemas() - data = oai.Schema() - name = "blah" - - prop, new_schemas = property_from_data( - name=name, required=True, data=data, schemas=schemas, parent_name="parent", config=MagicMock() - ) - - assert prop == any_property_factory(name=name, required=True, default=None) - assert new_schemas == schemas - class TestStringBasedProperty: - @pytest.mark.parametrize("required", (True, False)) - def test_no_format(self, string_property_factory, required, config): - from openapi_python_client.parser.properties import property_from_data - - name = "some_prop" - data = oai.Schema.model_construct(type="string", default='"hello world"', pattern="abcdef") - - p, _ = property_from_data( - name=name, required=required, data=data, parent_name=None, config=config, schemas=Schemas() - ) - - assert p == string_property_factory( - name=name, required=required, default="'\\\\\"hello world\\\\\"'", pattern=data.pattern - ) - - def test_datetime_format(self, date_time_property_factory, config): - from openapi_python_client.parser.properties import property_from_data - - name = "datetime_prop" - required = True - data = oai.Schema.model_construct(type="string", schema_format="date-time", default="2020-11-06T12:00:00") - - p, _ = property_from_data( - name=name, required=required, data=data, schemas=Schemas(), config=config, parent_name="" - ) - - assert p == date_time_property_factory(name=name, required=required, default=f"isoparse('{data.default}')") - - def test_datetime_bad_default(self, config): - from openapi_python_client.parser.properties import property_from_data - - name = "datetime_prop" - required = True - data = oai.Schema.model_construct(type="string", schema_format="date-time", default="a") - - result, _ = property_from_data( - name=name, required=required, data=data, schemas=Schemas(), config=config, parent_name="" - ) - - assert isinstance(result, PropertyError) - assert result.detail.startswith("Invalid datetime") - - def test_date_format(self, date_property_factory, config): - from openapi_python_client.parser.properties import property_from_data - - name = "date_prop" - required = True - - data = oai.Schema.model_construct(type="string", schema_format="date", default="2020-11-06") - - p, _ = property_from_data( - name=name, required=required, data=data, schemas=Schemas(), config=config, parent_name="" - ) - - assert p == date_property_factory(name=name, required=required, default=f"isoparse('{data.default}').date()") - - def test_date_format_bad_default(self, config): - from openapi_python_client.parser.properties import property_from_data - - name = "date_prop" - required = True - - data = oai.Schema.model_construct(type="string", schema_format="date", default="a") - - p, _ = property_from_data( - name=name, required=required, data=data, schemas=Schemas(), config=config, parent_name="" - ) - - assert isinstance(p, PropertyError) - assert p.detail.startswith("Invalid date") - def test__string_based_property_binary_format(self, file_property_factory, config): - from openapi_python_client.parser.properties import property_from_data - name = "file_prop" required = True data = oai.Schema.model_construct(type="string", schema_format="binary", default="a") @@ -824,163 +202,65 @@ def test__string_based_property_binary_format(self, file_property_factory, confi ) assert p == file_property_factory(name=name, required=required) - def test__string_based_property_unsupported_format(self, string_property_factory, config): - from openapi_python_client.parser.properties import property_from_data - - name = "unknown" - required = True - data = oai.Schema.model_construct(type="string", schema_format="blah") - - p, _ = property_from_data( - name=name, required=required, data=data, schemas=Schemas(), config=config, parent_name="" - ) - - assert p == string_property_factory(name=name, required=required) - -class TestCreateSchemas: - def test_skips_references_and_keeps_going(self, mocker, config): - from openapi_python_client.parser.properties import Schemas, _create_schemas - from openapi_python_client.schema import Reference, Schema - - components = {"a_ref": Reference.model_construct(), "a_schema": Schema.model_construct()} - update_schemas_with_data = mocker.patch(f"{MODULE_NAME}.update_schemas_with_data") - parse_reference_path = mocker.patch(f"{MODULE_NAME}.parse_reference_path") - schemas = Schemas() - - result = _create_schemas(components=components, schemas=schemas, config=config) - # Should not even try to parse a path for the Reference - parse_reference_path.assert_called_once_with("#/components/schemas/a_schema") - update_schemas_with_data.assert_called_once_with( - ref_path=parse_reference_path.return_value, - config=config, - data=components["a_schema"], - schemas=Schemas( - errors=[PropertyError(detail="Reference schemas are not supported.", data=components["a_ref"])] +class TestProcessModels: + def test_resolve_reference_to_single_allof_reference(self, config, model_property_factory): + # test for https://github.com/openapi-generators/openapi-python-client/issues/1091 + + components = { + UntrustedString("Model1"): oai.Schema.model_construct( + type="object", + properties={ + UntrustedString("prop1"): oai.Schema.model_construct(type="string"), + }, ), - ) - assert result == update_schemas_with_data.return_value - - def test_records_bad_uris_and_keeps_going(self, mocker, config): - from openapi_python_client.parser.properties import Schemas, _create_schemas - from openapi_python_client.schema import Schema - - components = {"first": Schema.model_construct(), "second": Schema.model_construct()} - update_schemas_with_data = mocker.patch(f"{MODULE_NAME}.update_schemas_with_data") - parse_reference_path = mocker.patch( - f"{MODULE_NAME}.parse_reference_path", side_effect=[PropertyError(detail="some details"), "a_path"] - ) - schemas = Schemas() - - result = _create_schemas(components=components, schemas=schemas, config=config) - parse_reference_path.assert_has_calls( - [ - call("#/components/schemas/first"), - call("#/components/schemas/second"), - ] - ) - update_schemas_with_data.assert_called_once_with( - ref_path="a_path", - config=config, - data=components["second"], - schemas=Schemas(errors=[PropertyError(detail="some details", data=components["first"])]), - ) - assert result == update_schemas_with_data.return_value - - def test_retries_failing_properties_while_making_progress(self, mocker, config): - from openapi_python_client.parser.properties import Schemas, _create_schemas - from openapi_python_client.schema import Schema - - components = {"first": Schema.model_construct(), "second": Schema.model_construct()} - update_schemas_with_data = mocker.patch( - f"{MODULE_NAME}.update_schemas_with_data", side_effect=[PropertyError(), Schemas(), PropertyError()] - ) - parse_reference_path = mocker.patch(f"{MODULE_NAME}.parse_reference_path") + UntrustedString("Model2"): oai.Schema.model_construct( + allOf=[ + oai.Reference.model_construct(ref=Ref("#/components/schemas/Model1")), + ] + ), + UntrustedString("Model3"): oai.Schema.model_construct( + allOf=[ + oai.Reference.model_construct(ref=Ref("#/components/schemas/Model2")), + oai.Schema.model_construct( + type="object", + properties={ + UntrustedString("prop2"): oai.Schema.model_construct(type="string"), + }, + ), + ], + ), + } schemas = Schemas() - result = _create_schemas(components=components, schemas=schemas, config=config) - parse_reference_path.assert_has_calls( - [ - call("#/components/schemas/first"), - call("#/components/schemas/second"), - call("#/components/schemas/first"), - ] - ) - assert update_schemas_with_data.call_count == 3 # noqa: PLR2004 - assert result.errors == [PropertyError()] + result = build_schemas(components=components, schemas=schemas, config=config) + assert result.errors == [] + assert result.models_to_process == [] -class TestProcessModels: - def test_retries_failing_models_while_making_progress( - self, mocker, model_property_factory, any_property_factory, config - ): - from openapi_python_client.parser.properties import _process_models + # Classes should only be generated for Model1 and Model3 + assert result.classes_by_name.keys() == {"Model1", "Model3"} - first_model = model_property_factory() - second_class_name = ClassName("second", "") - schemas = Schemas( - classes_by_name={ - ClassName("first", ""): first_model, - second_class_name: model_property_factory(), - ClassName("non-model", ""): any_property_factory(), - } - ) - process_model = mocker.patch( - f"{MODULE_NAME}.process_model", side_effect=[PropertyError(), Schemas(), PropertyError()] - ) - process_model_errors = mocker.patch(f"{MODULE_NAME}._process_model_errors", return_value=["error"]) - - result = _process_models(schemas=schemas, config=config) - - process_model.assert_has_calls( - [ - call(first_model, schemas=schemas, config=config), - call(schemas.classes_by_name[second_class_name], schemas=schemas, config=config), - call(first_model, schemas=result, config=config), - ] - ) - assert process_model_errors.was_called_once_with([(first_model, PropertyError())]) - assert all(error in result.errors for error in process_model_errors.return_value) - - def test_detect_recursive_allof_reference_no_retry(self, mocker, model_property_factory, config): - from openapi_python_client.parser.properties import Class, _process_models - from openapi_python_client.schema import Reference - - class_name = ClassName("class_name", "") - recursive_model = model_property_factory( - class_info=Class(name=class_name, module_name=PythonIdentifier("module_name", "")) - ) - schemas = Schemas( - classes_by_name={ - "recursive": recursive_model, - "second": model_property_factory(), - } + # References to Model2 should be resolved to the same class as Model1 + assert result.classes_by_reference.keys() == { + "/components/schemas/Model1", + "/components/schemas/Model2", + "/components/schemas/Model3", + } + assert ( + result.classes_by_reference[ReferencePath(UntrustedString("/components/schemas/Model2"))].class_info + == result.classes_by_reference[ReferencePath(UntrustedString("/components/schemas/Model1"))].class_info ) - recursion_error = PropertyError(data=Reference.model_construct(ref=f"#/{class_name}")) - process_model = mocker.patch(f"{MODULE_NAME}.process_model", side_effect=[recursion_error, Schemas()]) - process_model_errors = mocker.patch(f"{MODULE_NAME}._process_model_errors", return_value=["error"]) - - result = _process_models(schemas=schemas, config=config) - process_model.assert_has_calls( - [ - call(recursive_model, schemas=schemas, config=config), - call(schemas.classes_by_name["second"], schemas=schemas, config=config), - ] - ) - assert process_model_errors.was_called_once_with([(recursive_model, recursion_error)]) - assert all(error in result.errors for error in process_model_errors.return_value) - assert "\n\nRecursive allOf reference found" in recursion_error.detail + # Verify that Model3 extended the properties from Model1 + assert [p.name for p in result.classes_by_name["Model3"].optional_properties] == ["prop1", "prop2"] class TestPropogateRemoval: def test_propogate_removal_class_name(self): - from openapi_python_client.parser.properties import ReferencePath, _propogate_removal - from openapi_python_client.utils import ClassName - - root = ClassName("ClassName", "") - ref_path = ReferencePath("/reference") - other_class_name = ClassName("OtherClassName", "") + root = ClassName(UntrustedString("ClassName"), "") + ref_path = ReferencePath(UntrustedString("/reference")) + other_class_name = ClassName(UntrustedString("OtherClassName"), "") schemas = Schemas( classes_by_name={root: None, other_class_name: None}, classes_by_reference={ref_path: None}, @@ -995,12 +275,9 @@ def test_propogate_removal_class_name(self): assert not error.detail def test_propogate_removal_ref_path(self): - from openapi_python_client.parser.properties import ReferencePath, _propogate_removal - from openapi_python_client.utils import ClassName - - root = ReferencePath("/root/reference") - class_name = ClassName("ClassName", "") - ref_path = ReferencePath("/ref/path") + root = ReferencePath(UntrustedString("/root/reference")) + class_name = ClassName(UntrustedString("ClassName"), "") + ref_path = ReferencePath(UntrustedString("/ref/path")) schemas = Schemas( classes_by_name={class_name: None}, classes_by_reference={root: None, ref_path: None}, @@ -1012,31 +289,28 @@ def test_propogate_removal_ref_path(self): assert schemas.classes_by_name == {} assert schemas.classes_by_reference == {} - assert error.detail == f"\n{root}\n{ref_path}" + assert error.detail == f"\n{root.get_untrusted_value()}\n{ref_path.get_untrusted_value()}" def test_propogate_removal_ref_path_no_refs(self): - from openapi_python_client.parser.properties import ReferencePath, _propogate_removal - from openapi_python_client.utils import ClassName - - root = ReferencePath("/root/reference") - class_name = ClassName("ClassName", "") - ref_path = ReferencePath("/ref/path") - schemas = Schemas(classes_by_name={class_name: None}, classes_by_reference={root: None, ref_path: None}) + root = ReferencePath(UntrustedString("/root/reference")) + class_name = ClassName(UntrustedString("ClassName"), "") + ref_path = ReferencePath(UntrustedString("/ref/path")) + schemas = Schemas( + classes_by_name={class_name: None}, + classes_by_reference={root: None, ref_path: None}, + ) error = PropertyError() _propogate_removal(root=root, schemas=schemas, error=error) assert schemas.classes_by_name == {class_name: None} assert schemas.classes_by_reference == {ref_path: None} - assert error.detail == f"\n{root}" + assert error.detail == f"\n{root.get_untrusted_value()}" def test_propogate_removal_ref_path_already_removed(self): - from openapi_python_client.parser.properties import ReferencePath, _propogate_removal - from openapi_python_client.utils import ClassName - - root = ReferencePath("/root/reference") - class_name = ClassName("ClassName", "") - ref_path = ReferencePath("/ref/path") + root = ReferencePath(UntrustedString("/root/reference")) + class_name = ClassName(UntrustedString("ClassName"), "") + ref_path = ReferencePath(UntrustedString("/ref/path")) schemas = Schemas( classes_by_name={class_name: None}, classes_by_reference={ref_path: None}, @@ -1049,120 +323,3 @@ def test_propogate_removal_ref_path_already_removed(self): assert schemas.classes_by_name == {class_name: None} assert schemas.classes_by_reference == {ref_path: None} assert not error.detail - - -def test_process_model_errors(mocker, model_property_factory): - from openapi_python_client.parser.properties import _process_model_errors - - propogate_removal = mocker.patch(f"{MODULE_NAME}._propogate_removal") - model_errors = [ - (model_property_factory(roots={"root1", "root2"}), PropertyError(detail="existing detail")), - (model_property_factory(roots=set()), PropertyError()), - (model_property_factory(roots={"root1", "root3"}), PropertyError(detail="other existing detail")), - ] - schemas = Schemas() - - result = _process_model_errors(model_errors, schemas=schemas) - - propogate_removal.assert_has_calls( - [call(root=root, schemas=schemas, error=error) for model, error in model_errors for root in model.roots] - ) - assert result == [error for _, error in model_errors] - assert all("\n\nFailure to process schema has resulted in the removal of:" in error.detail for error in result) - - -class TestBuildParameters: - def test_skips_references_and_keeps_going(self, mocker, config): - from openapi_python_client.parser.properties import Parameters, build_parameters - from openapi_python_client.schema import Parameter, Reference - - parameters = { - "reference": Reference(ref="#/components/parameters/another_parameter"), - "defined": Parameter( - name="page", - param_in="query", - required=False, - style="form", - explode=True, - schema=oai.Schema(type="integer", default=0), - ), - } - - update_parameters_with_data = mocker.patch(f"{MODULE_NAME}.update_parameters_with_data") - parse_reference_path = mocker.patch(f"{MODULE_NAME}.parse_reference_path") - - result = build_parameters(components=parameters, parameters=Parameters(), config=config) - # Should not even try to parse a path for the Reference - parse_reference_path.assert_called_once_with("#/components/parameters/defined") - update_parameters_with_data.assert_called_once_with( - ref_path=parse_reference_path.return_value, - data=parameters["defined"], - parameters=Parameters( - errors=[ParameterError(detail="Reference parameters are not supported.", data=parameters["reference"])] - ), - config=config, - ) - assert result == update_parameters_with_data.return_value - - def test_records_bad_uris_and_keeps_going(self, mocker, config): - from openapi_python_client.parser.properties import Parameters, build_parameters - from openapi_python_client.schema import Parameter - - parameters = {"first": Parameter.model_construct(), "second": Parameter.model_construct()} - update_parameters_with_data = mocker.patch(f"{MODULE_NAME}.update_parameters_with_data") - parse_reference_path = mocker.patch( - f"{MODULE_NAME}.parse_reference_path", side_effect=[ParameterError(detail="some details"), "a_path"] - ) - - result = build_parameters(components=parameters, parameters=Parameters(), config=config) - parse_reference_path.assert_has_calls( - [ - call("#/components/parameters/first"), - call("#/components/parameters/second"), - ] - ) - update_parameters_with_data.assert_called_once_with( - ref_path="a_path", - data=parameters["second"], - parameters=Parameters(errors=[ParameterError(detail="some details", data=parameters["first"])]), - config=config, - ) - assert result == update_parameters_with_data.return_value - - def test_retries_failing_parameters_while_making_progress(self, mocker, config): - from openapi_python_client.parser.properties import Parameters, build_parameters - from openapi_python_client.schema import Parameter - - parameters = {"first": Parameter.model_construct(), "second": Parameter.model_construct()} - update_parameters_with_data = mocker.patch( - f"{MODULE_NAME}.update_parameters_with_data", side_effect=[ParameterError(), Parameters(), ParameterError()] - ) - - parse_reference_path = mocker.patch(f"{MODULE_NAME}.parse_reference_path") - result = build_parameters(components=parameters, parameters=Parameters(), config=config) - parse_reference_path.assert_has_calls( - [ - call("#/components/parameters/first"), - call("#/components/parameters/second"), - call("#/components/parameters/first"), - ] - ) - assert update_parameters_with_data.call_count == 3 # noqa: PLR2004 - assert result.errors == [ParameterError()] - - -def test_build_schemas(mocker, config): - from openapi_python_client.parser.properties import Schemas, build_schemas - from openapi_python_client.schema import Reference, Schema - - create_schemas = mocker.patch(f"{MODULE_NAME}._create_schemas") - process_models = mocker.patch(f"{MODULE_NAME}._process_models") - - components = {"a_ref": Reference.model_construct(), "a_schema": Schema.model_construct()} - schemas = Schemas() - - result = build_schemas(components=components, schemas=schemas, config=config) - - create_schemas.assert_called_once_with(components=components, schemas=schemas, config=config) - process_models.assert_called_once_with(schemas=create_schemas.return_value, config=config) - assert result == process_models.return_value diff --git a/tests/test_parser/test_properties/test_int.py b/tests/test_parser/test_properties/test_int.py deleted file mode 100644 index e50166e4a..000000000 --- a/tests/test_parser/test_properties/test_int.py +++ /dev/null @@ -1,35 +0,0 @@ -from openapi_python_client.parser.errors import PropertyError -from openapi_python_client.parser.properties import IntProperty -from openapi_python_client.parser.properties.protocol import Value - - -def test_invalid_default(): - err = IntProperty.build( - default="not a float", - description=None, - example=None, - required=False, - python_name="not_a_float", - name="not_a_float", - ) - - assert isinstance(err, PropertyError) - - -def test_convert_from_string(): - val = IntProperty.convert_value("1") - assert isinstance(val, Value) - assert val == "1" - - -def test_invalid_type_default(): - err = IntProperty.build( - default=True, - description=None, - example=None, - required=False, - python_name="not_a_float", - name="not_a_float", - ) - - assert isinstance(err, PropertyError) diff --git a/tests/test_parser/test_properties/test_list_property.py b/tests/test_parser/test_properties/test_list_property.py deleted file mode 100644 index bac87e669..000000000 --- a/tests/test_parser/test_properties/test_list_property.py +++ /dev/null @@ -1,85 +0,0 @@ -import attr - -import openapi_python_client.schema as oai -from openapi_python_client.parser.errors import PropertyError -from openapi_python_client.parser.properties import ListProperty -from openapi_python_client.schema import DataType - - -def test_build_list_property_no_items(config): - from openapi_python_client.parser import properties - - name = "list_prop" - required = True - data = oai.Schema(type=DataType.ARRAY) - schemas = properties.Schemas() - - p, new_schemas = ListProperty.build( - name=name, - required=required, - data=data, - schemas=schemas, - parent_name="parent", - config=config, - process_properties=True, - roots={"root"}, - ) - - assert p == PropertyError(data=data, detail="type array must have items defined") - assert new_schemas == schemas - - -def test_build_list_property_invalid_items(config): - from openapi_python_client.parser import properties - - name = "name" - required = True - data = oai.Schema( - type=DataType.ARRAY, - items=oai.Reference(ref="doesnt exist"), - ) - schemas = properties.Schemas(errors=["error"]) - process_properties = False - roots = {"root"} - - p, new_schemas = ListProperty.build( - name=name, - required=required, - data=data, - schemas=attr.evolve(schemas), - parent_name="parent", - config=config, - roots=roots, - process_properties=process_properties, - ) - - assert isinstance(p, PropertyError) - assert p.data == data.items - assert p.header.startswith(f"invalid data in items of array {name}") - assert new_schemas == schemas - - -def test_build_list_property(any_property_factory, config): - from openapi_python_client.parser import properties - - name = "prop" - data = oai.Schema( - type=DataType.ARRAY, - items=oai.Schema(), - ) - schemas = properties.Schemas(errors=["error"]) - - p, new_schemas = ListProperty.build( - name=name, - required=True, - data=data, - schemas=schemas, - parent_name="parent", - config=config, - roots={"root"}, - process_properties=True, - ) - - assert isinstance(p, properties.ListProperty) - assert p.inner_property == any_property_factory(name=f"{name}_item") - assert new_schemas == schemas diff --git a/tests/test_parser/test_properties/test_merge_properties.py b/tests/test_parser/test_properties/test_merge_properties.py new file mode 100644 index 000000000..ea77e080b --- /dev/null +++ b/tests/test_parser/test_properties/test_merge_properties.py @@ -0,0 +1,292 @@ +from itertools import permutations + +import pytest +from attr import evolve + +from openapi_python_client.parser.errors import PropertyError +from openapi_python_client.parser.properties.float import FloatProperty +from openapi_python_client.parser.properties.int import IntProperty +from openapi_python_client.parser.properties.merge_properties import merge_properties +from openapi_python_client.parser.properties.protocol import Value +from openapi_python_client.parser.properties.schemas import Class +from openapi_python_client.parser.properties.string import StringProperty +from openapi_python_client.strings import PythonCode + +MODULE_NAME = "openapi_python_client.parser.properties.merge_properties" + + +def test_merge_basic_attributes_same_type( + boolean_property_factory, + int_property_factory, + float_property_factory, + string_property_factory, + list_property_factory, + model_property_factory, +): + basic_props = [ + boolean_property_factory(default=Value(python_code=PythonCode("True"), raw_value="True")), + int_property_factory(default=Value(PythonCode("1"), 1)), + float_property_factory(default=Value(PythonCode("1.5"), 1.5)), + string_property_factory(default=StringProperty.convert_value("x")), + list_property_factory(), + model_property_factory(), + ] + for basic_prop in basic_props: + with_required = evolve(basic_prop, required=True) + assert merge_properties(basic_prop, with_required) == with_required + assert merge_properties(with_required, basic_prop) == with_required + without_default = evolve(basic_prop, default=None) + assert merge_properties(basic_prop, without_default) == basic_prop + assert merge_properties(without_default, basic_prop) == basic_prop + with_desc1 = evolve(basic_prop, description="desc1") + with_desc2 = evolve(basic_prop, description="desc2") + assert merge_properties(basic_prop, with_desc1) == with_desc1 + assert merge_properties(with_desc1, basic_prop) == with_desc1 + assert merge_properties(with_desc1, with_desc2) == with_desc2 + + +def test_incompatible_types( + boolean_property_factory, + int_property_factory, + float_property_factory, + string_property_factory, + list_property_factory, + model_property_factory, +): + props = [ + boolean_property_factory(default=True), + int_property_factory(default=1), + float_property_factory(default=1.5), + string_property_factory(default="x"), + list_property_factory(), + model_property_factory(), + ] + + for prop1, prop2 in permutations(props, 2): + if {prop1.__class__, prop2.__class__} == {IntProperty, FloatProperty}: + continue # the int+float case is covered in another test + error = merge_properties(prop1, prop2) + assert isinstance(error, PropertyError), f"Expected {type(prop1)} and {type(prop2)} to be incompatible" + + +def test_merge_int_with_float(int_property_factory, float_property_factory): + int_prop = int_property_factory(description="desc1") + float_prop = float_property_factory(default=Value(PythonCode("2"), 2), description="desc2") + + assert merge_properties(int_prop, float_prop) == ( + evolve(int_prop, default=Value(PythonCode("2"), 2), description=float_prop.description) + ) + assert merge_properties(float_prop, int_prop) == evolve(int_prop, default=Value(PythonCode("2"), 2)) + + float_prop_with_non_int_default = evolve(float_prop, default=Value(PythonCode("2.5"), 2.5)) + error = merge_properties(int_prop, float_prop_with_non_int_default) + assert isinstance(error, PropertyError), "Expected invalid default to error" + assert error.detail == "Invalid int value: 2.5" + + +def test_merge_with_any( + any_property_factory, + boolean_property_factory, + int_property_factory, + float_property_factory, + string_property_factory, + model_property_factory, +): + original_desc = "description" + props = [ + boolean_property_factory(default=Value(PythonCode("True"), "True"), description=original_desc), + int_property_factory(default=Value(PythonCode("1"), "1"), description=original_desc), + float_property_factory(default=Value(PythonCode("1.5"), "1.5"), description=original_desc), + string_property_factory(default=StringProperty.convert_value("x"), description=original_desc), + model_property_factory(description=original_desc), + ] + any_prop = any_property_factory() + for prop in props: + assert merge_properties(any_prop, prop) == prop + assert merge_properties(prop, any_prop) == prop + + +@pytest.mark.parametrize("literal_enums", (False, True)) +def test_merge_enums(literal_enums, enum_property_factory, literal_enum_property_factory, config): + if literal_enums: + enum_with_fewer_values = literal_enum_property_factory( + description="desc1", + values={"A", "B"}, + value_type=str, + ) + enum_with_more_values = literal_enum_property_factory( + example="example2", + values={"A", "B", "C"}, + value_type=str, + ) + else: + enum_with_fewer_values = enum_property_factory( + description="desc1", + values={"A": "A", "B": "B"}, + value_type=str, + ) + enum_with_more_values = enum_property_factory( + example="example2", + values={"A": "A", "B": "B", "C": "C"}, + value_type=str, + ) + + # Setting class_info separately because it doesn't get initialized by the constructor - we want + # to make sure the right enum class name gets used in the merged property + enum_with_fewer_values.class_info = Class.from_string(string="FewerValuesEnum", config=config) + enum_with_more_values.class_info = Class.from_string(string="MoreValuesEnum", config=config) + + assert merge_properties(enum_with_fewer_values, enum_with_more_values) == evolve( + enum_with_more_values, + values=enum_with_fewer_values.values, + class_info=enum_with_fewer_values.class_info, + description=enum_with_fewer_values.description, + ) + assert merge_properties(enum_with_more_values, enum_with_fewer_values) == evolve( + enum_with_fewer_values, + example=enum_with_more_values.example, + ) + + +@pytest.mark.parametrize("literal_enums", (False, True)) +def test_merge_string_with_string_enum( + literal_enums, string_property_factory, enum_property_factory, literal_enum_property_factory +): + string_prop = string_property_factory(default=Value(PythonCode("A"), "A"), description="desc1", example="example1") + enum_prop = ( + literal_enum_property_factory( + default=Value(PythonCode("'B'"), "B"), + description="desc2", + example="example2", + values={"A", "B"}, + value_type=str, + ) + if literal_enums + else enum_property_factory( + default=Value(PythonCode("Test.B"), "B"), + description="desc2", + example="example2", + values={"A": "A", "B": "B"}, + value_type=str, + ) + ) + + assert merge_properties(string_prop, enum_prop) == evolve(enum_prop, required=True) + assert merge_properties(enum_prop, string_prop) == evolve( + enum_prop, + required=True, + default=Value(PythonCode("'A'") if literal_enums else PythonCode("Test.A"), "A"), + description=string_prop.description, + example=string_prop.example, + ) + + +@pytest.mark.parametrize("literal_enums", (False, True)) +def test_merge_int_with_int_enum( + literal_enums, int_property_factory, enum_property_factory, literal_enum_property_factory +): + int_prop = int_property_factory(default=Value(PythonCode("1"), 1), description="desc1", example="example1") + enum_prop = ( + literal_enum_property_factory( + default=Value(PythonCode("1"), 1), + description="desc2", + example="example2", + values={1, 2}, + value_type=int, + ) + if literal_enums + else enum_property_factory( + default=Value(PythonCode("Test.VALUE_1"), 1), + description="desc2", + example="example2", + values={"VALUE_1": 1, "VALUE_2": 2}, + value_type=int, + ) + ) + + assert merge_properties(int_prop, enum_prop) == evolve(enum_prop, required=True) + assert merge_properties(enum_prop, int_prop) == evolve( + enum_prop, required=True, description=int_prop.description, example=int_prop.example + ) + + +@pytest.mark.parametrize("literal_enums", (False, True)) +def test_merge_with_incompatible_enum( + literal_enums, + boolean_property_factory, + int_property_factory, + float_property_factory, + string_property_factory, + enum_property_factory, + literal_enum_property_factory, + model_property_factory, +): + props = [ + boolean_property_factory(), + int_property_factory(), + float_property_factory(), + string_property_factory(), + model_property_factory(), + enum_property_factory(values={"INCOMPATIBLE": "INCOMPATIBLE"}), + literal_enum_property_factory(values={"INCOMPATIBLE"}), + ] + string_enum_prop = ( + literal_enum_property_factory(value_type=str, values={"A"}) + if literal_enums + else enum_property_factory(value_type=str, values={"A": "A"}) + ) + int_enum_prop = ( + literal_enum_property_factory(value_type=int, values={1}) + if literal_enums + else enum_property_factory(value_type=int, values={"VALUE_1": 1}) + ) + for prop in props: + if not isinstance(prop, StringProperty): + assert isinstance(merge_properties(prop, string_enum_prop), PropertyError) + assert isinstance(merge_properties(string_enum_prop, prop), PropertyError) + if not isinstance(prop, IntProperty): + assert isinstance(merge_properties(prop, int_enum_prop), PropertyError) + assert isinstance(merge_properties(int_enum_prop, prop), PropertyError) + + +def test_merge_string_with_formatted_string( + date_property_factory, + date_time_property_factory, + file_property_factory, + string_property_factory, +): + string_prop = string_property_factory(description="a plain string") + string_prop_with_invalid_default = string_property_factory( + default=StringProperty.convert_value("plain string value") + ) + formatted_props = [ + date_property_factory(description="a date"), + date_time_property_factory(description="a datetime"), + file_property_factory(description="a file"), + ] + for formatted_prop in formatted_props: + merged1 = merge_properties(string_prop, formatted_prop) + assert isinstance(merged1, formatted_prop.__class__) + assert merged1.description == formatted_prop.description + + merged2 = merge_properties(formatted_prop, string_prop) + assert isinstance(merged2, formatted_prop.__class__) + assert merged2.description == string_prop.description + + assert isinstance(merge_properties(string_prop_with_invalid_default, formatted_prop), PropertyError) + assert isinstance(merge_properties(formatted_prop, string_prop_with_invalid_default), PropertyError) + + +def test_merge_lists(int_property_factory, list_property_factory, string_property_factory): + string_prop_1 = string_property_factory(description="desc1") + string_prop_2 = string_property_factory(example="desc2") + int_prop = int_property_factory() + list_prop_1 = list_property_factory(inner_property=string_prop_1) + list_prop_2 = list_property_factory(inner_property=string_prop_2) + list_prop_3 = list_property_factory(inner_property=int_prop) + + assert merge_properties(list_prop_1, list_prop_2) == evolve( + list_prop_1, inner_property=merge_properties(string_prop_1, string_prop_2) + ) + + assert isinstance(merge_properties(list_prop_1, list_prop_3), PropertyError) diff --git a/tests/test_parser/test_properties/test_model_property.py b/tests/test_parser/test_properties/test_model_property.py index 917582042..b8dc09213 100644 --- a/tests/test_parser/test_properties/test_model_property.py +++ b/tests/test_parser/test_properties/test_model_property.py @@ -1,46 +1,45 @@ -from typing import Optional - import pytest from attr import evolve import openapi_python_client.schema as oai from openapi_python_client.parser.errors import PropertyError -from openapi_python_client.parser.properties import Schemas, StringProperty -from openapi_python_client.parser.properties.model_property import _process_properties +from openapi_python_client.parser.properties import Class, ModelProperty, Schemas, StringProperty +from openapi_python_client.parser.properties.model_property import ( + ANY_ADDITIONAL_PROPERTY, + _process_properties, + _PropertyData, + process_model, +) +from openapi_python_client.schema import DataType +from openapi_python_client.schema.ref import Ref +from openapi_python_client.strings import PythonCode MODULE_NAME = "openapi_python_client.parser.properties.model_property" class TestModelProperty: @pytest.mark.parametrize( - "no_optional,required,json,quoted,expected", + "no_optional,required,json,expected", [ - (False, False, False, False, "Union[Unset, MyClass]"), - (False, True, False, False, "MyClass"), - (True, False, False, False, "MyClass"), - (True, True, False, False, "MyClass"), - (False, True, True, False, "Dict[str, Any]"), - (False, False, False, True, "Union[Unset, 'MyClass']"), - (False, True, False, True, "'MyClass'"), - (True, False, False, True, "'MyClass'"), - (True, True, False, True, "'MyClass'"), - (False, True, True, True, "Dict[str, Any]"), + (False, False, False, "MyClass | Unset"), + (False, True, False, "MyClass"), + (True, False, False, "MyClass"), + (True, True, False, "MyClass"), + (False, True, True, "dict[str, Any]"), ], ) - def test_get_type_string(self, no_optional, required, json, expected, model_property_factory, quoted): + def test_get_type_string(self, no_optional, required, json, expected, model_property_factory): prop = model_property_factory( required=required, ) - assert prop.get_type_string(no_optional=no_optional, json=json, quoted=quoted) == expected + assert prop.get_type_string(no_optional=no_optional, json=json) == PythonCode(expected) def test_get_imports(self, model_property_factory): prop = model_property_factory(required=False) assert prop.get_imports(prefix="..") == { - "from typing import Union", "from ..types import UNSET, Unset", - "from typing import Dict", "from typing import cast", } @@ -51,31 +50,21 @@ def test_get_lazy_imports(self, model_property_factory): "from ..models.my_module import MyClass", } - def test_is_base_type(self, model_property_factory): - assert model_property_factory().is_base_type is False - - @pytest.mark.parametrize( - "quoted,expected", - [ - (False, "MyClass"), - (True, '"MyClass"'), - ], - ) - def test_get_base_type_string(self, quoted, expected, model_property_factory): + def test_get_base_type_string(self, model_property_factory): m = model_property_factory() - assert m.get_base_type_string(quoted=quoted) == expected + assert m.get_base_type_string() == PythonCode("MyClass") class TestBuild: @pytest.mark.parametrize( "additional_properties_schema, expected_additional_properties", [ - (True, True), - (oai.Schema.model_construct(), True), - (None, True), - (False, False), + (True, ANY_ADDITIONAL_PROPERTY), + (oai.Schema.model_construct(), ANY_ADDITIONAL_PROPERTY), + (None, ANY_ADDITIONAL_PROPERTY), + (False, None), ( - oai.Schema.model_construct(type="string"), + oai.Schema(type=DataType.STRING), StringProperty( name="AdditionalProperty", required=True, @@ -88,8 +77,6 @@ class TestBuild: ], ) def test_additional_schemas(self, additional_properties_schema, expected_additional_properties, config): - from openapi_python_client.parser.properties import ModelProperty, Schemas - data = oai.Schema.model_construct( additionalProperties=additional_properties_schema, ) @@ -108,8 +95,6 @@ def test_additional_schemas(self, additional_properties_schema, expected_additio assert model.additional_properties == expected_additional_properties def test_happy_path(self, model_property_factory, string_property_factory, date_time_property_factory, config): - from openapi_python_client.parser.properties import Class, ModelProperty, Schemas - name = "prop" required = True @@ -156,19 +141,15 @@ def test_happy_path(self, model_property_factory, string_property_factory, date_ optional_properties=[date_time_property_factory(name="opt", required=False)], description=data.description, relative_imports={ - "from dateutil.parser import isoparse", "from typing import cast", "import datetime", "from ..types import UNSET, Unset", - "from typing import Union", }, lazy_imports=set(), - additional_properties=True, + additional_properties=ANY_ADDITIONAL_PROPERTY, ) def test_model_name_conflict(self, config): - from openapi_python_client.parser.properties import ModelProperty - data = oai.Schema.model_construct() schemas = Schemas(classes_by_name={"OtherModel": None}) @@ -208,14 +189,12 @@ def test_model_name_conflict(self, config): def test_model_naming( self, name: str, - title: Optional[str], - parent_name: Optional[str], + title: str | None, + parent_name: str | None, use_title_prefixing: bool, expected: str, config, ): - from openapi_python_client.parser.properties import ModelProperty - data = oai.Schema( title=title, properties={}, @@ -234,11 +213,9 @@ def test_model_naming( assert result.class_info.name == expected def test_model_bad_properties(self, config): - from openapi_python_client.parser.properties import ModelProperty - data = oai.Schema( properties={ - "bad": oai.Reference.model_construct(ref="#/components/schema/NotExist"), + "bad": oai.Reference.model_construct(ref=Ref("#/components/schema/NotExist")), }, ) result = ModelProperty.build( @@ -254,8 +231,6 @@ def test_model_bad_properties(self, config): assert isinstance(result, PropertyError) def test_model_bad_additional_properties(self, config): - from openapi_python_client.parser.properties import ModelProperty - additional_properties = oai.Schema( type="object", properties={ @@ -276,8 +251,6 @@ def test_model_bad_additional_properties(self, config): assert isinstance(result, PropertyError) def test_process_properties_false(self, model_property_factory, config): - from openapi_python_client.parser.properties import Class, ModelProperty - name = "prop" required = True @@ -325,19 +298,20 @@ def test_process_properties_false(self, model_property_factory, config): class TestProcessProperties: def test_conflicting_properties_different_types( - self, model_property_factory, string_property_factory, date_time_property_factory, config + self, model_property_factory, string_property_factory, int_property_factory, config ): data = oai.Schema.model_construct( - allOf=[oai.Reference.model_construct(ref="#/First"), oai.Reference.model_construct(ref="#/Second")] + allOf=[ + oai.Reference.model_construct(ref=Ref("#/First")), + oai.Reference.model_construct(ref=Ref("#/Second")), + ] ) schemas = Schemas( classes_by_reference={ "/First": model_property_factory( required_properties=[], optional_properties=[string_property_factory()] ), - "/Second": model_property_factory( - required_properties=[], optional_properties=[date_time_property_factory()] - ), + "/Second": model_property_factory(required_properties=[], optional_properties=[int_property_factory()]), } ) @@ -348,7 +322,7 @@ def test_conflicting_properties_different_types( def test_process_properties_reference_not_exist(self, config): data = oai.Schema( properties={ - "bad": oai.Reference.model_construct(ref="#/components/schema/NotExist"), + "bad": oai.Reference.model_construct(ref=Ref("#/components/schema/NotExist")), }, ) @@ -357,7 +331,9 @@ def test_process_properties_reference_not_exist(self, config): assert isinstance(result, PropertyError) def test_process_properties_all_of_reference_not_exist(self, config): - data = oai.Schema.model_construct(allOf=[oai.Reference.model_construct(ref="#/components/schema/NotExist")]) + data = oai.Schema.model_construct( + allOf=[oai.Reference.model_construct(ref=Ref("#/components/schema/NotExist"))] + ) result = _process_properties(data=data, class_name="", schemas=Schemas(), config=config, roots={"root"}) @@ -372,7 +348,7 @@ def test_process_properties_model_property_roots(self, model_property_factory, c assert all(root in result.optional_props[0].roots for root in roots) def test_invalid_reference(self, config): - data = oai.Schema.model_construct(allOf=[oai.Reference.model_construct(ref="ThisIsNotGood")]) + data = oai.Schema.model_construct(allOf=[oai.Reference.model_construct(ref=Ref("ThisIsNotGood"))]) schemas = Schemas() result = _process_properties(data=data, schemas=schemas, class_name="", config=config, roots={"root"}) @@ -380,7 +356,7 @@ def test_invalid_reference(self, config): assert isinstance(result, PropertyError) def test_non_model_reference(self, enum_property_factory, config): - data = oai.Schema.model_construct(allOf=[oai.Reference.model_construct(ref="#/First")]) + data = oai.Schema.model_construct(allOf=[oai.Reference.model_construct(ref=Ref("#/First"))]) schemas = Schemas( classes_by_reference={ "/First": enum_property_factory(), @@ -392,7 +368,7 @@ def test_non_model_reference(self, enum_property_factory, config): assert isinstance(result, PropertyError) def test_reference_not_processed(self, model_property_factory, config): - data = oai.Schema.model_construct(allOf=[oai.Reference.model_construct(ref="#/Unprocessed")]) + data = oai.Schema.model_construct(allOf=[oai.Reference.model_construct(ref=Ref("#/Unprocessed"))]) schemas = Schemas( classes_by_reference={ "/Unprocessed": model_property_factory(), @@ -403,30 +379,14 @@ def test_reference_not_processed(self, model_property_factory, config): assert isinstance(result, PropertyError) - def test_conflicting_properties_same_types(self, model_property_factory, string_property_factory, config): - data = oai.Schema.model_construct( - allOf=[oai.Reference.model_construct(ref="#/First"), oai.Reference.model_construct(ref="#/Second")] - ) - schemas = Schemas( - classes_by_reference={ - "/First": model_property_factory( - required_properties=[], optional_properties=[string_property_factory(default="abc")] - ), - "/Second": model_property_factory( - required_properties=[], optional_properties=[string_property_factory()] - ), - } - ) - - result = _process_properties(data=data, schemas=schemas, class_name="", config=config, roots={"root"}) - - assert isinstance(result, PropertyError) - def test_allof_string_and_string_enum( self, model_property_factory, enum_property_factory, string_property_factory, config ): data = oai.Schema.model_construct( - allOf=[oai.Reference.model_construct(ref="#/First"), oai.Reference.model_construct(ref="#/Second")] + allOf=[ + oai.Reference.model_construct(ref=Ref("#/First")), + oai.Reference.model_construct(ref=Ref("#/Second")), + ] ) enum_property = enum_property_factory( values={"foo": "foo"}, @@ -448,7 +408,10 @@ def test_allof_string_enum_and_string( self, model_property_factory, enum_property_factory, string_property_factory, config ): data = oai.Schema.model_construct( - allOf=[oai.Reference.model_construct(ref="#/First"), oai.Reference.model_construct(ref="#/Second")] + allOf=[ + oai.Reference.model_construct(ref=Ref("#/First")), + oai.Reference.model_construct(ref=Ref("#/Second")), + ] ) enum_property = enum_property_factory( required=False, @@ -469,7 +432,10 @@ def test_allof_string_enum_and_string( def test_allof_int_and_int_enum(self, model_property_factory, enum_property_factory, int_property_factory, config): data = oai.Schema.model_construct( - allOf=[oai.Reference.model_construct(ref="#/First"), oai.Reference.model_construct(ref="#/Second")] + allOf=[ + oai.Reference.model_construct(ref=Ref("#/First")), + oai.Reference.model_construct(ref=Ref("#/Second")), + ] ) enum_property = enum_property_factory( values={"foo": 1}, @@ -489,7 +455,10 @@ def test_allof_enum_incompatible_type( self, model_property_factory, enum_property_factory, int_property_factory, config ): data = oai.Schema.model_construct( - allOf=[oai.Reference.model_construct(ref="#/First"), oai.Reference.model_construct(ref="#/Second")] + allOf=[ + oai.Reference.model_construct(ref=Ref("#/First")), + oai.Reference.model_construct(ref=Ref("#/Second")), + ] ) enum_property = enum_property_factory( values={"foo": 1}, @@ -507,7 +476,10 @@ def test_allof_enum_incompatible_type( def test_allof_string_enums(self, model_property_factory, enum_property_factory, config): data = oai.Schema.model_construct( - allOf=[oai.Reference.model_construct(ref="#/First"), oai.Reference.model_construct(ref="#/Second")] + allOf=[ + oai.Reference.model_construct(ref=Ref("#/First")), + oai.Reference.model_construct(ref=Ref("#/Second")), + ] ) enum_property1 = enum_property_factory( name="an_enum", @@ -531,7 +503,10 @@ def test_allof_string_enums(self, model_property_factory, enum_property_factory, def test_allof_int_enums(self, model_property_factory, enum_property_factory, config): data = oai.Schema.model_construct( - allOf=[oai.Reference.model_construct(ref="#/First"), oai.Reference.model_construct(ref="#/Second")] + allOf=[ + oai.Reference.model_construct(ref=Ref("#/First")), + oai.Reference.model_construct(ref=Ref("#/Second")), + ] ) enum_property1 = enum_property_factory( name="an_enum", @@ -555,7 +530,10 @@ def test_allof_int_enums(self, model_property_factory, enum_property_factory, co def test_allof_enums_are_not_subsets(self, model_property_factory, enum_property_factory, config): data = oai.Schema.model_construct( - allOf=[oai.Reference.model_construct(ref="#/First"), oai.Reference.model_construct(ref="#/Second")] + allOf=[ + oai.Reference.model_construct(ref=Ref("#/First")), + oai.Reference.model_construct(ref=Ref("#/Second")), + ] ) enum_property1 = enum_property_factory( name="an_enum", @@ -579,7 +557,10 @@ def test_allof_enums_are_not_subsets(self, model_property_factory, enum_property def test_duplicate_properties(self, model_property_factory, string_property_factory, config): data = oai.Schema.model_construct( - allOf=[oai.Reference.model_construct(ref="#/First"), oai.Reference.model_construct(ref="#/Second")] + allOf=[ + oai.Reference.model_construct(ref=Ref("#/First")), + oai.Reference.model_construct(ref=Ref("#/Second")), + ] ) prop = string_property_factory(required=False) schemas = Schemas( @@ -593,6 +574,42 @@ def test_duplicate_properties(self, model_property_factory, string_property_fact assert result.optional_props == [prop], "There should only be one copy of duplicate properties" + def test_allof_required_override(self, model_property_factory, string_property_factory, config): + """Test that required field can be overridden in allOf schemas""" + # Simulates: + # FooBase: + # type: object + # properties: + # bar: {type: string} + # baz: {type: string} + # FooCreate: + # allOf: + # - $ref: '#/components/schemas/FooBase' + # - type: object + # required: [bar] + bar_prop = string_property_factory(name="bar", required=False) + baz_prop = string_property_factory(name="baz", required=False) + + data = oai.Schema.model_construct( + allOf=[ + oai.Reference.model_construct(ref=Ref("#/FooBase")), + oai.Schema.model_construct(type="object", required=["bar"]), + ] + ) + schemas = Schemas( + classes_by_reference={ + "/FooBase": model_property_factory(required_properties=[], optional_properties=[bar_prop, baz_prop]), + } + ) + + result = _process_properties(data=data, schemas=schemas, class_name="FooCreate", config=config, roots={"root"}) + + # bar should now be required, baz should remain optional + assert len(result.required_props) == 1 + assert result.required_props[0].name == "bar" + assert len(result.optional_props) == 1 + assert result.optional_props[0].name == "baz" + @pytest.mark.parametrize("first_required", [True, False]) @pytest.mark.parametrize("second_required", [True, False]) def test_mixed_requirements( @@ -604,7 +621,10 @@ def test_mixed_requirements( config, ): data = oai.Schema.model_construct( - allOf=[oai.Reference.model_construct(ref="#/First"), oai.Reference.model_construct(ref="#/Second")] + allOf=[ + oai.Reference.model_construct(ref=Ref("#/First")), + oai.Reference.model_construct(ref=Ref("#/Second")), + ] ) schemas = Schemas( classes_by_reference={ @@ -663,12 +683,36 @@ def test_conflicting_property_names(self, config): result = _process_properties(data=data, schemas=schemas, class_name="", config=config, roots={"root"}) assert isinstance(result, PropertyError) + def test_merge_inline_objects(self, model_property_factory, enum_property_factory, config): + data = oai.Schema.model_construct( + allOf=[ + oai.Schema.model_construct( + type="object", + properties={ + "prop1": oai.Schema.model_construct(type="string", default="a"), + }, + ), + oai.Schema.model_construct( + type="object", + properties={ + "prop1": oai.Schema.model_construct(type="string", description="desc"), + }, + ), + ] + ) + schemas = Schemas() + + result = _process_properties(data=data, schemas=schemas, class_name="", config=config, roots={"root"}) + assert not isinstance(result, PropertyError) + assert len(result.optional_props) == 1 + prop1 = result.optional_props[0] + assert isinstance(prop1, StringProperty) + assert prop1.description == "desc" + assert prop1.default == StringProperty.convert_value("a") + class TestProcessModel: def test_process_model_error(self, mocker, model_property_factory, config): - from openapi_python_client.parser.properties import Schemas - from openapi_python_client.parser.properties.model_property import process_model - model_prop = model_property_factory() schemas = Schemas() process_property_data = mocker.patch(f"{MODULE_NAME}._process_property_data") @@ -683,9 +727,6 @@ def test_process_model_error(self, mocker, model_property_factory, config): assert model_prop.additional_properties is None def test_process_model(self, mocker, model_property_factory, config): - from openapi_python_client.parser.properties import Schemas - from openapi_python_client.parser.properties.model_property import _PropertyData, process_model - model_prop = model_property_factory() schemas = Schemas() property_data = _PropertyData( @@ -710,11 +751,9 @@ def test_process_model(self, mocker, model_property_factory, config): def test_set_relative_imports(model_property_factory): - from openapi_python_client.parser.properties import Class - class_info = Class("ClassName", module_name="module_name") - relative_imports = {"from typing import List", f"from ..models.{class_info.module_name} import {class_info.name}"} + relative_imports = {f"from ..models.{class_info.module_name} import {class_info.name}"} model_property = model_property_factory(class_info=class_info, relative_imports=relative_imports) - assert model_property.relative_imports == {"from typing import List"} + assert model_property.relative_imports == set() diff --git a/tests/test_parser/test_properties/test_none.py b/tests/test_parser/test_properties/test_none.py index 500d078e9..760f6c702 100644 --- a/tests/test_parser/test_properties/test_none.py +++ b/tests/test_parser/test_properties/test_none.py @@ -1,9 +1,12 @@ from openapi_python_client.parser.errors import PropertyError from openapi_python_client.parser.properties import NoneProperty from openapi_python_client.parser.properties.protocol import Value +from openapi_python_client.strings import PythonIdentifier def test_default(): + # currently this is testing an unused code path: + # https://github.com/openapi-generators/openapi-python-client/issues/1162 err = NoneProperty.build( default="not None", description=None, @@ -18,11 +21,11 @@ def test_default(): def test_dont_retest_values(): prop = NoneProperty.build( - default=Value("not None"), + default=Value("not None", "not None"), description=None, example=None, required=False, - python_name="not_none", + python_name=PythonIdentifier("not_none", ""), name="not_none", ) diff --git a/tests/test_parser/test_properties/test_protocol.py b/tests/test_parser/test_properties/test_protocol.py index a110f4ed9..c69aa955b 100644 --- a/tests/test_parser/test_properties/test_protocol.py +++ b/tests/test_parser/test_properties/test_protocol.py @@ -1,47 +1,49 @@ -import pytest +from __future__ import annotations +import pytest -def test_is_base_type(any_property_factory): - assert any_property_factory().is_base_type is True +from openapi_python_client.parser.properties import AnyProperty +from openapi_python_client.parser.properties.protocol import Value, convert_example +from openapi_python_client.schema.untrusted_string import UntrustedString +from openapi_python_client.strings import PythonCode @pytest.mark.parametrize( - "required,no_optional,json,quoted,expected", + "required,no_optional,json,expected", [ - (False, False, False, False, "Union[Unset, TestType]"), - (False, True, False, False, "TestType"), - (True, False, False, False, "TestType"), - (True, True, False, False, "TestType"), - (False, False, True, False, "Union[Unset, str]"), - (False, True, True, False, "str"), - (True, False, True, False, "str"), - (True, True, True, False, "str"), + (False, False, False, "TestType | Unset"), + (False, True, False, "TestType"), + (True, False, False, "TestType"), + (True, True, False, "TestType"), + (False, False, True, "str | Unset"), + (False, True, True, "str"), + (True, False, True, "str"), + (True, True, True, "str"), ], ) -def test_get_type_string(any_property_factory, mocker, required, no_optional, json, expected, quoted): - from openapi_python_client.parser.properties import AnyProperty - +def test_get_type_string(any_property_factory, mocker, required, no_optional, json, expected): mocker.patch.object(AnyProperty, "_type_string", "TestType") mocker.patch.object(AnyProperty, "_json_type_string", "str") p = any_property_factory(required=required) - assert p.get_type_string(no_optional=no_optional, json=json, quoted=quoted) == expected + assert p.get_type_string(no_optional=no_optional, json=json) == PythonCode(expected) @pytest.mark.parametrize( "default,required,expected", [ - (None, False, "test: Union[Unset, TestType] = UNSET"), - (None, True, "test: TestType"), - ("Test", False, "test: Union[Unset, TestType] = Test"), - ("Test", True, "test: TestType = Test"), + (None, False, "test: Any | Unset = UNSET"), + (None, True, "test: Any"), + ("Test", False, "test: Any | Unset = Test"), + ("Test", True, "test: Any = Test"), ], ) -def test_to_string(mocker, default, required, expected, any_property_factory): +def test_to_string(default: str | None, required: bool, expected: str, any_property_factory): name = "test" - mocker.patch("openapi_python_client.parser.properties.AnyProperty._type_string", "TestType") - p = any_property_factory(name=name, required=required, default=default) + p = any_property_factory( + name=name, required=required, default=Value(PythonCode(default), default) if default is not None else None + ) - assert p.to_string() == expected + assert p.to_string() == PythonCode(expected) def test_get_imports(any_property_factory): @@ -49,34 +51,67 @@ def test_get_imports(any_property_factory): assert p.get_imports(prefix="") == set() p = any_property_factory(name="test", required=False, default=None) - assert p.get_imports(prefix="") == {"from types import UNSET, Unset", "from typing import Union"} + assert p.get_imports(prefix="") == {"from types import UNSET, Unset"} -@pytest.mark.parametrize( - "quoted,expected", - [ - (False, "TestType"), - (True, "TestType"), - ], -) -def test_get_base_type_string(quoted, expected, any_property_factory, mocker): - from openapi_python_client.parser.properties import AnyProperty +def test_to_docstring_escapes_description_and_example(any_property_factory): + """Descriptions and examples must not be able to break out of the docstring""" + p = any_property_factory( + description='Break out """ print("uh oh")', + example='Example """ print("uh oh")', + ) - mocker.patch.object(AnyProperty, "_type_string", "TestType") - p = any_property_factory() - assert p.get_base_type_string(quoted=quoted) is expected + doc = p.to_docstring() + assert '"""' not in doc + assert r'\"\"\" print("uh oh")' in doc -@pytest.mark.parametrize( - "quoted,expected", - [ - (False, "str"), - (True, "str"), - ], -) -def test_get_base_json_type_string(quoted, expected, any_property_factory, mocker): - from openapi_python_client.parser.properties import AnyProperty - mocker.patch.object(AnyProperty, "_json_type_string", "str") +def test_to_docstring_escapes_type_string(any_property_factory, mocker): + """A type string containing literal values (e.g. const) must not break out of the docstring""" + mocker.patch.object(AnyProperty, "_type_string", 'Literal[\'"""\']') p = any_property_factory() - assert p.get_base_json_type_string(quoted=quoted) is expected + + doc = p.to_docstring() + + assert '"""' not in doc + + +def test_to_docstring_escapes_default(any_property_factory): + """A default's python_code must not be able to break out of the docstring""" + # python_code for the string default '"""' is the 5-char source: "\"\"\"" + p = any_property_factory(default=Value(python_code=PythonCode('"\\"\\"\\""'), raw_value='"""')) + + doc = p.to_docstring() + + # The raw triple-quote must not survive into the docstring text + assert '"""' not in doc + + +def test_get_instance_type_string(any_property_factory): + p = any_property_factory(required=False) + assert p.get_instance_type_string() == PythonCode("Any") + + +class TestConvertExample: + def test_none(self): + assert convert_example(None) is None + + def test_untrusted_string_passes_through(self): + example = UntrustedString("an example") + assert convert_example(example) is example + + def test_string_is_wrapped(self): + converted = convert_example("an example") + assert isinstance(converted, UntrustedString) + assert converted == "an example" + + def test_non_string_is_stringified(self): + """OpenAPI examples can be any type; they only appear in docstrings so stringify them""" + converted = convert_example({"a": 1}) + assert isinstance(converted, UntrustedString) + assert converted == "{'a': 1}" + + def test_property_converts_example(self, any_property_factory): + p = any_property_factory(example={"a": 1}) + assert p.example == "{'a': 1}" diff --git a/tests/test_parser/test_properties/test_schemas.py b/tests/test_parser/test_properties/test_schemas.py index 5560795cf..8433404d2 100644 --- a/tests/test_parser/test_properties/test_schemas.py +++ b/tests/test_parser/test_properties/test_schemas.py @@ -1,18 +1,23 @@ import pytest from attr import evolve +from openapi_python_client.config import ClassOverride from openapi_python_client.parser.errors import ParameterError from openapi_python_client.parser.properties import Class, Parameters -from openapi_python_client.parser.properties.schemas import parameter_from_reference -from openapi_python_client.schema import Parameter, Reference -from openapi_python_client.utils import ClassName +from openapi_python_client.parser.properties.schemas import ( + ReferencePath, + parameter_from_data, + parameter_from_reference, +) +from openapi_python_client.schema import Parameter, ParameterLocation, Reference, Schema +from openapi_python_client.schema.ref import Ref +from openapi_python_client.schema.untrusted_string import UntrustedString +from openapi_python_client.strings import ClassName MODULE_NAME = "openapi_python_client.parser.properties.schemas" def test_class_from_string_default_config(config): - from openapi_python_client.parser.properties import Class - class_ = Class.from_string(string="#/components/schemas/PingResponse", config=config) assert class_.name == "PingResponse" @@ -29,9 +34,6 @@ def test_class_from_string_default_config(config): ), ) def test_class_from_string(class_override, module_override, expected_class, expected_module, config): - from openapi_python_client.config import ClassOverride - from openapi_python_client.parser.properties import Class - ref = "#/components/schemas/MyResponse" config = evolve( config, class_overrides={"MyResponse": ClassOverride(class_name=class_override, module_name=module_override)} @@ -44,9 +46,6 @@ def test_class_from_string(class_override, module_override, expected_class, expe class TestParameterFromData: def test_cannot_parse_parameters_by_reference(self, config): - from openapi_python_client.parser.properties import Parameters - from openapi_python_client.parser.properties.schemas import parameter_from_data - ref = Reference.model_construct(ref="#/components/parameters/a_param") parameters = Parameters() param_or_error, new_parameters = parameter_from_data( @@ -56,10 +55,6 @@ def test_cannot_parse_parameters_by_reference(self, config): assert new_parameters == parameters def test_parameters_without_schema_are_ignored(self, config): - from openapi_python_client.parser.properties import Parameters - from openapi_python_client.parser.properties.schemas import parameter_from_data - from openapi_python_client.schema import ParameterLocation - param = Parameter(name="a_schemaless_param", param_in=ParameterLocation.QUERY) parameters = Parameters() param_or_error, new_parameters = parameter_from_data( @@ -69,12 +64,8 @@ def test_parameters_without_schema_are_ignored(self, config): assert new_parameters == parameters def test_registers_new_parameters(self, config): - from openapi_python_client.parser.properties import Parameters - from openapi_python_client.parser.properties.schemas import parameter_from_data - from openapi_python_client.schema import ParameterLocation, Schema - param = Parameter.model_construct( - name="a_param", param_in=ParameterLocation.QUERY, param_schema=Schema.model_construct() + name=UntrustedString("a_param"), param_in=ParameterLocation.QUERY, param_schema=Schema.model_construct() ) parameters = Parameters() param_or_error, new_parameters = parameter_from_data( @@ -92,10 +83,10 @@ def test_returns_parameter_if_parameter_provided(self): assert param_or_error == param def test_errors_out_if_reference_not_in_parameters(self): - ref = Reference.model_construct(ref="#/components/parameters/a_param") - class_info = Class(name="a_param", module_name="module_name") + ref = Reference.model_construct(ref=Ref("#/components/parameters/a_param")) + class_info = Class(name=ClassName(UntrustedString("a_param"), prefix=""), module_name="module_name") existing_param = Parameter.model_construct(name="a_param") - param_by_ref = Reference.model_construct(ref="#/components/parameters/another_param") + param_by_ref = Reference.model_construct(ref=Ref("#/components/parameters/another_param")) params = Parameters( classes_by_name={class_info.name: existing_param}, classes_by_reference={ref.ref: existing_param} ) @@ -106,53 +97,12 @@ def test_errors_out_if_reference_not_in_parameters(self): def test_returns_reference_from_registry(self): existing_param = Parameter.model_construct(name="a_param") - class_info = Class(name="MyParameter", module_name="module_name") + class_info = Class(name=ClassName(UntrustedString("MyParameter"), prefix=""), module_name="module_name") params = Parameters( classes_by_name={class_info.name: existing_param}, - classes_by_reference={"/components/parameters/a_param": existing_param}, + classes_by_reference={ReferencePath(UntrustedString("/components/parameters/a_param")): existing_param}, ) - param_by_ref = Reference.model_construct(ref="#/components/parameters/a_param") + param_by_ref = Reference.model_construct(ref=Ref("#/components/parameters/a_param")) param_or_error = parameter_from_reference(param=param_by_ref, parameters=params) assert param_or_error == existing_param - - -class TestUpdateParametersFromData: - def test_reports_parameters_with_errors(self, mocker, config): - from openapi_python_client.parser.properties.schemas import update_parameters_with_data - from openapi_python_client.schema import ParameterLocation, Schema - - parameters = Parameters() - param = Parameter.model_construct( - name="a_param", param_in=ParameterLocation.QUERY, param_schema=Schema.model_construct() - ) - parameter_from_data = mocker.patch( - f"{MODULE_NAME}.parameter_from_data", side_effect=[(ParameterError(), parameters)] - ) - ref_path = Reference.model_construct(ref="#/components/parameters/a_param") - new_parameters_or_error = update_parameters_with_data( - ref_path=ref_path.ref, data=param, parameters=parameters, config=config - ) - - parameter_from_data.assert_called_once() - assert new_parameters_or_error == ParameterError( - detail="Unable to parse this part of your OpenAPI document: : None", - header="Unable to parse parameter #/components/parameters/a_param", - ) - - def test_records_references_to_parameters(self, mocker, config): - from openapi_python_client.parser.properties.schemas import update_parameters_with_data - from openapi_python_client.schema import ParameterLocation, Schema - - parameters = Parameters() - param = Parameter.model_construct( - name="a_param", param_in=ParameterLocation.QUERY, param_schema=Schema.model_construct() - ) - parameter_from_data = mocker.patch(f"{MODULE_NAME}.parameter_from_data", side_effect=[(param, parameters)]) - ref_path = "#/components/parameters/a_param" - new_parameters = update_parameters_with_data( - ref_path=ref_path, data=param, parameters=parameters, config=config - ) - - parameter_from_data.assert_called_once() - assert new_parameters.classes_by_reference[ref_path] == param diff --git a/tests/test_parser/test_properties/test_union.py b/tests/test_parser/test_properties/test_union.py index d8a5d762c..b86100b69 100644 --- a/tests/test_parser/test_properties/test_union.py +++ b/tests/test_parser/test_properties/test_union.py @@ -1,69 +1,17 @@ import openapi_python_client.schema as oai -from openapi_python_client.parser.errors import ParseError, PropertyError -from openapi_python_client.parser.properties import Schemas, UnionProperty +from openapi_python_client import UntrustedString +from openapi_python_client.parser.errors import ParseError +from openapi_python_client.parser.properties import Schemas, UnionProperty, property_from_data from openapi_python_client.schema import DataType, ParameterLocation -def test_property_from_data_union(union_property_factory, date_time_property_factory, string_property_factory, config): - from openapi_python_client.parser.properties import Schemas, property_from_data - - name = "union_prop" - required = True - data = oai.Schema( - anyOf=[oai.Schema(type=DataType.STRING, default="a")], - oneOf=[ - oai.Schema(type=DataType.STRING, schema_format="date-time"), - ], - ) - expected = union_property_factory( - name=name, - required=required, - inner_properties=[ - string_property_factory(name=f"{name}_type_0", default="'a'"), - date_time_property_factory(name=f"{name}_type_1"), - ], - ) - - p, s = property_from_data( - name=name, required=required, data=data, schemas=Schemas(), parent_name="parent", config=config - ) - - assert p == expected - assert s == Schemas() - - -def test_build_union_property_invalid_property(config): - name = "bad_union" - required = True - reference = oai.Reference.model_construct(ref="#/components/schema/NotExist") - data = oai.Schema(anyOf=[reference]) - - p, s = UnionProperty.build( - name=name, required=required, data=data, schemas=Schemas(), parent_name="parent", config=config - ) - assert p == PropertyError(detail=f"Invalid property in union {name}", data=reference) - - -def test_invalid_default(config): - data = oai.Schema( - type=[DataType.NUMBER, DataType.INTEGER], - default="a", - ) - - err, _ = UnionProperty.build( - data=data, required=True, schemas=Schemas(), parent_name="parent", name="name", config=config - ) - - assert isinstance(err, PropertyError) - - def test_invalid_location(config): data = oai.Schema( type=[DataType.NUMBER, DataType.NULL], ) prop, _ = UnionProperty.build( - data=data, required=True, schemas=Schemas(), parent_name="parent", name="name", config=config + data=data, required=True, schemas=Schemas(), parent_name="parent", name=UntrustedString("name"), config=config ) err = prop.validate_location(ParameterLocation.PATH) @@ -76,8 +24,60 @@ def test_not_required_in_path(config): ) prop, _ = UnionProperty.build( - data=data, required=False, schemas=Schemas(), parent_name="parent", name="name", config=config + data=data, required=False, schemas=Schemas(), parent_name="parent", name=UntrustedString("name"), config=config ) err = prop.validate_location(ParameterLocation.PATH) assert isinstance(err, ParseError) + + +def test_union_oneOf_descriptive_type_name( + union_property_factory, + date_time_property_factory, + string_property_factory, + boolean_property_factory, + date_property_factory, + int_property_factory, + float_property_factory, + config, +): + nested_schema_variant_A = oai.Schema(type=DataType.STRING, title="A") + nested_schema_variant_B = oai.Schema(type=DataType.INTEGER, title="B") + nested_schema_variant_2 = oai.Schema(type=DataType.NUMBER) + nested_schema_variant_C = oai.Schema(type=DataType.BOOLEAN, title="C") + + name = "union_prop" + required = True + data = oai.Schema( + anyOf=[ + # AnyOf retains the old naming convention + nested_schema_variant_C, + oai.Schema(type=DataType.STRING, schema_format="date"), + ], + oneOf=[ + # OneOf fields that define their own titles will have those titles as their Type names + nested_schema_variant_A, + nested_schema_variant_B, + nested_schema_variant_2, + oai.Schema(type=DataType.STRING, schema_format="date-time"), + ], + ) + expected = union_property_factory( + name=name, + required=required, + inner_properties=[ + boolean_property_factory(name=f"{name}_C"), + date_property_factory(name=f"{name}_type_1"), + string_property_factory(name=f"{name}_A"), + int_property_factory(name=f"{name}_B"), + float_property_factory(name=f"{name}_type_4"), + date_time_property_factory(name=f"{name}_type_5"), + ], + ) + + p, s = property_from_data( + name=UntrustedString(name), required=required, data=data, schemas=Schemas(), parent_name="parent", config=config + ) + + assert p == expected + assert s == Schemas() diff --git a/tests/test_parser/test_responses.py b/tests/test_parser/test_responses.py index 0ac885764..70cbd88d3 100644 --- a/tests/test_parser/test_responses.py +++ b/tests/test_parser/test_responses.py @@ -1,28 +1,37 @@ from unittest.mock import MagicMock +import pytest + import openapi_python_client.schema as oai +from openapi_python_client import UntrustedString +from openapi_python_client.parser import responses from openapi_python_client.parser.errors import ParseError, PropertyError from openapi_python_client.parser.properties import Schemas -from openapi_python_client.parser.responses import JSON_SOURCE, NONE_SOURCE +from openapi_python_client.parser.responses import ( + JSON_SOURCE, + NONE_SOURCE, + HTTPStatusPattern, + Response, + response_from_data, +) MODULE_NAME = "openapi_python_client.parser.responses" def test_response_from_data_no_content(any_property_factory): - from openapi_python_client.parser.responses import Response, response_from_data - data = oai.Response.model_construct(description="") - response, schemas = response_from_data( - status_code=200, + response, _schemas = response_from_data( + status_code=HTTPStatusPattern(pattern="200", code_range=(200, 200)), data=data, schemas=Schemas(), + responses={}, parent_name="parent", config=MagicMock(), ) assert response == Response( - status_code=200, + status_code=HTTPStatusPattern(pattern="200", code_range=(200, 200)), prop=any_property_factory( name="response_200", default=None, @@ -34,67 +43,43 @@ def test_response_from_data_no_content(any_property_factory): ) -def test_response_from_data_reference(any_property_factory): - from openapi_python_client.parser.responses import Response, response_from_data - - data = oai.Reference.model_construct() - - response, schemas = response_from_data( - status_code=200, - data=data, - schemas=Schemas(), - parent_name="parent", - config=MagicMock(), - ) - - assert response == Response( - status_code=200, - prop=any_property_factory( - name="response_200", - default=None, - required=True, - ), - source=NONE_SOURCE, - data=data, - ) +status_code = HTTPStatusPattern(pattern="200", code_range=(200, 200)) def test_response_from_data_unsupported_content_type(): - from openapi_python_client.parser.responses import response_from_data - - data = oai.Response.model_construct(description="", content={"blah": None}) + data = oai.Response.model_construct(description="", content={oai.UntrustedString("blah"): None}) config = MagicMock() config.content_type_overrides = {} - response, schemas = response_from_data( - status_code=200, + response, _schemas = response_from_data( + status_code=status_code, data=data, schemas=Schemas(), + responses={}, parent_name="parent", config=config, ) - assert response == ParseError(data=data, detail="Unsupported content_type {'blah': None}") + assert response == ParseError(data=data, detail="Unsupported content_type blah") def test_response_from_data_no_content_schema(any_property_factory): - from openapi_python_client.parser.responses import Response, response_from_data - data = oai.Response.model_construct( description="", - content={"application/vnd.api+json; version=2.2": oai.MediaType.model_construct()}, + content={oai.UntrustedString("application/vnd.api+json; version=2.2"): oai.MediaType.model_construct()}, ) config = MagicMock() config.content_type_overrides = {} - response, schemas = response_from_data( - status_code=200, + response, _schemas = response_from_data( + status_code=status_code, data=data, schemas=Schemas(), + responses={}, parent_name="parent", config=config, ) assert response == Response( - status_code=200, + status_code=status_code, prop=any_property_factory( name="response_200", default=None, @@ -107,20 +92,19 @@ def test_response_from_data_no_content_schema(any_property_factory): def test_response_from_data_property_error(mocker): - from openapi_python_client.parser import responses - property_from_data = mocker.patch.object(responses, "property_from_data", return_value=(PropertyError(), Schemas())) data = oai.Response.model_construct( description="", - content={"application/json": oai.MediaType.model_construct(media_type_schema="something")}, + content={oai.UntrustedString("application/json"): oai.MediaType.model_construct(media_type_schema="something")}, ) config = MagicMock() config.content_type_overrides = {} - response, schemas = responses.response_from_data( - status_code=400, + response, _schemas = responses.response_from_data( + status_code=HTTPStatusPattern(pattern="400", code_range=(400, 400)), data=data, schemas=Schemas(), + responses={}, parent_name="parent", config=config, ) @@ -137,27 +121,27 @@ def test_response_from_data_property_error(mocker): def test_response_from_data_property(mocker, any_property_factory): - from openapi_python_client.parser import responses - prop = any_property_factory() property_from_data = mocker.patch.object(responses, "property_from_data", return_value=(prop, Schemas())) data = oai.Response.model_construct( description="", - content={"application/json": oai.MediaType.model_construct(media_type_schema="something")}, + content={oai.UntrustedString("application/json"): oai.MediaType.model_construct(media_type_schema="something")}, ) config = MagicMock() config.content_type_overrides = {} + status_code = HTTPStatusPattern(pattern="400", code_range=(400, 400)) - response, schemas = responses.response_from_data( - status_code=400, + response, _schemas = responses.response_from_data( + status_code=status_code, data=data, schemas=Schemas(), + responses={}, parent_name="parent", config=config, ) assert response == responses.Response( - status_code=400, + status_code=status_code, prop=prop, source=JSON_SOURCE, data=data, @@ -173,24 +157,23 @@ def test_response_from_data_property(mocker, any_property_factory): def test_response_from_data_content_type_overrides(any_property_factory): - from openapi_python_client.parser.responses import Response, response_from_data - data = oai.Response.model_construct( description="", - content={"application/zip": oai.MediaType.model_construct()}, + content={oai.UntrustedString("application/zip"): oai.MediaType.model_construct()}, ) config = MagicMock() config.content_type_overrides = {"application/zip": "application/octet-stream"} - response, schemas = response_from_data( - status_code=200, + response, _schemas = response_from_data( + status_code=HTTPStatusPattern(pattern="200", code_range=(200, 200)), data=data, schemas=Schemas(), + responses={}, parent_name="parent", config=config, ) assert response == Response( - status_code=200, + status_code=HTTPStatusPattern(pattern="200", code_range=(200, 200)), prop=any_property_factory( name="response_200", default=None, @@ -200,3 +183,23 @@ def test_response_from_data_content_type_overrides(any_property_factory): source=NONE_SOURCE, data=data, ) + + +@pytest.mark.parametrize( + "pattern1, pattern2, result", + [ + ("400", "401", True), + ("503", "500", False), + ("default", "400", False), + ("400", "default", True), + ("2XX", "3XX", True), + ("3XX", "2XX", False), + ("2XX", "400", False), + ], +) +def test_http_status_pattern_lt(pattern1: str, pattern2: str, result: bool) -> None: + first = HTTPStatusPattern.parse(UntrustedString(pattern1)) + second = HTTPStatusPattern.parse(UntrustedString(pattern2)) + assert isinstance(first, HTTPStatusPattern) + assert isinstance(second, HTTPStatusPattern) + assert (first < second) == result diff --git a/tests/test_schema/test_data_type.py b/tests/test_schema/test_data_type.py index 19aa256eb..0a4d9681d 100644 --- a/tests/test_schema/test_data_type.py +++ b/tests/test_schema/test_data_type.py @@ -1,3 +1,4 @@ +import pydantic import pytest import openapi_python_client.schema as oai @@ -5,8 +6,6 @@ class TestDataType: def test_schema_bad_types(self): - import pydantic - with pytest.raises(pydantic.ValidationError): oai.Schema(type="bad_type") diff --git a/tests/test_schema/test_noisy_refs.py b/tests/test_schema/test_noisy_refs.py new file mode 100644 index 000000000..ff5a7cf1c --- /dev/null +++ b/tests/test_schema/test_noisy_refs.py @@ -0,0 +1,89 @@ +# If a field may be reference (`Union[Reference, OtherType]`) and the dictionary +# being processed for it contains "$ref", it seems like it should preferentially +# be parsed as a `Reference`[1]. Since the models are defined with +# `extra="allow"`, Pydantic won't guarantee this parse if the dictionary is in +# an unspecified sense a "better match" for `OtherType`[2], e.g., perhaps if it +# has several more fields matching that type versus the single match for `$ref`. +# +# We can use a discriminated union to force parsing these dictionaries as +# `Reference`s. +# +# References: +# [1] https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#reference-object +# [2] https://docs.pydantic.dev/latest/concepts/unions/#smart-mode +from typing import Annotated, TypeVar, get_args, get_origin + +import pytest +from pydantic import TypeAdapter + +from openapi_python_client.schema.openapi_schema_pydantic import ( + Callback, + Example, + Header, + Link, + Parameter, + PathItem, + Reference, + RequestBody, + Response, + Schema, + SecurityScheme, +) + +try: + from openapi_python_client.schema.openapi_schema_pydantic.reference import ReferenceOr +except ImportError: + T = TypeVar("T") + ReferenceOr = Reference | T + + +def get_example(base_type): + schema = base_type.model_json_schema() + if "examples" in schema: + return schema["examples"][0] + if "$defs" in schema: + return schema["$defs"][base_type.__name__]["examples"][0] + raise TypeError(f"No example found for {base_type.__name__}") + + +def deannotate_type(t): + while get_origin(t) is Annotated: + t = get_args(t)[0] + return t + + +# The following types occur in various models, so we want to make sure they +# parse properly. They are verified to /fail/ to parse as of commit 3bd12f86. + + +@pytest.mark.parametrize( + ("ref_or_type", "get_example_fn"), + [ + (ReferenceOr[Callback], lambda t: {"test1": get_example(PathItem), "test2": get_example(PathItem)}), + (ReferenceOr[Example], get_example), + (ReferenceOr[Header], get_example), + (ReferenceOr[Link], get_example), + (ReferenceOr[Parameter], get_example), + (ReferenceOr[RequestBody], get_example), + (ReferenceOr[Response], get_example), + (ReferenceOr[Schema], get_example), + (ReferenceOr[SecurityScheme], get_example), + ], +) +def test_type(ref_or_type, get_example_fn): + base_type = None + for maybe_annotated_type in get_args(deannotate_type(ref_or_type)): + each_type = deannotate_type(maybe_annotated_type) + if each_type is not Reference: + base_type = each_type + break + assert base_type is not None + + example = get_example_fn(base_type) + + parsed = TypeAdapter(ref_or_type).validate_python(example) + assert type(parsed) is get_origin(base_type) or base_type + + example["$ref"] = "ref" + parsed = TypeAdapter(ref_or_type).validate_python(example) + assert type(parsed) is Reference diff --git a/tests/test_schema/test_open_api.py b/tests/test_schema/test_open_api.py index bdab19eba..02b4946c1 100644 --- a/tests/test_schema/test_open_api.py +++ b/tests/test_schema/test_open_api.py @@ -2,6 +2,7 @@ from pydantic import ValidationError from openapi_python_client.schema import OpenAPI +from openapi_python_client.schema.untrusted_string import UntrustedString @pytest.mark.parametrize( @@ -40,6 +41,6 @@ def test_parse_with_callback(): } open_api = OpenAPI.model_validate(data) - create_endpoint = open_api.paths["/create"] + create_endpoint = open_api.paths[UntrustedString("/create")] assert "200" in create_endpoint.post.responses assert "200" in create_endpoint.post.callbacks["event"]["callback"].post.responses diff --git a/tests/test_schema/test_schema.py b/tests/test_schema/test_schema.py index 4b93f2c42..0aa892af1 100644 --- a/tests/test_schema/test_schema.py +++ b/tests/test_schema/test_schema.py @@ -12,6 +12,11 @@ def test_nullable_with_allof(): assert schema.allOf == [] +def test_constant_bool(): + schema = Schema.model_validate_json('{"type":"boolean", "enum":[true], "const":true, "default":true}') + assert schema.const is True + + def test_nullable_with_type_list(): schema = Schema.model_validate_json('{"type": ["string", "number"], "nullable": true}') assert schema.type == [DataType.STRING, DataType.NUMBER, DataType.NULL] @@ -25,3 +30,39 @@ def test_nullable_with_any_of(): def test_nullable_with_one_of(): schema = Schema.model_validate_json('{"oneOf": [{"type": "string"}], "nullable": true}') assert schema.oneOf == [Schema(type=DataType.STRING), Schema(type=DataType.NULL)] + + +def test_exclusive_minimum_as_boolean(): + schema = Schema.model_validate_json('{"minimum": 10, "exclusiveMinimum": true}') + assert schema.exclusiveMinimum == 10 + assert schema.minimum is None + + +def test_exclusive_maximum_as_boolean(): + schema = Schema.model_validate_json('{"maximum": 100, "exclusiveMaximum": true}') + assert schema.exclusiveMaximum == 100 + assert schema.maximum is None + + +def test_exclusive_minimum_as_number(): + schema = Schema.model_validate_json('{"exclusiveMinimum": 5}') + assert schema.exclusiveMinimum == 5 + assert schema.minimum is None + + +def test_exclusive_maximum_as_number(): + schema = Schema.model_validate_json('{"exclusiveMaximum": 50}') + assert schema.exclusiveMaximum == 50 + assert schema.maximum is None + + +def test_exclusive_minimum_as_false_boolean(): + schema = Schema.model_validate_json('{"minimum": 10, "exclusiveMinimum": false}') + assert schema.exclusiveMinimum is None + assert schema.minimum == 10 + + +def test_exclusive_maximum_as_false_boolean(): + schema = Schema.model_validate_json('{"maximum": 100, "exclusiveMaximum": false}') + assert schema.exclusiveMaximum is None + assert schema.maximum == 100 diff --git a/tests/test_schema/test_untrusted_string.py b/tests/test_schema/test_untrusted_string.py new file mode 100644 index 000000000..54350daf1 --- /dev/null +++ b/tests/test_schema/test_untrusted_string.py @@ -0,0 +1,31 @@ +from pydantic import BaseModel + +from openapi_python_client.schema.ref import Ref +from openapi_python_client.schema.untrusted_string import UntrustedString + + +class Model(BaseModel): + untrusted: UntrustedString + + +class RefModel(BaseModel): + ref: Ref + + +def test_ref_json_serialization(): + """Ref must serialize to its raw value in JSON mode so error messages can include it.""" + m = RefModel.model_validate({"ref": "#/components/schemas/Foo"}) + assert m.model_dump_json() == '{"ref":"#/components/schemas/Foo"}' + + +def test_untrusted_string_deserialization(): + m = Model.model_validate_json('{"untrusted":"hello"}') + assert m.untrusted.get_untrusted_value() == "hello" + + +def test_untrusted_string_json_serialization(): + """UntrustedString must serialize to its raw value in JSON mode so error messages can include it.""" + m = Model.model_validate_json('{"untrusted":"hello"}') + assert m.model_dump_json() == '{"untrusted":"hello"}' + # Python mode keeps the wrapper intact so it can't leak into generated code + assert isinstance(m.model_dump()["untrusted"], UntrustedString) diff --git a/tests/test_strings.py b/tests/test_strings.py new file mode 100644 index 000000000..a90fb6e2a --- /dev/null +++ b/tests/test_strings.py @@ -0,0 +1,328 @@ +import ast +import copy +import textwrap +import warnings + +import pytest + +from openapi_python_client import strings +from openapi_python_client.schema.untrusted_string import UntrustedString + + +class TestPythonIdentifier: + def test_valid_identifier_is_not_changed(self): + assert strings.PythonIdentifier(value="valid_field", prefix="field") == "valid_field" + + def test_numbers_are_prefixed(self): + assert strings.PythonIdentifier(value="1", prefix="field") == "field1" + + def test_invalid_symbols_are_stripped(self): + assert strings.PythonIdentifier(value="$abc", prefix="prefix") == "abc" + + def test_keywords_are_postfixed(self): + assert strings.PythonIdentifier(value="for", prefix="prefix") == "for_" + + def test_empty_is_prefixed(self): + assert strings.PythonIdentifier(value="", prefix="something") == "something" + + def test_skip_snake_case_preserves_case(self): + assert strings.PythonIdentifier(value="fooBar", prefix="field", skip_snake_case=True) == "fooBar" + + def test_skip_snake_case_strips_delimiters(self): + assert strings.PythonIdentifier(value="foo-bar", prefix="field", skip_snake_case=True) == "foobar" + assert strings.PythonIdentifier(value="foo bar", prefix="field", skip_snake_case=True) == "foobar" + assert strings.PythonIdentifier(value="foo.bar", prefix="field", skip_snake_case=True) == "foobar" + + def test_skip_snake_case_keeps_underscores(self): + assert strings.PythonIdentifier(value="foo_bar", prefix="field", skip_snake_case=True) == "foo_bar" + + def test_skip_snake_case_result_is_always_valid_identifier(self): + result = strings.PythonIdentifier(value="foo-bar", prefix="field", skip_snake_case=True) + assert result.isidentifier() + assert strings.PythonIdentifier(value="1-2", prefix="field", skip_snake_case=True).isidentifier() + assert strings.PythonIdentifier(value="---", prefix="field", skip_snake_case=True).isidentifier() + + def test_non_identifier_unicode_is_stripped(self): + # U+00BC VULGAR FRACTION ONE QUARTER matches \w but is not valid in identifiers + assert strings.PythonIdentifier(value="¼", prefix="field") == "field" + assert strings.PythonIdentifier(value="¼", prefix="field").isidentifier() + + +class TestClassName: + def test_valid_is_not_changed(self): + assert strings.ClassName(value=UntrustedString("ValidClass"), prefix="field") == "ValidClass" + + def test_numbers_are_prefixed(self): + assert strings.ClassName(value=UntrustedString("1"), prefix="field") == "Field1" + + def test_invalid_symbols_are_stripped(self): + assert strings.ClassName(value=UntrustedString("$abc"), prefix="prefix") == "Abc" + + def test_keywords_are_postfixed(self): + assert strings.ClassName(value=UntrustedString("none"), prefix="prefix") == "None_" + + def test_empty_is_prefixed(self): + assert strings.ClassName(value=UntrustedString(""), prefix="something") == "Something" + + def test_deepcopy_returns_self(self): + name = strings.ClassName(value=UntrustedString("ValidClass"), prefix="field") + assert copy.deepcopy(name) is name + + +@pytest.mark.parametrize( + "before, after", + [ + ("connectionID", ["connection", "ID"]), + ("connection_id", ["connection", "id"]), + ("connection-id", ["connection", "id"]), + ("Response200", ["Response", "200"]), + ("Response200Okay", ["Response", "200", "Okay"]), + ("S3Config", ["S3", "Config"]), + ("s3config", ["s3config"]), + ("fully.qualified.Name", ["fully", "qualified", "Name"]), + ], +) +def test_split_words(before, after): + assert strings.split_words(before) == after + + +def test_snake_case_uppercase_str(): + assert strings.snake_case("HTTP") == "http" + assert strings.snake_case("HTTP RESPONSE") == "http_response" + + +def test_snake_case_from_pascal_with_acronyms(): + assert strings.snake_case("HTTPResponse") == "http_response" + assert strings.snake_case("APIClientHTTPResponse") == "api_client_http_response" + assert strings.snake_case("OAuthClientHTTPResponse") == "o_auth_client_http_response" + assert strings.snake_case("S3Config") == "s3_config" + + +def test_snake_case_from_pascal_with_numbers(): + assert strings.snake_case("Response200") == "response_200" + assert strings.snake_case("Response200WithContent") == "response_200_with_content" + + +def test_snake_case_from_pascal(): + assert strings.snake_case("HttpResponsePascalCase") == "http_response_pascal_case" + + +def test_snake_case_from_camel(): + assert strings.snake_case("httpResponseLowerCamel") == "http_response_lower_camel" + assert strings.snake_case("connectionID") == "connection_id" + + +def test_snake_case_untrusted_string(): + assert strings.snake_case(UntrustedString("httpResponse")) == "http_response" + + +def test_kebab_case(): + assert strings.kebab_case("keep_alive") == "keep-alive" + + +def test_sanitize(): + assert strings.sanitize("some.thing*~with lots_- of weird things}=") == "some.thingwith lots_- of weird things" + + +def test_sanitize_strips_non_identifier_unicode(): + # ¼ matches \w but cannot appear in a Python identifier; digits must be kept for splitting + assert strings.sanitize("¼") == "" + assert strings.sanitize("S3Config") == "S3Config" + + +def test_split_words_on_backslash(): + # Backslash is a delimiter; it must actually split, not leak into the word + assert strings.split_words("one\\two") == ["one", "two"] + assert strings.snake_case("one\\two") == "one_two" + + +@pytest.mark.parametrize( + "value, expected", + [ + ('an "evil" string', r"an \"evil\" string"), + (r"an \"evil string", r"an \\\"evil string"), + ], +) +def test_no_string_escapes(value: str, expected: str): + assert strings.remove_string_escapes(value) == expected + + +@pytest.mark.parametrize( + "reserved_word, expected", + [ + ("self", "self_"), + ("int", "int_"), + ("dict", "dict_"), + ("not_reserved", "not_reserved"), + ("type", "type_"), + ("id", "id"), + ("None", "None_"), + ], +) +def test__fix_reserved_words(reserved_word: str, expected: str): + assert strings.fix_reserved_words(reserved_word) == expected + + +@pytest.mark.parametrize( + "before, after", + [ + ("PascalCase", "PascalCase"), + ("snake_case", "SnakeCase"), + ("TLAClass", "TLAClass"), + ("Title Case", "TitleCase"), + ("s3_config", "S3Config"), + ("__LeadingUnderscore", "LeadingUnderscore"), + ], +) +def test_pascalcase(before, after): + assert strings.pascal_case(before) == after + + +@pytest.mark.parametrize( + "content_type, expected", + [ + pytest.param("application/json", "application/json"), + pytest.param("application/vnd.api+json", "application/vnd.api+json"), + pytest.param("application/json;charset=utf-8", "application/json"), + pytest.param("application/vnd.api+json;charset=utf-8", "application/vnd.api+json"), + ], +) +def test_get_content_type(content_type: str, expected: str, config) -> None: + assert strings.get_content_type(content_type, config) == expected + + +@pytest.mark.parametrize( + "untrusted, expected", + [ + ("innocuous", "innocuous"), + ('can contain "quotes"', 'can contain "quotes"'), + ("backslash\\ should be escaped", "backslash\\\\ should be escaped"), + ('triple quotes """ are an issue', 'triple quotes \\"\\"\\" are an issue'), + # Control characters which are illegal in Python source must be stripped + ("null\x00byte", "nullbyte"), + ("bell\x07rings", "bellrings"), + ("newlines\nand\ttabs\r\nstay", "newlines\nand\ttabs\r\nstay"), + ], +) +def test_safe_for_docstring(untrusted: str, expected: str) -> None: + assert strings.safe_for_docstring(UntrustedString(untrusted)) == expected + + +def test_safe_for_docstring_non_string() -> None: + """Non-string values (e.g. dict examples) are stringified instead of crashing""" + assert strings.safe_for_docstring({"nested": 'has "quotes"'}) == "{'nested': 'has \"quotes\"'}" + + +@pytest.mark.parametrize( + "untrusted, expected", + [ + ("innocuous", "innocuous"), + ('quotes "break out" of literals', 'quotes \\"break out\\" of literals'), + ("backslash\\ escapes", "backslash\\\\ escapes"), + ("newlines\nand\ttabs", "newlinesand\\ttabs"), + ("backspace\bform-feed\f", "backspace\\bform-feed\\f"), + ("single 'quotes' are fine", "single 'quotes' are fine"), + ("astral character \U00010000", "astral character \U00010000"), + ("\x7f\N{NEXT LINE}\N{LINE SEPARATOR}\N{PARAGRAPH SEPARATOR}", ""), + ("bidirectional\u202etext", "bidirectionaltext"), + ], +) +def test_in_double_quote_literal(untrusted: str, expected: str) -> None: + assert strings.in_double_quote_literal(UntrustedString(untrusted)) == expected + + +@pytest.mark.parametrize( + "untrusted, expected", + [ + ("innocuous", "innocuous"), + ('quotes "break out"', 'quotes \\"break out\\"'), + ("{braces} inject code", "{{braces}} inject code"), + ("{x!r:>10}", "{{x!r:>10}}"), + ("backslash\\", "backslash\\\\"), + ], +) +def test_in_f_string_literal(untrusted: str, expected: str) -> None: + assert strings.in_f_string_literal(UntrustedString(untrusted)) == expected + + +class TestPythonCode: + def test_get_code_returns_raw_source(self) -> None: + assert strings.PythonCode("'some' + code").as_unembedded_code() == "'some' + code" + + def test_repr_does_not_contain_code(self) -> None: + """The repr is what a template that forgets to unwrap renders: it must never contain the code""" + code = strings.PythonCode('""" + print("uh oh")') + assert "print" not in repr(code) + assert "PythonCode object at 0x" in repr(code) + + def test_no_str(self) -> None: + """PythonCode must not be implicitly convertible to str, so str() falls back to the safe repr""" + assert "__str__" not in vars(strings.PythonCode) + code = strings.PythonCode("1 + 1") + assert str(code) == repr(code) + assert "1 + 1" not in str(code) + + +def test_in_double_quote_literal_accepts_python_code() -> None: + assert strings.in_double_quote_literal(strings.PythonCode('"quoted"')) == '\\"quoted\\"' + + +def test_safe_for_docstring_accepts_python_code() -> None: + assert strings.safe_for_docstring(strings.PythonCode('a"""b')) == 'a\\"\\"\\"b' + + +def _wordwrap_like_templates(text: str, width: int) -> str: + """Replicates the `wordwrap` filter as used in templates (per-paragraph textwrap)""" + return "\n".join( + "\n".join( + textwrap.wrap( + line, + width=width, + expand_tabs=False, + replace_whitespace=False, + break_long_words=True, + break_on_hyphens=True, + ) + ) + for line in text.splitlines() + ) + + +# Widths passed to the wordwrap filter in templates +@pytest.mark.parametrize("width", [90, 100, 101, 112, 116]) +def test_safe_for_docstring_output_survives_wordwrap(width: int) -> None: + """wordwrap hard-splits over-long words; escaped content must stay valid Python wherever it lands""" + nasty = ( + 'has """ triple \\ quotes and \U001060ef astral chars and \x00nulls ' * 5 + # One long unbroken word: \U and \N are hard SyntaxErrors if a split leaves them dangling + + r"C:\Users\New\Documents\foo" * 8 + + " " + + '"' * 200 + ) + escaped = strings.safe_for_docstring(nasty) + wrapped = _wordwrap_like_templates(escaped, width) + with warnings.catch_warnings(): + warnings.simplefilter("error") # invalid escape sequences would warn (SyntaxError in future Python) + parsed = ast.parse(f'"""\n{wrapped}\n"""') + docstring = parsed.body[0].value.value + assert isinstance(docstring, str) # nothing broke out of the docstring + + +def test_safe_for_docstring_chunks_long_words_at_escape_safe_points() -> None: + """Inserted line breaks must not interrupt an escape sequence or change the content""" + word = r"C:\Users\New\Documents\foo" * 8 + escaped = strings.safe_for_docstring(word) + lines = escaped.split("\n") + assert len(lines) > 1 + assert all(len(line) <= strings._MAX_ESCAPED_WORD_LENGTH for line in lines) + for line in lines: + trailing_backslashes = len(line) - len(line.rstrip("\\")) + assert trailing_backslashes % 2 == 0 + # Only newlines were inserted; the escaped content is otherwise untouched + assert escaped.replace("\n", "") == word.replace("\\", "\\\\") + + +def test_safe_for_docstring_does_not_chunk_words_without_backslashes() -> None: + """Words with no escape sequences (e.g. URLs) can be hard-split anywhere, so leave them alone""" + word = "https://example.com/" + "a" * 500 + assert strings.safe_for_docstring(word) == word diff --git a/tests/test_templates/conftest.py b/tests/test_templates/conftest.py index 09fd63f6c..e41b84308 100644 --- a/tests/test_templates/conftest.py +++ b/tests/test_templates/conftest.py @@ -4,9 +4,8 @@ @pytest.fixture(scope="session") def env() -> Environment: - from openapi_python_client import utils + from openapi_python_client import TEMPLATE_FILTERS - TEMPLATE_FILTERS = {"snakecase": utils.snake_case, "kebabcase": utils.kebab_case} env = Environment(loader=PackageLoader("openapi_python_client"), trim_blocks=True, lstrip_blocks=True) env.filters.update(TEMPLATE_FILTERS) return env diff --git a/tests/test_templates/test_endpoint_macros.py b/tests/test_templates/test_endpoint_macros.py new file mode 100644 index 000000000..c601e0e30 --- /dev/null +++ b/tests/test_templates/test_endpoint_macros.py @@ -0,0 +1,36 @@ +from types import SimpleNamespace + +from openapi_python_client.strings import PythonCode + + +def _render_docstring(env, return_string, is_detailed: bool) -> str: + template = env.get_template("endpoint_macros.py.jinja") + endpoint = SimpleNamespace(summary=None, description=None, list_all_parameters=lambda: []) + return template.module.docstring(endpoint, return_string, is_detailed) + + +def test_endpoint_docstring_escapes_return_string(env) -> None: + """The return type is rendered inside endpoint docstrings; it must not be able to break out. + + Type strings can embed literal values (e.g. const `Literal[...]`), so the docstring macro must pass the + return string through `safe_for_docstring` rather than rendering the raw code. Note that a raw breakout + would still be *valid* Python (that's the point of an escape), so this asserts on the docstring content, + not just parseability. + """ + nasty = 'Literal[\'""" + print("uh oh") + """\']' + + for is_detailed in (True, False): + result = _render_docstring(env, nasty, is_detailed) + # Only the two docstring delimiters; the value's triple-quotes must be escaped + assert result.count('"""') == 2 + assert '\\"\\"\\"' in result + + +def test_endpoint_docstring_unwraps_python_code_return_string(env) -> None: + """A PythonCode return type must render its (escaped) code in the docstring, not the safe pointer repr""" + code = PythonCode("MyModel | None") + + result = _render_docstring(env, code, is_detailed=False) + + assert "MyModel | None" in result + assert "object at 0x" not in result diff --git a/tests/test_templates/test_model_template.py b/tests/test_templates/test_model_template.py new file mode 100644 index 000000000..1443f6c98 --- /dev/null +++ b/tests/test_templates/test_model_template.py @@ -0,0 +1,41 @@ +from __future__ import annotations + +from types import SimpleNamespace + +from openapi_python_client import UntrustedString + + +def _section(content: str, start: str, end: str | None = None) -> str: + section = content.split(start, 1)[1] + if end is not None: + section = section.split(end, 1)[0] + return section + + +def test_model_template_renders_lazy_imports_in_stable_order(env) -> None: + template = env.get_template("model.py.jinja") + + model = SimpleNamespace( + is_multipart_body=True, + relative_imports=set(), + lazy_imports={"from ..models.z import Z", "from ..models.a import A"}, + additional_properties=False, + class_info=SimpleNamespace(name="MyModel", module_name="my_model"), + title=UntrustedString(""), + description=UntrustedString(""), + example=UntrustedString(""), + required_properties=[], + optional_properties=[], + ) + config = SimpleNamespace(docstrings_on_attributes=False) + + content = template.render(model=model, config=config) + + sections = [ + _section(content, "if TYPE_CHECKING:", "T = TypeVar"), + _section(content, "def to_dict(self)", "def to_multipart(self)"), + _section(content, "def to_multipart(self)", "@classmethod"), + _section(content, "def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:", "return my_model"), + ] + for section in sections: + assert section.index("from ..models.a import A") < section.index("from ..models.z import Z") diff --git a/tests/test_templates/test_property_templates/test_date_property/date_property_template.py b/tests/test_templates/test_property_templates/test_date_property/date_property_template.py.jinja similarity index 78% rename from tests/test_templates/test_property_templates/test_date_property/date_property_template.py rename to tests/test_templates/test_property_templates/test_date_property/date_property_template.py.jinja index 3709963fe..071aef509 100644 --- a/tests/test_templates/test_property_templates/test_date_property/date_property_template.py +++ b/tests/test_templates/test_property_templates/test_date_property/date_property_template.py.jinja @@ -1,7 +1,6 @@ +import datetime from datetime import date -from typing import cast, Union -from dateutil.parser import isoparse {% from "property_templates/date_property.py.jinja" import transform, construct %} some_source = date(2020, 10, 12) {{ transform(property, "some_source", "some_destination") }} diff --git a/tests/test_templates/test_property_templates/test_date_property/required_not_null.py b/tests/test_templates/test_property_templates/test_date_property/required_not_null.py index ad4f380a4..f27bc455f 100644 --- a/tests/test_templates/test_property_templates/test_date_property/required_not_null.py +++ b/tests/test_templates/test_property_templates/test_date_property/required_not_null.py @@ -1,9 +1,8 @@ +import datetime from datetime import date -from typing import cast, Union -from dateutil.parser import isoparse some_source = date(2020, 10, 12) some_destination = some_source.isoformat() -a_prop = isoparse(some_destination).date() +a_prop = datetime.date.fromisoformat(some_destination) diff --git a/tests/test_templates/test_property_templates/test_date_property/test_date_property.py b/tests/test_templates/test_property_templates/test_date_property/test_date_property.py index 98999b910..89944994c 100644 --- a/tests/test_templates/test_property_templates/test_date_property/test_date_property.py +++ b/tests/test_templates/test_property_templates/test_date_property/test_date_property.py @@ -27,7 +27,7 @@ def test_required(): lstrip_blocks=True ) - template = env.get_template("date_property_template.py") + template = env.get_template("date_property_template.py.jinja") content = template.render(property=prop) expected = here / "required_not_null.py" assert content == expected.read_text() diff --git a/tests/test_templates/test_property_templates/test_datetime_property/datetime_property_template.py b/tests/test_templates/test_property_templates/test_datetime_property/datetime_property_template.py.jinja similarity index 78% rename from tests/test_templates/test_property_templates/test_datetime_property/datetime_property_template.py rename to tests/test_templates/test_property_templates/test_datetime_property/datetime_property_template.py.jinja index 85fa1548d..3b428734d 100644 --- a/tests/test_templates/test_property_templates/test_datetime_property/datetime_property_template.py +++ b/tests/test_templates/test_property_templates/test_datetime_property/datetime_property_template.py.jinja @@ -1,7 +1,6 @@ +import datetime from datetime import date -from typing import cast, Union -from dateutil.parser import isoparse {% from "property_templates/datetime_property.py.jinja" import transform, construct %} some_source = date(2020, 10, 12) {{ transform(property, "some_source", "some_destination") }} diff --git a/tests/test_templates/test_property_templates/test_datetime_property/required_not_null.py b/tests/test_templates/test_property_templates/test_datetime_property/required_not_null.py index 8253828e3..c55e883d7 100644 --- a/tests/test_templates/test_property_templates/test_datetime_property/required_not_null.py +++ b/tests/test_templates/test_property_templates/test_datetime_property/required_not_null.py @@ -1,9 +1,8 @@ +import datetime from datetime import date -from typing import cast, Union -from dateutil.parser import isoparse some_source = date(2020, 10, 12) some_destination = some_source.isoformat() -a_prop = isoparse(some_destination) +a_prop = datetime.datetime.fromisoformat(some_destination) diff --git a/tests/test_templates/test_property_templates/test_datetime_property/test_datetime_property.py b/tests/test_templates/test_property_templates/test_datetime_property/test_datetime_property.py index 83d91ff3a..bb9a3bd10 100644 --- a/tests/test_templates/test_property_templates/test_datetime_property/test_datetime_property.py +++ b/tests/test_templates/test_property_templates/test_datetime_property/test_datetime_property.py @@ -27,7 +27,7 @@ def test_required(): lstrip_blocks=True ) - template = env.get_template("datetime_property_template.py") + template = env.get_template("datetime_property_template.py.jinja") content = template.render(property=prop) expected = here / "required_not_null.py" assert content == expected.read_text() diff --git a/tests/test_templates/test_property_templates/test_uuid_property/__init__.py b/tests/test_templates/test_property_templates/test_uuid_property/__init__.py new file mode 100644 index 000000000..839bd41fd --- /dev/null +++ b/tests/test_templates/test_property_templates/test_uuid_property/__init__.py @@ -0,0 +1 @@ +"""Tests for UUID property templates.""" diff --git a/tests/test_templates/test_property_templates/test_uuid_property/test_uuid_multipart.py b/tests/test_templates/test_property_templates/test_uuid_property/test_uuid_multipart.py new file mode 100644 index 000000000..224b7b855 --- /dev/null +++ b/tests/test_templates/test_property_templates/test_uuid_property/test_uuid_multipart.py @@ -0,0 +1,70 @@ +"""Tests for UUID property multipart macro functionality.""" + +from pathlib import Path +from typing import Any +from uuid import UUID + +import jinja2 +import pytest + +from openapi_python_client.parser.properties import UuidProperty +from openapi_python_client.strings import PythonIdentifier + + +def uuid_property(required: bool = True, default: Any = None) -> UuidProperty: + """Helper to create a UuidProperty for testing.""" + return UuidProperty( + name="test_uuid", + required=required, + default=default, + python_name=PythonIdentifier(value="test_uuid", prefix=""), + description="A test UUID property", + example="550e8400-e29b-41d4-a716-446655440000", + ) + + +@pytest.fixture +def jinja_env() -> jinja2.Environment: + """Create a Jinja2 environment with the property templates loaded.""" + templates_dir = Path(__file__).parent.parent.parent.parent.parent / "openapi_python_client" / "templates" + env = jinja2.Environment( + loader=jinja2.FileSystemLoader(templates_dir), + trim_blocks=True, + lstrip_blocks=True, + ) + return env + + +def test_multipart_macro_generates_syntactically_correct_code_for_required_uuid(jinja_env: jinja2.Environment) -> None: + """Test that the multipart macro generates syntactically correct Python code for required UUID properties.""" + prop = uuid_property(required=True) + + template = jinja_env.get_template("property_templates/uuid_property.py.jinja") + + # Render the multipart macro + multipart_code = template.module.multipart(prop, "test_uuid", '"test_uuid"') # type: ignore[attr-defined] + + # Verify the generated code is syntactically correct + expected = 'files.append(("test_uuid", (None, str(test_uuid), "text/plain")))' + assert multipart_code.strip() == expected + + # Verify it compiles as valid Python + compile(multipart_code, "", "exec") + + +def test_multipart_macro_generates_syntactically_correct_code_for_optional_uuid(jinja_env: jinja2.Environment) -> None: + """Test that the multipart macro generates syntactically correct Python code for optional UUID properties.""" + prop = uuid_property(required=False) + + template = jinja_env.get_template("property_templates/uuid_property.py.jinja") + + # Render the multipart macro + multipart_code = template.module.multipart(prop, "test_uuid", '"test_uuid"') # type: ignore[attr-defined] + + # Verify the generated code is syntactically correct + expected = 'files.append(("test_uuid", (None, str(test_uuid), "text/plain")))' + assert multipart_code.strip() == expected + + # Verify it compiles as valid Python + compile(multipart_code, "", "exec") + \ No newline at end of file diff --git a/tests/test_utils.py b/tests/test_utils.py deleted file mode 100644 index e7dccf9a8..000000000 --- a/tests/test_utils.py +++ /dev/null @@ -1,136 +0,0 @@ -import pytest - -from openapi_python_client import utils - - -class TestPythonIdentifier: - def test_valid_identifier_is_not_changed(self): - assert utils.PythonIdentifier(value="valid_field", prefix="field") == "valid_field" - - def test_numbers_are_prefixed(self): - assert utils.PythonIdentifier(value="1", prefix="field") == "field1" - - def test_invalid_symbols_are_stripped(self): - assert utils.PythonIdentifier(value="$abc", prefix="prefix") == "abc" - - def test_keywords_are_postfixed(self): - assert utils.PythonIdentifier(value="for", prefix="prefix") == "for_" - - def test_empty_is_prefixed(self): - assert utils.PythonIdentifier(value="", prefix="something") == "something" - - -class TestClassName: - def test_valid_is_not_changed(self): - assert utils.ClassName(value="ValidClass", prefix="field") == "ValidClass" - - def test_numbers_are_prefixed(self): - assert utils.ClassName(value="1", prefix="field") == "Field1" - - def test_invalid_symbols_are_stripped(self): - assert utils.ClassName(value="$abc", prefix="prefix") == "Abc" - - def test_keywords_are_postfixed(self): - assert utils.ClassName(value="none", prefix="prefix") == "None_" - - def test_empty_is_prefixed(self): - assert utils.ClassName(value="", prefix="something") == "Something" - - -@pytest.mark.parametrize( - "before, after", - [ - ("connectionID", ["connection", "ID"]), - ("connection_id", ["connection", "id"]), - ("connection-id", ["connection", "id"]), - ("Response200", ["Response", "200"]), - ("Response200Okay", ["Response", "200", "Okay"]), - ("S3Config", ["S3", "Config"]), - ("s3config", ["s3config"]), - ("fully.qualified.Name", ["fully", "qualified", "Name"]), - ], -) -def test_split_words(before, after): - assert utils.split_words(before) == after - - -def test_snake_case_uppercase_str(): - assert utils.snake_case("HTTP") == "http" - assert utils.snake_case("HTTP RESPONSE") == "http_response" - - -def test_snake_case_from_pascal_with_acronyms(): - assert utils.snake_case("HTTPResponse") == "http_response" - assert utils.snake_case("APIClientHTTPResponse") == "api_client_http_response" - assert utils.snake_case("OAuthClientHTTPResponse") == "o_auth_client_http_response" - assert utils.snake_case("S3Config") == "s3_config" - - -def test_snake_case_from_pascal_with_numbers(): - assert utils.snake_case("Response200") == "response_200" - assert utils.snake_case("Response200WithContent") == "response_200_with_content" - - -def test_snake_case_from_pascal(): - assert utils.snake_case("HttpResponsePascalCase") == "http_response_pascal_case" - - -def test_snake_case_from_camel(): - assert utils.snake_case("httpResponseLowerCamel") == "http_response_lower_camel" - assert utils.snake_case("connectionID") == "connection_id" - - -def test_kebab_case(): - assert utils.kebab_case("keep_alive") == "keep-alive" - - -def test_sanitize(): - assert utils.sanitize("some.thing*~with lots_- of weird things}=") == "some.thingwith lots_- of weird things" - - -def test_no_string_escapes(): - assert utils.remove_string_escapes('an "evil" string') == 'an \\"evil\\" string' - - -@pytest.mark.parametrize( - "reserved_word, expected", - [ - ("self", "self_"), - ("int", "int_"), - ("dict", "dict_"), - ("not_reserved", "not_reserved"), - ("type", "type"), - ("id", "id"), - ("None", "None_"), - ], -) -def test__fix_reserved_words(reserved_word: str, expected: str): - assert utils.fix_reserved_words(reserved_word) == expected - - -@pytest.mark.parametrize( - "before, after", - [ - ("PascalCase", "PascalCase"), - ("snake_case", "SnakeCase"), - ("TLAClass", "TLAClass"), - ("Title Case", "TitleCase"), - ("s3_config", "S3Config"), - ("__LeadingUnderscore", "LeadingUnderscore"), - ], -) -def test_pascalcase(before, after): - assert utils.pascal_case(before) == after - - -@pytest.mark.parametrize( - "content_type, expected", - [ - pytest.param("application/json", "application/json"), - pytest.param("application/vnd.api+json", "application/vnd.api+json"), - pytest.param("application/json;charset=utf-8", "application/json"), - pytest.param("application/vnd.api+json;charset=utf-8", "application/vnd.api+json"), - ], -) -def test_get_content_type(content_type: str, expected: str, config) -> None: - assert utils.get_content_type(content_type, config) == expected