Skip to content

Commit

Permalink
Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
roo-oliv committed Jun 30, 2017
1 parent 001141f commit b235e98
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,30 @@ Take a look at `examples/validation.py` for more information.

All validation options can be found at http://json-schema.org/latest/json-schema-validation.html

# Get defined schemas as python dictionaries

You may wish to use schemas you defined in your Swagger specs for
further validation such as dropping additional parameters. For that you
can use the `get_schema` method:

```python
from flasgger import Swagger, swag_from

swagger = Swagger(app)

@swagger.validate('Product')
@swag_from('swagger.yml')
def post():
return something

...

product_schema = swagger.get_schema('product')
```

This method returns a dictionary which contains the Flasgger schema id,
all defined parameters and which parameters are required.

# HTML sanitizer

By default Flasgger will try to sanitize the content in YAML definitions
Expand Down
2 changes: 1 addition & 1 deletion examples/officer_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ parameters:

responses:
200:
description: A single officer item
description: The officer inserted in the database
schema:
$ref: '#/definitions/Officer'
17 changes: 15 additions & 2 deletions flasgger/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def post():
This annotation only works if the endpoint is already swagged,
i.e. placing @swag_from above @validate or not declaring the
swagger specifications in the method's docstring **won't work**
swagger specifications in the method's docstring *won't work*
Naturally, if you use @app.route annotation it still needs to
be the outermost annotation
Expand All @@ -474,9 +474,22 @@ def wrapper(*args, **kwargs):
return decorator

def get_schema(self, schema_id):
"""
This method finds a schema known to Flasgger and returns it.
:raise KeyError: when the specified :param schema_id: is not
found by Flasgger
:param schema_id: the id of the desired schema
"""
schema_specs = get_schema_specs(schema_id, self)

if schema_specs is None:
raise KeyError('Specified schema_id \'{0}\' not found')

for schema in (
parameter.get('schema') for parameter in
get_schema_specs(schema_id, self)['parameters']):
schema_specs['parameters']):
if schema is not None and schema.get('id').lower() == schema_id:
return schema

Expand Down

0 comments on commit b235e98

Please sign in to comment.