Closed amilner42 closed 7 years ago
The mongoStringID kleen schema is here. You'll notice it is for strings-only: primitiveType: kleen.kindOfPrimitive.string
, make it the anySchema
and then instead add a restriction which uses the isValid
from mongodb. That way we allow both strings and ObjectID
s.
When we receive data from the user we always get the IDs in string form, and so that kleen schema works. But sometimes we get data from the DB and then use that data to make more calls to the db, and when we get data from the DB the IDs are going to be ObjectID
s, not string
s, which means that we have to manually convert the ObjectID
s -> string
s to make sure our validation doesn't fail, this is annoying.
We won't be soon, on the QA branch for the new QA endpoints I started having validation be optional, specifically so we only validate when the user is making requests. Once I merge that QA branch, we'll have to go to the existing endpoints and also have them switch to optional validation, that issue is here.
Do we want union of string and anySchema with isValid restriction?
Check if ObjectID.isValid
will validify a string as well. I'm pretty sure it will validify both strings and ObjectID
s, so you won't need a union.
Once this issue is complete we should change
MongoStringIDSchema
->MongoIDSchema
, you can use the new WildCardSchema to ignore the type and inside the restriction use the built-in method in the mongo driver to check if something is a valid object ID. This way bothstring
s andObjectID
s are validated.