Skip to content

Commit 8bc519b

Browse files
committed
fix, test for #1070
1 parent 280da07 commit 8bc519b

File tree

4 files changed

+41
-17
lines changed

4 files changed

+41
-17
lines changed

modules/swagger-jaxrs/src/main/java/com/wordnik/swagger/jaxrs/ParameterProcessor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.wordnik.swagger.jaxrs;
22

3+
import com.wordnik.swagger.util.Json;
4+
35
import java.lang.annotation.Annotation;
46
import java.lang.reflect.Method;
57
import java.util.EnumMap;
@@ -108,7 +110,6 @@ public static Parameter applyAnnotations(Swagger swagger, Parameter parameter, C
108110
} else {
109111
innerType = cls.getComponentType();
110112
}
111-
LOGGER.debug("inner type: " + innerType + " from " + cls);
112113
Property innerProperty = ModelConverters.getInstance().readAsProperty(innerType);
113114
if(innerProperty == null) {
114115
Map<String, Model> models = ModelConverters.getInstance().read(innerType);
@@ -168,6 +169,8 @@ public static Parameter applyAnnotations(Swagger swagger, Parameter parameter, C
168169
if(prop != null) {
169170
ModelImpl model = new ModelImpl();
170171
model.setType(prop.getType());
172+
model.setFormat(prop.getFormat());
173+
model.setDescription(prop.getDescription());
171174
bp.setSchema(model);
172175
}
173176
}

modules/swagger-jaxrs/src/test/scala/SimpleScannerTest.scala

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,30 @@ class SimpleScannerTest extends FlatSpec with Matchers {
295295
swagger.getDefinitions().containsKey("Description") should be (true)
296296
}
297297

298+
it should "scan defaultValue and required per #937" in {
299+
val swagger = new Reader(new Swagger()).read(classOf[Resource937])
300+
val get = swagger.getPaths().get("/external/info").getGet()
301+
val param = get.getParameters().get(0).asInstanceOf[QueryParameter]
302+
param.getRequired should be (false)
303+
param.getDefaultValue should be ("dogs")
304+
}
305+
306+
it should "scan a resource with all hidden values #1073" in {
307+
val swagger = new Reader(new Swagger()).read(classOf[Resource1073])
308+
swagger.getPaths() should be (null)
309+
}
310+
}
311+
312+
@RunWith(classOf[JUnitRunner])
313+
class SimpleScannerTest2 extends FlatSpec with Matchers {
298314
it should "scan a resource with body parameters" in {
299315
val swagger = new Reader(new Swagger()).read(classOf[ResourceWithBodyParams])
316+
val param = swagger.getPaths().get("/testShort").getPost().getParameters().get(0).asInstanceOf[BodyParameter]
317+
param.getDescription() should be ("a short input")
318+
val schema = param.getSchema.asInstanceOf[ModelImpl]
319+
320+
schema.getType() should be ("integer")
321+
schema.getFormat() should be ("int32")
300322

301323
swagger.getDefinitions().keySet().asScala should be (Set("Tag"))
302324

@@ -326,18 +348,4 @@ class SimpleScannerTest extends FlatSpec with Matchers {
326348
item.getParameters().size() should be (1)
327349
}
328350
}
329-
330-
it should "scan defaultValue and required per #937" in {
331-
val swagger = new Reader(new Swagger()).read(classOf[Resource937])
332-
val get = swagger.getPaths().get("/external/info").getGet()
333-
val param = get.getParameters().get(0).asInstanceOf[QueryParameter]
334-
param.getRequired should be (false)
335-
param.getDefaultValue should be ("dogs")
336-
}
337-
338-
it should "scan a resource with all hidden values #1073" in {
339-
val swagger = new Reader(new Swagger()).read(classOf[Resource1073])
340-
Json.prettyPrint(swagger)
341-
}
342-
}
343-
351+
}

modules/swagger-jaxrs/src/test/scala/resources/ResourceWithBodyParams.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void testPrimitiveBytes(byte[] input) {
7575
@POST
7676
@Path("/testShort")
7777
@ApiOperation("Tests parameter of the short type")
78-
public void testPrimitiveShort(short input) {
78+
public void testPrimitiveShort(@ApiParam(value = "a short input") short input) {
7979
}
8080

8181
@POST

modules/swagger-models/src/main/java/com/wordnik/swagger/models/ModelImpl.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
public class ModelImpl extends AbstractModel {
1515
public static final String OBJECT = "object";
1616
private String type;
17+
private String format;
1718
private String name;
1819
private List<String> required;
1920
private Map<String, Property> properties;
@@ -34,6 +35,11 @@ public ModelImpl type(String type) {
3435
return this;
3536
}
3637

38+
public ModelImpl format(String format) {
39+
this.setFormat(format);
40+
return this;
41+
}
42+
3743
public ModelImpl name(String name) {
3844
this.setName(name);
3945
return this;
@@ -108,6 +114,13 @@ public void setType(String type) {
108114
this.type = type;
109115
}
110116

117+
public String getFormat() {
118+
return format;
119+
}
120+
public void setFormat(String format) {
121+
this.format = format;
122+
}
123+
111124
public void addRequired(String name) {
112125
Property p = properties.get(name);
113126
if(p != null)

0 commit comments

Comments
 (0)