OpenAPIDereferenceError
The Cause
Section titled “The Cause”Thymian failed to dereference all internal $ref references in your OpenAPI document. This occurs when:
- A
$refpoints to a location that doesn’t exist in the document - 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 existThe 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' -
Use external references sparingly - This error only concerns internal references. External references (URLs) are handled differently and cannot be dereferenced locally.
-
Validate your document - Use an OpenAPI validator to catch reference errors early:
Terminal window thymian openapi validate openapi.yaml
If you continue to see this error, enable debug output to see which specific references are failing:
DEBUG=thymian:* thymian openapi validate openapi.yaml