text: from __future__ import absolute_import
  from swagger_py_codegen.parser import Swagger
  
  
  def test_swagger_ref_count_01():
      data = {
          'definitions': {
              'Product': {
                  'properties': {
                      'price': {'type': 'number'},
                      'name': {'type': 'string'},
                      'seller': {
                          '$ref': '#/definitions/User'
                      }
                  }
              },
              'User': {
                  'properties': {
                      'name': {'type': 'string'},
                      'age': {'type': 'number'},
                  }
              }
          }
      }
      swagger = Swagger(data)
      assert swagger.definitions[0] == ('definitions', 'Product')
      assert swagger.definitions[1] == ('definitions', 'User')
  
  
  def test_swagger_ref_count_02():
      data = {
          'definitions': {
              'Order': {
                  'properties': {
                      'customer': {
                          '$ref': '#/definitions/User'
                      },
                      'seller': {
                          '$ref': '#/definitions/User'
                      },
                      'products': {
                          'type': 'array',
                          'items': {
                              '$ref': '#/definitions/Product'
                          }
                      }
                  }
              },
              'Product': {
                  'properties': {
                      'price': {'type': 'number'},
                      'name': {'type': 'string'},
                      'seller': {
                          '$ref': '#/definitions/User'
                      }
                  }
              },
              'User': {
                  'properties': {
                      'name': {'type': 'string'},
                      'age': {'type': 'number'},
                  }
              }
          }
      }
      swagger = Swagger(data)
      assert swagger.definitions[0] == ('definitions', 'Order')
      assert swagger.definitions[1] == ('definitions', 'Product')
      assert swagger.definitions[2] == ('definitions', 'User')
  
  
  def test_swagger_ref_count_03():
      data = {
          'definitions': {
              'Order': {
                  'properties': {
                      'customer': {
                          '$ref': '#/definitions/User'
                      },
                      'seller': {
                          '$ref': '#/definitions/User'
                      },
                      'products': {
                          'type': 'array',
                          'items': {
                              '$ref': '#/definitions/Product'
                          }
                      }
                  }
              },
              'Product': {
                  'properties': {
                      'price': {'type': 'number'},
                      'name': {'type': 'string'},
                      'seller': {
                          '$ref': '#/definitions/User'
                      }
                  }
              },
              'User': {
                  'properties': {
                      'name': {'type': 'string'},
                      'age': {'type': 'number'},
                  }
              },
              'OrderList': {
                  'properties': {
                      'orders': {
                          '$ref': '#/definitions/Order'
                      }
                  }
              }
          }
      }
      swagger = Swagger(data)
      assert swagger.definitions[0] == ('definitions', 'Order')
      assert swagger.definitions[1] == ('definitions', 'OrderList')
      assert swagger.definitions[2] == ('definitions', 'Product')
      assert swagger.definitions[3] == ('definitions', 'User')
  
  
  def test_swagger_ref_count_04():
      data = {
          'definitions': {
              'Order': {
                  'properties': {
                      'customer': {
                          '$ref': '#/definitions/User'
                      },
                      'seller': {
                          '$ref': '#/definitions/User'
                      },
                      'products': {
                          'type': 'array',
                          'items': {
                              '$ref': '#/definitions/Product'
                          }
                      }
                  }
              },
              'Product': {
                  'properties': {
                      'price': {'type': 'number'},
                      'name': {'type': 'string'},
                      'seller': {
                          '$ref': '#/definitions/User'
                      }
                  }
              },
              'User': {
                  'properties': {
                      'name': {'type': 'string'},
                      'age': {'type': 'number'},
                      'orders': {
                          'type': 'array',
                          'items': {
                              '$ref': '#/definitions/Order'
                          }
                      }
                  }
              }
          }
      }
      Swagger(data)
  
  
  def test_swagger_ref_node():
      data = {
          'definitions': {
              'Order': {
                  'properties': {
                      'customer': {
                          '$ref': '#/definitions/User'
                      },
                      'seller': {
                          '$ref': '#/definitions/User'
                      },
                      'products': {
                          'type': 'array',
                          'items': {
                              '$ref': '#/definitions/Product'
                          }
                      }
                  }
              },
              'Product': {
                  'properties': {
                      'price': {'type': 'number'},
                      'name': {'type': 'string'},
                      'seller': {
                          '$ref': '#/definitions/User'
                      }
                  }
              },
              'User': {
                  'properties': {
                      'name': {'type': 'string'},
                      'age': {'type': 'number'},
                  }
              }
          }
      }
      swagger = Swagger(data)
      p = swagger.get(
          ['definitions', 'Order', 'properties', 'products', 'items'])
      assert p['properties']['name']['type'] == 'string'
      assert p['properties']['seller']['properties']['age']['type'] == 'number'
  