49 Commits

Author SHA1 Message Date
Robert Schweizer
6a43a371f1
fix: Configure python urllib3 connection pool size (#17323)
This was removed in #16802, but using a higher value than 1,
or at least making this configurable makes complete sense.

Without this, we get a lot of these log messages:

[ WARNING] Connection pool is full, discarding connection:
2023-12-06 15:49:10 +08:00
William Cheng
8e36014ae6 update samples 2023-11-19 17:36:25 +08:00
William Cheng
d9920a5b81 update samples 2023-11-16 00:56:05 +08:00
Tomohiko Ozawa
37451fa569
[Java][resttemplate] Add test for bearer auth (#17081)
* add bearer auth API to echo-api

* run generate-samples.sh

* add resttemplate echo-api sample

* add bearer auth test

* remove @Ignore
2023-11-16 00:38:49 +08:00
Robert Schweizer
e47e7041f7
[python][Feat] Deserialize error responses (#17038)
* refactor: Clean up _response_types_map formatting

It matches black's behavior of having trailing commas now.

* test: Add test to reproduce #16967

* fix: deserialize responses even if no returnType

Closes #16967

* refactor: Simplify ApiException subclasses

* refactor: Move exception subtype choice to ApiException

* feat: Deserialize error responses and add to exceptions

* test: Add for error responses with model
2023-11-16 00:37:04 +08:00
Robert Schweizer
61fde48501
fix: Disable warnings for model_* properties (#17066)
For model classes with model_something fields, pydantic raises a warning by default:
`Field "model_something" has conflict with protected namespace "model_".`.

These warnings make no sense here, because most users of the generator have established APIs
that they cannot change to conform to pydantic's safety rules.

Pydantic will raise an error if we ever conflict with a current attribute like `model_dump`.
2023-11-14 21:50:35 +08:00
Rolf Rando
2ca958642b
Add socks5 proxy support for OpenAPI generated python client (#16918)
* add socks5 proxy support (requires additional import)

* updated examples

* build samples. updated to support pydantic python option

* rename sock to socks for correct protocol name

* add proxy headers for pydantic

* fixed param changes from conflict resolution
2023-11-14 12:28:05 +08:00
OliverTetzTT
d1b148a7d3
[python] added handling for boolean content type (#17020)
* added handling for boolean content type

* adapted addition to newer version of template

* [python] updated samples
2023-11-14 11:30:10 +08:00
William Cheng
53289263d9
Prepare v7.2.0 (#17050)
* update version to 7.2.0-SNAPSHOT

* update samples

* update doc
2023-11-13 18:53:20 +08:00
Robert Schweizer
65ccf0492c
fix: Raise exceptions on non-2xx responses (#16999) 2023-11-07 10:44:45 +08:00
William Cheng
49208144e1
Better handling of allOf in request body (#16991)
* better handling of allOf in request body, add tests

* additional checks

* fix description
2023-11-05 22:43:45 +08:00
Yohei Kitamura
61629ae8ed
[python] Add back __enter__ and __exit__ methods for non asyncio (#16979) 2023-11-04 16:54:17 +08:00
Mark Haley
a4267ee630
fix parameters_to_url_query returns booleans with upper letter (#16947)
* chore: add test to show python bool url params are not lower case

* fix: python parameters_to_url_query template to properly detect booleans

* fix: typo in test

* fix: typo in test

* chore: update test name to snake case and be more descriptive
2023-11-01 23:30:32 +08:00
ふぁ
8827da8012
[python] fix typing for API responses (#16802)
* [python] remove _preload_content

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] remove _return_http_data_only

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] remove async_req

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] fix typing for API responses

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] update samples

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] fix AttributeError

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] remove _preload_content

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] fix response_type

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] fix typo

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] update simplify RESTClientObject

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] update split call_api into 4 functions

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] update samples

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] update improve stream

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] remove kwargs

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] update ApiResponse

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] add method for each return value

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] update test

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] update samples

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] update docs

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] add constantParams

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] fix ImportError

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] fix SyntaxError in RESTResponse

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] add ApiResponse model_config

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] fix when isBinary is str

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] update type

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] update samples

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] add rest with pydantic v1

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] update format

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] update format and type

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] add test

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] update type to pydantic strict type

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] remove leftover files

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] remove descriptions per field

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] add test

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] fix test

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] fix test

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] remove multiprocessing

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] update samples

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] add blank line to docstring

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] update docstring

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] remove unwanted imports in rest

