OpenAPIDereferenceError
The Cause
Section titled “The Cause”Thymian failed to resolve the $ref references in your OpenAPI document. This occurs when:
- A
$refpoints to a location that doesn’t exist in the document - A
$refpoints to an external file or URL that cannot be loaded (missing, unreadable, a directory, or unreachable) - A
$refuses an invalid path or pointer format (e.g., malformed JSON Pointer) - A
$refis circular or contains unresolvable nested references - The referenced schema or object is missing required fields
For example:
# ❌ Invalid: $ref points to non-existent pathcomponents: schemas: User: properties: role: $ref: '#/components/schemas/InvalidRole' # InvalidRole doesn't existA $ref can also point to another file. Thymian resolves the file path relative to the document that contains the $ref, and names the file in the error when it cannot be loaded:
# ❌ Invalid: openapi.yaml references a file that doesn't existpaths: /things: get: responses: '200': description: ok content: application/json: schema: $ref: './schemas/missing.yaml#/Thing' # schemas/missing.yaml doesn't exist next to openapi.yamlThe Solution
Section titled “The Solution”-
Verify all
$refpaths exist - Check that each reference points to an actual component or schema in your document.# ✅ Correct: $ref points to existing schemacomponents:schemas:User:properties:role:$ref: '#/components/schemas/Role' # Role is definedRole:type: stringenum: [admin, user, guest] -
Check JSON Pointer syntax - Ensure
$refpaths follow the JSON Pointer format:# ✅ Correct patterns:$ref: '#/components/schemas/User'$ref: '#/components/responses/NotFound'$ref: '#/paths/~1users/get' # Use ~1 for / in path segments -
Avoid circular references - If references form a cycle, use
allOf,oneOf, oranyOfto break the cycle:# ❌ Circular (User -> Address -> User)# ✅ Better: Break cycle with explicit schema compositionUser:type: objectproperties:address:allOf:- $ref: '#/components/schemas/Address' -
Check external file references - External references are supported. A
$refsuch as./schemas/user.yaml#/Useris resolved relative to the document that contains the$ref, not relative to the current working directory or the root document. Check that the referenced file exists and that its relative path is spelled correctly; a URL must be reachable, and an absolute path is used as written. -
Validate your document - Use an OpenAPI validator to catch reference errors early:
Terminal window thymian validate --spec openapi:openapi.yaml
If you continue to see this error, enable debug output to see which specific references are failing:
thymian validate --spec openapi:openapi.yaml --log-level debug