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

Commit 85d830c

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 642c346 commit 85d830c

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
@@ -83,7 +83,7 @@ public class PythonClientCodegen extends AbstractPythonCodegen {
8383

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

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

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

@@ -422,7 +422,8 @@ public void processOpts() {
422422

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

428429
supportingFiles.add(new SupportingFile("api_client." + templateExtension, packagePath(), "api_client.py"));
@@ -440,9 +441,17 @@ public void processOpts() {
440441
supportingFiles.add(new SupportingFile("schemas." + templateExtension, packagePath(), "schemas.py"));
441442

442443
// add the models and apis folders
443-
supportingFiles.add(new SupportingFile("__init__models." + templateExtension, packagePath() + File.separatorChar + "models", "__init__.py"));
444-
supportingFiles.add(new SupportingFile("__init__model." + templateExtension, packagePath() + File.separatorChar + modelPackage, "__init__.py"));
445-
supportingFiles.add(new SupportingFile("__init__apis." + templateExtension, packagePath() + File.separatorChar + apiPackage, "__init__.py"));
444+
String modelPackages = modelPackage + "s";
445+
supportingFiles.add(new SupportingFile("__init__." + templateExtension, packagePath() + File.separatorChar + "components" , "__init__.py"));
446+
boolean generateModels = (boolean) additionalProperties().get(CodegenConstants.GENERATE_MODELS);
447+
if (generateModels) {
448+
supportingFiles.add(new SupportingFile("__init__schemas." + templateExtension, packagePath() + File.separatorChar + modelPackages.replace('.', File.separatorChar), "__init__.py"));
449+
supportingFiles.add(new SupportingFile("__init__schema." + templateExtension, packagePath() + File.separatorChar + modelPackage.replace('.', File.separatorChar), "__init__.py"));
450+
}
451+
boolean generateApis = (boolean) additionalProperties().get(CodegenConstants.GENERATE_APIS);
452+
if (generateApis) {
453+
supportingFiles.add(new SupportingFile("__init__apis." + templateExtension, packagePath() + File.separatorChar + apiPackage, "__init__.py"));
454+
}
446455
// Generate the 'signing.py' module, but only if the 'HTTP signature' security scheme is specified in the OAS.
447456
Map<String, SecurityScheme> securitySchemeMap = openAPI != null ?
448457
(openAPI.getComponents() != null ? openAPI.getComponents().getSecuritySchemes() : null) : null;
@@ -669,21 +678,21 @@ protected void generateEndpoints(OperationsMap objs) {
669678
tagToApiMap.put("apiClassname", "Api");
670679
tagToApiMap.put("tagModuleNameToApiClassname", tagModuleNameToApiClassname);
671680
tagToApiMap.put("tagEnumToApiClassname", tagEnumToApiClassname);
672-
outputFilename = packageFilename(Arrays.asList("apis", "tag_to_api.py"));
681+
outputFilename = packageFilename(Arrays.asList(apiPackage, "tag_to_api.py"));
673682
apisFiles.add(Arrays.asList(tagToApiMap, "apis_tag_to_api.handlebars", outputFilename));
674683
// apis.path_to_api.py
675684
Map<String, Object> allByPathsFileMap = new HashMap<>();
676685
allByPathsFileMap.put("packageName", packageName);
677686
allByPathsFileMap.put("apiClassname", "Api");
678687
allByPathsFileMap.put("pathModuleToApiClassname", pathModuleToApiClassname);
679688
allByPathsFileMap.put("pathEnumToApiClassname", pathEnumToApiClassname);
680-
outputFilename = packageFilename(Arrays.asList("apis", "path_to_api.py"));
689+
outputFilename = packageFilename(Arrays.asList(apiPackage, "path_to_api.py"));
681690
apisFiles.add(Arrays.asList(allByPathsFileMap, "apis_path_to_api.handlebars", outputFilename));
682691
// apis.paths.__init__.py
683692
Map<String, Object> initApiTagsMap = new HashMap<>();
684693
initApiTagsMap.put("packageName", packageName);
685694
initApiTagsMap.put("enumToTag", enumToTag);
686-
outputFilename = packageFilename(Arrays.asList("apis", "tags", "__init__.py"));
695+
outputFilename = packageFilename(Arrays.asList(apiPackage, "tags", "__init__.py"));
687696
apisFiles.add(Arrays.asList(initApiTagsMap, "__init__apis_tags.handlebars", outputFilename));
688697

689698
// paths.__init__.py (contains path str enum)
@@ -694,7 +703,7 @@ protected void generateEndpoints(OperationsMap objs) {
694703
outputFilename = packageFilename(Arrays.asList("paths", "__init__.py"));
695704
pathsFiles.add(Arrays.asList(initOperationMap, "__init__paths_enum.handlebars", outputFilename));
696705
// apis.paths.__init__.py
697-
outputFilename = packageFilename(Arrays.asList("apis", "paths", "__init__.py"));
706+
outputFilename = packageFilename(Arrays.asList(apiPackage, "paths", "__init__.py"));
698707
apisFiles.add(Arrays.asList(initOperationMap, "__init__paths.handlebars", outputFilename));
699708
// paths.some_path.__init__.py
700709
// apis.paths.some_path.py
@@ -2580,7 +2589,7 @@ public String apiFileFolder() {
25802589

25812590
@Override
25822591
public String modelFileFolder() {
2583-
return outputFolder + File.separatorChar + packagePath() + File.separatorChar + modelPackage();
2592+
return outputFolder + File.separatorChar + packagePath() + File.separator + modelPackage().replace('.', File.separatorChar);
25842593
}
25852594

25862595
@Override
@@ -2590,7 +2599,7 @@ public String apiTestFileFolder() {
25902599

25912600
@Override
25922601
public String modelTestFileFolder() {
2593-
return outputFolder + File.separatorChar + testFolder + File.separatorChar + "test_models";
2602+
return outputFolder + File.separatorChar + testFolder + File.separatorChar + modelPackage.replace('.', File.separatorChar);
25942603
}
25952604

25962605
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)