---
title: Demonstrate oneOf, allOf, and anyOf
slug: mihai/demonstrate-oneof-allof-and-anyof
docTags: 
createdAt: 2026-03-19T09:41:40.820Z
---

{
  "id": "3UixS77SxVVfUwo3eYPUA",
  "type": "api-oas-v2",
  "data": {
    "method": "POST",
    "url": "/example",
    "servers": [],
    "name": "Demonstrate oneOf, allOf, and anyOf",
    "description": "",
    "contentType": "application/json",
    "request": {
      "pathParameters": [],
      "headerParameters": [],
      "queryParameters": [],
      "bodyDataParameters": [
        {
          "kind": "optional",
          "name": "body",
          "type": "object",
          "description": "",
          "schema": [
            {
              "name": "oneOfExample",
              "kind": "required",
              "type": "object",
              "description": "",
              "complexType": "oneOf",
              "complexItems": [
                {
                  "name": "Cat",
                  "description": "",
                  "modelRef": "#/components/schemas/Cat",
                  "schema": [
                    {
                      "name": "name",
                      "kind": "required",
                      "type": "string",
                      "description": "",
                      "example": ""
                    },
                    {
                      "name": "meows",
                      "kind": "required",
                      "type": "boolean",
                      "description": "",
                      "example": ""
                    }
                  ]
                },
                {
                  "name": "Dog",
                  "description": "",
                  "modelRef": "#/components/schemas/Dog",
                  "schema": [
                    {
                      "name": "name",
                      "kind": "required",
                      "type": "string",
                      "description": "",
                      "example": ""
                    },
                    {
                      "name": "barks",
                      "kind": "required",
                      "type": "boolean",
                      "description": "",
                      "example": ""
                    }
                  ]
                }
              ],
              "schema": []
            },
            {
              "name": "allOfExample",
              "kind": "required",
              "type": "object",
              "description": "",
              "complexType": "allOf",
              "complexItems": [
                {
                  "name": "Animal",
                  "description": "",
                  "modelRef": "#/components/schemas/Animal",
                  "schema": [
                    {
                      "name": "name",
                      "kind": "required",
                      "type": "string",
                      "description": "",
                      "example": ""
                    },
                    {
                      "name": "age",
                      "kind": "optional",
                      "type": "integer",
                      "description": "",
                      "example": 0
                    }
                  ]
                },
                {
                  "name": "object",
                  "description": "",
                  "schema": [
                    {
                      "name": "petType",
                      "kind": "required",
                      "type": "string<Cat | Dog>",
                      "description": "",
                      "example": "",
                      "enum": [
                        "Cat",
                        "Dog"
                      ]
                    }
                  ]
                }
              ],
              "schema": []
            },
            {
              "name": "anyOfExample",
              "kind": "required",
              "type": "object",
              "description": "",
              "complexType": "anyOf",
              "complexItems": [
                {
                  "name": "Car",
                  "description": "",
                  "modelRef": "#/components/schemas/Car",
                  "schema": [
                    {
                      "name": "brand",
                      "kind": "required",
                      "type": "string",
                      "description": "",
                      "example": ""
                    },
                    {
                      "name": "model",
                      "kind": "required",
                      "type": "string",
                      "description": "",
                      "example": ""
                    }
                  ]
                },
                {
                  "name": "Bike",
                  "description": "",
                  "modelRef": "#/components/schemas/Bike",
                  "schema": [
                    {
                      "name": "brand",
                      "kind": "required",
                      "type": "string",
                      "description": "",
                      "example": ""
                    },
                    {
                      "name": "type",
                      "kind": "required",
                      "type": "string",
                      "description": "",
                      "example": ""
                    }
                  ]
                }
              ],
              "schema": []
            }
          ],
          "isExpanded": true
        }
      ],
      "formDataParameters": [],
      "oAuthParameters": []
    },
    "responses": [
      {
        "statusCode": "200",
        "description": "Successful response",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "description": "",
            "schema": [
              {
                "name": "message",
                "kind": "optional",
                "type": "string",
                "description": "",
                "example": ""
              }
            ],
            "isExpanded": true
          }
        ]
      }
    ],
    "hasXCodeSamples": false,
    "examples": {
      "languages": [
        {
          "id": "NTT-QFghRNdWA25glhLSZ",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request POST \\\n     --url /example \\\n     --header 'accept: application/json' \\\n     --header 'content-type: application/json' \\\n     --data '{\n     \"oneOfExample\": {\n     \"name\": \"\",\n     \"meows\": \"\"\n     },\n     \"allOfExample\": {\n     \"name\": \"\",\n     \"petType\": \"\"\n     },\n     \"anyOfExample\": {\n     \"brand\": \"\",\n     \"model\": \"\"\n     }\n     }'"
        },
        {
          "id": "migyZe2SY6gO3YkNuYZBa",
          "language": "javascript",
          "label": "javascript",
          "code": "var myHeaders = new Headers();\nmyHeaders.append(\"accept\", \"application/json\");\nmyHeaders.append(\"content-type\", \"application/json\");\n\nvar raw = JSON.stringify({\n   \"oneOfExample\": {\n      \"name\": \"\",\n      \"meows\": \"\"\n   },\n   \"allOfExample\": {\n      \"name\": \"\",\n      \"petType\": \"\"\n   },\n   \"anyOfExample\": {\n      \"brand\": \"\",\n      \"model\": \"\"\n   }\n});\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   body: raw,\n   redirect: 'follow'\n};\n\nfetch(\"/example\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "4Iju4YCzzxMdHCjJxgvjm",
          "language": "ruby",
          "label": "Ruby",
          "code": "require \"uri\"\nrequire \"json\"\nrequire \"net/http\"\n\nurl = URI(\"/example\")\n\nhttp = Net::HTTP.new(url.host, url.port);\nrequest = Net::HTTP::Post.new(url)\nrequest[\"accept\"] = \"application/json\"\nrequest[\"content-type\"] = \"application/json\"\nrequest.body = JSON.dump({\n   \"oneOfExample\": {\n      \"name\": \"\",\n      \"meows\": \"\"\n   },\n   \"allOfExample\": {\n      \"name\": \"\",\n      \"petType\": \"\"\n   },\n   \"anyOfExample\": {\n      \"brand\": \"\",\n      \"model\": \"\"\n   }\n})\n\nresponse = http.request(request)\nputs response.read_body\n"
        },
        {
          "id": "v7_-CNhhX_QKNm3DB8Y0J",
          "language": "python",
          "label": "Python",
          "code": "import requests\nimport json\n\nurl = \"/example\"\n\npayload = json.dumps({\n   \"oneOfExample\": {\n      \"name\": \"\",\n      \"meows\": \"\"\n   },\n   \"allOfExample\": {\n      \"name\": \"\",\n      \"petType\": \"\"\n   },\n   \"anyOfExample\": {\n      \"brand\": \"\",\n      \"model\": \"\"\n   }\n})\nheaders = {\n   'accept': 'application/json',\n   'content-type': 'application/json'\n}\n\nresponse = requests.request(\"POST\", url, headers=headers, data=payload)\n\nprint(response.text)\n"
        }
      ],
      "selectedLanguageId": "NTT-QFghRNdWA25glhLSZ"
    },
    "results": {
      "languages": [
        {
          "id": "2HD1Bi_gvCS7368m5xnN3",
          "language": "200",
          "code": "// Successful response\n{\n  \"message\": \"\"\n}"
        }
      ],
      "selectedLanguageId": "2HD1Bi_gvCS7368m5xnN3"
    }
  },
  "children": [
    {
      "text": ""
    }
  ]
}