DATAMONGO-2282 - Add shortcut to create JsonSchemaProperty for ObjectId.
Original pull request: #757.
This commit is contained in:
committed by
Mark Paluch
parent
d937460351
commit
2a6107fcb6
@@ -90,6 +90,18 @@ public interface JsonSchemaProperty extends JsonSchemaObject {
|
||||
return new ObjectJsonSchemaProperty(identifier, JsonSchemaObject.object());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link JsonSchemaProperty} with given {@literal identifier} of {@code bsonType : 'objectId'}.
|
||||
*
|
||||
* @param identifier the {@literal property} name or {@literal patternProperty} regex. Must not be {@literal null} nor
|
||||
* {@literal empty}.
|
||||
* @return new instance of {@link JsonSchemaProperty}.
|
||||
* @since 2.2
|
||||
*/
|
||||
static JsonSchemaProperty objectId(String identifier) {
|
||||
return JsonSchemaProperty.named(identifier).ofType(Type.objectIdType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link NumericJsonSchemaProperty} with given {@literal identifier} of {@code type : 'number'}.
|
||||
*
|
||||
|
||||
@@ -63,4 +63,9 @@ public class JsonSchemaPropertyUnitTests {
|
||||
public void shouldRenderTimestampCorrectly() {
|
||||
assertThat(JsonSchemaProperty.timestamp("foo").toDocument()).containsEntry("foo.bsonType", "timestamp");
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2282
|
||||
public void objectIdShouldBeRenderedCorrectly() {
|
||||
assertThat(JsonSchemaProperty.objectId("_id").toDocument()).containsEntry("_id.bsonType", "objectId");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user