schema-else-only-with-if-clause
Overview
This rule belongs to the openapi-v3-standards-validation
ruleset and states that:
Property else
can be used in a Schema Object along with the if
clause to apply subschemas conditionally. When if
is not present, the else
property will be entirely ignored.
Property | Value |
---|---|
Enabled | Yes |
Maximum Severity | Error |
Message | Schema Object property else used without the if clause. |
Code | OPENAPI3STANDARDS_V347 |
Type | Validation |
Rule System | Semantic |
Broad Category | Schemas |
Products Impacted | API Transformer, Code Generation, Developer Experience Portal |
Tags | openapi3 openapi standards semantic validation if else json schema schema |
Suggested Fixes
- Add the subschema in the Schema Object that needs to be evaluated, using the
if
property. - If you do not want to apply a subschema conditionally remove the
else
property from the Schema Object. - Only schemas that are not valid against a subschema in
if
are evaluated against theelse
subschema. Therefore, propertyelse
alone has no effect during schema validation and works along withif
to produce the overall evaluation result.
For More Information
- https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-10.2.2
- https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-10.2.2.3
- https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-10.2.2.1
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#openapi-specification
- https://docs.apimatic.io/rulesets/overview/