Merge remote-tracking branch 'swagger/develop_2.0' into php-upgrades

This commit is contained in:
nmonterroso 2015-06-22 20:29:09 -07:00
commit 61e368ce87
2 changed files with 34 additions and 0 deletions

View File

@ -144,6 +144,10 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
// replace - with _ e.g. created-at => created_at
name = name.replaceAll("-", "_");
if("_".equals(name)) {
name = "_u";
}
// if it's all uppper case, do nothing
if (name.matches("^[A-Z_]*$")) {
return name;

View File

@ -3,6 +3,7 @@ package Java
import io.swagger.codegen.languages.JavaClientCodegen
import io.swagger.models._
import io.swagger.models.properties._
import io.swagger.util.Json
import org.junit.runner.RunWith
import org.scalatest.{FlatSpec, Matchers}
import org.scalatest.junit.JUnitRunner
@ -344,3 +345,32 @@ class JavaModelTest extends FlatSpec with Matchers {
cm.classname should be("WithDots")
}
}
@RunWith(classOf[JUnitRunner])
class JavaModelTest2 extends FlatSpec with Matchers {
it should "translate an invalid param name" in {
val model = new ModelImpl()
.description("a model with a 2nd char upper-case property names")
.property("_", new StringProperty())
val codegen = new JavaClientCodegen()
val cm = codegen.fromModel("sample", model)
cm.name should be("sample")
cm.classname should be("Sample")
cm.vars.size should be(1)
val vars = cm.vars
Json.prettyPrint(vars.get(0))
vars.get(0).baseName should be("_")
vars.get(0).getter should be("getU")
vars.get(0).setter should be("setU")
vars.get(0).datatype should be("String")
vars.get(0).name should be("u")
vars.get(0).defaultValue should be("null")
vars.get(0).baseType should be("String")
vars.get(0).hasMore should equal(null)
vars.get(0).isNotContainer should equal(true)
}
}