OpenAPITools / OpenAPITools/openapi-generator

[BUG][gradle plugin] User-defined templates do not work with the gradle plugin

Open
#13,705 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description

Following the instructions from the documentation:
https://github.com/OpenAPITools/openapi-generator/blob/master/docs/templating.md

I got the CLI, created the following config.json file:

{
  "generatorName": "typescript-angular",
  "inputSpec": "spec.json",
  "outputDir": "gen",
  "templateDir": "templates",
  "files": {
    "AUTHORS.md": {}
  }
}

Created the templates directory, added an empty AUTHORS.md file and executed the following command:
openapi-generator-cli generate -c config.json

This resulted in the expected generated typescript projet, witht he additional AUTHORS.md file.

Afterwards I tried to make the same change to my gradle configuration:

    task("openApiGenerateClient_spec", type: GenerateTask, group: 'openapi subtasks') {
        generatorName = "typescript-angular"
        inputSpec = "spec.json"
        outputDir = "gen"
        // lines below are newly added
        templateDir = "templates"
        files = {
            AUTHORS.md = {}
        }
    }

However, when I now run this task, I get the following error:

> Could not set unknown property 'files' for task ':openApiGenerateClient_spec' of type org.openapitools.generator.gradle.plugin.tasks.GenerateTask.

Which corresponds to the GenerateTask not having a files property:
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/GenerateTask.kt

openapi-generator version

6.2.0

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 modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/GenerateTask.kt and compare its configuration with the templating documentation and the working CLI config. Run the Gradle task from the reported example; done means the Gradle plugin accepts templateDir and files and generates AUTHORS.md.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.