Skip to content

Commit f5f7f51

Browse files
committed
run swagger-ui along with flask output code
1 parent 9a490c9 commit f5f7f51

File tree

8 files changed

+82
-8
lines changed

8 files changed

+82
-8
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/FlaskConnexionCodegen.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,13 @@ public void processOpts() {
175175
supportingFiles.add(new SupportingFile("__main__.mustache", packageName, "__main__.py"));
176176
supportingFiles.add(new SupportingFile("encoder.mustache", packageName, "encoder.py"));
177177
supportingFiles.add(new SupportingFile("util.mustache", packageName, "util.py"));
178+
supportingFiles.add(new SupportingFile("type_util.mustache", packageName, "type_util.py"));
178179
supportingFiles.add(new SupportingFile("__init__.mustache", packageName + File.separatorChar + controllerPackage, "__init__.py"));
179180
supportingFiles.add(new SupportingFile("__init__model.mustache", packageName + File.separatorChar + modelPackage, "__init__.py"));
180181
supportingFiles.add(new SupportingFile("base_model_.mustache", packageName + File.separatorChar + modelPackage, "base_model_.py"));
181182
supportingFiles.add(new SupportingFile("__init__test.mustache", packageName + File.separatorChar + testPackage, "__init__.py"));
182183
supportingFiles.add(new SupportingFile("swagger.mustache", packageName + File.separatorChar + "swagger", "swagger.yaml"));
184+
supportingFiles.add(new SupportingFile("authorization_controller.mustache", packageName + File.separatorChar + controllerPackage, "authorization_controller.py"));
183185

184186
modelPackage = packageName + "." + modelPackage;
185187
controllerPackage = packageName + "." + controllerPackage;

modules/swagger-codegen/src/main/resources/flaskConnexion/__main__.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ from {{packageName}} import encoder
1313
def main():
1414
app = connexion.App(__name__, specification_dir='./swagger/')
1515
app.app.json_encoder = encoder.JSONEncoder
16-
app.add_api('swagger.yaml', arguments={'title': '{{appName}}'})
16+
app.add_api('swagger.yaml', arguments={'title': '{{appName}}'}, pythonic_params=True)
1717
app.run(port={{serverPort}})
1818

1919

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from typing import List
2+
"""
3+
controller generated to handled auth operation described at:
4+
https://connexion.readthedocs.io/en/latest/security.html
5+
"""
6+
{{#authMethods}}
7+
{{#isApiKey}}
8+
def check_{{name}}(api_key, required_scopes):
9+
return {'test_key': 'test_value'}
10+
11+
{{/isApiKey}}
12+
{{#isBasic}}
13+
def check_{{name}}(username, password, required_scopes):
14+
return {'test_key': 'test_value'}
15+
16+
{{/isBasic}}
17+
{{#isBearer}}
18+
def check_{{name}}(token):
19+
return {'test_key': 'test_value'}
20+
21+
{{/isBearer}}
22+
{{#isOAuth}}
23+
def check_{{name}}(token):
24+
return {'scopes': ['read:pets', 'write:pets'], 'uid': 'test_value'}
25+
26+
def validate_scope_{{name}}(required_scopes, token_scopes):
27+
return set(required_scopes).issubset(set(token_scopes))
28+
29+
{{/isOAuth}}
30+
{{/authMethods}}
31+

modules/swagger-codegen/src/main/resources/flaskConnexion/model.mustache

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ from datetime import date, datetime # noqa: F401
66
from typing import List, Dict # noqa: F401
77

88
from {{modelPackage}}.base_model_ import Model
9+
{{#imports}}
10+
{{import}}
11+
{{/imports}}
912
from {{packageName}} import util
1013

1114

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
connexion == 1.1.15
1+
connexion >= 2.6.0
2+
connexion[swagger-ui] >= 2.6.0
23
python_dateutil == 2.6.0
34
{{#supportPython2}}
45
typing == 3.5.2.2
56
{{/supportPython2}}
67
setuptools >= 21.0.0
8+
swagger-ui-bundle >= 0.0.2

modules/swagger-codegen/src/main/resources/flaskConnexion/setup.mustache

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ VERSION = "{{packageVersion}}"
1313
# prerequisite: setuptools
1414
# http://pypi.python.org/pypi/setuptools
1515

16-
REQUIRES = ["connexion"]
16+
REQUIRES = [
17+
"connexion",
18+
"swagger-ui-bundle>=0.0.2"
19+
]
1720

1821
setup(
1922
name=NAME,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# coding: utf-8
2+
3+
import sys
4+
5+
if sys.version_info < (3, 7):
6+
import typing
7+
8+
def is_generic(klass):
9+
""" Determine whether klass is a generic class """
10+
return type(klass) == typing.GenericMeta
11+
12+
def is_dict(klass):
13+
""" Determine whether klass is a Dict """
14+
return klass.__extra__ == dict
15+
16+
def is_list(klass):
17+
""" Determine whether klass is a List """
18+
return klass.__extra__ == list
19+
20+
else:
21+
22+
def is_generic(klass):
23+
""" Determine whether klass is a generic class """
24+
return hasattr(klass, '__origin__')
25+
26+
def is_dict(klass):
27+
""" Determine whether klass is a Dict """
28+
return klass.__origin__ == dict
29+
30+
def is_list(klass):
31+
""" Determine whether klass is a List """
32+
return klass.__origin__ == list

modules/swagger-codegen/src/main/resources/flaskConnexion/util.mustache

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import datetime
22

33
import six
44
import typing
5+
from {{packageName}} import type_util
56

67

78
def _deserialize(data, klass):
@@ -15,18 +16,18 @@ def _deserialize(data, klass):
1516
if data is None:
1617
return None
1718

18-
if klass in six.integer_types or klass in (float, str, bool):
19+
if klass in six.integer_types or klass in (float, str, bool, bytearray):
1920
return _deserialize_primitive(data, klass)
2021
elif klass == object:
2122
return _deserialize_object(data)
2223
elif klass == datetime.date:
2324
return deserialize_date(data)
2425
elif klass == datetime.datetime:
2526
return deserialize_datetime(data)
26-
elif type(klass) == typing.GenericMeta:
27-
if klass.__extra__ == list:
27+
elif type_util.is_generic(klass):
28+
if type_util.is_list(klass):
2829
return _deserialize_list(data, klass.__args__[0])
29-
if klass.__extra__ == dict:
30+
if type_util.is_dict(klass):
3031
return _deserialize_dict(data, klass.__args__[1])
3132
else:
3233
return deserialize_model(data, klass)
@@ -51,7 +52,7 @@ def _deserialize_primitive(data, klass):
5152

5253

5354
def _deserialize_object(value):
54-
"""Return a original value.
55+
"""Return an original value.
5556

5657
:return: object.
5758
"""

0 commit comments

Comments
 (0)