cancel
Showing results for 
Search instead for 
Did you mean: 

Mandatory/Conditional/Optional Fields

Highlighted
New Member

Mandatory/Conditional/Optional Fields

HI, I need help to create json schema with mandatory/conditional/optional field. For mandatory i am taking it inside "required". Those fields which are not under "required" will consider as "optional" 

 

But question is, how should i mention the fileds which are conditional. Meaning, there would be feilds which are optional but mandatory in case of dependant feild. 

 

Example:

There is object "services" and string is "name"

"code" string should come in case of "name" 

 

how can i show "code" in json schema? 

1 REPLY 1
Moderator

Re: Mandatory/Conditional/Optional Fields

There's no way to define conditional fields directly. What you can do is build a schema that's built of several schemas, using keywords like 'allOf', 'oneOf', 'anyOf' and 'not', to build sub-cases for the conditions. By doing that, you can say, for example, that if field X is defined, then fields Y and Z are required, whereas in other cases they are optional.

New Here?
Join us and watch the welcome video:
Top Kudoed Authors