Asterisk - The Open Source Telephony Project GIT-master-2de1a68
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 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.

60def 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)

Referenced by ParsingContext.version_less_than().

◆ get_list_parameter_type()

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

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

Referenced by SwaggerType.load().

◆ load_allowable_values()

def 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.

240def 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 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 762 of file swagger_model.py.

762def validate_required_fields(json, required_fields, context):
763 """Checks a JSON object for a set of required fields.
764
765 If any required field is missing, a SwaggerError is raised.
766
767 @param json: JSON object to check.
768 @param required_fields: List of required fields.
769 @param context: Current context in the API.
770 """
771 missing_fields = [f for f in required_fields if not f in json]
772
773 if missing_fields:
774 raise SwaggerError(
775 "Missing fields: %s" % ', '.join(missing_fields), context)
def validate_required_fields(json, required_fields, context)

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

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.