OpenAPITools / OpenAPITools/openapi-generator

[REQ] Specify folder for API and Model files

Open
#14,658 1 comment 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

The docs for user defined templates show folder being provided to control the directory a supporting file goes:

templateDir: my_custom_templates
additionalProperties:
  artifactId: kotlin-petstore-client
  serializableModel: "true"
  dateLibrary: java8
files:
  AUTHORS.md: {}
  api_interfaces.mustache:
    templateType: API
    destinationFilename: Interface.kt
  api.mustache:
    templateType: API
    destinationFilename: Impl.kt
  other/check.mustache:
    folder: scripts            <--------- FOLDER
    destinationFilename: check.sh
    templateType: SupportingFiles

This is really useful. However, folder cannot be specified for any other template types (I've only tried API and Model). The generator I'm using creates a whole project and I don't want to follow its directory structure, but I'm forced to right now.

Describe the solution you'd like

It would be great to be able to control the destination folder of all files specified in the config!

Describe alternatives you've considered

I don't see any complete workarounds. The aspnetcore generator, for example, puts API files in {output dir}/src/{packageName}/Controllers/. I have my own project and want generated files to go in {my project dir}/Generated/. I've used .openapi-generator-ignore to skip generating project files, set the output dir to be the project root, and configured src to be Generated. This means my API files are put in {my project dir}/Generated/{packageName}/Controllers. This is better, but I'd really like {output dir} to be Generated/ and have API files go into API/ not Controllers/ so overall my API files would go in {my project dir}/Generated/API/. Same for all of the other template types.

EDIT/UPDATE: Just in case anyone comes across this, I was able to get the aspnetcore generator to skip the extra directory by specifying sourceFolder: .. and packageName: Generated under additionalProperties in my config.yaml. I then used a custom property to specify the actual package name and used it in place of packageName in the templates.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the user-defined templates customization documentation and the configuration handling for the API and Model template types. Compare their folder behavior with SupportingFiles, using the aspnetcore generator and config.yaml examples mentioned in the issue. Done means folder can control the destination for every configured template type, including API and Model files.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, yaml
Domain
api, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.