Skip to content

Commit

Permalink
Added tests for item property creation
Browse files Browse the repository at this point in the history
Also rearranged methods to put public methods on top

related to #956
  • Loading branch information
dilipkrish committed Jan 2, 2016
1 parent 3ffb268 commit 7b30754
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public class ModelRef implements ModelReference {
private final Optional<ModelReference> itemModel;
private final Optional<AllowableValues> allowableValues;

public ModelRef(String type) {
this(type, null, null);
}

public ModelRef(String type, ModelReference itemType) {
this(type, itemType, false);
}
Expand All @@ -52,10 +56,6 @@ public ModelRef(String type, ModelReference itemModel, AllowableValues allowable
this.itemModel = Optional.fromNullable(itemModel);
}

public ModelRef(String type) {
this(type, null, null);
}

@Override
public String getType() {
return type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ public static Property property(final String typeName) {
return propertyLookup.apply(safeTypeName.toLowerCase()).apply(safeTypeName);
}

public static Ordering<String> defaultOrdering(Map<String, ModelProperty> properties) {
return Ordering.from(byPosition(properties)).compound(byName());
}

public static Property itemTypeProperty(ModelReference paramModel) {
if (paramModel.isCollection()) {
return new ArrayProperty(itemTypeProperty(paramModel.itemModel().get()));
}
return property(paramModel.getType());
}

private static <T extends Property> Function<String, T> newInstanceOf(final Class<T> clazz) {
return new Function<String, T>() {
@Override
Expand Down Expand Up @@ -122,10 +133,6 @@ public Property apply(String input) {
};
}

public static Ordering<String> defaultOrdering(Map<String, ModelProperty> properties) {
return Ordering.from(byPosition(properties)).compound(byName());
}

private static Comparator<String> byName() {
return new Comparator<String>() {
@Override
Expand All @@ -145,11 +152,4 @@ public int compare(String first, String second) {
}
};
}

public static Property itemTypeProperty(ModelReference paramModel) {
if (paramModel.isCollection()) {
return new ArrayProperty(itemTypeProperty(paramModel.itemModel().get()));
}
return property(paramModel.getType());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package springfox.documentation.swagger2.mappers

import io.swagger.models.properties.*
import springfox.documentation.schema.ModelRef

import static springfox.documentation.swagger2.mappers.Properties.*

Expand All @@ -26,6 +27,19 @@ class PropertiesSpec extends Specification {
byteProp instanceof StringProperty
byteProp.format == "byte"
}

def "Nested collection properties are supported" () {
when:
def prop = itemTypeProperty(ref)
then:
prop == expected
where:
ref | expected
new ModelRef("string") | new StringProperty()
new ModelRef("List", new ModelRef("string")) | new ArrayProperty(new StringProperty())
new ModelRef("List", new ModelRef("List", new ModelRef("string"))) | new ArrayProperty(new ArrayProperty(new StringProperty()))
}

def "Properties are inferred given the type as a string"() {
expect:
property(typeName).class.isAssignableFrom(expected)
Expand Down

0 comments on commit 7b30754

Please sign in to comment.