Showing results for 
Search instead for 
Did you mean: 

Mandatory/Conditional/Optional Fields

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. 



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

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


how can i show "code" in json schema? 


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.

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
New Here?
Join us and watch the welcome video:
Top Kudoed Authors