Cornice 的文档提到了如何使用滤锅的MappingSchema
子类来验证您的模式。为了同样的目的,我们应该如何使用 colanderalchemy 模式?因为如果我们使用文档中所述的 colanderalchemy 创建模式,则模式对象已经实例化了滤锅的类,我认为这会导致错误。
更准确地说,这是我的示例代码:
from sqlalchemy.ext.declarative import declarative_base
from cornice.resource import resource, view
from colanderalchemy import SQLAlchemySchemaNode
from sqlalchemy import (
Column,
Integer,
Unicode,
)
Base = declarative_base()
'''
SQLAlchemy part
'''
class DBTable(Base):
__tablename__ = 'mytable'
id = Column(Integer, primary_key=True,
info={'colanderalchemy': {'exclude': True}})
name = Column(Unicode(70), nullable=False)
description = Column(Unicode(256))
'''
ColanderAlchemy part
'''
ClndrTable = SQLAlchemySchemaNode(DBTable)
'''
Cornice part
'''
PRF='api'
@resource(collection_path='%s/' % PRF, path='%s/{fid}' % PRF)
class TableApi(object):
def __init__(self, request):
self.request = request
@view(schema=ClndrTable, renderer='json')
def put(self):
# do my stuff here
pass
ClndrTable
我的自动生成的架构在哪里。现在,在尝试部署此代码时,我收到以下错误:
NotImplementedError: Schema node construction without a typ argument or a schema_type() callable present on the node class
As I've mentioned earlier, I am suspecting that the problem is that ClndrTable
(given as an argument to the view
decorator) is an instantiation of the automatically generated schema by colanderalchemy.
Anyone knowing how to resolve this?
Thanks all in advance!