Signed-off-by: ふぁ <yuki@yuki0311.com>

---------

Signed-off-by: ふぁ <yuki@yuki0311.com>
2023-10-30 12:37:23 +08:00
Robert Schweizer
2b6b3b0883
[python] Do not pydantic-validate function args twice (#16776)
* refactor: Use newlines in _with_http_info call

This prevents too-long lines and matches the style that
black would enforce.

* fix: Do not pydantic-validate function args twice

Closes #15757
2023-10-11 13:57:52 +08:00
Robert Schweizer
7af459396c
docs: Improve docstring in to_dict() method (#16777)
It was often confusing to me why this method is even there.

Also using more line breaks and matching how black would format this.
2023-10-11 13:51:37 +08:00
Robert Schweizer
f03cbea971
feat: Add line breaks in Python API methods (#16770) 2023-10-10 18:32:52 +08:00
Robert Schweizer
9e07f85eb5
[python] Add tests and fix enum path parameters (#16769)
* test: Tests for enum params in path, query and header

* fix: Get enum ref values correctly in path parameters

Closes #16688

* fix java tests failure

---------

Co-authored-by: William Cheng <wing328hk@gmail.com>
2023-10-10 17:10:30 +08:00
Jonathan Ballet
cec5b8965a
python: type generated client using Self (#16693)
* python: type generated client using Self

This doesn't offer a clear win but this helps for:

* Using modern types and making the typing intent clearer
* Decreasing the need for `from __future__ import annotations`, since a
  class can now refer to itself without using its name
* Using more `cls` to automatically refer to the class, instead of
  respecifying the class name every time

Self is available from Python 3.11 and is provided in typing_extensions
(since 4.0.0) as a fallback for older versions

See: https://peps.python.org/pep-0673/
See: https://github.com/python/typing_extensions/blob/main/CHANGELOG.md#added-in-version-400

* generate code
2023-10-01 23:31:39 +08:00
Jonathan Ballet
03781d3a93
python: remove aenum in favor of stdlib's enum (#16691)
The aenum dependency didn't provide any specific improvements over the
stdlib's enum module.
aenum also doesn't provide typing information at the moment.

This removes one dependency and will help for completing the typing of
the generated client.
2023-10-01 21:22:42 +08:00
Jonathan Ballet
56bc383dc1
python: type API client internal structures (#16692)
* In samples/openapi3/client/petstore/python, this reduces the mypy errors from 435 to 178 errors
* In samples/openapi3/client/petstore/python-aiohttp, this reduces the mypy errors from 381 to 124 errors
* In samples/client/echo_api/python, this reduces the mypy errors from 131 to 25 errors
2023-10-01 20:45:11 +08:00
William Cheng
ce4b2fe7bd
[Python] add float to reserved word list (#16689)
* add float as reserved world

* clean up

* update samples

* Update modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java

Co-authored-by: Jonathan Ballet <jon@multani.info>

* update doc

* uncomment test

---------

Co-authored-by: Jonathan Ballet <jon@multani.info>
2023-10-01 20:41:54 +08:00
William Cheng
3fcf5584c6
Add tests for python client with disallowAdditionalPropertiesIfNotPresent set to true (#16690)
* add tests for python client with different option

* update samples

* update tests
2023-10-01 17:34:52 +08:00
ふぁ
c6e9a4e1ae
[python] change Private attr to Class vars (#16687)
* [python] fix TypeError

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] update Private model attributes to Class vars

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] rename the List of test cases to ListClass

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] update samples

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] rename the List of v1 test cases to ListClass

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python] rename the List of v1-aiohttp test cases to ListClass

Signed-off-by: ふぁ <yuki@yuki0311.com>

* update samples

---------

Signed-off-by: ふぁ <yuki@yuki0311.com>
Co-authored-by: William Cheng <wing328hk@gmail.com>
2023-10-01 16:52:23 +08:00
ふぁ
e2f249ba35
[PYTHON] generate code based on pydantic v2 (#16685)
* [python] replace validator with field_validator

* [python] replace parse_obj with model_validate

* [python] replace dict with model_dump

* [python] replace construct with model_construct

* [python] replace __fields_set__ with model_fields_set

* [python] replace __fields_set__ in the test cases with model_fields_set

* [python] replace validate_arguments with validate_call

* [python] replace max_items, min_items with max_length, min_length

* [python] replace Config class with model_config

* [python] replace allow_population_by_field_name with populate_by_name

* [python] remove {{{classname}}}_ONE_OF_SCHEMAS

* [python] update test cases

* [python] update samples

* [python] fix typos in test cases
2023-09-29 16:45:46 +08:00
Jonathan Ballet
04fa53b692
python: generate Pydantic v2 + typing complete code (#16624)
* python: improve type generation with more specific typing

* Annotate function parameters

* Remove unused imports

* remove unused files

* remove temporary hack

* remove lock file

* fix Annotated import

* support Python 3.7

* Regenerate code with typing-extensions

* Fix setup.py

* More Pydantic v2 compatibility

* depend on pydantic v2

* fix client_echo tests

* fix JSON serialization

* Fix references

* Skip circular dependency tests for now

* Temporarily hide the "float" property

The "float" property aliases the "float" type and completely breaks the
model: all the properties that were "float" now become the type of the
"float" property instead.

* Fix errors

* Import Literal from typing_extensions

* Fix GitHub Action workflows

* Fix Python 3.7 failure

* Fix quotes

* Apply suggestions from code review

* Fix tests

* split model imports from other modules imports

* fix workflow

* Comment the array unique items convertion, remove set translation

* Replace alias usage
2023-09-28 19:13:14 +08:00
William Cheng
16c6cff28f
fix required parameter check (#16628) 2023-09-20 17:05:55 +08:00
Jonathan Ballet
a2f6b8eae5
python: remove non-async code path from the aiohttp generator (#16601)
* python: remove non-async code path from the aiohttp generator

This removes all the non-async code from the aiohttp generator:

* all the methods that should be asynchronous are marked as `async`
* the `async_req` parameter is gone; calls are directly awaitables now
* the async calls into a thread pool are gone and the thread pool is
  gone too (now useless)

Closes: #15824
Closes: #5539
Related: #763
Related: #3696

* Fix empty line

* remove more
2023-09-20 10:48:31 +08:00
William Cheng
5e8e2d7f6d
Prepare v7.1.0 in master (#16608)
* prepare v7.1.0 in master

* update
2023-09-18 17:37:36 +08:00
William Cheng
a5f79a7bdc
[python] Update github workflow, use debug instead of warning (#16565)
* update github workflow, use debug instead of warning

* use debug instead of warn
2023-09-12 16:55:53 +08:00
William Cheng
dee536f7f7
import Annotated if needed (#16521) 2023-09-07 14:36:45 +08:00
jessemyers-lettuce
b34a10aee7
python: ignore long lines for model descriptions (#16518)
Descriptions can easily exceed line-length limits because they are often
extracted from doc/comments strings, which may use unexpected formatting.

Python doc strings, in particular, are likely to use newlines, which mustache
does not preserve, causing descriptions to be condensed to a single line.
2023-09-06 10:48:43 +08:00
jessemyers-lettuce
1b32088c2d
python: use isinstance instead of type() (#16516)
Use of `isinstance` is preferred (and validated by common linters).
2023-09-05 23:45:18 +08:00
William Cheng
47a85e880b
Add tests for http basic authentication in python client (#16488)
* add tests for http basic auth in python client

* add new files
2023-09-03 19:11:53 +08:00
William Cheng
ebc9bcda44
[java][native] Add tests for oneOf form parameters (#16487)
* add tests for oneOf form parameters

* update samples
2023-09-03 16:15:54 +08:00
jessemyers-lettuce
40731ed52d
python: several typing and style improvements (#16378)
* python: several typing and style improvements

The generated (python) code fails with several standard validation tools,
including `flake8`, `mypy`, and `autoflake`. While fixing every possible
violation -- especially wrto typing -- woudl be a project, some of the
changes are fairly easy.

 - The `autoflake` tool picks up on unused imports. These can just be removed.

 - The `mypy` tool picks up on numerious typing violations, especially if set
   to its strictest mode. As a starting point, all functions ought to annotate
   a return type, including constructors, even if the return type is `None`
   because otherwise the functions are omitted from type checking and it's
   impossible to make incremental progress towards adding types.

 - The `flake8` tool mostly finds whitespace and line-length issues; while
   line-length standards very, the source already includes several flake8
   ignores, so it seems safe to add a few more.

* Add generated files

* Restore imports used by `AbstractPythonCodegen.java`

* Update generated files
2023-09-02 01:03:02 +08:00
Davy Durham
4a1c70f2f1
fix: python client generator didn't respect range response specification (#16451)
* bug: python client generator didn't respect range response specification (e.g. "1XX", "2XX", etx.).  Return values tended to become None as a result

* update samples

---------

Co-authored-by: William Cheng <wing328hk@gmail.com>
2023-08-31 10:15:30 +08:00
William Cheng
80121aa88f
Prepare v7.0.1 (#16409)
* prepare 7.0.1 in master

* update doc
2023-08-25 16:11:29 +08:00
ふぁ
f3b930c48c
[python-nextgen] Fix noqa: E501 position (#16280)
* Fix `noqa: E501` position

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python-nextgen] update samples

Signed-off-by: ふぁ <yuki@yuki0311.com>

---------

Signed-off-by: ふぁ <yuki@yuki0311.com>
2023-08-08 20:42:12 +08:00
ふぁ
48ff57b4f6
[python-nextgen] fix #16010 circular refs lead to no imports (#16199)
* [python-nextgen] fix #16010 circular refs lead to no imports

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python-nextgen] update samples

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python-nextgen] remove unnecessary Postponed annotations

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python-nextgen] update samples

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python-nextgen] remove unnecessary Postponed annotations

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python-nextgen] update samples

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python-nextgen] update samples

Signed-off-by: ふぁ <yuki@yuki0311.com>

---------

Signed-off-by: ふぁ <yuki@yuki0311.com>
2023-07-30 00:42:46 +08:00
ふぁ
d9fc039dcf
[python-nextgen] fix #16151 Disallow additional properties if not present - missing Any and Dict import (#16208)
* [python-nextgen] fix #16151 Disallow additional properties if not present - missing Any and Dict import

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python-nextgen] update samples

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python-nextgen] remove unwanted imports

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python-nextgen] update samples

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python-nextgen] remove unwanted imports

Signed-off-by: ふぁ <yuki@yuki0311.com>

* [python-nextgen] update samples

Signed-off-by: ふぁ <yuki@yuki0311.com>

---------

Signed-off-by: ふぁ <yuki@yuki0311.com>
2023-07-29 10:51:28 +08:00
Luca
584f8448ee
[Java][Native] Fix multipart builder files array (#16055) (#16094)
* [Java] Fixed bug in native client generation when API accepts array of files (#16055)

* Adding test for java native client

* Updated samples
2023-07-24 15:57:21 +08:00
William Cheng
7b3681af47
fix isMap (#16043) 2023-07-11 17:14:44 +08:00
William Cheng
d2e10a7229
install urllib3 < 2.1.0 (#15810) 2023-06-12 15:58:51 +08:00
William Cheng
6788f43af0
Better handling of Inline schema (#15682)
* skip allOf inline subschema created as $ref

* add option for fallback

* add back atleastonemodel

* add log

* update java, kotlin, js samples

* update tests

* fix native client test

* fix java client errors by regenerating test files

* clean up python

* clean up powershell

* clean up php

* clean up ruby

* update erlang, elixir

* update dart samples

* update ts samples

* update r, go samples

* update perl

* update swift

* add back files

* add back files

* remove outdated test files

* fix test
2023-06-11 15:35:58 +08:00
William Cheng
21748e024a
add py.typed (#15804) 2023-06-10 21:48:54 +08:00
gyoganathan
fc474eab5f
Added BadRequestException as a subclass in python (#15722)
Co-authored-by: Gomathi Yoganathan <gyoganathan@C02G45FPMD6R.corp.proofpoint.com>
2023-06-10 15:27:18 +08:00
William Cheng
10c270fda6
fix date isinstance check (#15675) 2023-05-31 00:03:14 +08:00
William Cheng
01ed5975e1
rename python-nextgen to python (#15504) 2023-05-16 13:54:07 +08:00