Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ros): Copy better typing information from Notifications/Spreed app #49192

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/private/RichObjectStrings/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
/**
* Class Validator
*
* @psalm-import-type RichObjectParameter from IValidator
* @package OCP\RichObjectStrings
* @since 11.0.0
*/
Expand All @@ -27,7 +28,7 @@ public function __construct(

/**
* @param string $subject
* @param array<non-empty-string, array<non-empty-string, string>> $parameters
* @param array<non-empty-string, RichObjectParameter> $parameters
* @throws InvalidObjectExeption
* @since 11.0.0
*/
Expand Down
32 changes: 31 additions & 1 deletion lib/public/RichObjectStrings/IValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,36 @@
/**
* Class Validator
*
* @psalm-type RichObjectParameter = array{
Copy link
Member

@provokateurin provokateurin Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do this even better, by creating the exact types from

like this:

/**
 * @psalm-type RichObjectParameterAddressbook = array{
 *     id: string,
 *     type: string,
 *     name: string,
 * }
 *
 * @psalm-type RichObjectParameterAnnouncement = array{
 *     id: string,
 *     type: string,
 *     name: string,
 *     link?: string,
 * }
 *
 * @psalm-type RichObjectParameter = RichObjectParameterAddressbook|RichObjectParameterAnnouncement
 */

Of course this would be with all types, not just these ones.
Then every consumer knows exactly what they can use, because even with this annotation psalm will not yet prevent you from adding keys that are for a different object type.

We could have a script for this to ensure the psalm types match the definitions and then also make it available as a type for OpenAPI.
Maybe this is a bit overkill

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this is a bit overkill

Glad you noticed it yourself :P

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I have written this exact logic for a different use-case already, so it's not completely out of reach, just wanted to mention it would be possible to make it even stricter.

* type: string,
* id: string,
* name: string,
* server?: string,
* link?: string,
* 'call-type'?: 'one2one'|'group'|'public',
* 'icon-url'?: string,
* 'message-id'?: string,
* boardname?: string,
* stackname?: string,
* size?: string,
* path?: string,
* mimetype?: string,
* 'preview-available'?: 'yes'|'no',
* mtime?: string,
* latitude?: string,
* longitude?: string,
* description?: string,
* thumb?: string,
* website?: string,
* visibility?: '0'|'1',
* assignable?: '0'|'1',
* conversation?: string,
* etag?: string,
* permissions?: string,
* width?: string,
* height?: string,
* }
*
* @since 11.0.0
*/
interface IValidator {
Expand All @@ -22,7 +52,7 @@ interface IValidator {

/**
* @param string $subject
* @param array<non-empty-string, array<non-empty-string, string>> $parameters
* @param array<non-empty-string, RichObjectParameter> $parameters
* @throws InvalidObjectExeption
* @since 11.0.0
*/
Expand Down
Loading