Skip to content

feat: templatize api, endpoint init files #403

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

Closed
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
1 change: 1 addition & 0 deletions end_to_end_tests/custom-templates-golden-record/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
my-test-api-client
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
""" Contains methods for accessing the API """

from typing import Type

from my_test_api_client.api.default import DefaultEndpoints
from my_test_api_client.api.parameters import ParametersEndpoints
from my_test_api_client.api.tests import TestsEndpoints


class MyTestApiClientApi:
@classmethod
def tests(cls) -> Type[TestsEndpoints]:
return TestsEndpoints

@classmethod
def default(cls) -> Type[DefaultEndpoints]:
return DefaultEndpoints

@classmethod
def parameters(cls) -> Type[ParametersEndpoints]:
return ParametersEndpoints
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
""" Contains methods for accessing the API Endpoints """

import types

from my_test_api_client.api.default import get_common_parameters, post_common_parameters


class DefaultEndpoints:
@classmethod
def get_common_parameters(cls) -> types.ModuleType:
return get_common_parameters

@classmethod
def post_common_parameters(cls) -> types.ModuleType:
return post_common_parameters
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
""" Contains methods for accessing the API Endpoints """

import types

from my_test_api_client.api.parameters import get_same_name_multiple_locations_param


class ParametersEndpoints:
@classmethod
def get_same_name_multiple_locations_param(cls) -> types.ModuleType:
return get_same_name_multiple_locations_param
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
""" Contains methods for accessing the API Endpoints """

import types

from my_test_api_client.api.tests import (
defaults_tests_defaults_post,
get_basic_list_of_booleans,
get_basic_list_of_floats,
get_basic_list_of_integers,
get_basic_list_of_strings,
get_user_list,
int_enum_tests_int_enum_post,
json_body_tests_json_body_post,
no_response_tests_no_response_get,
octet_stream_tests_octet_stream_get,
optional_value_tests_optional_query_param,
post_form_data,
test_inline_objects,
token_with_cookie_auth_token_with_cookie_get,
unsupported_content_tests_unsupported_content_get,
upload_file_tests_upload_post,
)


class TestsEndpoints:
@classmethod
def get_user_list(cls) -> types.ModuleType:
"""
Get a list of things
"""
return get_user_list

@classmethod
def get_basic_list_of_strings(cls) -> types.ModuleType:
"""
Get a list of strings
"""
return get_basic_list_of_strings

@classmethod
def get_basic_list_of_integers(cls) -> types.ModuleType:
"""
Get a list of integers
"""
return get_basic_list_of_integers

@classmethod
def get_basic_list_of_floats(cls) -> types.ModuleType:
"""
Get a list of floats
"""
return get_basic_list_of_floats

@classmethod
def get_basic_list_of_booleans(cls) -> types.ModuleType:
"""
Get a list of booleans
"""
return get_basic_list_of_booleans

@classmethod
def post_form_data(cls) -> types.ModuleType:
"""
Post form data
"""
return post_form_data

@classmethod
def upload_file_tests_upload_post(cls) -> types.ModuleType:
"""
Upload a file
"""
return upload_file_tests_upload_post

@classmethod
def json_body_tests_json_body_post(cls) -> types.ModuleType:
"""
Try sending a JSON body
"""
return json_body_tests_json_body_post

@classmethod
def defaults_tests_defaults_post(cls) -> types.ModuleType:
"""
Defaults
"""
return defaults_tests_defaults_post

@classmethod
def octet_stream_tests_octet_stream_get(cls) -> types.ModuleType:
"""
Octet Stream
"""
return octet_stream_tests_octet_stream_get

@classmethod
def no_response_tests_no_response_get(cls) -> types.ModuleType:
"""
No Response
"""
return no_response_tests_no_response_get

@classmethod
def unsupported_content_tests_unsupported_content_get(cls) -> types.ModuleType:
"""
Unsupported Content
"""
return unsupported_content_tests_unsupported_content_get

@classmethod
def int_enum_tests_int_enum_post(cls) -> types.ModuleType:
"""
Int Enum
"""
return int_enum_tests_int_enum_post

@classmethod
def test_inline_objects(cls) -> types.ModuleType:
"""
Test Inline Objects
"""
return test_inline_objects

@classmethod
def optional_value_tests_optional_query_param(cls) -> types.ModuleType:
"""
Test optional query parameters
"""
return optional_value_tests_optional_query_param

@classmethod
def token_with_cookie_auth_token_with_cookie_get(cls) -> types.ModuleType:
"""
Test optional cookie parameters
"""
return token_with_cookie_auth_token_with_cookie_get
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
from ...client import Client
from ...models.body_upload_file_tests_upload_post import BodyUploadFileTestsUploadPost
from ...models.http_validation_error import HTTPValidationError
from ...types import UNSET, File, Response, Unset
from ...types import UNSET, Response, Unset


def _get_kwargs(
@@ -22,21 +22,14 @@ def _get_kwargs(
if keep_alive is not UNSET:
headers["keep-alive"] = keep_alive

files = {}
data = {}
for key, value in multipart_data.to_dict().items():
if isinstance(value, File):
files[key] = value
else:
data[key] = value
multipart_multipart_data = multipart_data.to_multipart()

return {
"url": url,
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
"files": files,
"data": data,
"files": multipart_multipart_data,
}


Original file line number Diff line number Diff line change
@@ -9,6 +9,10 @@
from .an_int_enum import AnIntEnum
from .another_all_of_sub_model import AnotherAllOfSubModel
from .body_upload_file_tests_upload_post import BodyUploadFileTestsUploadPost
from .body_upload_file_tests_upload_post_additional_property import BodyUploadFileTestsUploadPostAdditionalProperty
from .body_upload_file_tests_upload_post_some_nullable_object import BodyUploadFileTestsUploadPostSomeNullableObject
from .body_upload_file_tests_upload_post_some_object import BodyUploadFileTestsUploadPostSomeObject
from .body_upload_file_tests_upload_post_some_optional_object import BodyUploadFileTestsUploadPostSomeOptionalObject
from .different_enum import DifferentEnum
from .free_form_model import FreeFormModel
from .http_validation_error import HTTPValidationError
Loading