DATAMONGO-2282 - Add shortcut to create JsonSchemaProperty for ObjectId.

Original pull request: #757.
This commit is contained in:
Christoph Strobl
2019-05-22 12:07:27 +02:00
committed by Mark Paluch
parent d937460351
commit 2a6107fcb6
2 changed files with 17 additions and 0 deletions

View File

@@ -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'}.
*

View File

@@ -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");
}
}