DATAMONGO-2613 - Fix single element ArrayJsonSchemaObject to document mapping.
Now toDocument calls toDocument on items correctly. Original Pull Request: #883
This commit is contained in:
committed by
Christoph Strobl
parent
553912a380
commit
25840d61fc
@@ -41,6 +41,7 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
* @author Michał Kurcius
|
||||
* @since 2.1
|
||||
*/
|
||||
public class TypedJsonSchemaObject extends UntypedJsonSchemaObject {
|
||||
@@ -1194,7 +1195,7 @@ public class TypedJsonSchemaObject extends UntypedJsonSchemaObject {
|
||||
Document doc = new Document(super.toDocument());
|
||||
|
||||
if (!CollectionUtils.isEmpty(items)) {
|
||||
doc.append("items", items.size() == 1 ? items.iterator().next()
|
||||
doc.append("items", items.size() == 1 ? items.iterator().next().toDocument()
|
||||
: items.stream().map(JsonSchemaObject::toDocument).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import static org.springframework.data.mongodb.core.schema.JsonSchemaObject.of;
|
||||
import static org.springframework.data.mongodb.test.util.Assertions.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.junit.Test;
|
||||
@@ -33,6 +34,7 @@ import org.springframework.data.domain.Range.*;
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
* @author Michał Kurcius
|
||||
*/
|
||||
public class JsonSchemaObjectUnitTests {
|
||||
|
||||
@@ -209,6 +211,13 @@ public class JsonSchemaObjectUnitTests {
|
||||
.append("items", Arrays.asList(new Document("type", "string"), new Document("type", "boolean"))));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2613
|
||||
public void arrayObjectShouldRenderItemsCorrectlyAsObjectIfContainsOnlyOneElement() {
|
||||
|
||||
assertThat(array().items(Collections.singletonList(string())).toDocument()).isEqualTo(new Document("type", "array")
|
||||
.append("items", new Document("type", "string")));
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-1835
|
||||
public void arrayObjectShouldRenderMaxItemsCorrectly() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user