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

Commit 6c5acc0

Browse files
committed
v2 Moves models into components.schema package (#60)
* python client modelPackage updated * Fixes links in model_doc template * Samples updated and python client path methods updated * Models sucessfully moved into components/schema in one sample * Replaces model import with components.schema * Fixes readme imports * Fixes model doc links from endpoint docs * Samples regenerated * Fixes manual test model imports * Samples regenerated, added init for test components * Removes model models folders * Removes lingering AbstractStep files, fixes its test * Removes lingering bad model test
1 parent d107a54 commit 6c5acc0

File tree

1,465 files changed

+4046
-4024
lines changed

Some content is hidden

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

1,465 files changed

+4046
-4024
lines changed

modules/openapi-json-schema-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java

+21-12
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public class PythonClientCodegen extends AbstractPythonCodegen {
8282

8383
protected String packageUrl;
8484
protected String apiDocPath = "docs/apis/tags/";
85-
protected String modelDocPath = "docs/models/";
85+
protected String modelDocPath = "docs/components/schema/";
8686
protected boolean useNose = false;
8787
protected boolean useInlineModelResolver = false;
8888

@@ -164,7 +164,7 @@ public PythonClientCodegen() {
164164
// at the moment
165165
importMapping.clear();
166166

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

@@ -420,7 +420,8 @@ public void processOpts() {
420420

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

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

440441
// add the models and apis folders
441-
supportingFiles.add(new SupportingFile("__init__models." + templateExtension, packagePath() + File.separatorChar + "models", "__init__.py"));
442-
supportingFiles.add(new SupportingFile("__init__model." + templateExtension, packagePath() + File.separatorChar + modelPackage, "__init__.py"));
443-
supportingFiles.add(new SupportingFile("__init__apis." + templateExtension, packagePath() + File.separatorChar + apiPackage, "__init__.py"));
442+
String modelPackages = modelPackage + "s";
443+
supportingFiles.add(new SupportingFile("__init__." + templateExtension, packagePath() + File.separatorChar + "components" , "__init__.py"));
444+
boolean generateModels = (boolean) additionalProperties().get(CodegenConstants.GENERATE_MODELS);
445+
if (generateModels) {
446+
supportingFiles.add(new SupportingFile("__init__schemas." + templateExtension, packagePath() + File.separatorChar + modelPackages.replace('.', File.separatorChar), "__init__.py"));
447+
supportingFiles.add(new SupportingFile("__init__schema." + templateExtension, packagePath() + File.separatorChar + modelPackage.replace('.', File.separatorChar), "__init__.py"));
448+
}
449+
boolean generateApis = (boolean) additionalProperties().get(CodegenConstants.GENERATE_APIS);
450+
if (generateApis) {
451+
supportingFiles.add(new SupportingFile("__init__apis." + templateExtension, packagePath() + File.separatorChar + apiPackage, "__init__.py"));
452+
}
444453
// Generate the 'signing.py' module, but only if the 'HTTP signature' security scheme is specified in the OAS.
445454
Map<String, SecurityScheme> securitySchemeMap = openAPI != null ?
446455
(openAPI.getComponents() != null ? openAPI.getComponents().getSecuritySchemes() : null) : null;
@@ -667,21 +676,21 @@ protected void generateEndpoints(OperationsMap objs) {
667676
tagToApiMap.put("apiClassname", "Api");
668677
tagToApiMap.put("tagModuleNameToApiClassname", tagModuleNameToApiClassname);
669678
tagToApiMap.put("tagEnumToApiClassname", tagEnumToApiClassname);
670-
outputFilename = packageFilename(Arrays.asList("apis", "tag_to_api.py"));
679+
outputFilename = packageFilename(Arrays.asList(apiPackage, "tag_to_api.py"));
671680
apisFiles.add(Arrays.asList(tagToApiMap, "apis_tag_to_api.handlebars", outputFilename));
672681
// apis.path_to_api.py
673682
Map<String, Object> allByPathsFileMap = new HashMap<>();
674683
allByPathsFileMap.put("packageName", packageName);
675684
allByPathsFileMap.put("apiClassname", "Api");
676685
allByPathsFileMap.put("pathModuleToApiClassname", pathModuleToApiClassname);
677686
allByPathsFileMap.put("pathEnumToApiClassname", pathEnumToApiClassname);
678-
outputFilename = packageFilename(Arrays.asList("apis", "path_to_api.py"));
687+
outputFilename = packageFilename(Arrays.asList(apiPackage, "path_to_api.py"));
679688
apisFiles.add(Arrays.asList(allByPathsFileMap, "apis_path_to_api.handlebars", outputFilename));
680689
// apis.paths.__init__.py
681690
Map<String, Object> initApiTagsMap = new HashMap<>();
682691
initApiTagsMap.put("packageName", packageName);
683692
initApiTagsMap.put("enumToTag", enumToTag);
684-
outputFilename = packageFilename(Arrays.asList("apis", "tags", "__init__.py"));
693+
outputFilename = packageFilename(Arrays.asList(apiPackage, "tags", "__init__.py"));
685694
apisFiles.add(Arrays.asList(initApiTagsMap, "__init__apis_tags.handlebars", outputFilename));
686695

687696
// paths.__init__.py (contains path str enum)
@@ -692,7 +701,7 @@ protected void generateEndpoints(OperationsMap objs) {
692701
outputFilename = packageFilename(Arrays.asList("paths", "__init__.py"));
693702
pathsFiles.add(Arrays.asList(initOperationMap, "__init__paths_enum.handlebars", outputFilename));
694703
// apis.paths.__init__.py
695-
outputFilename = packageFilename(Arrays.asList("apis", "paths", "__init__.py"));
704+
outputFilename = packageFilename(Arrays.asList(apiPackage, "paths", "__init__.py"));
696705
apisFiles.add(Arrays.asList(initOperationMap, "__init__paths.handlebars", outputFilename));
697706
// paths.some_path.__init__.py
698707
// apis.paths.some_path.py
@@ -2574,7 +2583,7 @@ public String apiFileFolder() {
25742583

25752584
@Override
25762585
public String modelFileFolder() {
2577-
return outputFolder + File.separatorChar + packagePath() + File.separatorChar + modelPackage();
2586+
return outputFolder + File.separatorChar + packagePath() + File.separator + modelPackage().replace('.', File.separatorChar);
25782587
}
25792588

25802589
@Override
@@ -2584,7 +2593,7 @@ public String apiTestFileFolder() {
25842593

25852594
@Override
25862595
public String modelTestFileFolder() {
2587-
return outputFolder + File.separatorChar + testFolder + File.separatorChar + "test_models";
2596+
return outputFolder + File.separatorChar + testFolder + File.separatorChar + modelPackage.replace('.', File.separatorChar);
25882597
}
25892598

25902599
public void setUseNose(String val) {

modules/openapi-json-schema-generator/src/main/resources/python/README_common.handlebars

+6-4
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,22 @@ Class | Method | HTTP request | Description
6868
{{/unless}}{{/each}}{{/with}}
6969
7070
## Notes for Large OpenAPI documents
71-
If the OpenAPI document is large, imports in {{{packageName}}}.apis and {{{packageName}}}.models may fail with a
71+
If the OpenAPI document is large, imports in {{{packageName}}}.{{apiPackage}}.tags.tag_to_api and {{{packageName}}}.{{modelPackage}}s may fail with a
7272
RecursionError indicating the maximum recursion limit has been exceeded. In that case, there are a couple of solutions:
7373
7474
Solution 1:
7575
Use specific imports for apis and models like:
7676
- `from {{{packageName}}}.{{apiPackage}}.default_api import DefaultApi`
77+
- `from {{{packageName}}}.{{apiPackage}}.paths.some_path import SomePath`
78+
- `from {{{packageName}}}.paths.some_path.get import ApiForget`
7779
- `from {{{packageName}}}.{{modelPackage}}.pet import Pet`
7880
79-
Solution 1:
81+
Solution 2:
8082
Before importing the package, adjust the maximum recursion limit as shown below:
8183
```
8284
import sys
8385
sys.setrecursionlimit(1500)
8486
import {{{packageName}}}
85-
from {{{packageName}}}.apis import *
86-
from {{{packageName}}}.models import *
87+
from {{{packageName}}}.{{apiPackage}}.tags.tag_to_api import *
88+
from {{{packageName}}}.{{modelPackage}}s import *
8789
```

modules/openapi-json-schema-generator/src/main/resources/python/__init__model.handlebars renamed to modules/openapi-json-schema-generator/src/main/resources/python/__init__schema.handlebars

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# reference which would not work in python2
33
# do not import all models into this module because that uses a lot of memory and stack frames
44
# if you need the ability to import all models from one package, import them with
5-
# from {{packageName}}.models import ModelA, ModelB
5+
# from {{packageName}}.{{modelPackage}}s import ModelA, ModelB

modules/openapi-json-schema-generator/src/main/resources/python/api_doc.handlebars

+8-8
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ skip_deserialization | bool | default is False | when True, headers and body wil
8484
### <a id="{{operationId}}.request_body" >body</a>
8585
{{#each content}}
8686
{{#with this.schema}}
87-
{{> api_doc_schema_type_hint anchorPrefix=../operationId schemaNamePrefix1="request_body" complexTypePrefix="../../models/" }}
87+
{{> api_doc_schema_type_hint anchorPrefix=../operationId schemaNamePrefix1="request_body" complexTypePrefix="../../components/schema/" }}
8888
{{/with}}
8989
{{/each}}
9090
{{/with}}
@@ -101,7 +101,7 @@ Key | Input Type | Description | Notes
101101
102102
{{#each queryParams}}
103103
{{#with schema}}
104-
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1=../paramName complexTypePrefix="../../models/" }}
104+
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1=../paramName complexTypePrefix="../../components/schema/" }}
105105
{{/with}}
106106
{{/each}}
107107
{{/if}}
@@ -117,7 +117,7 @@ Key | Input Type | Description | Notes
117117
{{/each}}
118118
{{#each headerParams}}
119119
{{#with schema}}
120-
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1=../paramName complexTypePrefix="../../models/" }}
120+
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1=../paramName complexTypePrefix="../../components/schema/" }}
121121
{{/with}}
122122
{{/each}}
123123
{{/if}}
@@ -133,7 +133,7 @@ Key | Input Type | Description | Notes
133133
{{/each}}
134134
{{#each pathParams}}
135135
{{#with schema}}
136-
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1=../paramName complexTypePrefix="../../models/" }}
136+
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1=../paramName complexTypePrefix="../../components/schema/" }}
137137
{{/with}}
138138
{{/each}}
139139
{{/if}}
@@ -149,7 +149,7 @@ Key | Input Type | Description | Notes
149149
{{/each}}
150150
{{#each cookieParams}}
151151
{{#with schema}}
152-
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1=../paramName complexTypePrefix="../../models/" }}
152+
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1=../paramName complexTypePrefix="../../components/schema/" }}
153153
{{/with}}
154154
{{/each}}
155155
{{/if}}
@@ -184,7 +184,7 @@ body | {{#unless content}}Unset{{else}}typing.Union[{{#each content}}{{#if this.
184184
headers | {{#unless responseHeaders}}Unset{{else}}[response_for_{{code}}.Headers](#{{operationId}}.response_for_{{code}}.Headers){{/unless}} | {{#unless responseHeaders}}headers were not defined{{/unless}} |
185185
{{#each content}}
186186
{{#with this.schema}}
187-
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1="response_for_" schemaNamePrefix2=../../code schemaNamePrefix3="." complexTypePrefix="../../models/" }}
187+
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1="response_for_" schemaNamePrefix2=../../code schemaNamePrefix3="." complexTypePrefix="../../components/schema/" }}
188188
{{/with}}
189189
{{/each}}
190190
{{#if responseHeaders}}
@@ -210,13 +210,13 @@ Key | Accessed Type | Description | Notes
210210
{{#each responseHeaders}}
211211
{{#if schema}}
212212
{{#with schema}}
213-
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1="response_for_" schemaNamePrefix2=../../code schemaNamePrefix3="." schemaNamePrefix4=../paramName schemaNamePrefix5="." complexTypePrefix="../../models/" }}
213+
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1="response_for_" schemaNamePrefix2=../../code schemaNamePrefix3="." schemaNamePrefix4=../paramName schemaNamePrefix5="." complexTypePrefix="../../components/schema/" }}
214214
{{/with}}
215215
{{else}}
216216
{{#each getContent}}
217217
{{#with this}}
218218
{{#with schema}}
219-
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1="response_for_" schemaNamePrefix2=../../code schemaNamePrefix3="." schemaNamePrefix4=../paramName schemaNamePrefix5="." complexTypePrefix="../../models/" }}
219+
{{> api_doc_schema_type_hint anchorPrefix=../../operationId schemaNamePrefix1="response_for_" schemaNamePrefix2=../../code schemaNamePrefix3="." schemaNamePrefix4=../paramName schemaNamePrefix5="." complexTypePrefix="../../components/schema/" }}
220220
{{/with}}
221221
{{/with}}
222222
{{/each}}

modules/openapi-json-schema-generator/src/main/resources/python/model_doc.handlebars

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
{{/with}}
66
{{/each}}
77

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

0 commit comments

Comments
 (0)