diff --git a/client-runtime/src/main/java/com/microsoft/rest/Validator.java b/client-runtime/src/main/java/com/microsoft/rest/Validator.java index f5279021a..84ac58aea 100644 --- a/client-runtime/src/main/java/com/microsoft/rest/Validator.java +++ b/client-runtime/src/main/java/com/microsoft/rest/Validator.java @@ -56,15 +56,29 @@ public static void validate(Object parameter) { || parameterToken.isSupertypeOf(Period.class)) { return; } + if (TypeToken.of(List.class).isSupertypeOf(parameterType)) { + List items = (List) parameter; + for (Object item : items) { + Validator.validate(item); + } + } + else if (TypeToken.of(Map.class).isSupertypeOf(parameterType)) { + Map entries = (Map) parameter; + for (Map.Entry entry : entries.entrySet()) { + Validator.validate(entry.getKey()); + Validator.validate(entry.getValue()); + } + } + else { + Annotation skipParentAnnotation = parameterType.getAnnotation(SkipParentValidation.class); - Annotation skipParentAnnotation = parameterType.getAnnotation(SkipParentValidation.class); - - if (skipParentAnnotation == null) { - for (Class c : parameterToken.getTypes().classes().rawTypes()) { - validateClass(c, parameter); + if (skipParentAnnotation == null) { + for (Class c : parameterToken.getTypes().classes().rawTypes()) { + validateClass(c, parameter); + } + } else { + validateClass(parameterType, parameter); } - } else { - validateClass(parameterType, parameter); } } diff --git a/client-runtime/src/test/java/com/microsoft/rest/ValidatorTests.java b/client-runtime/src/test/java/com/microsoft/rest/ValidatorTests.java index 421881164..658d30108 100644 --- a/client-runtime/src/test/java/com/microsoft/rest/ValidatorTests.java +++ b/client-runtime/src/test/java/com/microsoft/rest/ValidatorTests.java @@ -98,6 +98,17 @@ public void validateList() throws Exception { } } + @Test + public void validateListParameter() throws Exception { + ListWrapper body = new ListWrapper(); + body.list = new ArrayList(); + Validator.validate(body); // pass + StringWrapper wrapper = new StringWrapper(); + wrapper.value = "valid"; + body.list.add(wrapper); + Validator.validate(body.list); // pass + } + @Test public void validateMap() throws Exception { MapWrapper body = new MapWrapper();