OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.83k stars 6.59k forks source link

[REQ] Allow usage of custom TemplateTypes #8992

Open Symilan opened 3 years ago

Symilan commented 3 years ago

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

Hello !

I'm currently playing around a bit with the generation of a spring-boot web service from the petstore template to get more confident with openAPI generator in order to use it in a project, and here is my problem : I want to generate services from a .mustache I am working on, but there are only 7 TemplateTypes (API, APITests, APIDocs, Model, ModelTests, ModelDocs and SupportingFiles) that I can use through the 6 HashMaps corresponding (apiTemplateFiles, modelTemplateFiles, apiTestTemplateFiles, modelTestTemplateFiles, apiDocTemplateFiles, modelDocTemplateFiles) and none of them is appropriate.

Describe alternatives you've considered

A solution I thought could work is to choose APIDocs or APITests instead and just change the extension to Service.java, but the problem is that when I do that, the files are generated in a folder I don't seem to be able to choose, and the suffix "Api" is used even thought I didn't ask for it.

apiDocTemplateFiles.put( "service.mustache", "Service.sample");

image

Describe the solution you'd like

I think it would be a great addition if we were able to :

borsch commented 3 years ago

@Symilan if I get you question correctly then you have to use supportingFiles HashMap. See usage https://github.com/OpenAPITools/openapi-generator/search?q=supportingFiles

Symilan commented 3 years ago

The problem with supportingFiles is that it just generates one file, but I want to generate a file for each element of the model

notana commented 3 years ago

Another issue similar to this that my team has run into is that the folder config for custom files isn't respected (our issue is specifically for the typescript-fetch generator, but might be for other generators as well.

Example use case: We have set up a new doc file for each API endpoint to explain usage and parameters. Since we currently have 22 API definitions, this creates a lot of files so we want to move it out of the root folder. We tried using the folder parameter but that isn't respected when using the APIDocs template type.

files:
  docs/apis.mustache:
    templateType: APIDocs
    folder: docs/api
    destinationFilename: .md
tiagolobocastro commented 3 years ago

I was also wondering how to work around this issue. It now makes sense why some generators have "chunky" files. It would be nice to break those down for better code readability. For now I'm playing with using another extension, which though ugly because it's still in the same api dir does seem to "work around it":

        apiTemplateFiles.put("api.mustache", ".rs");
        apiTemplateFiles.put("handlers.mustache", "_handlers.rs");