Cornices / cornice

Build Web Services with Pyramid.
https://cornice.readthedocs.io
Other
384 stars 149 forks source link

Colander Schema's don't find parameters, CorniceSchemas' classmethod isn't callable #144

Closed ghost closed 11 years ago

ghost commented 11 years ago

""" Cornice services. """

from cornice import Service
import colander

hello = Service(name='hello', path='/', description="Simplest app")

class MyColanderSchema(colander.MappingSchema):
    my_test_value = colander.SchemaNode(
        colander.String(),
        title='my_test_value',
        description='A simple test.',
        )

@hello.get(schema=MyColanderSchema)
def get_info(request):
    """Returns Hello in JSON."""
    return {'Hello': 'World'}

http://0.0.0.0:6543/?my_test_value=will_not_work

{"status": "error", "errors": [{"location": "body", "name": "my_test_value", "description": "my_test_value is missing"}]}
""" Cornice services.
"""
from cornice import Service
from cornice.schemas import CorniceSchema
import colander

hello = Service(name='hello', path='/', description="Simplest app")

class MyColanderSchema(colander.MappingSchema):
    my_test_value = colander.SchemaNode(
        colander.String(),
        title='my_test_value',
        description='A simple test.',
        )

my_cornice_schema = CorniceSchema.from_colander(MyColanderSchema)

@hello.get(schema=my_cornice_schema)
def get_info(request):
    """Returns Hello in JSON."""
    return {'Hello': 'World'}
/Desktop/schema_test/local/lib/python2.7/site-packages/cornice/schemas.py", line 58, in from_colander
    return CorniceSchema(colander_schema().children)
TypeError: 'CorniceSchema' object is not callable

What am I doing wrong please?

almet commented 11 years ago

You need to pass a colander schema, not a cornice schema. CorniceSchema is just a way to deal with it internally.

what's wrong with the first approach you had?

amotl commented 11 years ago

@sudomake: You want to add location='querystring' to your schema, right?

class MyColanderSchema(colander.MappingSchema):
    my_test_value = colander.SchemaNode(
        colander.String(),
        location='querystring',
        title='my_test_value',
        description='A simple test.',
    )