# How to document multiple data types array in OpenAPI Definition

**URL:** <https://community.smartbear.com/t/how-to-document-multiple-data-types-array-in-openapi-definition/190>\
**Category:** Swagger OS\
**Tags:** api, migrated, swagger-oss, swagger-core\
**Created:** [October 24, 2021, 6:17am UTC](https://community.smartbear.com/t/how-to-document-multiple-data-types-array-in-openapi-definition/190 "2021-10-24T06:17:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [October 24, 2021, 6:17am UTC](https://community.smartbear.com/t/how-to-document-multiple-data-types-array-in-openapi-definition/190/1 "2021-10-24T06:17:54Z")

</div>

> Originally posted by **lnash94** on October 23, 2021

Hi all,

I’m looking for an OpenAPI representation for an array type when the array has one specific data type item at one time, the array data type can be multiple types. That means as an example:

let’s assume I have an array called `arry` with two data types **integer** and **string** , when I receive `arry`, It can be contained items only one type. It can be an **integer** array(**arry[] → [integer, integer, integer]**) or **string** array (**arry[] → [string, string, string]**).

If I use **oneOf** data model :

…

**arry:**

**type: array**

**items:**

**oneOf:**

**- type: string**

**- type: integer**

it will return the mixed type array **arry[]-\>[integer, string, integer, integer, string]**

Could you please let me know, how can I represent array **arry[] → [integer, integer, integer]** or **arry[] → [string, string, string]** in the OpenAPI definition?

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [December 13, 2021, 10:53pm UTC](https://community.smartbear.com/t/how-to-document-multiple-data-types-array-in-openapi-definition/190/2 "2021-12-13T22:53:11Z")

</div>

> Originally posted by **HKosova** on December 13, 2021

You are almost there. Here’s how to define a non-mixed array:

```auto
arry:
  oneOf:
    - type: array
      items:
        type: integer
    - type: array
      items:
        type: string

```

Depending on how well your tooling handles “oneOf”, this can be simplified into:

```auto
arry:
  type: array
  oneOf:
    - items:
        type: integer
    - items:
        type: string

```

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [January 11, 2022, 4:05am UTC](https://community.smartbear.com/t/how-to-document-multiple-data-types-array-in-openapi-definition/190/3 "2022-01-11T04:05:04Z")

</div>

> Originally posted by **lnash94** on January 10, 2022

Thank you HKosova , This solution fits to my requirement of tool 🙂

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [May 4, 2022, 1:30am UTC](https://community.smartbear.com/t/how-to-document-multiple-data-types-array-in-openapi-definition/190/4 "2022-05-04T01:30:02Z")

</div>

> Originally posted by **elanh** on May 03, 2022

Hey HKosova ,

I’m trying to do a mixed type array for a body parameter called params using the “anyOf” param but it seems to only let me choose ONE of the options instead of adding both into the array. For context, the request I’m trying to replicate looks like this:

```auto
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body: 
{
    "jsonrpc":"2.0",
    "method":"eth_getBlockByNumber",
    "params":["0x1b4", true],
    "id":0
}

```

The OpenAPI spec for “params” is what I’m planning on using the “anyOf” (or “allOf”) field for as follows:

```auto
            "params": {
              "type": "array",
              "items": {
                "anyOf": [
                  {
                    "type": "string",
                    "description": "yo yo"
                  },
                  {
                    "type": "boolean",
                    "description": "hello"
                  }
                ]
              },
              "description": "something"
            }

```

Any ideas on how to achieve this?

---

<div class="post-metadata">

**Author:** ![system](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@system](https://community.smartbear.com/u/system)\
**Post date:** [October 7, 2026, 5:13pm UTC](https://community.smartbear.com/t/how-to-document-multiple-data-types-array-in-openapi-definition/190/5 "2026-10-07T17:13:44Z")

</div>

Closed on October 7, 2026, 5:13pm UTC

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
