Skip to content

Commit b11d884

Browse files
committed
Merge pull request #1159 from tomtit/issue1155
Fixed #1155: Names inspection has been fixed.
2 parents 1ac4056 + c0a4e75 commit b11d884

File tree

3 files changed

+57
-8
lines changed

3 files changed

+57
-8
lines changed

modules/swagger-core/src/main/java/io/swagger/jackson/ModelResolver.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,13 @@ public Model resolve(JavaType type, ModelConverterContext context, Iterator<Mode
251251
if (member != null) {
252252
String altName = member.getName();
253253
if (altName != null) {
254-
if (altName.startsWith("get")) {
255-
if (!Character.isUpperCase(altName.charAt(3))) {
256-
propName = altName;
257-
}
258-
} else if (altName.startsWith("is")) {
259-
if (!Character.isUpperCase(altName.charAt(2))) {
254+
final int length = altName.length();
255+
for (String prefix : Arrays.asList("get", "is")) {
256+
final int offset = prefix.length();
257+
if (altName.startsWith(prefix) && length > offset
258+
&& !Character.isUpperCase(altName.charAt(offset))) {
260259
propName = altName;
260+
break;
261261
}
262262
}
263263
}

modules/swagger-core/src/test/scala/ModelConverterTest.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import org.junit.runner.RunWith
1212
import org.scalatest.{FlatSpec, Matchers}
1313
import org.scalatest.junit.JUnitRunner
1414

15+
import scala.collection.JavaConverters.asScalaSetConverter
1516
import scala.collection.JavaConverters.mapAsScalaMapConverter
1617

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

241242
it should "override the property name" in {
242243
val schemas = ModelConverters.getInstance().readAll(classOf[ModelWithAltPropertyName])
243-
val model = schemas.get("sample_model").asInstanceOf[ModelImpl]
244-
Json.prettyPrint(model)
244+
val properties = schemas.get("sample_model").asInstanceOf[ModelImpl].getProperties
245+
properties.get("id") should be (null)
246+
properties.get("the_id") should not be null
245247
}
246248

247249
it should "convert a model with enum array" in {
@@ -307,4 +309,10 @@ class ModelConverterTest extends FlatSpec with Matchers {
307309
property.getType should be("string")
308310
}
309311
}
312+
313+
it should "scan a model per #1155" in {
314+
var model = ModelConverters.getInstance().read(classOf[Model1155])
315+
model.get("Model1155").getProperties.keySet.asScala should be (Set("valid", "value", "is", "get", "isA", "getA",
316+
"is_persistent", "gettersAndHaters"))
317+
}
310318
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package models;
2+
3+
public class Model1155 {
4+
private boolean valid;
5+
private String value;
6+
public boolean is;
7+
public String get;
8+
public boolean isA;
9+
public String getA;
10+
11+
public boolean isValid() {
12+
return valid;
13+
}
14+
15+
public void setValid(boolean valid) {
16+
this.valid = valid;
17+
}
18+
19+
public String getValue() {
20+
return value;
21+
}
22+
23+
public void setValue(String value) {
24+
this.value = value;
25+
}
26+
27+
// jackson treats this as getter
28+
public boolean is_persistent() {
29+
return true;
30+
}
31+
32+
// jackson treats this as getter
33+
public String gettersAndHaters() {
34+
return null;
35+
}
36+
37+
// jackson doesn't treat this as getter
38+
boolean isometric() {
39+
return true;
40+
}
41+
}

0 commit comments

Comments
 (0)