“null” is not a valid type in swagger, nor is “anyOf” or multi-types.

 

 

 

From: 'Toe Dipper' via Swagger <swagger-swaggersocket@googlegroups.com>
Reply-To: "swagger-swaggersocket@googlegroups.com" 
<swagger-swaggersocket@googlegroups.com>
Date: Friday, 23 June 2017 at 11:54
To: Swagger <swagger-swaggersocket@googlegroups.com>
Subject: Re: How to specify a property can be null or a reference

 

I am also curious for support for "nullable" fields.  Support for "oneOf" and 
"anyOf" is not quite the same thing.  In JSON Schema, the "type" field can be 
an array, e.g. to indicate a nullable field: 

 

// In JSON Schema
{
   "type": ["string", "null"]
}
// Or, using anyOf
{
   "anyOf":[
      {"type": "string"},
      {"type": "null"}
   ]
}


The end result is equivalent to "anyOf"... arguably the JSON Schema spec should 
simplify so that the type is always a string and "anyOf" is the only way to 
support this "string OR null" value.

 

To clear, the "required" keyword does not cover this specific use case where a 
property needs to exist, but its value might need to be null.

 

Relatedly, the "swagger-cli" npm package DOES consider the type: ["string", 
"null"] as valid, but the online editor does not.  Which is correct?


Please NOTE: This electronic message, including any attachments, may include 
privileged, confidential and/or inside information owned by Leaf Group. Any 
distribution or use of this communication by anyone other than the intended 
recipient(s) is strictly prohibited and may be unlawful. If you are not the 
intended recipient, please notify the sender by replying to this message and 
then delete it from your system. Thank you. 

-- 
You received this message because you are subscribed to the Google Groups 
"Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to swagger-swaggersocket+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


-- 
You received this message because you are subscribed to the Google Groups 
"Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to swagger-swaggersocket+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to