cancel
Showing results for 
Search instead for 
Did you mean: 

Array null values

SOLVED
Highlighted
Member

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

Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions
Moderator

Re: Array null values

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.


Helen Kosova
SmartBear Technical Writer
________________________

 Join SmartBear Connect next April in Boston to meet with software development, API and testing experts from around the world! Get your ticket today!

View solution in original post

1 REPLY 1
Moderator

Re: Array null values

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.


Helen Kosova
SmartBear Technical Writer
________________________

 Join SmartBear Connect next April in Boston to meet with software development, API and testing experts from around the world! Get your ticket today!

View solution in original post