Is your feature request related to a problem? Please describe.
The OpenAPI specs I'm generating clients from are a bit convoluted. Lots of models with few differences, resulting in a lot of models submodules and classes. To make the clients more developer-friendly, I'm wrapping all their endpoints in one class each, flattening the arguments in each method.
A typical example:
classDatasets(_API):
"""The datasets API."""defcreate(self, solution_id: Optional[str] =None) ->Dataset:
returndatasets_api.create_dataset(client=self.client, json_body=DatasetCreate(solution_id=solution_id))
# _API is a base class setting self.client# datasets_api is the generated datasets_client.api.default module# Dataset and DatasetCreate are generated models
As you can see I'm simplifying the name and usage:
fromdatasets_clientimportClientfromdatasets_client.apiimportdefaultasdatasets_apifromdatasets_client.modelsimportDatasetCreateclient=Client(...)
datasets_api.create_dataset(client, json_body=DatasetCreate(solution_id=solution_id))
datasets_api.other_method(client, *other_nested_args_and_models)
...becomes:
fromdatasets_clientimportClient, Datasetsdatasets=Datasets(Client(...))
datasets.create(solution_id) # don't pass client each timedatasets.other_method(*other_flat_args)
I can then wrap multiple classes like that into a main one:
classAPI:
def__init__(self, base_url, token):
self.base_url=base_urlself.datasets=Datasets(
client=AuthenticatedClient(base_url=self.base_url+"/rest-of-the-url", token=token)
)
self.other_api=OtherAPI(
client=AuthenticatedClient(base_url=self.base_url+"/rest-of-the-other-url", token=token)
)
...
In the end, a developer can just import and instantiate the API class, and start using every possible endpoint, without importing any model or endpoint themselves:
fromprojectimportAPIapi=API("http://example.com", "secret")
api.datasets.create(...)
api.other_api.check_status(...)Anyway! (just explaning my use case)
Describe the solution you'd like
I'm not asking you to change how to generate clients. Rather, I'd like to be able to "add" templates to the generation process, so I could automatically (re)generate these wrapper classes of mine, using openapi-python-client's Jinja context. Sorry for the long introduction 😅
It could be done with a command line option to tell openapi-python-client to render every template within the specified folder into the generated client. The directory structure would be respected, allowing the user to "inject" new contents in any subfolder of the generated client.
Describe alternatives you've considered
Improve the OpenAPI specs I'm using, but it would result in breaking changes, so a lot more work for many other people in my team and other teams 😮
Additional context
Maybe what I'm doing here is plain wrong and I'm losing benefits of the generated clients layouts? Don't hesitate to share on this matter 😄
Is your feature request related to a problem? Please describe.
The OpenAPI specs I'm generating clients from are a bit convoluted. Lots of models with few differences, resulting in a lot of models submodules and classes. To make the clients more developer-friendly, I'm wrapping all their endpoints in one class each, flattening the arguments in each method.
A typical example:
As you can see I'm simplifying the name and usage:
...becomes:
I can then wrap multiple classes like that into a main one:
In the end, a developer can just import and instantiate the API class, and start using every possible endpoint, without importing any model or endpoint themselves:
Anyway! (just explaning my use case)
Describe the solution you'd like
I'm not asking you to change how to generate clients. Rather, I'd like to be able to "add" templates to the generation process, so I could automatically (re)generate these wrapper classes of mine, using
openapi-python-client's Jinja context. Sorry for the long introduction 😅It could be done with a command line option to tell
openapi-python-clientto render every template within the specified folder into the generated client. The directory structure would be respected, allowing the user to "inject" new contents in any subfolder of the generated client.Describe alternatives you've considered
Improve the OpenAPI specs I'm using, but it would result in breaking changes, so a lot more work for many other people in my team and other teams 😮
Additional context
Maybe what I'm doing here is plain wrong and I'm losing benefits of the generated clients layouts? Don't hesitate to share on this matter 😄