def schema(format: Format) -> None: # pragma: nocover """ Output an API Schema. """ from apistar.main import get_current_app from apistar.apischema import APISchema app = get_current_app() schema = APISchema.build(app) codec = codecs[format] output = codec.encode(schema) click.echo(output)
def schema(format: Format) -> None: # pragma: nocover """ Output an API Schema. """ from apistar.cli import get_current_app from apistar.apischema import APISchema app = get_current_app() schema = APISchema.build(app) codec = codecs[format] output = codec.encode(schema) click.echo(output)
def test_api_schema(): schema = APISchema.build(app) assert schema == expected
expected = APISchema(url='/schema/', content={ 'list_todo': Link(url='/todo/', action='GET', fields=[ Field(name='search', location='query', required=False, schema=coreschema.String()) ]), 'add_todo': Link(url='/todo/', action='POST', fields=[ Field(name='note', location='body', required=True, schema=coreschema.String()) ]), 'show_todo': Link(url='/todo/{ident}/', action='GET', fields=[ Field(name='ident', location='path', required=True, schema=coreschema.String()) ]), 'set_complete': Link(url='/todo/{ident}/', action='PUT', fields=[ Field(name='ident', location='path', required=True, schema=coreschema.String()), Field(name='complete', location='form', required=False, schema=coreschema.String()) ]) })
expected = APISchema(url='/schema/', content={ 'list_todo': Link( url='/todo/', action='GET', fields=[Field(name='search', location='query', required=False, schema=coreschema.String())] ), 'add_todo': Link( url='/todo/', action='POST', fields=[Field(name='note', location='body', required=True, schema=coreschema.String())] ), 'show_todo': Link( url='/todo/{ident}/', action='GET', fields=[Field(name='ident', location='path', required=True, schema=coreschema.Integer())] ), 'set_complete': Link( url='/todo/{ident}/', action='PUT', fields=[ Field(name='ident', location='path', required=True, schema=coreschema.Integer()), Field(name='complete', location='form', required=False, schema=coreschema.Boolean()) ] ), 'set_percent_complete': Link( url='/todo/{ident}/percent_complete', action='PUT', fields=[ Field(name='ident', location='path', required=True, schema=coreschema.Integer()), Field(name='percent_complete', location='form', required=False, schema=coreschema.Number()) ] ), 'set_category': Link( url='/todo/{ident}/category', action='PUT', fields=[ Field(name='ident', location='path', required=True, schema=coreschema.Integer()), Field(name='category', location='form', required=False, schema=coreschema.Enum(enum=['shop', 'chore'])) ] ) })