Asterisk - The Open Source Telephony Project  18.5.0
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 586 of file swagger_model.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self)

Definition at line 597 of file swagger_model.py.

597  def __init__(self):
598  self.swagger_version = None
599  self.author = None
600  self.copyright = None
601  self.api_version = None
602  self.base_path = None
603  self.resource_path = None
604  self.apis = []
605  self.models = []
606 

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 633 of file swagger_model.py.

References ApiDeclaration.api_version, ApiDeclaration.author, ApiDeclaration.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, ApiDeclaration.resource_path, ParsingContext.swagger_version, ApiDeclaration.swagger_version, and swagger_model.validate_required_fields().

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

633  def load(self, api_decl_json, processor, context):
634  """Loads a resource from a single Swagger resource.json file.
635  """
636  # If the version doesn't match, all bets are off.
637  self.swagger_version = api_decl_json.get('swaggerVersion')
638  context = context.next(version=self.swagger_version)
639  if not self.swagger_version in SWAGGER_VERSIONS:
640  raise SwaggerError(
641  "Unsupported Swagger version %s" % self.swagger_version, context)
642 
643  validate_required_fields(api_decl_json, self.required_fields, context)
644 
645  self.author = api_decl_json.get('_author')
646  self.copyright = api_decl_json.get('_copyright')
647  self.api_version = api_decl_json.get('apiVersion')
648  self.base_path = api_decl_json.get('basePath')
649  self.resource_path = api_decl_json.get('resourcePath')
650  self.requires_modules = api_decl_json.get('requiresModules') or []
651  api_json = api_decl_json.get('apis') or []
652  self.apis = [
653  Api().load(j, processor, context) for j in api_json]
654  paths = set()
655  for api in self.apis:
656  if api.path in paths:
657  raise SwaggerError("API with duplicated path: %s" % api.path, context)
658  paths.add(api.path)
659  self.has_websocket = any(api.has_websocket for api in self.apis)
660  models = api_decl_json.get('models').items() or []
661  self.models = [Model().load(id, json, processor, context)
662  for (id, json) in models]
663  self.models = sorted(self.models, key=lambda m: m.id)
664  # Now link all base/extended types
665  model_dict = dict((m.id, m) for m in self.models)
666  for m in self.models:
667  def link_subtype(name):
668  res = model_dict.get(name)
669  if not res:
670  raise SwaggerError("%s has non-existing subtype %s",
671  m.id, name)
672  res.set_extends_type(m)
673  return res;
674  if m.subtypes:
675  m.set_subtype_types([
676  link_subtype(subtype) for subtype in m.subtypes])
677  return self
678 
679 
def validate_required_fields(json, required_fields, context)
static int set(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition: func_logic.c:206

◆ load_file()

def load_file (   self,
  api_declaration_file,
  processor 
)

Definition at line 607 of file swagger_model.py.

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

607  def load_file(self, api_declaration_file, processor):
608  context = ParsingContext(None, [api_declaration_file])
609  try:
610  return self.__load_file(api_declaration_file, processor, context)
611  except SwaggerError:
612  raise
613  except Exception as e:
614  print("Error: ", traceback.format_exc(), file=sys.stderr)
615  raise SwaggerError(
616  "Error loading %s" % api_declaration_file, context, e)
617 
static int load_file(const char *filename, char **ret)
Read a TEXT file into a string and return the length.

Field Documentation

◆ api_version

api_version

Definition at line 601 of file swagger_model.py.

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

◆ apis

apis

Definition at line 604 of file swagger_model.py.

Referenced by ResourceListing.load().

◆ author

author

Definition at line 599 of file swagger_model.py.

Referenced by ApiDeclaration.load().

◆ base_path

base_path

Definition at line 602 of file swagger_model.py.

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

◆ copyright

copyright

Definition at line 600 of file swagger_model.py.

Referenced by ApiDeclaration.load().

◆ has_websocket

has_websocket

Definition at line 659 of file swagger_model.py.

◆ models

models

Definition at line 605 of file swagger_model.py.

◆ required_fields

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

Definition at line 592 of file swagger_model.py.

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

◆ requires_modules

requires_modules

Definition at line 650 of file swagger_model.py.

◆ resource_path

resource_path

Definition at line 603 of file swagger_model.py.

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

◆ swagger_version

swagger_version

Definition at line 598 of file swagger_model.py.

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


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