Closed schristley closed 11 months ago
Personally, I think that is dangerous. How do you differentiate that from me defining a field where "null" as a string is one of the allowed enum values. I think this would be a quite common use case. Similar to having "NA" or "None", "null" would be a relatively common string to find in an enum definition.
If you want the string "null" then put quotes around it in the enum like so, the following allows both the null
value and the string "null"
as acceptable values.
sex:
type: string
enum:
- male
- female
- pooled
- hermaphrodite
- intersex
- "not collected"
- "not applicable"
- "null"
- null
nullable: true
description: Biological sex of subject
title: Sex
example: female
x-airr:
miairr: important
adc-query-support: true
set: 1
subset: subject
name: Sex
format: controlled vocabulary
As OpenAPI is based on JSON schema spec, only null
is a special value, stuff like "NA" and "None" are just strings.
While working on airr-js, I was getting validation errors for fields with
nullable: true
andenum
when the field value wasnull
. I'm using the ajv package for validation, instead of custom written like our python library. Apparently, there has been various discussions about this as OpenAPI schema and JSON schema aren't 100% equivalent. From what I can gather, the conclusion was thatnull
needs to be added to theenum
list. When I do that, as shown below, then validation passes.This really only applies to the OpenAPI V3 spec. This is a simple fix but it might effect UIs that display those enum lists.