[python-experimental] adds missing init files in endpoint modules (#12077)

* Adds mising init files inthe endpoint modules

* Reverts versin file

* Fixes test

* Samples regenerated
This commit is contained in:
Justin Black
2022-04-07 13:23:52 -07:00
committed by GitHub
parent fbe209ca84
commit 32295bf46f
11 changed files with 40 additions and 206 deletions

View File

@@ -434,6 +434,7 @@ public class PythonExperimentalClientCodegen extends AbstractPythonCodegen {
}
OperationMap operations = objs.getOperations();
List<CodegenOperation> codegenOperations = operations.getOperation();
Set<String> tagsNeedingInitFiles = new HashSet<>();
for (CodegenOperation co: codegenOperations) {
for (Tag tag: co.tags) {
String tagName = tag.getName();
@@ -445,6 +446,7 @@ public class PythonExperimentalClientCodegen extends AbstractPythonCodegen {
String templateName = "endpoint.handlebars";
String filename = endpointFilename(templateName, pythonTagName, co.operationId);
tagsNeedingInitFiles.add(pythonTagName);
try {
processTemplateToFile(operationMap, templateName, filename, true, CodegenConstants.APIS);
} catch (IOException e) {
@@ -452,6 +454,20 @@ public class PythonExperimentalClientCodegen extends AbstractPythonCodegen {
}
}
}
String templateName = "__init__api_endpoints.handlebars";
for (String tagNeedingInitFiles: tagsNeedingInitFiles) {
try {
Map<String, Object> operationMap = new HashMap<>();
String apiModuleName = toApiFilename(tagNeedingInitFiles);
operationMap.put("packageName", packageName);
operationMap.put("apiModuleName", apiModuleName);
operationMap.put("classname", toApiName(tagNeedingInitFiles));
String filename = endpointFilename(templateName, tagNeedingInitFiles, "__init__");
processTemplateToFile(operationMap, templateName, filename, true, CodegenConstants.APIS);
} catch (IOException e) {
LOGGER.error("Error when writing endpoint __init__ file {}", e.toString());
}
}
}
/*

View File

@@ -0,0 +1,3 @@
# do not import all endpoints into this module because that uses a lot of memory and stack frames
# if you need the ability to import all endpoints from this module, import them with
# from {{packageName}}.api.{{apiModuleName}} import {{classname}}

View File

@@ -0,0 +1,3 @@
# do not import all endpoints into this module because that uses a lot of memory and stack frames
# if you need the ability to import all endpoints from this module, import them with
# from petstore_api.api.another_fake_api import AnotherFakeApi

View File

@@ -0,0 +1,3 @@
# do not import all endpoints into this module because that uses a lot of memory and stack frames
# if you need the ability to import all endpoints from this module, import them with
# from petstore_api.api.default_api import DefaultApi

View File

@@ -0,0 +1,3 @@
# do not import all endpoints into this module because that uses a lot of memory and stack frames
# if you need the ability to import all endpoints from this module, import them with
# from petstore_api.api.fake_api import FakeApi

View File

@@ -0,0 +1,3 @@
# do not import all endpoints into this module because that uses a lot of memory and stack frames
# if you need the ability to import all endpoints from this module, import them with
# from petstore_api.api.fake_classname_tags123_api import FakeClassnameTags123Api

View File

@@ -1,170 +0,0 @@
# coding: utf-8
"""
Generated by: https://openapi-generator.tech
"""
from dataclasses import dataclass
import re # noqa: F401
import sys # noqa: F401
import typing
import urllib3
from urllib3._collections import HTTPHeaderDict
from petstore_api import api_client, exceptions
import decimal # noqa: F401
from datetime import date, datetime # noqa: F401
from frozendict import frozendict # noqa: F401
from petstore_api.schemas import ( # noqa: F401
AnyTypeSchema,
ComposedSchema,
DictSchema,
ListSchema,
StrSchema,
IntSchema,
Int32Schema,
Int64Schema,
Float32Schema,
Float64Schema,
NumberSchema,
DateSchema,
DateTimeSchema,
DecimalSchema,
BoolSchema,
BinarySchema,
NoneSchema,
none_type,
Configuration,
Unset,
unset,
ComposedBase,
ListBase,
DictBase,
NoneBase,
StrBase,
IntBase,
Int32Base,
Int64Base,
Float32Base,
Float64Base,
NumberBase,
DateBase,
DateTimeBase,
BoolBase,
BinaryBase,
Schema,
_SchemaValidator,
_SchemaTypeChecker,
_SchemaEnumMaker
)
from petstore_api.model.client import Client
# body param
SchemaForRequestBodyApplicationJson = Client
request_body_client = api_client.RequestBody(
content={
'application/json': api_client.MediaType(
schema=SchemaForRequestBodyApplicationJson),
},
required=True,
)
_path = '/fake_classname_test'
_method = 'PATCH'
_auth = [
'api_key_query',
]
SchemaFor200ResponseBodyApplicationJson = Client
@dataclass
class ApiResponseFor200(api_client.ApiResponse):
response: urllib3.HTTPResponse
body: typing.Union[
SchemaFor200ResponseBodyApplicationJson,
]
headers: Unset = unset
_response_for_200 = api_client.OpenApiResponse(
response_cls=ApiResponseFor200,
content={
'application/json': api_client.MediaType(
schema=SchemaFor200ResponseBodyApplicationJson),
},
)
_status_code_to_response = {
'200': _response_for_200,
}
_all_accept_content_types = (
'application/json',
)
class Classname(api_client.Api):
def classname(
self: api_client.Api,
body: typing.Union[SchemaForRequestBodyApplicationJson],
content_type: str = 'application/json',
accept_content_types: typing.Tuple[str] = _all_accept_content_types,
stream: bool = False,
timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
skip_deserialization: bool = False,
) -> typing.Union[
ApiResponseFor200,
api_client.ApiResponseWithoutDeserialization
]:
"""
To test class name in snake case
:param skip_deserialization: If true then api_response.response will be set but
api_response.body and api_response.headers will not be deserialized into schema
class instances
"""
_headers = HTTPHeaderDict()
# TODO add cookie handling
if accept_content_types:
for accept_content_type in accept_content_types:
_headers.add('Accept', accept_content_type)
if body is unset:
raise exceptions.ApiValueError(
'The required body parameter has an invalid value of: unset. Set a valid value instead')
_fields = None
_body = None
serialized_data = request_body_client.serialize(body, content_type)
_headers.add('Content-Type', content_type)
if 'fields' in serialized_data:
_fields = serialized_data['fields']
elif 'body' in serialized_data:
_body = serialized_data['body']
response = self.api_client.call_api(
resource_path=_path,
method=_method,
headers=_headers,
fields=_fields,
body=_body,
auth_settings=_auth,
stream=stream,
timeout=timeout,
)
if skip_deserialization:
api_response = api_client.ApiResponseWithoutDeserialization(response=response)
else:
response_for_status = _status_code_to_response.get(str(response.status))
if response_for_status:
api_response = response_for_status.deserialize(response, self.api_client.configuration)
else:
api_response = api_client.ApiResponseWithoutDeserialization(response=response)
if not 200 <= response.status <= 299:
raise exceptions.ApiException(api_response=api_response)
return api_response

View File

@@ -0,0 +1,3 @@
# do not import all endpoints into this module because that uses a lot of memory and stack frames
# if you need the ability to import all endpoints from this module, import them with
# from petstore_api.api.pet_api import PetApi

View File

@@ -0,0 +1,3 @@
# do not import all endpoints into this module because that uses a lot of memory and stack frames
# if you need the ability to import all endpoints from this module, import them with
# from petstore_api.api.store_api import StoreApi

View File

@@ -0,0 +1,3 @@
# do not import all endpoints into this module because that uses a lot of memory and stack frames
# if you need the ability to import all endpoints from this module, import them with
# from petstore_api.api.user_api import UserApi

View File

@@ -1,36 +0,0 @@
# coding: utf-8
"""
OpenAPI Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501
The version of the OpenAPI document: 1.0.0
Generated by: https://openapi-generator.tech
"""
import unittest
import petstore_api
from petstore_api.api.fake_classname_tags_123_api import FakeClassnameTags123Api # noqa: E501
class TestFakeClassnameTags123Api(unittest.TestCase):
"""FakeClassnameTags123Api unit test stubs"""
def setUp(self):
self.api = FakeClassnameTags123Api() # noqa: E501
def tearDown(self):
pass
def test_classname(self):
"""Test case for classname
To test class name in snake case # noqa: E501
"""
pass
if __name__ == '__main__':
unittest.main()