48 Commits

Author SHA1 Message Date
Yousef Haggy
7a23ac7615
[Python] Bug Fix - model_generic templates to have valid imports for polymorphism (#20273)
* fix model_generic python templates to have valid imports for polymorphism

* update samples

* update samples

---------

Co-authored-by: yugi <yugi-big@proton.me>
2025-01-09 11:40:47 +08:00
Chirag Jain
67af02ccc8
python-pydantic-v1: Keep trailing commas for enum validation tuples (#19985)
* python-pydantic-v1: Keep trailing commas for tuples when enum has just single member

* Update samples

* Add test for single member enums

* Refactor test name
2024-11-02 15:26:19 +08:00
Rory Schadler
8171648eb4
fix(python,asyncio): multipart form data serialization (#19302)
* fix: object serialization for multipart requests

This PR is essentially
<https://github.com/OpenAPITools/openapi-generator/pull/18140> but for
the asyncio client.

* fix: int serialization for multipart requests

urllib3 handles serializing ints in post params (ref 1), while asyncio
explicitly does not (ref 2).

ref 1: <9316764e90/src/urllib3/filepost.py (L75-L76)>
ref 2: <https://github.com/aio-libs/aiohttp/issues/920>

* test: new fake multipart endpoint with files and body

* test: regression test for stringified body params

* fix: mypy tweak

* fix: FILES regeneration

* feat: object, int serialization for multipart reqs

Extends previous commits (and #18140) to cover the python-pydantic-v1
client as well.

* fix: use async with in test

* test: regression test for pydantic-v1-aiohttp

* test: add regression test to pydantic-v1

Also brings the second test in line with the first, patching
`urllib3.PoolManager.urlopen`
2024-09-09 17:43:25 +08:00
VelorumS
f082a35d2e
[Python] fix object arrays giving mypy error "Incompatible types in assignment" in to_dict() (#19223)
* [python] mypy fix for multiple arrays of objects

* [python] mypy test for multiple arrays of objects
2024-07-29 16:34:27 +08:00
William Cheng
0cc9644120
Add enum default value tests to python clients (#18883)
* add enum default value tests to python clients

* add new files
2024-06-08 17:34:57 +08:00
Mike Welsh
a5a99585ef
[Python] Add enum support when building default values for model properties when using $ref (#18796)
* Add enum support when building default values for model properties

* Update enum handling for Python for enum references

* Remove unused method

* Update mustaches for FastAPI, Pydantic, and Python for default values

* Address PR feedback and rebase main

* Remove old 2_0 samples
2024-06-08 16:18:03 +08:00
Lars van Leeuwen
8783ad8a18
[Python] List enum members in docs (#18804)
* List enum values in docs

* Remove newline

* Remove another newline

* Generate samples
2024-06-01 17:00:11 +08:00
0xMattijs
365fcd3fb4
Fix the post processing of enums in the Python generator, such that it uses the proper variable namesfrom x-enum-varnames (#18566)
Remove sample
2024-05-12 00:40:06 +08:00
Zishun (Zack) Wei
81fab15a33
[PYTHON] Fix for failing to lookup discriminator value using AllOf and discriminator (#18498)
* fix issue 18495

* add tests and update samples

* update samples
2024-04-30 14:21:20 +08:00
Kathryn DiPippo
0b3e6edb98
[python] Update docs/ Markdown files for Classes to fix _form_ typo and correct casing for class name when calling from_dict() (#18359)
* Update Python mustache templates to fix _form_ typo and correct casing for class name when calling from_dict()

* Results of 'build the project' checklist step
2024-04-12 12:29:20 +08:00
BaptisteSaves
6bcc28d06e
Python: Correctly serialize enum with its value (#18327) (#18328) 2024-04-10 21:12:37 +08:00
Zishun (Zack) Wei
453facc81c
Fix 18271: Circular imports on AllOf generation with REFACTOR_ALLOF_WITH_PROPERTIES_ONLY=True (#18272)
* fix issue 18271

* the same update for python-pydantic-v1

* add test

* update samples

* update samples

* put properties under allOf for python client tests

* update samples

* add a test in test model
2024-04-08 19:01:01 +08:00
William Cheng
2a39b29684
[python] Add field as a reserved word (#18279)
* add field as a reserved word

* remove tabs

* update
2024-04-03 16:43:51 +08:00
ふぁ
9acd620bbb
[Python] Add test object serialization for multipart requests (#18156)
* [Python] add test object serialization for multipart requests #18140

* [python] update samples

* [python] update samples
2024-03-24 09:37:44 +08:00
ふぁ
e39b99051c
[python] add test Missing the important statement for Datetime in Python binding generation (#18175)
* [python] add test on datetime response import

* [python] update sample

* [python] update sample
2024-03-21 15:40:33 +08:00
ふぁ
678db1e4af
[python] json like str response (#18069)
* [python] json like str response

* [python] fix response deserialize

* [python] update sample

* [python] fix echo_api test quotes
2024-03-11 20:27:26 +08:00
Kathryn DiPippo
c10c9146b9
[python] Update Markdown files for Models with fixed Python print() syntax (#17993)
* Update Markdown file with fixed Python example

* ./bin/generate-samples.sh ./bin/configs/*.yaml
2024-02-29 10:54:54 +08:00
ふぁ
ad08581f16
[python] Fix Circular imports on inherited discriminators. (#17886)
* [python] add inheritance discriminators test #16808

* [python] update samples

* [python] fix assert in test

* [python] fix inheritance discriminators circular import

* [python] update samples

* [python] undo type changes related to discriminator

* [python] remove extraneous processing

* [python-pydantic-v1] fix inheritance discriminators circular import

* [python] remove type ignore comment

* [python] update samples

* [python] fix avoid the empty line break

* [python] update samples
2024-02-20 12:17:32 +08:00
Jonathan Klaassen
6bcf8cd332
Fix Python codegen in specific additionalProperties case. (#17659)
* Fix Python codegen is specific additionalProperties case.

* Add generated test files.

* Apply fix to AbstractPythonPydanticV1Codegen.java.
2024-02-05 22:17:14 +08:00
William Cheng
c9204c4330
Update model_generic.mustache, tuple notation breaks when there is only one element in the tuple (#17749)
* Update model_generic.mustache, tuple notation breaks when there is only one element in the tuple

In this excerpt of the mustache template, the matching behaviour is bugged when there is only one element in the tuple notation. A single string with the tuple notation, e.g., `("string")`, will result in a string, and when values are compared with the string, it will do a `contains` match instead of an exact match, which is unintended behaviour.

* Update with samples, step 3

* Add test spec and regenerate samples

* Update samples

* Update spec and samples

* update samples

---------

Co-authored-by: Edmund Loo <edmundloo@users.noreply.github.com>
Co-authored-by: Edmund Loo <github.yn0u9@simplelogin.com>
2024-01-31 11:29:15 +08:00
martin-mfg
9afea50cab
use map/array model class only if it is generated (#17612)
* fix

* tests

* generate samples

* refactor
2024-01-29 21:35:21 +08:00
Huan-Cheng Chang
8e9a17fe02
[Python] Handle nullable dictionary values (#17605)
* fix nullable elements in maps

* update examples

* exclude values typed as Any
2024-01-13 18:45:22 +08:00
Huan-Cheng Chang
968c6dc418
[Python] Handle nullable list items (#17594)
* fix nullable elements

* update type info in docs

* update examples
2024-01-13 11:29:22 +08:00
Jonathan Ballet
22a0fc1727
python: adjust basic typing information (#17511)
* python: adjust basic typing information

This is an initial pass to fix and adjust the typing information for the
generated client. This is enough to have mypy runnning without complains
on all the (modern) generated clients (Pydantic v1 code is not checked
for instance)

mypy is also now run directly in the CI, so further changes will also be
checked and thus, will need to be compliant with good typing
information.

Note that this doesn't *fully* type all the code: mypy is not run in
"strict" mode and there are still many functions/methods/attributes
which are still not fully typed, but it's a first good step in that
direction.

* ApiResponse's raw_data can't be None

* Fix indentation

* Revert test changes

* run mypy on tests/ directory

* don't forcefully convert the client response headers to dict

* override petstore ApiResponse model

* adjust type of 'any/one_of_schemas' fields
2024-01-06 15:40:42 +08:00
William Cheng
c782526556 update samples 2024-01-05 14:28:13 +08:00
martin-mfg
64f2cad9e8
fix #17258 - use model class only if it is generated (#17490)
* fix  #16797 and #15796 spring child constructor missing parent params

* root cause and update the DefaultCodegen.java to add missing property when with multi inheritance

* rollback SpringCodegen.java

* update samples

* rollback with master cause #16992 fixed this issue too

* still using orignal design

* catchup master

* catchup master

* catchup master

* fix

* add tests

---------

Co-authored-by: dabdirb <dabdirb@gmail.com>
2024-01-05 10:30:28 +08:00
Jonathan Ballet
063865973d
python: simplify module imports (#17507)
In #16624, I introduced a new mechanism to record imports to other
modules, instead of having specialized datetime/typing/pydantic objects
to manage imports for these modules.

This change reuses the mechanism from #16624 and replace the specialized
import managers by the generic one. Unused imports from various
.mustache templates are also cleaned up.
2024-01-03 21:22:53 +08:00
William Cheng
a62132ecd9
fix exception in request body with enum ref (#17438) 2023-12-21 15:22:28 +08:00
William Cheng
8e36014ae6 update samples 2023-11-19 17:36:25 +08:00
Robert Schweizer
75ff110449
[python] Some cleanup of samples folder (#17127)
* Delete sample folders of discontinued clients

* Remove duplicate python-flask server sample

The python-flask sample actually lives in samples/server/petstore/python-flask.

* Move hand-written test to "tests" folder

Now, "test" only contains generated stubs and all hand-written tests are in "tests".

* Delete left-over files in Python samples

These are not created by the generators (anymore) and not hand-written
for testing.

* Regenerate test file to fix import error
2023-11-19 14:43:34 +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
f180aa0eec
[python] Fix unnamed dicts with additional properties (#16779)
* test: Add two extra models for testing

* Fix unnamed dicts with additional properties

Closes #16630
2023-10-11 13:55:53 +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
ふぁ
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
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
martin-mfg
2ca99bdf8e
use model class for request body with additionalProperties (#16613)
* try out simple fix

* add test case

* generate samples
2023-09-23 13:07:53 +08:00
William Cheng
b457c3de70
fix uuid example cast exception in python generators (#16432) 2023-08-29 13:34:54 +08:00
William Cheng
fd12bb3508
[python] Fix data type (#16291)
* fix data type in python client codegen

* add model mapping feature
2023-08-10 23:05:35 +08:00
William Cheng
f6fb83878b
[Default] update isAdditionalPropertiesTrue tag to cover more types (#16227)
* enhance additional properties support

* update samples

* update tests

* add more tests

* update samples

* fix samples
2023-08-05 13:32:43 +08:00
William Cheng
3278eea9a4
Add tests for #16217 (#16221)
* add tests for #16217

* add new files
2023-07-31 11:03:36 +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
William Cheng
d41fe12c1f
[python] Add tests for simple object with additional properties (#16218)
* add tests for simple object without additional properties

* update logic
2023-07-29 11:43:37 +08:00
William Cheng
7dee666826
add python name mapping support (#16120) 2023-07-20 17:30:01 +08:00
William Cheng
08c3f8973e
[python] Fix array of array of model's to_dict, from_dict (#16032)
* fix array of array of model's to_dict, from_dict

* update samples
2023-07-08 14:12:42 +08:00
William Cheng
b42234eb3c
[python] Fix map of array in property (#15844)
* fix map of array in property (python)

* update samples
2023-06-15 11:50:56 +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
48ef91acc4
[python] Add test for nullable property with pattern (#15625)
* add test for nullable property with pattern

* update samples
2023-05-24 15:13:53 +08:00
William Cheng
01ed5975e1
rename python-nextgen to python (#15504) 2023-05-16 13:54:07 +08:00