Skip to content

Commit 8497051

Browse files
committed
Merge branch 'master' of github.com:guokr/swagger-py-codegen into swagger-ui-3x
2 parents b443e28 + c8bbbdc commit 8497051

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ click
44
jinja2
55
dpath
66
PyYAML
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)

0 commit comments

Comments
 (0)