swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.98k stars 6.03k forks source link

[iOS][Swift5] Can't find template files #11121

Open AdrianZghibarta opened 3 years ago

AdrianZghibarta commented 3 years ago
Description

If I'll indicate a custom folder with template files for code generation, it will throw a file not found exception, more details bellow

Swagger-codegen version

3.0.26

Command line used for generation

swagger-codegen generate -i https://docs.helloreco.holiday/swagger/support.yaml -t handlebars -l swift5 -o TestOutput/

The handlebars is a folder located in /Users/username/Documents/project-ios/RecoSwaggerClient with this structure:

-- handlebars
     -- swift5
          -- model.mustache
          -- ... other mustache files

Result after running the command in /Users/username/Documents/project-ios/RecoSwaggerClient

13:42:18.248 [Thread-0] INFO  i.s.c.v.i.CodegenIgnoreProcessor - No .swagger-codegen-ignore file found.
Exception in thread "Thread-0" java.lang.RuntimeException: Could not generate model 'ApiErrorResponse'
    at io.swagger.codegen.v3.DefaultGenerator.generateModels(DefaultGenerator.java:451)
    at io.swagger.codegen.v3.DefaultGenerator.generate(DefaultGenerator.java:779)
    at io.swagger.codegen.v3.cli.cmd.Generate.run(Generate.java:378)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.io.FileNotFoundException: /Users/username/Documents/project-ios/RecoSwaggerClient/handlebars/handlebars/swift5/model.mustache
    at com.github.jknack.handlebars.io.URLTemplateLoader.sourceAt(URLTemplateLoader.java:70)
    at com.github.jknack.handlebars.Handlebars.compile(Handlebars.java:438)
    at com.github.jknack.handlebars.Handlebars.compile(Handlebars.java:419)
    at io.swagger.codegen.v3.templates.HandlebarTemplateEngine.getHandlebars(HandlebarTemplateEngine.java:52)
    at io.swagger.codegen.v3.templates.HandlebarTemplateEngine.getRendered(HandlebarTemplateEngine.java:25)
    at io.swagger.codegen.v3.DefaultGenerator.processTemplateToFile(DefaultGenerator.java:795)
    at io.swagger.codegen.v3.DefaultGenerator.generateModels(DefaultGenerator.java:438)
    ... 3 more

I had previously installed version 3.0.24 and all was working as expected, after updating to 3.0.24 I am having this error. It seems that it's trying to find the templates not directly in the indicated folder (from -t param). As well if I'll indicate another folder for -t param, let's say templates, it seems to use default templates and ignore the ones from fodler.

AdrianZghibarta commented 3 years ago

As well, is there any ways of downgrading to 3.0.24? I tried downloading the file from https://raw.githubusercontent.com/Homebrew/homebrew-core/e2c833d326c45d9aaf4e26af6dd8b2f31564dc04/Formula/swagger-codegen.rb and running brew install downloaded-file.rb .. but there are issues as well:

error: Failed to download resource "swagger-codegen_bottle_manifest"
Download failed: https://ghcr.io/v2/homebrew/core/swagger-codegen/manifests/3.0.24
eduardo-miranda-deltatre commented 3 years ago

try adding --template-engine mustache and in -t defining the exact relative folder, -t handlebars/swift5