ApiDeclaration Class Reference

Inheritance diagram for ApiDeclaration:

Inheritance graph
[legend]
Collaboration diagram for ApiDeclaration:

Collaboration graph
[legend]

Public Member Functions

def __init__
def load
def load_file

Data Fields

 api_version
 apis
 author
 base_path
 copyright
 has_websocket
 models
 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 583 of file swagger_model.py.


Member Function Documentation

def __init__ (   self  ) 

Definition at line 594 of file swagger_model.py.

00594                       :
00595         self.swagger_version = None
00596         self.author = None
00597         self.copyright = None
00598         self.api_version = None
00599         self.base_path = None
00600         self.resource_path = None
00601         self.apis = []
00602         self.models = []
00603 
    def load_file(self, api_declaration_file, processor):

def load (   self,
  api_decl_json,
  processor,
  context 
)

Loads a resource from a single Swagger resource.json file.

Definition at line 630 of file swagger_model.py.

00630                                                      :
00631         """Loads a resource from a single Swagger resource.json file.
00632         """
00633         # If the version doesn't match, all bets are off.
00634         self.swagger_version = api_decl_json.get('swaggerVersion')
00635         context = context.next(version=self.swagger_version)
00636         if not self.swagger_version in SWAGGER_VERSIONS:
00637             raise SwaggerError(
00638                 "Unsupported Swagger version %s" % self.swagger_version, context)
00639 
00640         validate_required_fields(api_decl_json, self.required_fields, context)
00641 
00642         self.author = api_decl_json.get('_author')
00643         self.copyright = api_decl_json.get('_copyright')
00644         self.api_version = api_decl_json.get('apiVersion')
00645         self.base_path = api_decl_json.get('basePath')
00646         self.resource_path = api_decl_json.get('resourcePath')
00647         api_json = api_decl_json.get('apis') or []
00648         self.apis = [
00649             Api().load(j, processor, context) for j in api_json]
00650         paths = set()
00651         for api in self.apis:
00652             if api.path in paths:
00653                 raise SwaggerError("API with duplicated path: %s" % api.path, context)
00654             paths.add(api.path)
00655         self.has_websocket = filter(lambda api: api.has_websocket,
00656                                     self.apis) == []
00657         models = api_decl_json.get('models').items() or []
00658         self.models = [Model().load(id, json, processor, context)
00659                        for (id, json) in models]
00660         self.models = sorted(self.models, key=lambda m: m.id)
00661         # Now link all base/extended types
00662         model_dict = dict((m.id, m) for m in self.models)
00663         for m in self.models:
00664             def link_subtype(name):
00665                 res = model_dict.get(subtype)
00666                 if not res:
00667                     raise SwaggerError("%s has non-existing subtype %s",
00668                                        m.id, name)
00669                 res.set_extends_type(m)
00670                 return res;
00671             if m.subtypes:
00672                 m.set_subtype_types([
00673                     link_subtype(subtype) for subtype in m.subtypes])
00674         return self
00675 
00676 
class ResourceApi(Stringify):

def load_file (   self,
  api_declaration_file,
  processor 
)

Definition at line 604 of file swagger_model.py.

00604                                                         :
00605         context = ParsingContext(None, [api_declaration_file])
00606         try:
00607             return self.__load_file(api_declaration_file, processor, context)
00608         except SwaggerError:
00609             raise
00610         except Exception as e:
00611             print >> sys.stderr, "Error: ", traceback.format_exc()
00612             raise SwaggerError(
00613                 "Error loading %s" % api_declaration_file, context, e)
00614 
    def __load_file(self, api_declaration_file, processor, context):


Field Documentation

Definition at line 598 of file swagger_model.py.

Definition at line 601 of file swagger_model.py.

Definition at line 596 of file swagger_model.py.

Definition at line 599 of file swagger_model.py.

Definition at line 597 of file swagger_model.py.

Definition at line 655 of file swagger_model.py.

Definition at line 602 of file swagger_model.py.

list required_fields [static]

Initial value:

[
        'swaggerVersion', '_author', '_copyright', 'apiVersion', 'basePath',
        'resourcePath', 'apis', 'models'
    ]

Definition at line 589 of file swagger_model.py.

Definition at line 600 of file swagger_model.py.

Definition at line 595 of file swagger_model.py.


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

Generated on Thu Apr 16 06:41:39 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6