required-dollar-id-in-root-schema
Overview
This rule belongs to the openapi-v3-standards-linting ruleset and states that:
The root schema of a JSON Schema document or a root Schema Object defined/referenced directly in a component of an OpenAPI document (e.g. Parameter Object, Header Object or a Media Type Object) should contain the $id property which uniquely identifies the schema and also helps indicate the Base URI for resolving relative references within the schema definition. The value of $id must be a valid absolute URI as per RFC3986. This URI must contain a scheme, but no fragment.
| Property | Value |
|---|---|
| Enabled | Yes |
| Maximum Severity | Warning |
| Message | $id is missing from root schema. |
| Code | OPENAPI3STANDARDS_L156 |
| Type | Linting |
| Rule System | Semantic |
| Broad Category | Schemas |
| Products Impacted | API Transformer, Code Generation, Developer Experience Portal |
| Tags | openapi3 openapi standards semantic linting id $id schema |
Suggested Fixes
- Add property
$idin the Schema Object with a value which is a valid URI, contains a scheme but no fragment. - Ensure that the $id value is non-empty and non-null.
- When a Schema Object references an external JSON schema document, the schema resource defined directly in this document at root level is considered the root schema.
- In an OpenAPI document a schema directly defined or referenced in a Parameter Object, Header Object or Media Type Object is considered a root schema.
For More Information
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object
- https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.2.1.1
- https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.2.1
- https://datatracker.ietf.org/doc/html/rfc3986
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md
- https://docs.apimatic.io/rulesets/overview/