{"action":"opened","issue":{"url":"https://api.github.com/repos/OpenAPITools/openapi-generator/issues/618","repository_url":"https://api.github.com/repos/OpenAPITools/openapi-generator","labels_url":"https://api.github.com/repos/OpenAPITools/openapi-generator/issues/618/labels{/name}","comments_url":"https://api.github.com/repos/OpenAPITools/openapi-generator/issues/618/comments","events_url":"https://api.github.com/repos/OpenAPITools/openapi-generator/issues/618/events","html_url":"https://github.com/OpenAPITools/openapi-generator/issues/618","id":343392207,"node_id":"MDU6SXNzdWUzNDMzOTIyMDc=","number":618,"title":"Discussion, Enhancement: customisation of generated structure through templating","user":{"login":"rienafairefr","id":758517,"node_id":"MDQ6VXNlcjc1ODUxNw==","avatar_url":"https://avatars2.githubusercontent.com/u/758517?v=4","gravatar_id":"","url":"https://api.github.com/users/rienafairefr","html_url":"https://github.com/rienafairefr","followers_url":"https://api.github.com/users/rienafairefr/followers","following_url":"https://api.github.com/users/rienafairefr/following{/other_user}","gists_url":"https://api.github.com/users/rienafairefr/gists{/gist_id}","starred_url":"https://api.github.com/users/rienafairefr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rienafairefr/subscriptions","organizations_url":"https://api.github.com/users/rienafairefr/orgs","repos_url":"https://api.github.com/users/rienafairefr/repos","events_url":"https://api.github.com/users/rienafairefr/events{/privacy}","received_events_url":"https://api.github.com/users/rienafairefr/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-22T09:39:05Z","updated_at":"2018-07-22T09:39:05Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"I've been thinking about some discussion/PR/issues (e.g. #470, #586, PR #580, #591 ), or others, and I felt that right now when you want to customise anything about the generated code that doesn't fit into the directory structure that have been defined in the java *Codegen class, you're stuck. \r\n\r\nThe tool allow people to specify a template directory to customise the output of the tool, by changing the templates. Why not allow them to modify the directory structure by also specifying a template ? I've pushed a PR to show a bit what I mean (\r\n\r\nRight now, the folder where models are generated, the folder where model docs/model tests, the location of the supporting Files, all of this is defined in Java. But with this, if there is a `structure.mustache` template, then the structure is defined by the folders/files hierarchy defined in the result of that template. Right now the example implementation assumes that the structure.mustache generates a YAML file, but that's not mandatory.\r\n\r\nFor example, in order to add a supportingFile to the output, you can either do\r\n```\r\nsupportingFiles.add(new SupportingFile(\"tox.mustache\", \"\", \"tox.ini\"));\r\n```\r\nin the java *Codegen code, or you can have your structure.mustache be like\r\n```\r\nsupportingFiles:\r\n  tox.ini: tox.mustache\r\n```\r\nThis way, it's painless (no java code modification) if you want to put a certain supporting file somewhere else, example\r\n```\r\nsupportingFiles:\r\n  common_package:\r\n    __init__.py: __init__package.mustache\r\n      client.py: api_client.mustache\r\n```\r\nif you want to generate the common (a file that doesnt depend on the spec) package in a certain subfolder of your output folder\r\n\r\n## Positive points\r\n* We can reuse the templating knowledge to customise the directory structure itself\r\n* In time, we can remove a bunch of methods in CodegenConfig that force a certain directory structure\r\n* backward compatibility (if there is no `structure.mustache` template then the generation is unchanged)\r\n\r\n## Negative points\r\n* Specifying model and api files (i.e. generate a bunch of files for each api or each model, docs for each, tests for each, etc) is not really intuitive in that model (the filename is the suffix for the file, the name of the file is still decided by the `config.toModelFilename(` and similar methods\r\nMaybe a template in a template ?\r\n\r\n\r\n```\r\napis:\r\n  {{ packageName }}:\r\n    api:\r\n{{=<% %>=}}\r\n      {{ apiFilename }}.py: api.mustache\r\n<%={{ }}=%>\r\n```"}}
{"actor":{"display_login":"rienafairefr"}}