Asterisk - The Open Source Telephony Project  21.4.1
Public Member Functions | Data Fields | Static Public Attributes
ApiDeclaration Class Reference
Inheritance diagram for ApiDeclaration:
Stringify

Public Member Functions

def __init__ (self)
 
def load (self, api_decl_json, processor, context)
 
def load_file (self, api_declaration_file, processor)
 
- Public Member Functions inherited from Stringify
def __repr__ (self)
 

Data Fields

 api_version
 
 apis
 
 author
 
 base_path
 
 copyright
 
 has_websocket
 
 models
 
 requires_modules
 
 resource_path
 
 swagger_version
 

Static Public Attributes

list required_fields
 

Detailed Description

Model class for an API Declaration.

See https://github.com/wordnik/swagger-core/wiki/API-Declaration

Definition at line 596 of file swagger_model.py.

Member Function Documentation

def load (   self,
  api_decl_json,
  processor,
  context 
)
Loads a resource from a single Swagger resource.json file.

Definition at line 643 of file swagger_model.py.

References ApiDeclaration.api_version, ApiDeclaration.apis, ApiDeclaration.author, ApiDeclaration.base_path, ApiDeclaration.copyright, Api.has_websocket, ApiDeclaration.has_websocket, ApiDeclaration.models, Parameter.required_fields, ErrorResponse.required_fields, Operation.required_fields, Api.required_fields, Property.required_fields, Model.required_fields, ApiDeclaration.required_fields, ApiDeclaration.requires_modules, ApiDeclaration.resource_path, ParsingContext.swagger_version, and ApiDeclaration.swagger_version.

643  def load(self, api_decl_json, processor, context):
644  """Loads a resource from a single Swagger resource.json file.
645  """
646  # If the version doesn't match, all bets are off.
647  self.swagger_version = api_decl_json.get('swaggerVersion')
648  context = context.next(version=self.swagger_version)
649  if not self.swagger_version in SWAGGER_VERSIONS:
650  raise SwaggerError(
651  "Unsupported Swagger version %s" % self.swagger_version, context)
652 
653  validate_required_fields(api_decl_json, self.required_fields, context)
654 
655  self.author = api_decl_json.get('_author')
656  self.copyright = api_decl_json.get('_copyright')
657  self.api_version = api_decl_json.get('apiVersion')
658  self.base_path = api_decl_json.get('basePath')
659  self.resource_path = api_decl_json.get('resourcePath')
660  self.requires_modules = api_decl_json.get('requiresModules') or []
661  api_json = api_decl_json.get('apis') or []
662  self.apis = [
663  Api().load(j, processor, context) for j in api_json]
664  paths = set()
665  for api in self.apis:
666  if api.path in paths:
667  raise SwaggerError("API with duplicated path: %s" % api.path, context)
668  paths.add(api.path)
669  self.has_websocket = any(api.has_websocket for api in self.apis)
670  models = api_decl_json.get('models').items() or []
671  self.models = [Model().load(id, json, processor, context)
672  for (id, json) in models]
673  self.models = sorted(self.models, key=lambda m: m.id)
674  # Now link all base/extended types
675  model_dict = dict((m.id, m) for m in self.models)
676  for m in self.models:
677  def link_subtype(name):
678  res = model_dict.get(name)
679  if not res:
680  raise SwaggerError("%s has non-existing subtype %s",
681  m.id, name)
682  res.set_extends_type(m)
683  return res;
684  if m.subtypes:
685  m.set_subtype_types([
686  link_subtype(subtype) for subtype in m.subtypes])
687  return self
688 
689 
def load(self, api_decl_json, processor, context)

Field Documentation

list required_fields
static
Initial value:
1 = [
2  'swaggerVersion', '_author', '_copyright', 'apiVersion', 'basePath',
3  'resourcePath', 'apis', 'models'
4  ]

Definition at line 602 of file swagger_model.py.

Referenced by ApiDeclaration.load().


The documentation for this class was generated from the following file: