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
Esempio n. 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)
Esempio n. 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))
Esempio n. 10
0
 class Schema:
     properties = Nested(ShoeTemplateSchemaProperties(partial=True))
Esempio n. 11
0
 class Schema:
     exemple2 = Nested(Exemple2Schema(only=('id', )))
     exemple = Nested(Exemple2Schema(only=('id', )))
Esempio n. 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)
Esempio n. 13
0
 class Schema:
     addresses = Nested(AddressSchema, many=True, exclude=('customer', ))
     tags = Nested(TagSchema, many=True)
Esempio n. 14
0
 class Schema:
     city = Nested(CitySchema)
Esempio n. 15
0
 class Schema:
     properties = Nested(ShoeItemSchemaProperties(partial=True))
Esempio n. 16
0
class AddressRequestSchema(FullRequestSchema):
    """Request validation for AddressSchema
    """
    body = Nested(AddressSchema(
        partial=('tags', 'addresses')))
    path = Nested(AddressSchema(only_primary_key=True))
Esempio n. 17
0
 class Schema:
     roles = Nested(UserRoleSchema, many=True, only=('name', 'label'))
     password = fields.Str()
     password2 = fields.Str()
Esempio n. 18
0
 class Schema:
     properties = Nested(ShoeFamilySchemaProperties(partial=True))