Esempio n. 1
0
  def testDetectInline(self):
    schema = {
      "types": [
        {
          "id": "Key",
          "items": {
            "$ref": "Value"
          }
        },
        {
          "id": "Value",
          "marker": True
        }
      ]
    }

    expected_schema = {
      "types": [
        {
          "id": "Key",
          "items": {
            "marker": True,
          }
        }
      ]
    }

    _DetectInlineableTypes(schema)
    _InlineDocs(schema)
    self.assertEqual(expected_schema, schema)
Esempio n. 2
0
  def testDetectInline(self):
    schema = {
      "types": [
        {
          "id": "Key",
          "items": {
            "$ref": "Value"
          }
        },
        {
          "id": "Value",
          "marker": True
        }
      ]
    }

    expected_schema = {
      "types": [
        {
          "id": "Key",
          "items": {
            "marker": True,
          }
        }
      ]
    }

    _DetectInlineableTypes(schema)
    _InlineDocs(schema)
    self.assertEqual(expected_schema, schema)
Esempio n. 3
0
  def testInlineDocs(self):
    schema = {
      "namespace": "storage",
      "properties": {
        "key2": {
          "description": "second key",
          "$ref": "Key"
        },
        "key1": {
          "description": "first key",
          "$ref": "Key"
        }
      },
      "types": [
        {
          "inline_doc": True,
          "type": "string",
          "id": "Key",  # Should be inlined into both properties and be removed
                        # from types.
          "description": "This is a key.",  # This description should disappear.
          "marker": True  # This should appear three times in the output.
        },
        {
          "items": {
            "$ref": "Key"
          },
          "type": "array",
          "id": "KeyList",
          "description": "A list of keys"
        }
      ]
    }

    expected_schema = {
      "namespace": "storage",
      "properties": {
        "key2": {
          "marker": True,
          "type": "string",
          "description": "second key"
        },
        "key1": {
          "marker": True,
          "type": "string",
          "description": "first key"
        }
      },
      "types": [
        {
          "items": {
            "marker": True,
            "type": "string"
          },
          "type": "array",
          "id": "KeyList",
          "description": "A list of keys"
        }
      ]
    }

    inlined_schema = copy.deepcopy(schema)
    _InlineDocs(inlined_schema)
    self.assertEqual(expected_schema, inlined_schema)
Esempio n. 4
0
  def testInlineDocs(self):
    schema = {
      "namespace": "storage",
      "properties": {
        "key2": {
          "description": "second key",
          "$ref": "Key"
        },
        "key1": {
          "description": "first key",
          "$ref": "Key"
        }
      },
      "types": [
        {
          "inline_doc": True,
          "type": "string",
          "id": "Key",  # Should be inlined into both properties and be removed
                        # from types.
          "description": "This is a key.",  # This description should disappear.
          "marker": True  # This should appear three times in the output.
        },
        {
          "items": {
            "$ref": "Key"
          },
          "type": "array",
          "id": "KeyList",
          "description": "A list of keys"
        }
      ]
    }

    expected_schema = {
      "namespace": "storage",
      "properties": {
        "key2": {
          "marker": True,
          "type": "string",
          "description": "second key"
        },
        "key1": {
          "marker": True,
          "type": "string",
          "description": "first key"
        }
      },
      "types": [
        {
          "items": {
            "marker": True,
            "type": "string"
          },
          "type": "array",
          "id": "KeyList",
          "description": "A list of keys"
        }
      ]
    }

    inlined_schema = copy.deepcopy(schema)
    _InlineDocs(inlined_schema)
    self.assertEqual(expected_schema, inlined_schema)