schema-then-only-with-if-clause
Overview
This rule belongs to the openapi-v3-standards-validation ruleset and states that:
Property then can be used in a Schema Object along with the if clause to apply subschemas conditionally. When if is not present, the then property will be entirely ignored.
| Property | Value |
|---|---|
| Enabled | Yes |
| Maximum Severity | Error |
| Message | Schema Object property then used without the if clause. |
| Code | OPENAPI3STANDARDS_V346 |
| Type | Validation |
| Rule System | Semantic |
| Broad Category | Schemas |
| Products Impacted | API Transformer, Code Generation, Developer Experience Portal |
| Tags | openapi3 openapi standards semantic validation if then json schema schema |
Suggested Fixes
- Add the subschema in the Schema Object that needs to be evaluated, using the
ifproperty. - If you do not want to apply a subschema conditionally remove the
thenproperty from the Schema Object. - Only schemas that are valid against a subschema in
ifare evaluated against thethensubschema. Therefore, propertythenalone has no effect during schema validation and works along withifto 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.2
- 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/