Skip to content

Commit ea1cd06

Browse files
committed
Merge branch 'master' of github.com:guokr/swagger-py-codegen into 113_fix_sanic_url_prefix
2 parents fe867b3 + 683e92a commit ea1cd06

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+279
-31612
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,6 @@ pip-selfcheck.json
107107
*.swp
108108
example-app
109109

110+
.DS_Store
111+
110112
# End of https://www.gitignore.io/api/python

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Command Options:
3939
-t, --template-dir Path of your custom templates directory.
4040
--spec, --specification Generate online specification json response.
4141
--ui Generate swagger ui.
42+
--validate Validate swagger file.
4243
-tlp, --templates gen flask/tornado/falcon templates, default flask.
4344
--version Show current version.
4445
--help Show this message and exit.

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ json-spec
33
click
44
jinja2
55
dpath
6-
PyYAML
6+
PyYAML==3.12
7+
flex

swagger_py_codegen/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
"""Version information."""
22

33
# The following line *must* be the last in the module, exactly as formatted:
4-
__version__ = "0.3.0"
4+
__version__ = "0.3.1"

swagger_py_codegen/command.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
import yaml
1313
import click
1414

15+
import flex
16+
from flex.exceptions import ValidationError
17+
1518
from ._version import __version__
1619
from .flask import FlaskGenerator
1720
from .tornado import TornadoGenerator
@@ -101,6 +104,9 @@ def print_version(ctx, param, value):
101104
@click.option('--ui',
102105
default=False, is_flag=True,
103106
help='Generate swagger ui.')
107+
@click.option('--validate',
108+
default=False, is_flag=True,
109+
help='Validate swagger file.')
104110
@click.option('-tlp', '--templates',
105111
default='flask',
106112
help='gen flask/tornado/falcon/sanic templates, default flask.')
@@ -109,9 +115,15 @@ def print_version(ctx, param, value):
109115
help='Show current version.')
110116
def generate(destination, swagger_doc, force=False, package=None,
111117
template_dir=None, templates='flask',
112-
specification=False, ui=False):
118+
specification=False, ui=False, validate=False):
113119
package = package or destination.replace('-', '_')
114120
data = spec_load(swagger_doc)
121+
if validate:
122+
try:
123+
flex.core.parse(data)
124+
click.echo("Validation passed")
125+
except ValidationError as e:
126+
raise click.ClickException(str(e))
115127
swagger = Swagger(data)
116128
if templates == 'tornado':
117129
generator = TornadoGenerator(swagger)

swagger_py_codegen/templates/sanic/schemas.tpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# TODO: datetime support
44

55
{% include '_do_not_change.tpl' %}
6+
import six
67

78
base_path = '{{base_path}}'
89

0 commit comments

Comments
 (0)