Пример #1
0
def string(min_len: Optional[int] = None,
           max_len: Optional[int] = None,
           default: Optional[str] = None) -> JSONSchema:
    return dict_no_nulls(type='string',
                         minLength=min_len,
                         maxLength=max_len,
                         default=default)
Пример #2
0
def integer(min: Optional[int] = None,
            max: Optional[int] = None,
            default: Optional[int] = None) -> JSONSchema:
    return dict_no_nulls(type='integer',
                         minimum=min,
                         maximum=max,
                         default=default)
Пример #3
0
def map(value_type: JSONSchema,
        key_type: Optional[JSONSchema] = None) -> JSONSchema:
    return dict_no_nulls(
        type='object',
        additionalProperties=value_type,
        propertyNames=key_type,
    )
Пример #4
0
def array(item_type: JSONSchema,
          min_length: Optional[str] = None,
          max_length: Optional[str] = None,
          default: Optional[List] = None) -> JSONSchema:
    return dict_no_nulls(
        type='array',
        items=item_type,
        minItems=min_length,
        maxItems=max_length,
        default=default,
    )
Пример #5
0
def tup(*item_types: Iterable[JSONSchema],
        default: Optional[List] = None) -> JSONSchema:
    item_types = list(item_types)

    return dict_no_nulls(
        type='array',
        items=item_types,
        minItems=len(item_types),
        maxItems=len(item_types),
        default=default,
    )
Пример #6
0
def regex(pattern: str, default: Optional[str] = None) -> JSONSchema:
    return dict_no_nulls(type='string', pattern=pattern, default=default)
Пример #7
0
def non_empty_str(default: Optional[str] = None) -> JSONSchema:
    return dict_no_nulls(type='string', minLength=1, default=default)
Пример #8
0
def boolean(default: Optional[bool] = None) -> JSONSchema:
    return dict_no_nulls(type='boolean', default=default)
Пример #9
0
def nul() -> JSONSchema:
    return dict_no_nulls(type='null')