Skip to content

Commit

Permalink
Merge dcec4bb into 20fb764
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornt committed Nov 16, 2018
2 parents 20fb764 + dcec4bb commit 63c9bce
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flask_potion/fields.py
Expand Up @@ -717,7 +717,7 @@ def _response_schema():
return {"$ref": "#"}
return {"$ref": self.target.routes["describedBy"].rule_factory(self.target)}

if not not self.patchable:
if not self.patchable:
return _response_schema()
else:
return _response_schema(), self.target.schema.patchable.update
Expand Down
29 changes: 29 additions & 0 deletions tests/test_model_resource.py
Expand Up @@ -85,3 +85,32 @@ class Meta:
foo.bind(BarResource)

self.assertEqual({'$ref': '/foo/schema'}, foo.response)

def test_schema_io_create_flag(self):

class FooResource(ModelResource):
class Schema:
name = fields.String()
slug = fields.String(io="cr")

class Meta:
name = "foo"

self.api.add_resource(FooResource)
data, code, headers = FooResource().described_by()
[create_link] = [
link for link in data['links'] if link['rel'] == 'create']
[update_link] = [
link for link in data['links'] if link['rel'] == 'update']
self.assertEqual({'$ref': '#'}, create_link['schema'])
self.assertEqual({
"type": "object",
"additionalProperties": False,
"properties": {
"name": {
"type": "string"
}
}
}, update_link["schema"])
self.assertEqual(
["$uri", "name", "slug"], sorted(data["properties"].keys()))

0 comments on commit 63c9bce

Please sign in to comment.