OpenAPITools / OpenAPITools/openapi-generator-cli

Unable to provide custom files for generation [BUG]

Open
#668 1 comment 1 reaction 1 assignee View on GitHub

@kay-schecker is already working on this.

Since Nov 1, 2022.

bug
Dominant language
TypeScript
Stars
2k
Forks
208
Avg merge
7h 12m
Merged PRs (30d)
6

Description

🐛 Bug Report:

Describe the bug

The openapi generator specifies the ability to provide custom files/templates (https://openapi-generator.tech/docs/customization).
This feature does not work with the current version of the CLI.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Install latest version of openapi-generator-cli (currently 5.4.0) npm install openapi-generator-cli@5.4.0

  2. Provide the following for the openapitools.json file (note the files keyword), e.g.

    {
        "$schema": "/path/to/schema",
        "generator-cli": {
            "version": "5.4.0",
            "generators": {
                 "nodejs": {
                     "templateDir": "#{cwd}/nodejs/templates",
                     "generator-name": "typescript",
                     "output": "#{cwd}/nodejs/sdk",
                     "inputSpec": "#{cwd}/openapi.json",
                     "additionalProperties": {
                        "esTargetVersion": "ES2020",
                        "moduleResolution": "nodejs",
                        "framework": "fetch-api",
                        "platform": "node",
                        "license": "MIT",
                        "useInversify": false,
                        "legacyDiscriminatorBehavior": false
                     },
                     "files": {
                         "api_test.mustache": {
                            "templateType": "ApiTests",
                            "destinationFilename": "spec/api_test.spec.ts"
                         }
                       }
                    }
                 }
            }
        }
    }
    
  3. Execute the generator
    openapi-generator-cli generate --generator-key nodejs

  4. See error

[[nodejs] #{cwd}/openapi.json] [error] Found unexpected parameters: [--files=api_test.mustache=[object Object]]
[[nodejs] #{cwd}/openapi.json] 
[[nodejs] #{cwd}/openapi.json] See 'openapi-generator-cli help' for usage.

  java -jar "node_modules/@openapitools/openapi-generator-cli/versions/5.4.0.jar" generate
--input-spec="/openapi.json"
--template-dir="/openapi-spec/nodejs/templates"
--generator-name="typescript" 
--output="/nodejs/sdk" 
--additional-properties="esTargetVersion=ES2020,moduleResolution=nodejs,framework=fetch-api,platform=node,license=MIT,useInversify=false,legacyDiscriminatorBehavior=false" 
--files="api_test.mustache=[object Object]" exited with code 1
Expected behavior

the "files" keyword gets resolved properly and all sub-properties are provided to the cli.

Operation System (please complete the following information):
  • OS: MacOS
  • Version 12.6.1
Package System (please complete the following information):
  • Version 5.4.0
Additional context

The typescript generator doesn't ship with a test runtime, so I was in the process of using the customization feature - ran into this instead.

Contributor guide

No contributing guide indexed for this repository

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.