Open reubentonna opened 6 years ago
The issues seems to be in DefaultGenerator.java line 1013 method getHandlebars.
The first part of this method has teh logic:
if (tempalteFile.startsWith(config.templateDir())) { templateFile = tempalteFile.replaceFirst(config.templateDir(0, StringUtils.Empty); }
template file is: v2\Java\model.mustache template dir is: v2\Java
This only happens in Windows for me, and I think has to do with the backslashes being misinterpreted in the replaceFirst()
first parameter which is supposed to be a regex string...
I have received the same error reliably in Windows, although the same commands work fine in macOs.
swagger-codegen-cli-3.0.0-20180523.181249-69.jar
My command line is
java -jar swagger-codegen-cli-3.0.0-SNAPSHOT.jar generate -i ./spec/openapi.yaml -l jaxrs-cxf -Dmodels --model-package com.testing.models -t C:\TestCodeGen\codegen\template
And my error message is:
Thread-1] INFO io.swagger.codegen.ignore.CodegenIgnoreProcessor - No .swagger-codegen-ignore file found.
[Thread-1] INFO io.swagger.codegen.languages.java.AbstractJavaCodegen - Invoker Package Name, originally not set, is now dervied from model package name: com.grainger.keepstock
Exception in thread "Thread-1" java.lang.RuntimeException: Could not generate model 'Audit'
at io.swagger.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:409)
at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:728)
at io.swagger.codegen.cmd.Generate.run(Generate.java:331)
at java.lang.Thread.run(Unknown Source)
Caused by: java.util.regex.PatternSyntaxException: Illegal/unsupported escape sequence near index 3
C:\TestCodeGen\codegen\template
^
at java.util.regex.Pattern.error(Unknown Source)
at java.util.regex.Pattern.escape(Unknown Source)
at java.util.regex.Pattern.atom(Unknown Source)
at java.util.regex.Pattern.sequence(Unknown Source)
at java.util.regex.Pattern.expr(Unknown Source)
at java.util.regex.Pattern.compile(Unknown Source)
at java.util.regex.Pattern.<init>(Unknown Source)
at java.util.regex.Pattern.compile(Unknown Source)
at java.lang.String.replaceFirst(Unknown Source)
at io.swagger.codegen.DefaultGenerator.getHandlebars(DefaultGenerator.java:1014)
at io.swagger.codegen.DefaultGenerator.processTemplateToFile(DefaultGenerator.java:744)
at io.swagger.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:396)
... 3 more
This happens in Windows 7 and Windows 10, JRE 8 or 9.
I will try to make a local build and fix the line.
Replacing the replaceFirst()
with StringUtils.replaceOnce()
in DefaultGenerator:1014
fixes the problem for Windows...
private com.github.jknack.handlebars.Template getHandlebars(String templateFile) throws IOException {
if (templateFile.startsWith(config.templateDir())) {
// templateFile = templateFile.replaceFirst(config.templateDir(), StringUtils.EMPTY);
templateFile = StringUtils.replaceOnce(templateFile, config.templateDir(), StringUtils.EMPTY);
}
@bigtlb - swagger-codegen 3.0.0 rc1 does not seem to have this fix. Do you know if it made to that release candidate? Running into this same exact issue and cant seem to download latest source with that line.
hey @bigtlb @murthy5 can you please try with https://github.com/swagger-api/swagger-codegen/releases/tag/v3.0.0 and let me know if there is something wrong?
I have added a fix for this issue in another GitHub issue which is about the same topic. #8273
Hello, I am still experiencing this issue with the following versions on Windows: swagger-codegen: 3.0.8
Frustrating that this is still an open issue 3 years later. Here's my stack trace:
[ERROR] java.lang.RuntimeException: Could not generate model 'CollimatorType' at io.swagger.codegen.DefaultGenerator.generateModels (DefaultGenerator.java:409) at io.swagger.codegen.DefaultGenerator.generate (DefaultGenerator.java:728) at io.swagger.codegen.plugin.CodeGenMojo.execute (CodeGenMojo.java:534) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager .java:137) at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:370) at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:351) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:171) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:163) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModule Builder.java:117) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModule Builder.java:81) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build ( SingleThreadedBuilder.java:56) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:294) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293) at org.apache.maven.cli.MavenCli.main (MavenCli.java:196) at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:498) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347) Caused by: java.util.regex.PatternSyntaxException: Illegal/unsupported escape sequence near ind ex 3 v2\Java ^ at java.util.regex.Pattern.error (Pattern.java:1969) at java.util.regex.Pattern.escape (Pattern.java:2485) at java.util.regex.Pattern.atom (Pattern.java:2212) at java.util.regex.Pattern.sequence (Pattern.java:2144) at java.util.regex.Pattern.expr (Pattern.java:2010) at java.util.regex.Pattern.compile (Pattern.java:1702) at java.util.regex.Pattern.<init> (Pattern.java:1352) at java.util.regex.Pattern.compile (Pattern.java:1028) at java.lang.String.replaceFirst (String.java:2178) at io.swagger.codegen.DefaultGenerator.getHandlebars (DefaultGenerator.java:1014) at io.swagger.codegen.DefaultGenerator.processTemplateToFile (DefaultGenerator.java:744) at io.swagger.codegen.DefaultGenerator.generateModels (DefaultGenerator.java:396) at io.swagger.codegen.DefaultGenerator.generate (DefaultGenerator.java:728) at io.swagger.codegen.plugin.CodeGenMojo.execute (CodeGenMojo.java:534) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager .java:137) at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:370) at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:351) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:171) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:163) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModule Builder.java:117) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModule Builder.java:81) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build ( SingleThreadedBuilder.java:56) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:294) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293) at org.apache.maven.cli.MavenCli.main (MavenCli.java:196) at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:498) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Description
When I try to generate java stubs from a simple yml api definition I am getting the following error.
I am able to generate using other language types - but were hoping that the "java" language option will yield a set of stubs that are framework agnostic. I would like the generated stubs to be simply the model and an interface for the service.
Exception in thread "Thread-1" java.lang.RuntimeException: Could not generate model 'AppConfig' at io.swagger.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:409) at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:728) at io.swagger.codegen.cmd.Generate.run(Generate.java:331) at java.lang.Thread.run(Unknown Source) Caused by: java.util.regex.PatternSyntaxException: Illegal/unsupported escape sequence near index 3 v2\Java ^ at java.util.regex.Pattern.error(Unknown Source) at java.util.regex.Pattern.escape(Unknown Source) at java.util.regex.Pattern.atom(Unknown Source) at java.util.regex.Pattern.sequence(Unknown Source) at java.util.regex.Pattern.expr(Unknown Source) at java.util.regex.Pattern.compile(Unknown Source) at java.util.regex.Pattern.(Unknown Source)
at java.util.regex.Pattern.compile(Unknown Source)
at java.lang.String.replaceFirst(Unknown Source)
at io.swagger.codegen.DefaultGenerator.getHandlebars(DefaultGenerator.java:1014)
at io.swagger.codegen.DefaultGenerator.processTemplateToFile(DefaultGenerator.java:744)
at io.swagger.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:396)
... 3 more
Swagger-codegen version
swagger-codegen-cli-3.0.0-20180515.103456-67.jar
Swagger declaration file content or url
Command line used for generation
java -jar swagger-codegen-cli-3.0.0-20180515.103456-67.jar generate -l java -i sample.yml -o ./dest
Steps to reproduce
Just run the command above.
Related issues/PRs
Suggest a fix/enhancement