dollar-schema-only-for-root-schema-of-external-schema-resource
Overview
This rule belongs to the openapi-v3-standards-validation
ruleset and states that:
If a schema definition is placed in an external/bare schema resource document (i.e. not an OpenAPI document), the $schema
property must only be used in the root schema of that document as it applies to the lexical scope of the entire schema resource. It must not appear in non-resource root schema objects.
Property | Value |
---|---|
Enabled | Yes |
Maximum Severity | Error |
Message | $schema is used in a non-root schema. |
Code | OPENAPI3STANDARDS_V340 |
Type | Validation |
Rule System | Semantic |
Broad Category | Schemas |
Products Impacted | API Transformer, Code Generation, Developer Experience Portal |
Tags | openapi3 openapi standards semantic validation root schema json schema $schema schema |
Suggested Fixes
- The top level schema object present directly in the external resource document is called the root schema.
- Remove $schema from all of the inline schema definitions (i.e. schemas defined at any level within the root schema) and declare it once in the root schema only.
- If a Schema Object is referenced from an external non-OAS resource document, the $schema rules of JSON schema Draft 2020-12 apply to it.
For More Information
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#specifying-schema-dialects
- https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-7.1
- https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.1.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/