def get_fields(cls, opts, base_fields, dict_cls):
        declared_fields = dict_cls()
        known_fields = [x[0] for x in base_fields]

        deserialization_fields = [
            x for x in ('collection_get', 'collection_post', 'get', 'put',
                        'patch', 'delete') if x not in known_fields
        ]
        deserialization_request_schema = opts.deserialization_request_schema
        if not deserialization_request_schema and opts.model:
            deserialization_request_schema = (
                cls.getDeserializationRequestSchema(opts))

        serialization_fields = [
            x for x in ('dschema', 'dschema_collection')
            if x not in known_fields
        ]
        serialization_model_schema = opts.serialization_model_schema
        if not serialization_model_schema and opts.model:
            serialization_model_schema = cls.getSerializationModelSchema(opts)

        if deserialization_request_schema:
            for field in deserialization_fields:
                declared_fields[field] = Nested(
                    deserialization_request_schema(
                        **getattr(opts, field + '_opts', {})))

        if serialization_model_schema:
            for field in serialization_fields:
                declared_fields[field] = Nested(
                    serialization_model_schema(
                        **getattr(opts, field + '_opts', {})))

        return declared_fields
Beispiel #2
0
    class Schema:
        # follow the relationship One2Many and Many2Many
        # - the many=True is required because it is *2Many
        # - exclude is used to forbid the recurse loop
        addresses = Nested(AddressSchema, many=True, exclude=('customer', ))
        tags = Nested(TagSchema, many=True)

        @validates_schema(pass_original=True)
        def check_unknown_fields(self, data, original_data):
            unknown = set(original_data) - set(self.fields)
            if unknown:
                raise ValidationError('Unknown field', unknown)
class CustomerSchema(ModelSchema):
    """Schema for 'Model.Customer'
    """

    # follow the relationship One2Many and Many2Many
    # - the many=True is required because it is *2Many
    # - exclude is used to forbid the recurse loop
    addresses = Nested(AddressSchema, many=True, exclude=('customer', ))
    tags = Nested(TagSchema, many=True)

    class Meta:
        model = 'Model.Customer'
class AddressSchema(ModelSchema):

    # follow the relationship Many2One and One2One
    city = Nested(CitySchema)

    class Meta:
        model = 'Model.Address'
class CustomerFullSchema(Schema):
    # fields for incoming request validation
    collection_post = Nested(CustomerRequestSchema(only=('body',)))
    collection_get = Nested(CustomerRequestSchema(only=('querystring',)))
    get = Nested(CustomerRequestSchema(only=('path',)))
    put = Nested(CustomerRequestSchema(only=('body', 'path',)))
    patch = Nested(CustomerRequestSchema(only=('body', 'path',)))
    delete = Nested(CustomerRequestSchema(only=('path',)))
    # fields for response deserialization
    dschema = Nested(CustomerSchema())
    dschema_collection = Nested(CustomerSchema(many=True))
class AddressFullSchema(Schema):
    collection_post = Nested(AddressRequestSchema(only='body'))
    collection_get = Nested(AddressRequestSchema(only='querystring'))
    get = Nested(AddressRequestSchema(only='path'))
    put = Nested(AddressRequestSchema(only=('body', 'path')))
    patch = Nested(AddressRequestSchema(only=('body', 'path')))
    delete = Nested(AddressRequestSchema(only='path'))
    def getDeserializationRequestSchema(cls, opts):
        name = "Deserialization.Schema." + opts.model
        properties = {}
        deserialization_model_schema = opts.deserialization_model_schema
        if not deserialization_model_schema and opts.model:
            deserialization_model_schema = (
                cls.getDeserializationModelSchema(opts))

        if deserialization_model_schema:
            for field in opts.request_fields:
                if field == 'querystring':
                    continue

                properties[field] = Nested(
                    deserialization_model_schema(
                        **getattr(opts, field + '_opts', {})))

        return type(name, (FullRequestSchema, ), properties)
Beispiel #8
0
 class Schema:
     # follow the relationship Many2One and One2One
     city = Nested(CitySchema)
class CustomerRequestSchema(FullRequestSchema):
    """Request validation for CustomerSchema
    """
    body = Nested(CustomerSchema(partial=True))
    path = Nested(CustomerSchema(only_primary_key=True))
    querystring = Nested(CustomerSchema(partial=True))
Beispiel #10
0
 class Schema:
     properties = Nested(ShoeTemplateSchemaProperties(partial=True))
Beispiel #11
0
 class Schema:
     exemple2 = Nested(Exemple2Schema(only=('id', )))
     exemple = Nested(Exemple2Schema(only=('id', )))
Beispiel #12
0
 class Schema:
     # follow the relationship One2Many and Many2Many
     # - the many=True is required because it is *2Many
     # - exclude is used to forbid the recurse loop
     addresses = Nested(AddressSchema, many=True, exclude=('customer', ))
     tags = Nested(TagSchema, many=True)
 class Schema:
     addresses = Nested(AddressSchema, many=True, exclude=('customer', ))
     tags = Nested(TagSchema, many=True)
 class Schema:
     city = Nested(CitySchema)
Beispiel #15
0
 class Schema:
     properties = Nested(ShoeItemSchemaProperties(partial=True))
class AddressRequestSchema(FullRequestSchema):
    """Request validation for AddressSchema
    """
    body = Nested(AddressSchema(
        partial=('tags', 'addresses')))
    path = Nested(AddressSchema(only_primary_key=True))
Beispiel #17
0
 class Schema:
     roles = Nested(UserRoleSchema, many=True, only=('name', 'label'))
     password = fields.Str()
     password2 = fields.Str()
Beispiel #18
0
 class Schema:
     properties = Nested(ShoeFamilySchemaProperties(partial=True))