You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 25, 2024. It is now read-only.
Copy file name to clipboardExpand all lines: modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/languages/PythonClientCodegen.java
Copy file name to clipboardExpand all lines: modules/openapi-json-schema-generator/src/main/resources/python/README.hbs
+3-88
Original file line number
Diff line number
Diff line change
@@ -19,94 +19,9 @@ For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
19
19
20
20
Python {{generatorLanguageVersion}}
21
21
22
-
## Migration from other generators like python and python-legacy
23
-
24
-
### Changes
25
-
1. This generator uses spec case for all (object) property names and parameter names.
26
-
- So if the spec has a property name like camelCase, it will use camelCase rather than camel_case
27
-
- So you will need to update how you input and read properties to use spec case
28
-
2. Endpoint parameters are stored in dictionaries to prevent collisions (explanation below)
29
-
- So you will need to update how you pass data in to endpoints
30
-
3. Endpoint responses now include the original response, the deserialized response body, and (todo)the deserialized headers
31
-
- So you will need to update your code to use response.body to access deserialized data
32
-
4. All validated data is instantiated in an instance that subclasses all validated Schema classes and Decimal/str/tuple/frozendict/NoneClass/BoolClass/bytes/io.FileIO
33
-
- This means that you can use isinstance to check if a payload validated against a schema class
34
-
- This means that no data will be of type None/True/False
35
-
- ingested None will subclass NoneClass
36
-
- ingested True will subclass BoolClass
37
-
- ingested False will subclass BoolClass
38
-
- So if you need to check is True/False/None, instead use instance.is_true_()/.is_false_()/.is_none_()
39
-
5. All validated class instances are immutable except for ones based on io.File
40
-
- This is because if properties were changed after validation, that validation would no longer apply
41
-
- So no changing values or property values after a class has been instantiated
42
-
6. String + Number types with formats
43
-
- String type data is stored as a string and if you need to access types based on its format like date,
44
-
date-time, uuid, number etc then you will need to use accessor functions on the instance
45
-
- type string + format: See .as_date_, .as_datetime_, .as_decimal_, .as_uuid_
46
-
- type number + format: See .as_float_, .as_int_
47
-
- this was done because openapi/json-schema defines constraints. string data may be type string with no format
48
-
keyword in one schema, and include a format constraint in another schema
49
-
- So if you need to access a string format based type, use as_date_/as_datetime_/as_decimal_/as_uuid_
50
-
- So if you need to access a number format based type, use as_int_/as_float_
51
-
7. Property access on AnyType(type unset) or object(dict) schemas
52
-
- Only required keys with valid python names are properties like .someProp and have type hints
53
-
- All optional keys may not exist, so properties are not defined for them
54
-
- One can access optional values with dict_instance['optionalProp'] and KeyError will be raised if it does not exist
55
-
- Use get_item_ if you need a way to always get a value whether or not the key exists
56
-
- If the key does not exist, schemas.unset is returned from calling dict_instance.get_item_('optionalProp')
57
-
- All required and optional keys have type hints for this method, and @typing.overload is used
58
-
- A type hint is also generated for additionalProperties accessed using this method
59
-
- So you will need to update you code to use some_instance['optionalProp'] to access optional property
60
-
and additionalProperty values
61
-
8. The location of the api classes has changed
62
-
- Api classes are located in your_package.apis.tags.some_api
63
-
- This change was made to eliminate redundant code generation
64
-
- Legacy generators generated the same endpoint twice if it had > 1 tag on it
65
-
- This generator defines an endpoint in one class, then inherits that class to generate
66
-
apis by tags and by paths
67
-
- This change reduces code and allows quicker run time if you use the path apis
68
-
- path apis are at your_package.apis.paths.some_path
69
-
- Those apis will only load their needed models, which is less to load than all of the resources needed in a tag api
70
-
- So you will need to update your import paths to the api classes
71
-
72
-
### Why are Leading and Trailing Underscores in class and method names?
73
-
Classes can have arbitrarily named properties set on them
74
-
Endpoints can have arbitrary operationId method names set
75
-
For those reasons, I use the prefix and suffix _ to greatly reduce the likelihood of collisions
76
-
on protected + public classes/methods.
77
-
78
-
### Object property spec case
79
-
This was done because when payloads are ingested, they can be validated against N number of schemas.
80
-
If the input signature used a different property name then that has mutated the payload.
81
-
So SchemaA and SchemaB must both see the camelCase spec named variable.
82
-
Also it is possible to send in two properties, named camelCase and camel_case in the same payload.
83
-
That use case should work, so spec case is used.
84
-
85
-
### Parameter spec case
86
-
Parameters can be included in different locations including:
87
-
- query
88
-
- path
89
-
- header
90
-
- cookie
91
-
92
-
Any of those parameters could use the same parameter names, so if every parameter
93
-
was included as an endpoint parameter in a function signature, they would collide.
94
-
For that reason, each of those inputs have been separated out into separate typed dictionaries:
95
-
- query_params
96
-
- path_params
97
-
- header_params
98
-
- cookie_params
99
-
100
-
So when updating your code, you will need to pass endpoint parameters in using those
101
-
dictionaries.
102
-
103
-
### Endpoint responses
104
-
Endpoint responses have been enriched to now include more information.
105
-
Any response reom an endpoint will now include the following properties:
106
-
response: urllib3.HTTPResponse
107
-
body: typing.Union[Unset, Schema]
108
-
headers: typing.Union[Unset, TODO]
109
-
Note: response header deserialization has not yet been added
22
+
## Migration Guides
23
+
- [2.0.0 Migration Guide](migration_2_0_0.md)
24
+
- [Migration from Other Python Generators](migration_other_python_generators.md)
0 commit comments