Title: Extending/adding templates · Issue #171 · openapi-generators/openapi-python-client · GitHub
Open Graph Title: Extending/adding templates · Issue #171 · openapi-generators/openapi-python-client
X Title: Extending/adding templates · Issue #171 · openapi-generators/openapi-python-client
Description: 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 clie...
Open Graph Description: 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 ...
X Description: 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 mod...
Opengraph URL: https://github.com/openapi-generators/openapi-python-client/issues/171
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Extending/adding templates","articleBody":"**Is your feature request related to a problem? Please describe.**\r\nThe 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.\r\n\r\nA typical example:\r\n\r\n```python\r\nclass Datasets(_API):\r\n \"\"\"The datasets API.\"\"\"\r\n\r\n def create(self, solution_id: Optional[str] = None) -\u003e Dataset:\r\n return datasets_api.create_dataset(client=self.client, json_body=DatasetCreate(solution_id=solution_id))\r\n\r\n# _API is a base class setting self.client\r\n# datasets_api is the generated datasets_client.api.default module\r\n# Dataset and DatasetCreate are generated models\r\n```\r\n\r\nAs you can see I'm simplifying the name and usage:\r\n```python\r\nfrom datasets_client import Client\r\nfrom datasets_client.api import default as datasets_api\r\nfrom datasets_client.models import DatasetCreate\r\n\r\nclient = Client(...)\r\ndatasets_api.create_dataset(client, json_body=DatasetCreate(solution_id=solution_id))\r\ndatasets_api.other_method(client, *other_nested_args_and_models)\r\n```\r\n\r\n...becomes:\r\n\r\n```python\r\nfrom datasets_client import Client, Datasets\r\n\r\ndatasets = Datasets(Client(...))\r\ndatasets.create(solution_id) # don't pass client each time\r\ndatasets.other_method(*other_flat_args)\r\n```\r\n\r\nI can then wrap multiple classes like that into a main one:\r\n\r\n```python\r\nclass API:\r\n def __init__(self, base_url, token):\r\n self.base_url = base_url\r\n self.datasets = Datasets(\r\n client=AuthenticatedClient(base_url=self.base_url + \"/rest-of-the-url\", token=token)\r\n )\r\n self.other_api= OtherAPI(\r\n client=AuthenticatedClient(base_url=self.base_url + \"/rest-of-the-other-url\", token=token)\r\n )\r\n ...\r\n```\r\n\r\nIn 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:\r\n\r\n```python\r\nfrom project import API\r\n\r\napi = API(\"http://example.com\", \"secret\")\r\napi.datasets.create(...)\r\napi.other_api.check_status(...)\r\n```\r\n\r\nAnyway! (just explaning my use case)\r\n\r\n**Describe the solution you'd like**\r\nI'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 😅 \r\n\r\nIt 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.\r\n\r\n**Describe alternatives you've considered**\r\nImprove 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 😮 \r\n\r\n**Additional context**\r\nMaybe 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 😄 \r\n","author":{"url":"https://github.com/pawamoy","@type":"Person","name":"pawamoy"},"datePublished":"2020-08-28T08:56:03.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/171/openapi-python-client/issues/171"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:acf2c7d7-a523-99d9-cf1f-4790039fbb55 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A396:398A3A:C5AC8CD:FD4CF20:697F54E0 |
| html-safe-nonce | adf1fc6ef4f7ec1dc47a01805399b4b1569c3a7cc31d8b188459ea18ac88faff |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMzk2OjM5OEEzQTpDNUFDOENEOkZENENGMjA6Njk3RjU0RTAiLCJ2aXNpdG9yX2lkIjoiNDQwOTEzMTg4MzU5NDQ3MDYyNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 66a9c7e8bc0ec2dac573e6ec6dd7be2cab620459404f49f97030b9e81e4fed2d |
| hovercard-subject-tag | issue:687921712 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/openapi-generators/openapi-python-client/171/issue_layout |
| twitter:image | https://opengraph.githubassets.com/98283355996a99be97ea086acced8e9e07a0817242db71380365185e169b52f9/openapi-generators/openapi-python-client/issues/171 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/98283355996a99be97ea086acced8e9e07a0817242db71380365185e169b52f9/openapi-generators/openapi-python-client/issues/171 |
| og:image:alt | 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 ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pawamoy |
| hostname | github.com |
| expected-hostname | github.com |
| None | 60279d4097367e16897439d16d6bbe4180663db828c666eeed2656988ffe59f6 |
| turbo-cache-control | no-preview |
| go-import | github.com/openapi-generators/openapi-python-client git https://github.com/openapi-generators/openapi-python-client.git |
| octolytics-dimension-user_id | 84925606 |
| octolytics-dimension-user_login | openapi-generators |
| octolytics-dimension-repository_id | 240776275 |
| octolytics-dimension-repository_nwo | openapi-generators/openapi-python-client |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 240776275 |
| octolytics-dimension-repository_network_root_nwo | openapi-generators/openapi-python-client |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7c85641c598ad130c74f7bcc27f58575cac69551 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width