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.79k stars 6.02k forks source link

[Java] Tags are not sanitized, yielding code that does not compile #1091

Closed who closed 8 years ago

who commented 8 years ago

If tags in a swagger spec contain a space, the java client generated by swagger-codegen will not compile.

Here is an example/repro (requires mvn, java) :

1. Make a temporary working directory

cd `mktemp -d /tmp/tmp.XXXXXXX`

2. Download swagger-codegen-cli.jar

mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:get  -DremoteRepositories=https://oss.sonatype.org/content/repositories/snapshots -Dartifact=io.swagger:swagger-codegen-cli:LATEST -Ddest=swagger-codegen-cli.jar

3. Invoke swagger-codegen-cli

java -jar swagger-codegen-cli.jar generate -l java -i https://gist.githubusercontent.com/who/5c4a962a2c5c200fe7bf/raw/62da511bfc668dc21944e9c1a474584af8db782b/spaced_tags.json

4. Compile the output

mvn compile

Result:

...
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project swagger-java-client: Compilation failure
[ERROR] /tmp/tmp.rNzUxyNeyy/src/main/java/io/swagger/client/api/FooBarApi.java:[8,0] error: package io.swagger.client.model does not exist
...
who commented 8 years ago

This was a red herring. My spec contained spaces in the tag names, but that wasn't the issue; the problem was that my spec did not contain any definitions, as everything was simple objects inline.