Skip to content

Commit

Permalink
Change schema_definition_x_property into schema_definition_extra_fields
Browse files Browse the repository at this point in the history
  • Loading branch information
lafrech committed Feb 20, 2017
1 parent 24736e5 commit 168611e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
12 changes: 4 additions & 8 deletions flask_rest_api/spec/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,12 @@ def flask_path_helper(spec, app, rule, operations=None, **kwargs):
return path


def schema_definition_x_property(spec, name, schema, **kwargs):
"""Pass provided extensions properties as is to the spec
Extensions properties begin with 'x-'
http://swagger.io/specification/#vendorExtensions
"""
return {k: v for k, v in kwargs.items() if k.startswith('x-')}
def schema_definition_extra_fields(spec, name, schema, extra_fields=None):
"""Add extra fields to the definition"""
return extra_fields or {}


def setup(spec):
"""Setup for the plugin."""
spec.register_path_helper(flask_path_helper)
spec.register_definition_helper(schema_definition_x_property)
spec.register_definition_helper(schema_definition_extra_fields)
21 changes: 21 additions & 0 deletions tests/test_spec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest

from marshmallow import Schema, fields

from flask_rest_api import Api

class TestSpec():

def test_schema_definition_extra_fields(self):

class MySchema(Schema):
field = fields.Str()

api = Api()
api.definition('MySchema')(
Schema,
extra_fields={'test': 'ok', 'x-test': 'check, check!'})

schema_def = api._apispec.spec.to_dict()['definitions']['MySchema']
assert schema_def['test'] == 'ok'
assert schema_def['x-test'] == 'check, check!'

0 comments on commit 168611e

Please sign in to comment.