code: def convert_schemas(d, definitions=None):
      
      if Schema is None:
          raise RuntimeError('Please install marshmallow and apispec')
  
      if definitions is None:
          definitions = {}
      definitions.update(d.get('definitions', {}))
  
      new = {}
      for k, v in d.items():
          if isinstance(v, dict):
              v = convert_schemas(v, definitions)
          if isinstance(v, (list, tuple)):
              new_v = []
              for item in v:
                  if isinstance(item, dict):
                      new_v.append(convert_schemas(item, definitions))
                  else:
                      new_v.append(item)
              v = new_v
          if inspect.isclass(v) and issubclass(v, Schema):
              definitions[v.__name__] = schema2jsonschema(v)
              ref = {
                  "$ref": "#/definitions/{0}".format(v.__name__)
              }
              if k == 'parameters':
                  new[k] = schema2parameters(v)
                  new[k][0]['schema'] = ref
              else:
                  new[k] = ref
          else:
              new[k] = v
  
      # This key is not permitted anywhere except the very top level.
      if 'definitions' in new:
          del new['definitions']
  
      return new
docs: Convert Marshmallow schemas to dict definitions
  
      Also updates the optional definitions argument with any definitions
      entries contained within the schema.