Skip to main content

Property Types

Apivalk provides several built-in property classes:
ClassDescriptionPHP TypeOpenAPI Type
StringPropertyTextual datastringstring
NumberPropertyNumeric data (int/float)int or floatnumber or integer
BooleanPropertyTrue/False valuesboolboolean
ArrayPropertyList of itemsarrayarray
AbstractObjectPropertyNested object structurearrayobject

Base Configuration

All properties share a common set of configuration methods:
  • setIsRequired(bool $required): Whether the property must be present.
  • setExample(string $example): A sample value for OpenAPI documentation.
  • addValidator(AbstractValidator $validator): Add custom validation logic.

Specific Features

StringProperty

  • setMinLength(int) / setMaxLength(int)
  • setPattern(string): Regex validation.
  • setEnum(array): List of allowed values.
  • setFormat(string): e.g., date, date-time, email, uuid, byte (base64).

NumberProperty

  • setMinimum(float) / setMaximum(float)
  • setExclusiveMinimum(bool) / setExclusiveMaximum(bool)
  • setFormat(string): e.g., int32, int64, float, double.

ArrayProperty

  • setItemProperty(AbstractProperty): Defines the type of items within the array.

AbstractObjectProperty

  • Used to define nested schemas. You extend this class and implement the getPropertyCollection() method to define the nested properties.

Validation Integration

When a property is instantiated, it automatically creates a corresponding validator via the ValidatorFactory. This validator is used by the RequestValidationMiddleware to ensure incoming data matches your definitions.
// Example: A required, 5-10 char long string matching a pattern
$prop = new StringProperty('username', 'The login name');
$prop->setIsRequired(true)
     ->setMinLength(5)
     ->setMaxLength(10)
     ->setPattern('/^[a-z0-9]+$/');