Skip to content

feat: Improve library interface #676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions end_to_end_tests/golden-record/my_test_api_client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
""" A client library for accessing My Test API """
from .client import AuthenticatedClient, Client

__all__ = (
"AuthenticatedClient",
"Client",
)
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,52 @@
from .test_inline_objects_json_body import TestInlineObjectsJsonBody
from .test_inline_objects_response_200 import TestInlineObjectsResponse200
from .validation_error import ValidationError

__all__ = (
"AFormData",
"AllOfSubModel",
"AllOfSubModelTypeEnum",
"AModel",
"AModelWithPropertiesReferenceThatAreNotObject",
"AnAllOfEnum",
"AnEnum",
"AnEnumWithNull",
"AnIntEnum",
"AnotherAllOfSubModel",
"AnotherAllOfSubModelType",
"AnotherAllOfSubModelTypeEnum",
"BodyUploadFileTestsUploadPost",
"BodyUploadFileTestsUploadPostAdditionalProperty",
"BodyUploadFileTestsUploadPostSomeNullableObject",
"BodyUploadFileTestsUploadPostSomeObject",
"BodyUploadFileTestsUploadPostSomeOptionalObject",
"DifferentEnum",
"FreeFormModel",
"GetLocationHeaderTypesIntEnumHeader",
"GetLocationHeaderTypesStringEnumHeader",
"HTTPValidationError",
"Import",
"ModelFromAllOf",
"ModelName",
"ModelReferenceWithPeriods",
"ModelWithAdditionalPropertiesInlined",
"ModelWithAdditionalPropertiesInlinedAdditionalProperty",
"ModelWithAdditionalPropertiesRefed",
"ModelWithAnyJsonProperties",
"ModelWithAnyJsonPropertiesAdditionalPropertyType0",
"ModelWithDateTimeProperty",
"ModelWithPrimitiveAdditionalProperties",
"ModelWithPrimitiveAdditionalPropertiesADateHolder",
"ModelWithPropertyRef",
"ModelWithUnionProperty",
"ModelWithUnionPropertyInlined",
"ModelWithUnionPropertyInlinedFruitType0",
"ModelWithUnionPropertyInlinedFruitType1",
"None_",
"PostFormDataInlineData",
"PostResponsesUnionsSimpleBeforeComplexResponse200",
"PostResponsesUnionsSimpleBeforeComplexResponse200AType1",
"TestInlineObjectsJsonBody",
"TestInlineObjectsResponse200",
"ValidationError",
)
5 changes: 5 additions & 0 deletions integration-tests/integration_tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
""" A client library for accessing OpenAPI Test Server """
from .client import AuthenticatedClient, Client

__all__ = (
"AuthenticatedClient",
"Client",
)
8 changes: 8 additions & 0 deletions integration-tests/integration_tests/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@
from .post_parameters_header_response_200 import PostParametersHeaderResponse200
from .problem import Problem
from .public_error import PublicError

__all__ = (
"PostBodyMultipartMultipartData",
"PostBodyMultipartResponse200",
"PostParametersHeaderResponse200",
"Problem",
"PublicError",
)
5 changes: 4 additions & 1 deletion openapi_python_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,14 @@ def _build_models(self) -> None:
models_dir.mkdir()
models_init = models_dir / "__init__.py"
imports = []
alls = []

model_template = self.env.get_template("model.py.jinja")
for model in self.openapi.models:
module_path = models_dir / f"{model.class_info.module_name}.py"
module_path.write_text(model_template.render(model=model), encoding=self.file_encoding)
imports.append(import_string_from_class(model.class_info))
alls.append(model.class_info.name)

# Generate enums
str_enum_template = self.env.get_template("str_enum.py.jinja")
Expand All @@ -250,9 +252,10 @@ def _build_models(self) -> None:
else:
module_path.write_text(str_enum_template.render(enum=enum), encoding=self.file_encoding)
imports.append(import_string_from_class(enum.class_info))
alls.append(enum.class_info.name)

models_init_template = self.env.get_template("models_init.py.jinja")
models_init.write_text(models_init_template.render(imports=imports), encoding=self.file_encoding)
models_init.write_text(models_init_template.render(imports=imports, alls=alls), encoding=self.file_encoding)

def _build_api(self) -> None:
# Generate Client
Expand Down
8 changes: 8 additions & 0 deletions openapi_python_client/templates/models_init.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@
{% for import in imports | sort %}
{{ import }}
{% endfor %}

{% if imports %}
__all__ = (
{% for all in alls | sort %}
"{{ all }}",
{% endfor %}
)
{% endif %}
5 changes: 5 additions & 0 deletions openapi_python_client/templates/package_init.py.jinja
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
""" {{ package_description }} """
from .client import AuthenticatedClient, Client

__all__ = (
"AuthenticatedClient",
"Client",
)