Skip to content

Commit 0cf5ed6

Browse files
authored
Add a new Python client generator - python-nextgen (#14157)
* add python-nextgen generator * remove client_side_validation from model * remove configuraiton import from models * add inheritance support * update test requirements, tox * add typings, pydanic to models * add test model * minor improvements * add enum support * add typing for parameters, remove validations * add oneof, anyof support * fix default value * fix deserialization, api tests passed * private variable naming, update tests, all tests passed * remove six * remove nose * update doc * remove sortParamsByRequiredFlag option * add parameter validation * add validation tests * simplify Field() * remove previous required parameter validation * improve parameter handling * support discriminator mapping * better typing discriminator mapping * format test code * fix tests * fix oneOf from_dict, add test * add set validation test * fix nested oneof serialization, add tests * add model import * remove models. prefix * remove import models * remove model import from api * simplify from_dict * add typing for return * skip pydantic import in return type * fix tests, fix enum * restore more enum schema tests * uncomment enum integer test * clean up getfullargspec import in model * clean up getfullargspec import * fix deserilizatoin for nested oneof * minor fixes, add tests * fix regular expression * add aiohttp samples, add tests * remove default content type to json * update template * fix select accept, content-type * move tests * move tests * fix url query parameters * fix list * fix samples * fix param pydantic, add list as reserved word * fix auto-generated doc * fix readme * fix list, fix special variable name with var_ * fix Literal in python 3.7 * fix default configuration * fix aiohttp tests * set default api client instance * deprecate get_default_copy method * fix enum model * fix enum serializatio/deserialization * add github workflow support * add regular expression validator * add enum validator * better model import * fix file, remove x-py-import-models * rename local var * better model example * fix regular expression warning, add special_name test, whitelist schema * skip self import * update samples * various fixes * add base64, json as reserved word * add http signature support * add http signature test * add additioanl properties support in python client * add decimal support * use strictstr instead of constr * fix test with virtualenv * add nullable support * add readonly support * add model name caching * fix circular reference import * add onelook discriminator lookup * add tests * update samples * fix locale * Fix client legacy generator asyncio README code example * test python-nextgen in circleci * fix pom.xml * update python to 3.7.15 * test with python 3.7.12 * various updates * fix python legacy
1 parent 6800905 commit 0cf5ed6

File tree

568 files changed

+56832
-272
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

568 files changed

+56832
-272
lines changed

CI/circle_parallel.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ elif [ "$NODE_INDEX" = "3" ]; then
5353
#./configure --enable-optimizations
5454
#sudo make altinstall
5555
pyenv install --list
56-
pyenv install 3.6.3
56+
pyenv install 3.7.12
5757
pyenv install 2.7.14
58-
pyenv global 3.6.3
58+
pyenv global 3.7.12
5959

6060
# Install node@stable (for angular 6)
6161
set +e
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
generatorName: python-nextgen
2+
outputDir: samples/openapi3/client/petstore/python-nextgen-aiohttp
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/python-nextgen
5+
library: asyncio
6+
additionalProperties:
7+
packageName: petstore_api

bin/configs/python-nextgen.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
generatorName: python-nextgen
2+
outputDir: samples/openapi3/client/petstore/python-nextgen
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/python-nextgen
5+
additionalProperties:
6+
packageName: petstore_api
7+
useOneOfDiscriminatorLookup: "true"
8+
disallowAdditionalPropertiesIfNotPresent: false

docs/generators.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ The following generators are available:
5252
* [powershell (beta)](generators/powershell.md)
5353
* [python](generators/python.md)
5454
* [python-legacy](generators/python-legacy.md)
55+
* [python-nextgen (beta)](generators/python-nextgen.md)
5556
* [python-prior](generators/python-prior.md)
5657
* [r](generators/r.md)
5758
* [ruby](generators/ruby.md)

docs/generators/python-legacy.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl
4545
## LANGUAGE PRIMITIVES
4646

4747
<ul class="column-ul">
48+
<li>Dict</li>
49+
<li>List</li>
4850
<li>bool</li>
4951
<li>bytes</li>
5052
<li>date</li>

docs/generators/python-nextgen.md

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
---
2+
title: Documentation for the python-nextgen Generator
3+
---
4+
5+
## METADATA
6+
7+
| Property | Value | Notes |
8+
| -------- | ----- | ----- |
9+
| generator name | python-nextgen | pass this to the generate command after -g |
10+
| generator stability | BETA | |
11+
| generator type | CLIENT | |
12+
| generator language | Python | |
13+
| generator language version | 3.7+ | |
14+
| generator default templating engine | mustache | |
15+
| helpTxt | Generates a Python client library. | |
16+
17+
## CONFIG OPTIONS
18+
These options may be applied as additional-properties (cli) or configOptions (plugins). Refer to [configuration docs](https://openapi-generator.tech/docs/configuration) for more details.
19+
20+
| Option | Description | Values | Default |
21+
| ------ | ----------- | ------ | ------- |
22+
|disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|<dl><dt>**false**</dt><dd>The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.</dd><dt>**true**</dt><dd>Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.</dd></dl>|true|
23+
|generateSourceCodeOnly|Specifies that only a library source code is to be generated.| |false|
24+
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
25+
|library|library template (sub-template) to use: asyncio, tornado (deprecated), urllib3| |urllib3|
26+
|packageName|python package name (convention: snake_case).| |openapi_client|
27+
|packageUrl|python package URL.| |null|
28+
|packageVersion|python package version.| |1.0.0|
29+
|projectName|python project name in setup.py (e.g. petstore-api).| |null|
30+
|recursionLimit|Set the recursion limit. If not set, use the system default value.| |null|
31+
32+
## IMPORT MAPPING
33+
34+
| Type/Alias | Imports |
35+
| ---------- | ------- |
36+
37+
38+
## INSTANTIATION TYPES
39+
40+
| Type/Alias | Instantiated By |
41+
| ---------- | --------------- |
42+
43+
44+
## LANGUAGE PRIMITIVES
45+
46+
<ul class="column-ul">
47+
<li>Dict</li>
48+
<li>List</li>
49+
<li>bool</li>
50+
<li>bytes</li>
51+
<li>date</li>
52+
<li>datetime</li>
53+
<li>decimal.Decimal</li>
54+
<li>dict</li>
55+
<li>float</li>
56+
<li>int</li>
57+
<li>list</li>
58+
<li>object</li>
59+
<li>str</li>
60+
</ul>
61+
62+
## RESERVED WORDS
63+
64+
<ul class="column-ul">
65+
<li>and</li>
66+
<li>as</li>
67+
<li>assert</li>
68+
<li>async</li>
69+
<li>await</li>
70+
<li>base64</li>
71+
<li>break</li>
72+
<li>class</li>
73+
<li>continue</li>
74+
<li>date</li>
75+
<li>def</li>
76+
<li>del</li>
77+
<li>elif</li>
78+
<li>else</li>
79+
<li>except</li>
80+
<li>exec</li>
81+
<li>false</li>
82+
<li>finally</li>
83+
<li>for</li>
84+
<li>from</li>
85+
<li>global</li>
86+
<li>if</li>
87+
<li>import</li>
88+
<li>in</li>
89+
<li>is</li>
90+
<li>json</li>
91+
<li>lambda</li>
92+
<li>none</li>
93+
<li>nonlocal</li>
94+
<li>not</li>
95+
<li>or</li>
96+
<li>pass</li>
97+
<li>print</li>
98+
<li>property</li>
99+
<li>raise</li>
100+
<li>return</li>
101+
<li>schema</li>
102+
<li>self</li>
103+
<li>true</li>
104+
<li>try</li>
105+
<li>while</li>
106+
<li>with</li>
107+
<li>yield</li>
108+
</ul>
109+
110+
## FEATURE SET
111+
112+
113+
### Client Modification Feature
114+
| Name | Supported | Defined By |
115+
| ---- | --------- | ---------- |
116+
|BasePath|✗|ToolingExtension
117+
|Authorizations|✗|ToolingExtension
118+
|UserAgent|✗|ToolingExtension
119+
|MockServer|✗|ToolingExtension
120+
121+
### Data Type Feature
122+
| Name | Supported | Defined By |
123+
| ---- | --------- | ---------- |
124+
|Custom|✗|OAS2,OAS3
125+
|Int32|✓|OAS2,OAS3
126+
|Int64|✓|OAS2,OAS3
127+
|Float|✓|OAS2,OAS3
128+
|Double|✓|OAS2,OAS3
129+
|Decimal|✓|ToolingExtension
130+
|String|✓|OAS2,OAS3
131+
|Byte|✓|OAS2,OAS3
132+
|Binary|✓|OAS2,OAS3
133+
|Boolean|✓|OAS2,OAS3
134+
|Date|✓|OAS2,OAS3
135+
|DateTime|✓|OAS2,OAS3
136+
|Password|✓|OAS2,OAS3
137+
|File|✓|OAS2
138+
|Uuid||
139+
|Array|✓|OAS2,OAS3
140+
|Null|✗|OAS3
141+
|AnyType|✗|OAS2,OAS3
142+
|Object|✓|OAS2,OAS3
143+
|Maps|✓|ToolingExtension
144+
|CollectionFormat|✓|OAS2
145+
|CollectionFormatMulti|✓|OAS2
146+
|Enum|✓|OAS2,OAS3
147+
|ArrayOfEnum|✓|ToolingExtension
148+
|ArrayOfModel|✓|ToolingExtension
149+
|ArrayOfCollectionOfPrimitives|✓|ToolingExtension
150+
|ArrayOfCollectionOfModel|✓|ToolingExtension
151+
|ArrayOfCollectionOfEnum|✓|ToolingExtension
152+
|MapOfEnum|✓|ToolingExtension
153+
|MapOfModel|✓|ToolingExtension
154+
|MapOfCollectionOfPrimitives|✓|ToolingExtension
155+
|MapOfCollectionOfModel|✓|ToolingExtension
156+
|MapOfCollectionOfEnum|✓|ToolingExtension
157+
158+
### Documentation Feature
159+
| Name | Supported | Defined By |
160+
| ---- | --------- | ---------- |
161+
|Readme|✓|ToolingExtension
162+
|Model|✓|ToolingExtension
163+
|Api|✓|ToolingExtension
164+
165+
### Global Feature
166+
| Name | Supported | Defined By |
167+
| ---- | --------- | ---------- |
168+
|Host|✓|OAS2,OAS3
169+
|BasePath|✓|OAS2,OAS3
170+
|Info|✓|OAS2,OAS3
171+
|Schemes|✗|OAS2,OAS3
172+
|PartialSchemes|✓|OAS2,OAS3
173+
|Consumes|✓|OAS2
174+
|Produces|✓|OAS2
175+
|ExternalDocumentation|✓|OAS2,OAS3
176+
|Examples|✓|OAS2,OAS3
177+
|XMLStructureDefinitions|✗|OAS2,OAS3
178+
|MultiServer|✗|OAS3
179+
|ParameterizedServer|✗|OAS3
180+
|ParameterStyling|✗|OAS3
181+
|Callbacks|✗|OAS3
182+
|LinkObjects|✗|OAS3
183+
184+
### Parameter Feature
185+
| Name | Supported | Defined By |
186+
| ---- | --------- | ---------- |
187+
|Path|✓|OAS2,OAS3
188+
|Query|✓|OAS2,OAS3
189+
|Header|✓|OAS2,OAS3
190+
|Body|✓|OAS2
191+
|FormUnencoded|✓|OAS2
192+
|FormMultipart|✓|OAS2
193+
|Cookie|✗|OAS3
194+
195+
### Schema Support Feature
196+
| Name | Supported | Defined By |
197+
| ---- | --------- | ---------- |
198+
|Simple|✓|OAS2,OAS3
199+
|Composite|✓|OAS2,OAS3
200+
|Polymorphism|✓|OAS2,OAS3
201+
|Union|✗|OAS3
202+
|allOf|✓|OAS2,OAS3
203+
|anyOf|✓|OAS3
204+
|oneOf|✓|OAS3
205+
|not|✗|OAS3
206+
207+
### Security Feature
208+
| Name | Supported | Defined By |
209+
| ---- | --------- | ---------- |
210+
|BasicAuth|✓|OAS2,OAS3
211+
|ApiKey|✓|OAS2,OAS3
212+
|OpenIDConnect|✗|OAS3
213+
|BearerToken|✓|OAS3
214+
|OAuth2_Implicit|✓|OAS2,OAS3
215+
|OAuth2_Password|✗|OAS2,OAS3
216+
|OAuth2_ClientCredentials|✗|OAS2,OAS3
217+
|OAuth2_AuthorizationCode|✗|OAS2,OAS3
218+
219+
### Wire Format Feature
220+
| Name | Supported | Defined By |
221+
| ---- | --------- | ---------- |
222+
|JSON|✓|OAS2,OAS3
223+
|XML|✓|OAS2,OAS3
224+
|PROTOBUF|✗|ToolingExtension
225+
|Custom|✓|OAS2,OAS3

docs/generators/python-prior.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl
4747
## LANGUAGE PRIMITIVES
4848

4949
<ul class="column-ul">
50+
<li>Dict</li>
51+
<li>List</li>
5052
<li>bool</li>
5153
<li>bytes</li>
5254
<li>date</li>

docs/generators/python.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl
4747
## LANGUAGE PRIMITIVES
4848

4949
<ul class="column-ul">
50+
<li>Dict</li>
51+
<li>List</li>
5052
<li>bool</li>
5153
<li>bytes</li>
5254
<li>date</li>

modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -637,14 +637,29 @@ protected void removeSelfReferenceImports(CodegenModel model) {
637637
}
638638

639639
public void setCircularReferences(Map<String, CodegenModel> models) {
640-
final Map<String, List<CodegenProperty>> dependencyMap = models.entrySet().stream()
641-
.collect(Collectors.toMap(Entry::getKey, entry -> getModelDependencies(entry.getValue())));
640+
// for allVars
641+
final Map<String, List<CodegenProperty>> allVarsDependencyMap = models.entrySet().stream()
642+
.collect(Collectors.toMap(Entry::getKey, entry -> getModelDependencies(entry.getValue().getAllVars())));
642643

643-
models.keySet().forEach(name -> setCircularReferencesOnProperties(name, dependencyMap));
644+
models.keySet().forEach(name -> setCircularReferencesOnProperties(name, allVarsDependencyMap));
645+
646+
// for vars
647+
final Map<String, List<CodegenProperty>> varsDependencyMap = models.entrySet().stream()
648+
.collect(Collectors.toMap(Entry::getKey, entry -> getModelDependencies(entry.getValue().getVars())));
649+
650+
models.keySet().forEach(name -> setCircularReferencesOnProperties(name, varsDependencyMap));
651+
652+
// for oneOf
653+
final Map<String, List<CodegenProperty>> oneOfDependencyMap = models.entrySet().stream()
654+
.collect(Collectors.toMap(Entry::getKey, entry -> getModelDependencies(
655+
(entry.getValue().getComposedSchemas() != null && entry.getValue().getComposedSchemas().getOneOf() != null)
656+
? entry.getValue().getComposedSchemas().getOneOf() : new ArrayList<CodegenProperty>())));
657+
658+
models.keySet().forEach(name -> setCircularReferencesOnProperties(name, oneOfDependencyMap));
644659
}
645660

646-
private List<CodegenProperty> getModelDependencies(CodegenModel model) {
647-
return model.getAllVars().stream()
661+
private List<CodegenProperty> getModelDependencies( List<CodegenProperty> vars) {
662+
return vars.stream()
648663
.map(prop -> {
649664
if (prop.isContainer) {
650665
return prop.items.dataType == null ? null : prop;

0 commit comments

Comments
 (0)