Asterisk - The Open Source Telephony Project GIT-master-a358458
Public Member Functions | Data Fields | Static Public Attributes
ApiDeclaration Class Reference
Inheritance diagram for ApiDeclaration:
Inheritance graph
[legend]
Collaboration diagram for ApiDeclaration:
Collaboration graph
[legend]

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.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self)

Definition at line 607 of file swagger_model.py.

607 def __init__(self):
608 self.swagger_version = None
609 self.author = None
610 self.copyright = None
611 self.api_version = None
612 self.base_path = None
613 self.resource_path = None
614 self.apis = []
615 self.models = []
616

Member Function Documentation

◆ load()

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.

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
static int set(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition: func_logic.c:238
def validate_required_fields(json, required_fields, context)

References ApiDeclaration.api_version, ResourceListing.api_version, ApiDeclaration.author, ApiDeclaration.base_path, ResourceListing.base_path, ApiDeclaration.copyright, Parameter.required_fields, ErrorResponse.required_fields, Operation.required_fields, Api.required_fields, Property.required_fields, Model.required_fields, ApiDeclaration.required_fields, ResourceApi.required_fields, ResourceListing.required_fields, ApiDeclaration.resource_path, ParsingContext.swagger_version, ApiDeclaration.swagger_version, ResourceListing.swagger_version, and swagger_model.validate_required_fields().

Referenced by ApiDeclaration.load_file(), and ResourceListing.load_file().

◆ load_file()

def load_file (   self,
  api_declaration_file,
  processor 
)

Definition at line 617 of file swagger_model.py.

617 def load_file(self, api_declaration_file, processor):
618 context = ParsingContext(None, [api_declaration_file])
619 try:
620 return self.__load_file(api_declaration_file, processor, context)
621 except SwaggerError:
622 raise
623 except Exception as e:
624 print("Error: ", traceback.format_exc(), file=sys.stderr)
625 raise SwaggerError(
626 "Error loading %s" % api_declaration_file, context, e)
627
static int load_file(const char *filename, char **ret)
Read a TEXT file into a string and return the length.

References ApiDeclaration.__load_file(), ResourceListing.__load_file(), ApiDeclaration.load(), Api.load(), ResourceApi.load(), ErrorResponse.load(), Model.load(), Operation.load(), Parameter.load(), Property.load(), ResourceListing.load(), SwaggerType.load(), ast_speech_engine.load, ast_sorcery_wizard.load, ast_module_info.load, replace(), and ApiDeclaration.resource_path.

Field Documentation

◆ api_version

api_version

Definition at line 611 of file swagger_model.py.

Referenced by ApiDeclaration.load(), and ResourceListing.load().

◆ apis

apis

Definition at line 614 of file swagger_model.py.

Referenced by ResourceListing.load().

◆ author

author

Definition at line 609 of file swagger_model.py.

Referenced by ApiDeclaration.load().

◆ base_path

base_path

Definition at line 612 of file swagger_model.py.

Referenced by ApiDeclaration.load(), and ResourceListing.load().

◆ copyright

copyright

Definition at line 610 of file swagger_model.py.

Referenced by ApiDeclaration.load().

◆ has_websocket

has_websocket

Definition at line 669 of file swagger_model.py.

◆ models

models

Definition at line 615 of file swagger_model.py.

◆ required_fields

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

Definition at line 602 of file swagger_model.py.

Referenced by ApiDeclaration.load(), Api.load(), ResourceApi.load(), ErrorResponse.load(), Model.load(), Operation.load(), Parameter.load(), Property.load(), and ResourceListing.load().

◆ requires_modules

requires_modules

Definition at line 660 of file swagger_model.py.

◆ resource_path

resource_path

Definition at line 613 of file swagger_model.py.

Referenced by ApiDeclaration.load(), and ApiDeclaration.load_file().

◆ swagger_version

swagger_version

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