Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static Map<String, Object> bind(List<ItemParam> declarations, Map<String,
private static Object bindScalarRoot(ItemParam decl, Map<String, Object> body, boolean isArray) {
Object raw = body.get(decl.getName());
if (!isArray) {
return coerceOrNull(decl, raw, decl.getName(), true);
return coerceOrNull(decl, raw, decl.getName(), Boolean.TRUE.equals(decl.getRequired()));
}
List<Object> values = raw instanceof List ? (List<Object>) raw : null;
if (null == values || values.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,40 @@ public void missingRequiredThrowsCommonException() {
}
}

@Test
public void requiredScalarWithBlankValueIsStillMissing() {
Map<String, Object> body = new HashMap<>();
body.put("name", " ");

try {
DataTaskParamBinder.bind(
Collections.singletonList(simple("name", ParamTypeEnum.STRING, false, true, null)), body);
Assert.fail("expected CommonException");
} catch (CommonException e) {
Assert.assertEquals(ResponseErrorCode.ERROR_INVALID_ARGUMENT, e.getCode());
}
}

@Test
public void optionalScalarWithBlankValueIsOmittedNotMissing() {
Map<String, Object> body = new HashMap<>();
body.put("arrivalAtStart", "");

Map<String, Object> bound = DataTaskParamBinder.bind(
Collections.singletonList(simple("arrivalAtStart", ParamTypeEnum.STRING, false, false, null)), body);

Assert.assertTrue("optional blank scalar must not be reported missing", bound.isEmpty());
}

@Test
public void optionalScalarAbsentIsOmitted() {
Map<String, Object> bound = DataTaskParamBinder.bind(
Collections.singletonList(simple("arrivalAtStart", ParamTypeEnum.STRING, false, false, null)),
Collections.emptyMap());

Assert.assertTrue(bound.isEmpty());
}

@Test
public void defaultValueAppliesWhenAbsent() {
Map<String, Object> bound = DataTaskParamBinder.bind(
Expand Down
Loading