Skip to content

Commit

Permalink
Add a new Python client generator - python-nextgen (#14157)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
wing328 committed Dec 17, 2022
1 parent 6800905 commit 0cf5ed6
Show file tree
Hide file tree
Showing 568 changed files with 56,832 additions and 272 deletions.
4 changes: 2 additions & 2 deletions CI/circle_parallel.sh
Expand Up @@ -53,9 +53,9 @@ elif [ "$NODE_INDEX" = "3" ]; then
#./configure --enable-optimizations
#sudo make altinstall
pyenv install --list
pyenv install 3.6.3
pyenv install 3.7.12
pyenv install 2.7.14
pyenv global 3.6.3
pyenv global 3.7.12

# Install node@stable (for angular 6)
set +e
Expand Down
7 changes: 7 additions & 0 deletions bin/configs/python-nextgen-aiohttp.yaml
@@ -0,0 +1,7 @@
generatorName: python-nextgen
outputDir: samples/openapi3/client/petstore/python-nextgen-aiohttp
inputSpec: modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/python-nextgen
library: asyncio
additionalProperties:
packageName: petstore_api
8 changes: 8 additions & 0 deletions bin/configs/python-nextgen.yaml
@@ -0,0 +1,8 @@
generatorName: python-nextgen
outputDir: samples/openapi3/client/petstore/python-nextgen
inputSpec: modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/python-nextgen
additionalProperties:
packageName: petstore_api
useOneOfDiscriminatorLookup: "true"
disallowAdditionalPropertiesIfNotPresent: false
1 change: 1 addition & 0 deletions docs/generators.md
Expand Up @@ -52,6 +52,7 @@ The following generators are available:
* [powershell (beta)](generators/powershell.md)
* [python](generators/python.md)
* [python-legacy](generators/python-legacy.md)
* [python-nextgen (beta)](generators/python-nextgen.md)
* [python-prior](generators/python-prior.md)
* [r](generators/r.md)
* [ruby](generators/ruby.md)
Expand Down
2 changes: 2 additions & 0 deletions docs/generators/python-legacy.md
Expand Up @@ -45,6 +45,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl
## LANGUAGE PRIMITIVES

<ul class="column-ul">
<li>Dict</li>
<li>List</li>
<li>bool</li>
<li>bytes</li>
<li>date</li>
Expand Down
225 changes: 225 additions & 0 deletions docs/generators/python-nextgen.md
@@ -0,0 +1,225 @@
---
title: Documentation for the python-nextgen Generator
---

## METADATA

| Property | Value | Notes |
| -------- | ----- | ----- |
| generator name | python-nextgen | pass this to the generate command after -g |
| generator stability | BETA | |
| generator type | CLIENT | |
| generator language | Python | |
| generator language version | 3.7+ | |
| generator default templating engine | mustache | |
| helpTxt | Generates a Python client library. | |

## CONFIG OPTIONS
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.

| Option | Description | Values | Default |
| ------ | ----------- | ------ | ------- |
|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|
|generateSourceCodeOnly|Specifies that only a library source code is to be generated.| |false|
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
|library|library template (sub-template) to use: asyncio, tornado (deprecated), urllib3| |urllib3|
|packageName|python package name (convention: snake_case).| |openapi_client|
|packageUrl|python package URL.| |null|
|packageVersion|python package version.| |1.0.0|
|projectName|python project name in setup.py (e.g. petstore-api).| |null|
|recursionLimit|Set the recursion limit. If not set, use the system default value.| |null|

## IMPORT MAPPING

| Type/Alias | Imports |
| ---------- | ------- |


## INSTANTIATION TYPES

| Type/Alias | Instantiated By |
| ---------- | --------------- |


## LANGUAGE PRIMITIVES

<ul class="column-ul">
<li>Dict</li>
<li>List</li>
<li>bool</li>
<li>bytes</li>
<li>date</li>
<li>datetime</li>
<li>decimal.Decimal</li>
<li>dict</li>
<li>float</li>
<li>int</li>
<li>list</li>
<li>object</li>
<li>str</li>
</ul>

## RESERVED WORDS

<ul class="column-ul">
<li>and</li>
<li>as</li>
<li>assert</li>
<li>async</li>
<li>await</li>
<li>base64</li>
<li>break</li>
<li>class</li>
<li>continue</li>
<li>date</li>
<li>def</li>
<li>del</li>
<li>elif</li>
<li>else</li>
<li>except</li>
<li>exec</li>
<li>false</li>
<li>finally</li>
<li>for</li>
<li>from</li>
<li>global</li>
<li>if</li>
<li>import</li>
<li>in</li>
<li>is</li>
<li>json</li>
<li>lambda</li>
<li>none</li>
<li>nonlocal</li>
<li>not</li>
<li>or</li>
<li>pass</li>
<li>print</li>
<li>property</li>
<li>raise</li>
<li>return</li>
<li>schema</li>
<li>self</li>
<li>true</li>
<li>try</li>
<li>while</li>
<li>with</li>
<li>yield</li>
</ul>

## FEATURE SET


### Client Modification Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|BasePath|✗|ToolingExtension
|Authorizations|✗|ToolingExtension
|UserAgent|✗|ToolingExtension
|MockServer|✗|ToolingExtension

### Data Type Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Custom|✗|OAS2,OAS3
|Int32|✓|OAS2,OAS3
|Int64|✓|OAS2,OAS3
|Float|✓|OAS2,OAS3
|Double|✓|OAS2,OAS3
|Decimal|✓|ToolingExtension
|String|✓|OAS2,OAS3
|Byte|✓|OAS2,OAS3
|Binary|✓|OAS2,OAS3
|Boolean|✓|OAS2,OAS3
|Date|✓|OAS2,OAS3
|DateTime|✓|OAS2,OAS3
|Password|✓|OAS2,OAS3
|File|✓|OAS2
|Uuid||
|Array|✓|OAS2,OAS3
|Null|✗|OAS3
|AnyType|✗|OAS2,OAS3
|Object|✓|OAS2,OAS3
|Maps|✓|ToolingExtension
|CollectionFormat|✓|OAS2
|CollectionFormatMulti|✓|OAS2
|Enum|✓|OAS2,OAS3
|ArrayOfEnum|✓|ToolingExtension
|ArrayOfModel|✓|ToolingExtension
|ArrayOfCollectionOfPrimitives|✓|ToolingExtension
|ArrayOfCollectionOfModel|✓|ToolingExtension
|ArrayOfCollectionOfEnum|✓|ToolingExtension
|MapOfEnum|✓|ToolingExtension
|MapOfModel|✓|ToolingExtension
|MapOfCollectionOfPrimitives|✓|ToolingExtension
|MapOfCollectionOfModel|✓|ToolingExtension
|MapOfCollectionOfEnum|✓|ToolingExtension

### Documentation Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Readme|✓|ToolingExtension
|Model|✓|ToolingExtension
|Api|✓|ToolingExtension

### Global Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Host|✓|OAS2,OAS3
|BasePath|✓|OAS2,OAS3
|Info|✓|OAS2,OAS3
|Schemes|✗|OAS2,OAS3
|PartialSchemes|✓|OAS2,OAS3
|Consumes|✓|OAS2
|Produces|✓|OAS2
|ExternalDocumentation|✓|OAS2,OAS3
|Examples|✓|OAS2,OAS3
|XMLStructureDefinitions|✗|OAS2,OAS3
|MultiServer|✗|OAS3
|ParameterizedServer|✗|OAS3
|ParameterStyling|✗|OAS3
|Callbacks|✗|OAS3
|LinkObjects|✗|OAS3

### Parameter Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Path|✓|OAS2,OAS3
|Query|✓|OAS2,OAS3
|Header|✓|OAS2,OAS3
|Body|✓|OAS2
|FormUnencoded|✓|OAS2
|FormMultipart|✓|OAS2
|Cookie|✗|OAS3

### Schema Support Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Simple|✓|OAS2,OAS3
|Composite|✓|OAS2,OAS3
|Polymorphism|✓|OAS2,OAS3
|Union|✗|OAS3
|allOf|✓|OAS2,OAS3
|anyOf|✓|OAS3
|oneOf|✓|OAS3
|not|✗|OAS3

### Security Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|BasicAuth|✓|OAS2,OAS3
|ApiKey|✓|OAS2,OAS3
|OpenIDConnect|✗|OAS3
|BearerToken|✓|OAS3
|OAuth2_Implicit|✓|OAS2,OAS3
|OAuth2_Password|✗|OAS2,OAS3
|OAuth2_ClientCredentials|✗|OAS2,OAS3
|OAuth2_AuthorizationCode|✗|OAS2,OAS3

### Wire Format Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|JSON|✓|OAS2,OAS3
|XML|✓|OAS2,OAS3
|PROTOBUF|✗|ToolingExtension
|Custom|✓|OAS2,OAS3
2 changes: 2 additions & 0 deletions docs/generators/python-prior.md
Expand Up @@ -47,6 +47,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl
## LANGUAGE PRIMITIVES

<ul class="column-ul">
<li>Dict</li>
<li>List</li>
<li>bool</li>
<li>bytes</li>
<li>date</li>
Expand Down
2 changes: 2 additions & 0 deletions docs/generators/python.md
Expand Up @@ -47,6 +47,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl
## LANGUAGE PRIMITIVES

<ul class="column-ul">
<li>Dict</li>
<li>List</li>
<li>bool</li>
<li>bytes</li>
<li>date</li>
Expand Down
Expand Up @@ -637,14 +637,29 @@ protected void removeSelfReferenceImports(CodegenModel model) {
}

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

models.keySet().forEach(name -> setCircularReferencesOnProperties(name, dependencyMap));
models.keySet().forEach(name -> setCircularReferencesOnProperties(name, allVarsDependencyMap));

// for vars
final Map<String, List<CodegenProperty>> varsDependencyMap = models.entrySet().stream()
.collect(Collectors.toMap(Entry::getKey, entry -> getModelDependencies(entry.getValue().getVars())));

models.keySet().forEach(name -> setCircularReferencesOnProperties(name, varsDependencyMap));

// for oneOf
final Map<String, List<CodegenProperty>> oneOfDependencyMap = models.entrySet().stream()
.collect(Collectors.toMap(Entry::getKey, entry -> getModelDependencies(
(entry.getValue().getComposedSchemas() != null && entry.getValue().getComposedSchemas().getOneOf() != null)
? entry.getValue().getComposedSchemas().getOneOf() : new ArrayList<CodegenProperty>())));

models.keySet().forEach(name -> setCircularReferencesOnProperties(name, oneOfDependencyMap));
}

private List<CodegenProperty> getModelDependencies(CodegenModel model) {
return model.getAllVars().stream()
private List<CodegenProperty> getModelDependencies( List<CodegenProperty> vars) {
return vars.stream()
.map(prop -> {
if (prop.isContainer) {
return prop.items.dataType == null ? null : prop;
Expand Down

0 comments on commit 0cf5ed6

Please sign in to comment.