Model Class Reference

Inheritance diagram for Model:

Inheritance graph
[legend]
Collaboration diagram for Model:

Collaboration graph
[legend]

Public Member Functions

def __init__
def all_subtypes
def discriminator
def extends
def has_properties
def has_subtypes
def load
def properties
def set_extends_type
def set_subtype_types

Data Fields

 description
 id
 model_json
 notes
 subtypes

Static Public Attributes

list required_fields = ['description', 'properties']

Detailed Description

Model of a Swagger model.

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

Definition at line 488 of file swagger_model.py.


Member Function Documentation

def __init__ (   self  ) 

Definition at line 496 of file swagger_model.py.

00496                       :
00497         self.id = None
00498         self.subtypes = []
00499         self.__subtype_types = []
00500         self.notes = None
00501         self.description = None
00502         self.__properties = None
00503         self.__discriminator = None
00504         self.__extends_type = None
00505 
    def load(self, id, model_json, processor, context):

def all_subtypes (   self  ) 

Returns the full list of all subtypes, including sub-subtypes.

Definition at line 569 of file swagger_model.py.

00569                           :
00570         """Returns the full list of all subtypes, including sub-subtypes.
00571         """
00572         res = self.__subtype_types + \
00573               [subsubtypes for subtype in self.__subtype_types
00574                for subsubtypes in subtype.all_subtypes()]
00575         return sorted(res, key=lambda m: m.id)
00576 
    def has_subtypes(self):

def discriminator (   self  ) 

Returns the discriminator, digging through base types if needed.

Definition at line 554 of file swagger_model.py.

00554                            :
00555         """Returns the discriminator, digging through base types if needed.
00556         """
00557         return self.__discriminator or \
00558             self.__extends_type and self.__extends_type.discriminator()
00559 
    def properties(self):

def extends (   self  ) 

Definition at line 545 of file swagger_model.py.

00545                      :
00546         return self.__extends_type and self.__extends_type.id
00547 
    def set_extends_type(self, extends_type):

def has_properties (   self  ) 

Definition at line 566 of file swagger_model.py.

00566                             :
00567         return len(self.properties()) > 0
00568 
    def all_subtypes(self):

def has_subtypes (   self  ) 

Returns True if type has any subtypes.

Definition at line 577 of file swagger_model.py.

00577                           :
00578         """Returns True if type has any subtypes.
00579         """
00580         return len(self.subtypes) > 0
00581 
00582 
class ApiDeclaration(Stringify):

def load (   self,
  id,
  model_json,
  processor,
  context 
)

Definition at line 506 of file swagger_model.py.

00506                                                       :
00507         context = context.next_stack(model_json, 'id')
00508         validate_required_fields(model_json, self.required_fields, context)
00509         # The duplication of the model's id is required by the Swagger spec.
00510         self.id = model_json.get('id')
00511         if id != self.id:
00512             raise SwaggerError("Model id doesn't match name", context)
00513         self.subtypes = model_json.get('subTypes') or []
00514         if self.subtypes and context.version_less_than("1.2"):
00515             raise SwaggerError("Type extension support added in Swagger 1.2",
00516                                context)
00517         self.description = model_json.get('description')
00518         props = model_json.get('properties').items() or []
00519         self.__properties = [
00520             Property(k).load(j, processor, context) for (k, j) in props]
00521         self.__properties = sorted(self.__properties, key=lambda p: p.name)
00522 
00523         discriminator = model_json.get('discriminator')
00524 
00525         if discriminator:
00526             if context.version_less_than("1.2"):
00527                 raise SwaggerError("Discriminator support added in Swagger 1.2",
00528                                    context)
00529 
00530             discr_props = [p for p in self.__properties if p.name == discriminator]
00531             if not discr_props:
00532                 raise SwaggerError(
00533                     "Discriminator '%s' does not name a property of '%s'" % (
00534                         discriminator, self.id),
00535                     context)
00536 
00537             self.__discriminator = discr_props[0]
00538 
00539         self.model_json = json.dumps(model_json,
00540                                      indent=2, separators=(',', ': '))
00541 
00542         processor.process_model(self, context)
00543         return self
00544 
    def extends(self):

def properties (   self  ) 

Definition at line 560 of file swagger_model.py.

00560                         :
00561         base_props = []
00562         if self.__extends_type:
00563             base_props = self.__extends_type.properties()
00564         return base_props + self.__properties
00565 
    def has_properties(self):

def set_extends_type (   self,
  extends_type 
)

Definition at line 548 of file swagger_model.py.

00548                                             :
00549         self.__extends_type = extends_type
00550 
    def set_subtype_types(self, subtype_types):

def set_subtype_types (   self,
  subtype_types 
)

Definition at line 551 of file swagger_model.py.

00551                                               :
00552         self.__subtype_types = subtype_types
00553 
    def discriminator(self):


Field Documentation

Definition at line 501 of file swagger_model.py.

id

Definition at line 497 of file swagger_model.py.

Definition at line 539 of file swagger_model.py.

Definition at line 500 of file swagger_model.py.

list required_fields = ['description', 'properties'] [static]

Definition at line 494 of file swagger_model.py.

Definition at line 498 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