Skip to content

Commit

Permalink
Merge pull request #1159 from tomtit/issue1155
Browse files Browse the repository at this point in the history
Fixed #1155: Names inspection has been fixed.
  • Loading branch information
webron committed Jul 14, 2015
2 parents 1ac4056 + c0a4e75 commit b11d884
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,13 @@ public Model resolve(JavaType type, ModelConverterContext context, Iterator<Mode
if (member != null) {
String altName = member.getName();
if (altName != null) {
if (altName.startsWith("get")) {
if (!Character.isUpperCase(altName.charAt(3))) {
propName = altName;
}
} else if (altName.startsWith("is")) {
if (!Character.isUpperCase(altName.charAt(2))) {
final int length = altName.length();
for (String prefix : Arrays.asList("get", "is")) {
final int offset = prefix.length();
if (altName.startsWith(prefix) && length > offset
&& !Character.isUpperCase(altName.charAt(offset))) {
propName = altName;
break;
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions modules/swagger-core/src/test/scala/ModelConverterTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.junit.runner.RunWith
import org.scalatest.{FlatSpec, Matchers}
import org.scalatest.junit.JUnitRunner

import scala.collection.JavaConverters.asScalaSetConverter
import scala.collection.JavaConverters.mapAsScalaMapConverter

@RunWith(classOf[JUnitRunner])
Expand Down Expand Up @@ -240,8 +241,9 @@ class ModelConverterTest extends FlatSpec with Matchers {

it should "override the property name" in {
val schemas = ModelConverters.getInstance().readAll(classOf[ModelWithAltPropertyName])
val model = schemas.get("sample_model").asInstanceOf[ModelImpl]
Json.prettyPrint(model)
val properties = schemas.get("sample_model").asInstanceOf[ModelImpl].getProperties
properties.get("id") should be (null)
properties.get("the_id") should not be null
}

it should "convert a model with enum array" in {
Expand Down Expand Up @@ -307,4 +309,10 @@ class ModelConverterTest extends FlatSpec with Matchers {
property.getType should be("string")
}
}

it should "scan a model per #1155" in {
var model = ModelConverters.getInstance().read(classOf[Model1155])
model.get("Model1155").getProperties.keySet.asScala should be (Set("valid", "value", "is", "get", "isA", "getA",
"is_persistent", "gettersAndHaters"))
}
}
41 changes: 41 additions & 0 deletions modules/swagger-core/src/test/scala/models/Model1155.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package models;

public class Model1155 {
private boolean valid;
private String value;
public boolean is;
public String get;
public boolean isA;
public String getA;

public boolean isValid() {
return valid;
}

public void setValid(boolean valid) {
this.valid = valid;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

// jackson treats this as getter
public boolean is_persistent() {
return true;
}

// jackson treats this as getter
public String gettersAndHaters() {
return null;
}

// jackson doesn't treat this as getter
boolean isometric() {
return true;
}
}

0 comments on commit b11d884

Please sign in to comment.