Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

[unused] moves models into components.schema package #51

Merged
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class PythonClientCodegen extends AbstractPythonCodegen {

protected String packageUrl;
protected String apiDocPath = "docs/apis/tags/";
protected String modelDocPath = "docs/models/";
protected String modelDocPath = "docs/components/schema/";
protected boolean useNose = false;
protected boolean useInlineModelResolver = false;

Expand Down Expand Up @@ -164,7 +164,7 @@ public PythonClientCodegen() {
// at the moment
importMapping.clear();

modelPackage = "model";
modelPackage = "components.schema";
apiPackage = "apis";
outputFolder = "generated-code" + File.separatorChar + "python";

Expand Down Expand Up @@ -420,7 +420,8 @@ public void processOpts() {

if (Boolean.FALSE.equals(excludeTests)) {
supportingFiles.add(new SupportingFile("__init__." + templateExtension, testFolder, "__init__.py"));
supportingFiles.add(new SupportingFile("__init__." + templateExtension, testFolder + File.separator + "test_models", "__init__.py"));
supportingFiles.add(new SupportingFile("__init__." + templateExtension, testFolder + File.separator + modelPackage.replace('.', File.separatorChar), "__init__.py"));
supportingFiles.add(new SupportingFile("__init__." + templateExtension, testFolder + File.separator + "components", "__init__.py"));
}

supportingFiles.add(new SupportingFile("api_client." + templateExtension, packagePath(), "api_client.py"));
Expand All @@ -438,9 +439,17 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("schemas." + templateExtension, packagePath(), "schemas.py"));

// add the models and apis folders
supportingFiles.add(new SupportingFile("__init__models." + templateExtension, packagePath() + File.separatorChar + "models", "__init__.py"));
supportingFiles.add(new SupportingFile("__init__model." + templateExtension, packagePath() + File.separatorChar + modelPackage, "__init__.py"));
supportingFiles.add(new SupportingFile("__init__apis." + templateExtension, packagePath() + File.separatorChar + apiPackage, "__init__.py"));
String modelPackages = modelPackage + "s";
supportingFiles.add(new SupportingFile("__init__." + templateExtension, packagePath() + File.separatorChar + "components" , "__init__.py"));
boolean generateModels = (boolean) additionalProperties().get(CodegenConstants.GENERATE_MODELS);
if (generateModels) {
supportingFiles.add(new SupportingFile("__init__schemas." + templateExtension, packagePath() + File.separatorChar + modelPackages.replace('.', File.separatorChar), "__init__.py"));
supportingFiles.add(new SupportingFile("__init__schema." + templateExtension, packagePath() + File.separatorChar + modelPackage.replace('.', File.separatorChar), "__init__.py"));
}
boolean generateApis = (boolean) additionalProperties().get(CodegenConstants.GENERATE_APIS);
if (generateApis) {
supportingFiles.add(new SupportingFile("__init__apis." + templateExtension, packagePath() + File.separatorChar + apiPackage, "__init__.py"));
}
// Generate the 'signing.py' module, but only if the 'HTTP signature' security scheme is specified in the OAS.
Map<String, SecurityScheme> securitySchemeMap = openAPI != null ?
(openAPI.getComponents() != null ? openAPI.getComponents().getSecuritySchemes() : null) : null;
Expand Down Expand Up @@ -667,21 +676,21 @@ protected void generateEndpoints(OperationsMap objs) {
tagToApiMap.put("apiClassname", "Api");
tagToApiMap.put("tagModuleNameToApiClassname", tagModuleNameToApiClassname);
tagToApiMap.put("tagEnumToApiClassname", tagEnumToApiClassname);
outputFilename = packageFilename(Arrays.asList("apis", "tag_to_api.py"));
outputFilename = packageFilename(Arrays.asList(apiPackage, "tag_to_api.py"));
apisFiles.add(Arrays.asList(tagToApiMap, "apis_tag_to_api.handlebars", outputFilename));
// apis.path_to_api.py
Map<String, Object> allByPathsFileMap = new HashMap<>();
allByPathsFileMap.put("packageName", packageName);
allByPathsFileMap.put("apiClassname", "Api");
allByPathsFileMap.put("pathModuleToApiClassname", pathModuleToApiClassname);
allByPathsFileMap.put("pathEnumToApiClassname", pathEnumToApiClassname);
outputFilename = packageFilename(Arrays.asList("apis", "path_to_api.py"));
outputFilename = packageFilename(Arrays.asList(apiPackage, "path_to_api.py"));
apisFiles.add(Arrays.asList(allByPathsFileMap, "apis_path_to_api.handlebars", outputFilename));
// apis.paths.__init__.py
Map<String, Object> initApiTagsMap = new HashMap<>();
initApiTagsMap.put("packageName", packageName);
initApiTagsMap.put("enumToTag", enumToTag);
outputFilename = packageFilename(Arrays.asList("apis", "tags", "__init__.py"));
outputFilename = packageFilename(Arrays.asList(apiPackage, "tags", "__init__.py"));
apisFiles.add(Arrays.asList(initApiTagsMap, "__init__apis_tags.handlebars", outputFilename));

// paths.__init__.py (contains path str enum)
Expand All @@ -692,7 +701,7 @@ protected void generateEndpoints(OperationsMap objs) {
outputFilename = packageFilename(Arrays.asList("paths", "__init__.py"));
pathsFiles.add(Arrays.asList(initOperationMap, "__init__paths_enum.handlebars", outputFilename));
// apis.paths.__init__.py
outputFilename = packageFilename(Arrays.asList("apis", "paths", "__init__.py"));
outputFilename = packageFilename(Arrays.asList(apiPackage, "paths", "__init__.py"));
apisFiles.add(Arrays.asList(initOperationMap, "__init__paths.handlebars", outputFilename));
// paths.some_path.__init__.py
// apis.paths.some_path.py
Expand Down Expand Up @@ -2563,7 +2572,7 @@ public String apiFileFolder() {

@Override
public String modelFileFolder() {
return outputFolder + File.separatorChar + packagePath() + File.separatorChar + modelPackage();
return outputFolder + File.separatorChar + packagePath() + File.separator + modelPackage().replace('.', File.separatorChar);
}

@Override
Expand All @@ -2573,7 +2582,7 @@ public String apiTestFileFolder() {

@Override
public String modelTestFileFolder() {
return outputFolder + File.separatorChar + testFolder + File.separatorChar + "test_models";
return outputFolder + File.separatorChar + testFolder + File.separatorChar + modelPackage.replace('.', File.separatorChar);
}

public void setUseNose(String val) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,22 @@ Class | Method | HTTP request | Description
{{/unless}}{{/each}}{{/with}}
## Notes for Large OpenAPI documents
If the OpenAPI document is large, imports in {{{packageName}}}.apis and {{{packageName}}}.models may fail with a
If the OpenAPI document is large, imports in {{{packageName}}}.{{apiPackage}}.tags.tag_to_api and {{{packageName}}}.{{modelPackage}}s may fail with a
RecursionError indicating the maximum recursion limit has been exceeded. In that case, there are a couple of solutions:
Solution 1:
Use specific imports for apis and models like:
- `from {{{packageName}}}.{{apiPackage}}.default_api import DefaultApi`
- `from {{{packageName}}}.{{apiPackage}}.paths.some_path import SomePath`
- `from {{{packageName}}}.paths.some_path.get import ApiForget`
- `from {{{packageName}}}.{{modelPackage}}.pet import Pet`
Solution 1:
Solution 2:
Before importing the package, adjust the maximum recursion limit as shown below:
```
import sys
sys.setrecursionlimit(1500)
import {{{packageName}}}
from {{{packageName}}}.apis import *
from {{{packageName}}}.models import *
from {{{packageName}}}.{{apiPackage}}.tags.tag_to_api import *
from {{{packageName}}}.{{modelPackage}}s import *
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# reference which would not work in python2
# do not import all models into this module because that uses a lot of memory and stack frames
# if you need the ability to import all models from one package, import them with
# from {{packageName}}.models import ModelA, ModelB
# from {{packageName}}.{{modelPackage}}s import ModelA, ModelB
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ skip_deserialization | bool | default is False | when True, headers and body wil
### <a id="{{operationId}}.request_body" >body</a>
{{#each content}}
{{#with this.schema}}
{{> api_doc_schema_type_hint anchorPrefix=../operationId schemaNamePrefix1="request_body" complexTypePrefix="../../models/" }}
{{> api_doc_schema_type_hint anchorPrefix=../operationId schemaNamePrefix1="request_body" complexTypePrefix="../../components/schema/" }}
{{/with}}
{{/each}}
{{/with}}
Expand All @@ -101,7 +101,7 @@ Key | Input Type | Description | Notes
{{#each queryParams}}
{{#with schema}}
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1=../paramName complexTypePrefix="../../models/" }}
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1=../paramName complexTypePrefix="../../components/schema/" }}
{{/with}}
{{/each}}
{{/if}}
Expand All @@ -117,7 +117,7 @@ Key | Input Type | Description | Notes
{{/each}}
{{#each headerParams}}
{{#with schema}}
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1=../paramName complexTypePrefix="../../models/" }}
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1=../paramName complexTypePrefix="../../components/schema/" }}
{{/with}}
{{/each}}
{{/if}}
Expand All @@ -133,7 +133,7 @@ Key | Input Type | Description | Notes
{{/each}}
{{#each pathParams}}
{{#with schema}}
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1=../paramName complexTypePrefix="../../models/" }}
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1=../paramName complexTypePrefix="../../components/schema/" }}
{{/with}}
{{/each}}
{{/if}}
Expand All @@ -149,7 +149,7 @@ Key | Input Type | Description | Notes
{{/each}}
{{#each cookieParams}}
{{#with schema}}
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1=../paramName complexTypePrefix="../../models/" }}
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1=../paramName complexTypePrefix="../../components/schema/" }}
{{/with}}
{{/each}}
{{/if}}
Expand Down Expand Up @@ -184,7 +184,7 @@ body | {{#unless content}}Unset{{else}}typing.Union[{{#each content}}{{#if this.
headers | {{#unless responseHeaders}}Unset{{else}}[response_for_{{code}}.Headers](#{{operationId}}.response_for_{{code}}.Headers){{/unless}} | {{#unless responseHeaders}}headers were not defined{{/unless}} |
{{#each content}}
{{#with this.schema}}
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1="response_for_" schemaNamePrefix2=../../code schemaNamePrefix3="." complexTypePrefix="../../models/" }}
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1="response_for_" schemaNamePrefix2=../../code schemaNamePrefix3="." complexTypePrefix="../../components/schema/" }}
{{/with}}
{{/each}}
{{#if responseHeaders}}
Expand All @@ -210,13 +210,13 @@ Key | Accessed Type | Description | Notes
{{#each responseHeaders}}
{{#if schema}}
{{#with schema}}
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1="response_for_" schemaNamePrefix2=../../code schemaNamePrefix3="." schemaNamePrefix4=../paramName schemaNamePrefix5="." complexTypePrefix="../../models/" }}
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1="response_for_" schemaNamePrefix2=../../code schemaNamePrefix3="." schemaNamePrefix4=../paramName schemaNamePrefix5="." complexTypePrefix="../../components/schema/" }}
{{/with}}
{{else}}
{{#each getContent}}
{{#with this}}
{{#with schema}}
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1="response_for_" schemaNamePrefix2=../../code schemaNamePrefix3="." schemaNamePrefix4=../paramName schemaNamePrefix5="." complexTypePrefix="../../models/" }}
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1="response_for_" schemaNamePrefix2=../../code schemaNamePrefix3="." schemaNamePrefix4=../paramName schemaNamePrefix5="." complexTypePrefix="../../components/schema/" }}
{{/with}}
{{/with}}
{{/each}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
{{/with}}
{{/each}}

[[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md)
[[Back to Model list]](../../../README.md#documentation-for-models) [[Back to API list]](../../../README.md#documentation-for-api-endpoints) [[Back to README]](../../../README.md)

Loading