Skip to content

Commit 2b60a97

Browse files
committed
Styling fixes, notes in README and 0.6.2 release
1 parent 9eaed60 commit 2b60a97

18 files changed

+61
-33
lines changed

.coveragerc

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
[run]
2-
include =
2+
include =
33
flasgger/*.py
4+
5+
[report]
6+
exclude_lines =
7+
pragma: no cover
8+
raise NotImplementedError.*
9+
raise RuntimeError.*
10+
warnings\.warn.*
11+
def __repr__
12+
def __str__
13+
def main()
14+
if __name__ == .__main__.:
15+
except ImportError.*

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ Flasgger also **provides validation** of the incoming data, using the same speci
1717

1818
Flasgger can work with simple function views or MethodViews using docstring for especification, or using `@swag_from` decorator to get specification from **YAML** or **dict** and also provides **SwaggerView** which can use **Marshmallow Schemas** as specification.
1919

20-
Flasgger is compatible with `Flask-RESTful` so you can use `Resources` and `swag` specifications together, take a look at [restful example.](examples/restfull.py)
20+
Flasgger is compatible with `Flask-RESTful` so you can use `Resources` and `swag` specifications together, take a look at [restful example.](examples/restful.py)
21+
22+
Flasgger also supports `Marshmallow APISpec` as base template for specification, if you are using APISPec from Marshmallow take a look at [apispec example.](examples/apispec_example.py)
23+
2124

2225
# Installation
2326

examples/README.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,26 @@ Please contribute adding your example to increase our test coverage
1313
The only rules to follow is:
1414

1515
- Add extra requirements to `requirements.txt`
16-
- use `if __name__ == '__main__':` before `app.run()`
16+
- use `if __name__ == '__main__':` before `app.run()`
1717

18+
# testing
19+
20+
You can also add extra tests to your example, just create a function called `test_swag` as:
21+
22+
23+
```python
24+
def test_swag(client, specs_data):
25+
"""
26+
This test is runs automatically in Travis CI
27+
28+
:param client: Flask app test client
29+
:param specs_data: {'url': {swag_specs}} for every spec in app
30+
"""
31+
for url, spec in specs_data.items():
32+
assert 'Palette' in spec['definitions']
33+
assert 'Color' in spec['definitions']
34+
# 'route '/colors/<palette>/' becomes '/colors/{palette}/'
35+
assert 'colors' in spec['paths']['/colors/{palette}/']['get']['tags']
36+
37+
```
1838

examples/apispec_example.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# coding: utf-8
22
from flask import Flask, jsonify
3-
from flasgger import (
4-
Swagger, APISpec, Schema, fields
5-
)
63

4+
from flasgger import APISpec, Schema, Swagger, fields
75

86
# Create an APISpec
97
spec = APISpec(
@@ -72,5 +70,3 @@ def random_pet():
7270

7371
if __name__ == '__main__':
7472
app.run(debug=True)
75-
76-

examples/base_model_view.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from flask import Flask, jsonify
2-
from flasgger import Swagger
32
from flask.views import MethodView
43

4+
from flasgger import Swagger
5+
56

67
class BaseAPIView(MethodView):
78
"""BAse view"""

examples/colors_from_specdict.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from flasgger import Swagger
44
from flasgger.utils import swag_from
55

6-
76
app = Flask(__name__)
87
app.config['SWAGGER'] = {
98
'title': 'Colors API',

examples/colors_with_schema.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# coding: utf-8
22
from flask import Flask, jsonify
3-
from flasgger import Swagger, SwaggerView, Schema, fields
3+
4+
from flasgger import Schema, Swagger, SwaggerView, fields
45

56

67
class Color(Schema):

examples/compat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88

99
from flask import Flask, jsonify, request
10-
from flasgger import Swagger
1110

11+
from flasgger import Swagger
1212

1313
app = Flask(__name__)
1414
app.config['SWAGGER'] = {

examples/example_blueprint.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from flasgger import Swagger
44
from flasgger.utils import swag_from
55

6-
76
app = Flask(__name__)
87

98
example_blueprint = Blueprint("example_blueprint", __name__)

examples/marshmallow_apispec.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# coding: utf-8
22

33
from flask import Flask, jsonify, request
4-
from flasgger import Swagger, SwaggerView, fields, Schema
54

5+
from flasgger import Schema, Swagger, SwaggerView, fields
66

77
app = Flask(__name__)
88
app.config['SWAGGER'] = {

examples/no_routes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"""
66
from flask import Flask
77
from flask.views import MethodView
8-
from flasgger import Swagger
98

9+
from flasgger import Swagger
1010

1111
app = Flask(__name__)
1212
swag = Swagger()

examples/restfull.py examples/restful.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
pip install flask-restful
44
"""
55
from flask import Flask
6+
from flask_restful import Api, Resource, abort, reqparse
7+
68
from flasgger import Swagger, swag_from
7-
from flask_restful import reqparse, abort, Api, Resource
89

910
app = Flask(__name__)
1011
api = Api(app)

examples/validation.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
from flask import Flask, jsonify, request, Blueprint
2-
from flasgger import (
3-
Schema,
4-
Swagger,
5-
SwaggerView,
6-
fields,
7-
swag_from,
8-
validate
9-
)
1+
from flask import Blueprint, Flask, jsonify, request
102

3+
from flasgger import Schema, Swagger, SwaggerView, fields, swag_from, validate
114

125
app = Flask(__name__)
136
Swagger(app)

flasgger/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
__version__ = '0.6.1'
2+
__version__ = '0.6.2'
33
__author__ = 'Bruno Rocha'
44
__email__ = '[email protected]'
55

flasgger/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
render_template, request, url_for)
1818
from flask.views import MethodView
1919
from mistune import markdown
20+
2021
from flasgger.constants import OPTIONAL_FIELDS
2122
from flasgger.marshmallow_apispec import SwaggerView, convert_schemas
2223

23-
2424
NO_SANITIZER = lambda text: text # noqa
2525
BR_SANITIZER = lambda text: text.replace('\n', '<br/>') if text else text # noqa
2626
MK_SANITIZER = lambda text: Markup(markdown(text)) if text else text # noqa

flasgger/marshmallow_apispec.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# coding: utf-8
22
import inspect
3+
34
from flask.views import MethodView
5+
46
import flasgger
57

68
try:

flasgger/utils.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
# coding: utf-8
22

3-
import os
43
import copy
54
import inspect
6-
from functools import wraps
5+
import os
76
from collections import OrderedDict
87
from copy import deepcopy
8+
from functools import wraps
99

1010
import jsonschema
1111
import yaml
12-
from flask import request, abort, Response
12+
from flask import Response, abort, request
1313
from jsonschema import ValidationError # noqa
1414
from six import string_types
15+
1516
from flasgger.base import _extract_definitions, load_from_file
1617

1718

tests/conftest.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import json
12
import os
2-
from importlib import import_module
3-
from flasgger import Swagger
43
import random
5-
import json
4+
from importlib import import_module
65

6+
from flasgger import Swagger
77

88
EXAMPLES_DIR = "examples/"
99

0 commit comments

Comments
 (0)