Skip to content

Commit

Permalink
Fix a logic error deciding whether to return a patchable schema (#153)
Browse files Browse the repository at this point in the history
This partly fixes issue #98, where a field that has io="cr" wouldn't
show up in the "create" schema.
  • Loading branch information
bjornt authored and lyschoening committed Nov 28, 2018
1 parent c173d3f commit c56df5b
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 c56df5b

Please sign in to comment.