|
|
|
@ -26,6 +26,7 @@ missing, or have incorrect values).
|
|
|
|
|
See https://github.com/wordnik/swagger-core/wiki/API-Declaration for the spec.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
|
import json
|
|
|
|
|
import os.path
|
|
|
|
|
import pprint
|
|
|
|
@ -75,7 +76,7 @@ def compare_versions(lhs, rhs):
|
|
|
|
|
'''
|
|
|
|
|
lhs = [int(v) for v in lhs.split('.')]
|
|
|
|
|
rhs = [int(v) for v in rhs.split('.')]
|
|
|
|
|
return cmp(lhs, rhs)
|
|
|
|
|
return (lhs > rhs) - (lhs < rhs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ParsingContext(object):
|
|
|
|
@ -441,8 +442,7 @@ class Api(Stringify):
|
|
|
|
|
op_json = api_json.get('operations')
|
|
|
|
|
self.operations = [
|
|
|
|
|
Operation().load(j, processor, context) for j in op_json]
|
|
|
|
|
self.has_websocket = \
|
|
|
|
|
filter(lambda op: op.is_websocket, self.operations) != []
|
|
|
|
|
self.has_websocket = any(op.is_websocket for op in self.operations)
|
|
|
|
|
processor.process_api(self, context)
|
|
|
|
|
return self
|
|
|
|
|
|
|
|
|
@ -608,7 +608,7 @@ class ApiDeclaration(Stringify):
|
|
|
|
|
except SwaggerError:
|
|
|
|
|
raise
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print >> sys.stderr, "Error: ", traceback.format_exc()
|
|
|
|
|
print("Error: ", traceback.format_exc(), file=sys.stderr)
|
|
|
|
|
raise SwaggerError(
|
|
|
|
|
"Error loading %s" % api_declaration_file, context, e)
|
|
|
|
|
|
|
|
|
@ -621,8 +621,8 @@ class ApiDeclaration(Stringify):
|
|
|
|
|
.replace(".json", ".{format}")
|
|
|
|
|
|
|
|
|
|
if self.resource_path != expected_resource_path:
|
|
|
|
|
print >> sys.stderr, \
|
|
|
|
|
"%s != %s" % (self.resource_path, expected_resource_path)
|
|
|
|
|
print("%s != %s" % (self.resource_path, expected_resource_path),
|
|
|
|
|
file=sys.stderr)
|
|
|
|
|
raise SwaggerError("resourcePath has incorrect value", context)
|
|
|
|
|
|
|
|
|
|
return self
|
|
|
|
@ -652,8 +652,7 @@ class ApiDeclaration(Stringify):
|
|
|
|
|
if api.path in paths:
|
|
|
|
|
raise SwaggerError("API with duplicated path: %s" % api.path, context)
|
|
|
|
|
paths.add(api.path)
|
|
|
|
|
self.has_websocket = filter(lambda api: api.has_websocket,
|
|
|
|
|
self.apis) == []
|
|
|
|
|
self.has_websocket = any(api.has_websocket for api in self.apis)
|
|
|
|
|
models = api_decl_json.get('models').items() or []
|
|
|
|
|
self.models = [Model().load(id, json, processor, context)
|
|
|
|
|
for (id, json) in models]
|
|
|
|
@ -662,7 +661,7 @@ class ApiDeclaration(Stringify):
|
|
|
|
|
model_dict = dict((m.id, m) for m in self.models)
|
|
|
|
|
for m in self.models:
|
|
|
|
|
def link_subtype(name):
|
|
|
|
|
res = model_dict.get(subtype)
|
|
|
|
|
res = model_dict.get(name)
|
|
|
|
|
if not res:
|
|
|
|
|
raise SwaggerError("%s has non-existing subtype %s",
|
|
|
|
|
m.id, name)
|
|
|
|
@ -721,7 +720,7 @@ class ResourceListing(Stringify):
|
|
|
|
|
except SwaggerError:
|
|
|
|
|
raise
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print >> sys.stderr, "Error: ", traceback.format_exc()
|
|
|
|
|
print("Error: ", traceback.format_exc(), file=sys.stderr)
|
|
|
|
|
raise SwaggerError(
|
|
|
|
|
"Error loading %s" % resource_file, context, e)
|
|
|
|
|
|
|
|
|
@ -734,7 +733,7 @@ class ResourceListing(Stringify):
|
|
|
|
|
self.swagger_version = resources_json.get('swaggerVersion')
|
|
|
|
|
if not self.swagger_version in SWAGGER_VERSIONS:
|
|
|
|
|
raise SwaggerError(
|
|
|
|
|
"Unsupported Swagger version %s" % swagger_version, context)
|
|
|
|
|
"Unsupported Swagger version %s" % self.swagger_version, context)
|
|
|
|
|
|
|
|
|
|
validate_required_fields(resources_json, self.required_fields, context)
|
|
|
|
|
self.api_version = resources_json['apiVersion']
|
|
|
|
|