original_docstring: Convert a restful.Field into a Swagger property declaration
docstring: Convert a restful.Field into a Swagger property declaration
docstring_tokens: Convert a restful . Field into a Swagger property declaration
code: def field_to_property(field):
      '''Convert a restful.Field into a Swagger property declaration'''
      prop = {'type': 'string'}
  
      if isinstance(field, fields.List):
          nested_field = field.container
          prop = {'type': 'array', 'items': field_to_property(nested_field)}
  
      elif isinstance(field, fields.Nested):
          nested_field = field.nested
          prop = {'$ref': nested_field.__apidoc__['name']}
          if getattr(field, '__apidoc__', {}).get('as_list'):
              prop = {'type': 'array', 'items': prop}
          elif not field.allow_null:
              prop['required'] = True
  
      elif field in mappings.FIELDS:
          prop = mappings.FIELDS[field].copy()
  
      elif field.__class__ in mappings.FIELDS:
          prop = mappings.FIELDS[field.__class__].copy()
  
      elif hasattr(field, '__apidoc__'):
          if 'type' in field.__apidoc__:
              prop = {'type': field.__apidoc__['type']}
              if 'format' in field.__apidoc__:
                  prop['format'] = field.__apidoc__['format']
          elif 'fields' in field.__apidoc__:
              prop = {'$ref': field.__apidoc__.get('name', field.__class__.__name__)}
  
      if getattr(field, 'description', None):
          prop['description'] = field.description
      if getattr(field, 'minimum', None) is not None:
          prop['minimum'] = field.minimum
      if getattr(field, 'maximum', None):
          prop['maximum'] = field.maximum
      if getattr(field, 'enum', None):
          prop['enum'] = field.enum
      if getattr(field, 'required', None):
          prop['required'] = field.required
      if getattr(field, 'default', None):
          prop['defaultValue'] = field.default
  
      return prop
code_tokens: def field_to_property ( field ) : prop = { 'type' : 'string' } if isinstance ( field , fields . List ) : nested_field = field . container prop = { 'type' : 'array' , 'items' : field_to_property ( nested_field ) } elif isinstance ( field , fields . Nested ) : nested_field = field . nested prop = { '$ref' : nested_field . __apidoc__ [ 'name' ] } if getattr ( field , '__apidoc__' , { } ) . get ( 'as_list' ) : prop = { 'type' : 'array' , 'items' : prop } elif not field . allow_null : prop [ 'required' ] = True elif field in mappings . FIELDS : prop = mappings . FIELDS [ field ] . copy ( ) elif field . __class__ in mappings . FIELDS : prop = mappings . FIELDS [ field . __class__ ] . copy ( ) elif hasattr ( field , '__apidoc__' ) : if 'type' in field . __apidoc__ : prop = { 'type' : field . __apidoc__ [ 'type' ] } if 'format' in field . __apidoc__ : prop [ 'format' ] = field . __apidoc__ [ 'format' ] elif 'fields' in field . __apidoc__ : prop = { '$ref' : field . __apidoc__ . get ( 'name' , field . __class__ . __name__ ) } if getattr ( field , 'description' , None ) : prop [ 'description' ] = field . description if getattr ( field , 'minimum' , None ) is not None : prop [ 'minimum' ] = field . minimum if getattr ( field , 'maximum' , None ) : prop [ 'maximum' ] = field . maximum if getattr ( field , 'enum' , None ) : prop [ 'enum' ] = field . enum if getattr ( field , 'required' , None ) : prop [ 'required' ] = field . required if getattr ( field , 'default' , None ) : prop [ 'defaultValue' ] = field . default return prop
short_docstring: Convert a restful.Field into a Swagger property declaration
short_docstring_tokens: Convert a restful . Field into a Swagger property declaration
comment: '''Convert a restful.Field into a Swagger property declaration'''