class Example(Structure): i = Integer(maximum=10) s = String(maxLength=5) array = Array[Integer(multiplesOf=5), Number] embedded = StructureReference(a1=Integer(), a2=Float()) simplestruct = SimpleStruct all = AllOf[Number, Integer] enum = Enum(values=[1, 2, 3])
class Example(Structure): i = Integer(maximum=10) s = String(maxLength=5) a = Array[Integer(multiplesOf=5), Number] foo = StructureReference(a1=Integer(), a2=Float()) ss = SimpleStruct all = AllOf[Number, Integer] any = AnyOf[Number(minimum=1), Integer] one = OneOf[Number(minimum=1), Integer] no = NotField(fields=[String]) enum = Enum(values=[1, 2, 3])
class Example(Structure): anything = Anything i = Integer(maximum=10) s = String(maxLength=5) any = AnyOf[Array[Person], Person] complex_allof = AllOf[ AnyOf[Integer, Person], BigPerson] # this is stupid, but we do it for testing people = Array[Person] array_of_one_of = Array[OneOf[ Float, Integer, Person, StructureReference(a1=Integer(), a2=Float())]] array = Array[Integer(multiplesOf=5), OneOf[Array[Person], Number]] embedded = StructureReference(a1=Integer(), a2=Float()) simplestruct = SimpleStruct all = AllOf[Number, Integer] enum = Enum(values=[1, 2, 3]) _required = []
class Person(Structure): _required = ['ssid'] name = String(pattern='[A-Za-z]+$', maxLength=8) ssid = String(minLength=3, pattern='[A-Za-z]+$') num = Integer(maximum=30, minimum=10, multiplesOf="dd", exclusiveMaximum=False) foo = StructureReference(a=String(), b=StructureReference(c=Number(minimum=10), d=Number(maximum=10)))
class Example(Structure): _additionalProperties = True _required = [] a = AllOf( [Number(multiplesOf=5, maximum=20, minimum=-10), Integer, Positive]) # Can also omit the parens b = AnyOf[Number(maximum=20, minimum=-10), Integer(), Positive, String] c = OneOf([ Number(multiplesOf=5, maximum=20, minimum=-10), Integer, Positive, String ]) d = NotField([Number(multiplesOf=5, maximum=20, minimum=-10), String]) e = AllOf([]) broken = AllOf[String, Integer] f = NotField[Number] g = AnyOf[Foo, Integer]
class Foo(Structure): a = Array(items=Integer())
class A(Structure): i = Integer()
class Foo(Structure): a = Integer b = Array[NotField[String(maxLength=3), Integer(minimum=4)]]
class Blah(Structure): x = Integer(default=5) y = Integer _required = [] _ignore_none = True
class MixedTypesExample(Structure): i: Integer(maximum=10) s: String(maxLength=5) s1: str a: dict simple: SimpleStruct
class ExampleWithTyping(Structure): mylist: List[List[int]] i: Integer(minimum=50) myset: FrozenSet
class Example(Structure): f: Float() = 0.5 map: dict arr: Array[SimpleStruct] = [SimpleStruct(name="John")] i = Integer(default=5) _required = ['arr', i]
class B(Structure): e = Integer(minimum=0, maximum=10, exclusiveMaximum=True)
def test_invalid_defaults_raise_error2(): with pytest.raises(ValueError) as excinfo: Integer(minimum=5, default=2)
class Foo(Structure): i = Integer(default="x")
def func() -> Field: return Integer(minimum=10)