koda_validate.serialization¶
- class SerializableErr(obj)¶
Bases:
ValidationErrBaseA validation error where you may simply want to produce a human-readable message.
- obj¶
The error contents you want to return.
- to_json_schema(obj)¶
Produces a
Serializablefrom aValidator,PredicateorPredicateAsyncthat conforms to a valid JSON Schema.- Parameters:
obj (
Union[Validator[Any],Predicate[Any],PredicateAsync[Any]]) – the Validator being described- Return type:
dict[str,Union[None,int,str,bool,float,list[Union[None,int,str,bool,float,list[Serializable],tuple[Serializable,...],dict[str, Serializable]]],tuple[Union[None,int,str,bool,float,list[Serializable],tuple[Serializable,...],dict[str, Serializable]],...],dict[str,Union[None,int,str,bool,float,list[Serializable],tuple[Serializable,...],dict[str, Serializable]]]]]- Returns:
a
Serializablecompatible with JSON Schema
- to_named_json_schema(schema_name, obj, ref_location='#/components/schemas/')¶
Produces a
Serializablefrom aValidator,PredicateorPredicateAsyncthat conforms to a valid JSON Schema. The root dict’s only key is the schema name, which has the full JSON Schema as its value.- Parameters:
schema_name (
str) – mainly required when recursive objects need to related to themselvesobj (
Union[Validator[Any],Predicate[Any],PredicateAsync[Any]]) – the Validator being describedref_location (
str, default:'#/components/schemas/') – where the schema name will be found if/when making a recursive reference to it
- Return type:
dict[str,Union[None,int,str,bool,float,list[Union[None,int,str,bool,float,list[Serializable],tuple[Serializable,...],dict[str, Serializable]]],tuple[Union[None,int,str,bool,float,list[Serializable],tuple[Serializable,...],dict[str, Serializable]],...],dict[str,Union[None,int,str,bool,float,list[Serializable],tuple[Serializable,...],dict[str, Serializable]]]]]- Returns:
a
Serializablecompatible with JSON Schema
- to_serializable_errs(invalid, next_level=None)¶
Convert an
Invalidinstance to human readable (English)Serializablerepresentation ofInvalid.It can serve as an example of how to build similar functions to convert
Invalidinstances to other formats, other languages, etc.- Parameters:
invalid (
Invalid) – The error you’d like to representnext_level (
Optional[Callable[[Invalid],Union[None,int,str,bool,float,list[Union[None,int,str,bool,float,list[Serializable],tuple[Serializable,...],dict[str, Serializable]]],tuple[Union[None,int,str,bool,float,list[Serializable],tuple[Serializable,...],dict[str, Serializable]],...],dict[str,Union[None,int,str,bool,float,list[Serializable],tuple[Serializable,...],dict[str, Serializable]]]]]], default:None) – If supplied, this callable will handle any calls for containerErrType``s such as ``ContainerErr,KeyErr, and so on
- Return type:
Union[None,int,str,bool,float,list[Union[None,int,str,bool,float,list[Serializable],tuple[Serializable,...],dict[str, Serializable]]],tuple[Union[None,int,str,bool,float,list[Serializable],tuple[Serializable,...],dict[str, Serializable]],...],dict[str,Union[None,int,str,bool,float,list[Serializable],tuple[Serializable,...],dict[str, Serializable]]]]- Returns:
an error message appropriate for serializing in JSON or YAML. Because this function can handle any kind of Invalid, any type narrowing desired beyond
Serializableneeds to be done outside of this function.
- Serializable¶
alias of
None|int|str|bool|float|list[Serializable] |tuple[Serializable, …] |dict[str, Serializable]