php-openapi-generator

Readonly Model Classes

Generated DTOs target PHP 8.2+ and can use readonly for immutability.

Behavior

When $config->phpReadonly = true and constructor generation is enabled, model templates emit class-level readonly DTOs where possible.

Example:

readonly class Pet
{
    public function __construct(
        public int $id,
        public string $name,
        public ?string $tag = null,
    ) {
    }
}

Why This Helps

Notes