The Concept
Reusable response objects are implemented as subclasses ofAbstractObjectProperty. They define a fixed set of properties that can be included in multiple ApivalkResponseDocumentation definitions.
Built-in Examples
ErrorApivalkObject
This object is used to represent a single validation error or a generic error message.
Structure:
name(string): The name of the field that caused the error.error(string): The human-readable error message.
Creating Your Own
You can create custom reusable objects by following these steps:- Create a Property Collection: Extend
AbstractPropertyCollectionand add your properties. - Create the Object: Extend
AbstractObjectPropertyand return your collection ingetPropertyCollection().
Example: UserObject
Benefits
- Consistency: All endpoints returning a “User” will have the exact same structure.
- Maintenance: If you add a field to the
UserObject, it is automatically updated in the OpenAPI documentation for all endpoints that use it. - DRY: You don’t have to redefine the same properties repeatedly.