Is there a way to get the Cerberus Schema through the API?

31 views Asked by At

I am trying to implement an API for other users that is based around YAML files and am using Cerberus to validate the contents of those files. I want to allow the user to specify their own Cerberus schema within those YAML files and validate them as well.

I would like to validate my YAML files using a Cerberus schema like this:

description:
  type: string
  required: true
  empty: false
created_on:
  type: datetime
  required: true
created_by:
  type: string
  required: true
  empty: false
properties_schema:
  type: dict
  required: true
  schema: <cerberus_schema>

The simplest "solution" is to not validate the contents of the "properties_schema" at all:

...
properties_schema:
  type: dict
  required: true

This doesn't actually solve the problem though.

I've found an example of the schema in the documentation and how the InspectorValidator generates that schema from the docstrings of the methods. I haven't been able to find a good way to get that schema information from the Validator though. With the example schema, I could copy the documented schema into my Cerberus schema above and use that but I am worried about maintaining that between Cerberus versions.

I've also found two different stackoverflow questions (1 and 2) requesting a similar feature that don't really solve my problem unfortunately.

My ideal solution would be to have the Cerberus schema in the schema_registry and reference it within the schema I provide but I know that isn't in place by default. Is there a programmatic solution to get the Cerberus schema instead of just copying it from the documentation into my schema?

0

There are 0 answers