Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Functions | Variables
swagger_model Namespace Reference

Data Structures

class  AllowableList
 
class  AllowableRange
 
class  Api
 
class  ApiDeclaration
 
class  ErrorResponse
 
class  Model
 
class  Operation
 
class  Parameter
 
class  ParsingContext
 
class  Property
 
class  ResourceApi
 
class  ResourceListing
 
class  Stringify
 
class  SwaggerError
 
class  SwaggerPostProcessor
 
class  SwaggerType
 

Functions

def compare_versions (lhs, rhs)
 
def get_list_parameter_type (type_string)
 
def load_allowable_values (json, context)
 
def validate_required_fields (json, required_fields, context)
 

Variables

list SWAGGER_PRIMITIVES
 
list SWAGGER_VERSIONS = ["1.1", "1.2"]
 

Function Documentation

◆ compare_versions()

def swagger_model.compare_versions (   lhs,
  rhs 
)
Performs a lexicographical comparison between two version numbers.

This properly handles simple major.minor.whatever.sure.why.not version
numbers, but fails miserably if there's any letters in there.

For reference:
  1.0 == 1.0
  1.0 < 1.0.1
  1.2 < 1.10

@param lhs Left hand side of the comparison
@param rhs Right hand side of the comparison
@return  < 0 if lhs  < rhs
@return == 0 if lhs == rhs
@return  > 0 if lhs  > rhs

Definition at line 60 of file swagger_model.py.

Referenced by ParsingContext.version_less_than().

60 def compare_versions(lhs, rhs):
61  '''Performs a lexicographical comparison between two version numbers.
62 
63  This properly handles simple major.minor.whatever.sure.why.not version
64  numbers, but fails miserably if there's any letters in there.
65 
66  For reference:
67  1.0 == 1.0
68  1.0 < 1.0.1
69  1.2 < 1.10
70 
71  @param lhs Left hand side of the comparison
72  @param rhs Right hand side of the comparison
73  @return < 0 if lhs < rhs
74  @return == 0 if lhs == rhs
75  @return > 0 if lhs > rhs
76  '''
77  lhs = [int(v) for v in lhs.split('.')]
78  rhs = [int(v) for v in rhs.split('.')]
79  return (lhs > rhs) - (lhs < rhs)
80 
81 
def compare_versions(lhs, rhs)

◆ get_list_parameter_type()

def swagger_model.get_list_parameter_type (   type_string)
Returns the type parameter if the given type_string is List[].

@param type_string: Type string to parse
@returns Type parameter of the list, or None if not a List.

Definition at line 453 of file swagger_model.py.

Referenced by SwaggerType.load().

453 def get_list_parameter_type(type_string):
454  """Returns the type parameter if the given type_string is List[].
455 
456  @param type_string: Type string to parse
457  @returns Type parameter of the list, or None if not a List.
458  """
459  list_match = re.match('^List\[(.*)\]$', type_string)
460  return list_match and list_match.group(1)
461 
462 
def get_list_parameter_type(type_string)

◆ load_allowable_values()

def swagger_model.load_allowable_values (   json,
  context 
)
Parse a JSON allowableValues object.

This returns None, AllowableList or AllowableRange, depending on the
valueType in the JSON. If the valueType is not recognized, a SwaggerError
is raised.

Definition at line 240 of file swagger_model.py.

240 def load_allowable_values(json, context):
241  """Parse a JSON allowableValues object.
242 
243  This returns None, AllowableList or AllowableRange, depending on the
244  valueType in the JSON. If the valueType is not recognized, a SwaggerError
245  is raised.
246  """
247  if not json:
248  return None
249 
250  if not 'valueType' in json:
251  raise SwaggerError("Missing valueType field", context)
252 
253  value_type = json['valueType']
254 
255  if value_type == 'RANGE':
256  if not 'min' in json and not 'max' in json:
257  raise SwaggerError("Missing fields min/max", context)
258  return AllowableRange(json.get('min'), json.get('max'))
259  if value_type == 'LIST':
260  if not 'values' in json:
261  raise SwaggerError("Missing field values", context)
262  return AllowableList(json['values'])
263  raise SwaggerError("Unkown valueType %s" % value_type, context)
264 
265 
def load_allowable_values(json, context)

◆ validate_required_fields()

def swagger_model.validate_required_fields (   json,
  required_fields,
  context 
)
Checks a JSON object for a set of required fields.

If any required field is missing, a SwaggerError is raised.

@param json: JSON object to check.
@param required_fields: List of required fields.
@param context: Current context in the API.

Definition at line 752 of file swagger_model.py.

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

752 def validate_required_fields(json, required_fields, context):
753  """Checks a JSON object for a set of required fields.
754 
755  If any required field is missing, a SwaggerError is raised.
756 
757  @param json: JSON object to check.
758  @param required_fields: List of required fields.
759  @param context: Current context in the API.
760  """
761  missing_fields = [f for f in required_fields if not f in json]
762 
763  if missing_fields:
764  raise SwaggerError(
765  "Missing fields: %s" % ', '.join(missing_fields), context)
766 
def validate_required_fields(json, required_fields, context)

Variable Documentation

◆ SWAGGER_PRIMITIVES

list SWAGGER_PRIMITIVES

Definition at line 40 of file swagger_model.py.

◆ SWAGGER_VERSIONS

list SWAGGER_VERSIONS = ["1.1", "1.2"]

Definition at line 38 of file swagger_model.py.