3

I have a few deprecated custom endpoints in my application to support migration from an old API to Eve. One of my custom endpoints implements an endpoint for updating documents in the MongoDB database. The collection associated with those documents has a schema defined in settings.py which works as expected when performing a normal post. However, when I use update_one() instead of going directly through the API provided by Eve the schema is not respected.

Is the schema that is defined in settings.py not applied to the collection itself in the database? Is there a good way to apply that schema to the collection?

Vorticity
  • 4,582
  • 4
  • 32
  • 49

1 Answers1

1

No, it is not, the schema is taken into account mostly during cerberus validation step which is called internaly during POST request.

If you wan't repeat this behaviour you can try do like this:

from eve.utils import config
from flask import current_app as app

resource_def = app.config['DOMAIN'][resource]
schema = resource_def['schema']
validator = app.validator(schema, resource=resource)
validator.validate(document)
Maksym Rudenko
  • 706
  • 5
  • 16