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

Commit 56524d6

Browse files
committed
v3 code reduction w/ shared_imports (#168)
* Adds typing_imports * Adds typing_imports for header and parameter * Updates request body imports * Adds response_imports * Adds schema_imports * Adds security_scheme_imports * Adds server imports * Adds operation_imports * typing_imports -> header_imports * Sample regen
1 parent 92c5c05 commit 56524d6

1,071 files changed

Lines changed: 1323 additions & 7947 deletions

File tree

Some content is hidden

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

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,15 @@ public void processOpts() {
704704

705705
supportingFiles.add(new SupportingFile("exceptions.hbs", packagePath(), "exceptions.py"));
706706

707+
// shared_imports
708+
supportingFiles.add(new SupportingFile("__init__.hbs", packagePath() + File.separator + "shared_imports", "__init__.py"));
709+
supportingFiles.add(new SupportingFile("shared_imports/header_imports.hbs", packagePath() + File.separator + "shared_imports", "header_imports.py"));
710+
supportingFiles.add(new SupportingFile("shared_imports/response_imports.hbs", packagePath() + File.separator + "shared_imports", "response_imports.py"));
711+
supportingFiles.add(new SupportingFile("shared_imports/schema_imports.hbs", packagePath() + File.separator + "shared_imports", "schema_imports.py"));
712+
supportingFiles.add(new SupportingFile("shared_imports/security_scheme_imports.hbs", packagePath() + File.separator + "shared_imports", "security_scheme_imports.py"));
713+
supportingFiles.add(new SupportingFile("shared_imports/server_imports.hbs", packagePath() + File.separator + "shared_imports", "server_imports.py"));
714+
supportingFiles.add(new SupportingFile("shared_imports/operation_imports.hbs", packagePath() + File.separator + "shared_imports", "operation_imports.py"));
715+
707716
if (Boolean.FALSE.equals(excludeTests)) {
708717
supportingFiles.add(new SupportingFile("__init__.hbs", testFolder, "__init__.py"));
709718
supportingFiles.add(new SupportingFile("__init__.hbs", testFolder + File.separator + modelPackage.replace('.', File.separatorChar), "__init__.py"));

modules/openapi-json-schema-generator/src/main/resources/python/_helper_imports_schema_types.hbs

Lines changed: 0 additions & 11 deletions
This file was deleted.

modules/openapi-json-schema-generator/src/main/resources/python/components/headers/header.hbs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@
1010
{{> _helper_imports }}
1111
{{jsonPathPiece.camelCase}} = {{refInfo.refModule}}.{{refInfo.refClass}}
1212
{{else}}
13-
{{#if content}}
14-
import typing, typing_extensions
15-
16-
{{/if}}
17-
from {{packageName}} import api_client
13+
from {{packageName}}.shared_imports.header_imports import *
1814
{{#if schema}}
15+
1916
{{#with schema}}
2017
from . import {{jsonPathPiece.snakeCase}}
2118
{{/with}}
2219
{{else}}
2320
{{#if content}}
21+
2422
{{#each content}}
2523
{{#with this}}
2624
{{#with schema}}

modules/openapi-json-schema-generator/src/main/resources/python/components/parameters/parameter.hbs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,15 @@
1010
{{> _helper_imports }}
1111
{{jsonPathPiece.camelCase}} = {{refInfo.refModule}}.{{refInfo.refClass}}
1212
{{else}}
13-
{{#if content}}
14-
import typing, typing_extensions
15-
16-
{{/if}}
17-
from {{packageName}} import api_client
18-
13+
from {{packageName}}.shared_imports.header_imports import *
1914
{{#if schema}}
15+
2016
{{#with schema}}
2117
from . import {{jsonPathPiece.snakeCase}}
2218
{{/with}}
2319
{{else}}
2420
{{#if content}}
21+
2522
{{#each content}}
2623
{{#with this}}
2724
{{#with schema}}

modules/openapi-json-schema-generator/src/main/resources/python/components/request_bodies/request_body.hbs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
{{> _helper_imports }}
1111
{{jsonPathPiece.camelCase}} = {{refInfo.refModule}}.{{refInfo.refClass}}
1212
{{else}}
13-
import typing, typing_extensions
13+
from {{packageName}}.shared_imports.header_imports import *
1414

15-
from {{packageName}} import api_client
1615
{{#each content}}
1716
{{#with this}}
1817
{{#with schema}}

modules/openapi-json-schema-generator/src/main/resources/python/components/responses/response.hbs

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,22 @@
1010
{{> _helper_imports }}
1111
{{jsonPathPiece.camelCase}} = {{refInfo.refModule}}.{{refInfo.refClass}}
1212
{{else}}
13-
import dataclasses
14-
{{#or content headers}}
15-
{{#if headers}}
16-
import datetime
17-
import decimal
18-
import io
19-
{{/if}}
20-
import typing
21-
{{#if headers}}
22-
import uuid
23-
{{/if}}
24-
25-
{{#if headers}}
26-
import frozendict
27-
{{/if}}
28-
import typing_extensions
29-
{{/or}}
30-
import urllib3
31-
32-
from {{packageName}} import api_client
33-
from {{packageName}} import schemas
13+
from {{packageName}}.shared_imports.response_imports import *
3414
{{#if content}}
15+
3516
{{#each content}}
3617
{{#with this.schema}}
3718
from .content.{{../@key.snakeCase}} import {{jsonPathPiece.snakeCase}} as {{../@key.snakeCase}}_{{jsonPathPiece.snakeCase}}
3819
{{/with}}
3920
{{/each}}
4021
{{/if}}
41-
{{#each headers}}
42-
from .headers import {{jsonPathPiece.snakeCase}}
43-
{{/each}}
4422
{{#if headers}}
23+
{{#unless content}}
24+
25+
{{/unless}}
26+
{{#each headers}}
27+
from .headers import {{jsonPathPiece.snakeCase}}
28+
{{/each}}
4529
{{> components/responses/_helper_header_schema_and_def xParams=headers xParamsName="Header" }}
4630
{{/if}}
4731

modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/schema.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
{{> _helper_imports }}
1111
{{> components/schemas/_helper_schema_switch_case identifierPieces=(append identifierPieces jsonPathPiece) }}
1212
{{else}}
13-
{{> _helper_imports_schema_types }}
13+
from {{packageName}}.shared_imports.schema_imports import *
1414
{{> components/schemas/_helper_schema_switch_case identifierPieces=(append identifierPieces jsonPathPiece) }}
1515
{{#if imports}}
1616

modules/openapi-json-schema-generator/src/main/resources/python/components/security_schemes/security_scheme.hbs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@
1010
{{> _helper_imports }}
1111
{{jsonPathPiece.camelCase}} = {{refInfo.refModule}}.{{refInfo.refClass}}
1212
{{else}}
13-
import dataclasses
14-
import typing
15-
import typing_extensions
16-
17-
from {{packageName}} import security_schemes
13+
from {{packageName}}.shared_imports.security_scheme_imports import *
1814

1915
{{#eq type "apiKey"}}
2016
@dataclasses.dataclass

modules/openapi-json-schema-generator/src/main/resources/python/paths/path/verb/operation.hbs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,7 @@ from {{packageName}}.security import (
2020
{{/gt}}
2121
{{/neq}}
2222
{{/eq}}
23-
import datetime # noqa: F401
24-
import decimal # noqa: F401
25-
import io # noqa: F401
26-
import typing # noqa: F401
27-
import typing_extensions # noqa: F401
28-
import uuid # noqa: F401
29-
30-
import frozendict # noqa: F401
31-
32-
from {{packageName}} import schemas # noqa: F401
23+
from {{packageName}}.shared_imports.operation_imports import *
3324
{{#if imports}}
3425

3526
{{/if}}

modules/openapi-json-schema-generator/src/main/resources/python/servers/server.hbs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
# coding: utf-8
22
{{> _helper_header }}
33

4-
import dataclasses
5-
import typing
6-
{{#if server.variables}}
7-
import typing_extensions
8-
{{/if}}
4+
from {{packageName}}.shared_imports.server_imports import *
95
{{#with server}}
10-
11-
from {{packageName}} import server{{#if variables}}, schemas{{/if}}
126
{{#if variables}}
137

148

0 commit comments

Comments
 (0)