Skip to content

Conversation

@abnegate
Copy link
Member

@abnegate abnegate commented Sep 22, 2025

With this you can define a model type per parameter, and the framework will take care of transforming the JSON into the model, and then you can validate against the actual model type as well.

With this as the base, from Appwrite, we can define a base request model class, pretty much exactly the same as we have for response models. Request classes can extend the base model, implement the utopia interface, then at spec generation time we have all we need to create proper schema models as we do for responses. Then SDKs can generate fully typed request models wherever needed

Example in the API:

class User extends Model implements UtopiaModel
{
    final public function __construct(
        public string $name,
        public int $age,
        public ?string $email = null
    ) {
        $this->addRule('name', [
            'type' => self::TYPE_STRING,
            'description' => 'Users name.',
            'default' => '',
            'example' => 'jake',
        ]);
        ...
    }

    public static function fromArray(array $value): static
    {
        return new static(
            $value['name'],
            $value['age'],
            $value['email'] ?? null
        );
    }
}
App::post('/users')
    ->param('user', null, new UserValidator(), ..., model: User::class)
    ->action(function (?User $user) {
      ...
    });

And from SDKs:

$users->create(new User(name: '...', ...));

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 22, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat-request-model

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants