Forum Discussion

radekoziol's avatar
6 years ago

Array null values

Hello,

 

Is it possible to define an array that can not contain null? 

I'm compiling it to Java with Open API 3.0

 

f.e for this example

A:
type: array
minItems: 1
items:
$ref: "#/components/schemas/B"
B:
type: string
pattern: ^[a-z]+$

 I consider [null] or ["abc",null] invalid

 

Thanks in advance

  • Hi radekoziol,

     

    Your example is correct. In OpenAPI 3.0, null values are only allowed if the schema has the nullable: true attribute. Since the B schema is not marked as nullable, it only allows string values but not nulls.

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Hi radekoziol,

     

    Your example is correct. In OpenAPI 3.0, null values are only allowed if the schema has the nullable: true attribute. Since the B schema is not marked as nullable, it only allows string values but not nulls.