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

user_status: Add OpenAPI spec #36408

Closed
wants to merge 1 commit into from

Conversation

provokateurin
Copy link
Member

@provokateurin provokateurin commented Jan 27, 2023

Summary

Adapts the code to make it friendly for https://github.com/nextcloud-gmbh/openapi-extractor and add the automatically generated spec.

TODO

Checklist

Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Psalm found more than 10 potential problems in the proposed changes. Check the Files changed tab for more details.

apps/user_status/lib/Controller/HeartbeatController.php Outdated Show resolved Hide resolved
Comment on lines +73 to +78
* @return DataResponse<PrivateUserStatus> 200 Status successfully updated
* @return DataResponse 204 User has no status to update
* @return DataResponse 400 Invalid status to update
Copy link
Contributor

Choose a reason for hiding this comment

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

Several @return is not allowed it seems, see psalm errors.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah this is still a problem I have no solution for. I really need to have this working, but I don't know how. Only a single return annotation is kind of impossible or will get really ugly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would PHP attributes be a possible solution here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Wdym? We probably found a solution for this problem, but I first need to test it.

Copy link
Member

Choose a reason for hiding this comment

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

https://www.php.net/manual/de/language.attributes.syntax.php it something we could use in Nextcloud 26+ as it requires PHP8+

Sample in #36363

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm I see, but it wouldn't help with static analysis, right? The idea seems pretty good though.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you define am attribute and scan statically for that attribute, you can find these. You might be able to use reflections to let the PHP parser do the scanning even.
As PHP 7 is EOL, it should be good to go in general.
You could add a parameter to the attribute that contains an array. The keys would be the status codes and the value either a string of even a structure to describe the status.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but this won't help psalm validate the code in the method, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe i got the problem wrong. Are you concerned about static code analysis using psalm or about the extraction of the API specification from the code?
For psalm a single return should be sufficient, right?

Copy link
Member Author

@provokateurin provokateurin Feb 9, 2023

Choose a reason for hiding this comment

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

Both. Please let us discuss this in #36513

apps/user_status/lib/Controller/HeartbeatController.php Outdated Show resolved Hide resolved
@@ -57,12 +60,12 @@ public function __construct(string $appName,
/**
* @NoAdminRequired
*
* @return DataResponse
* @return DataResponse<PredefinedStatus[]> 200
Copy link
Contributor

Choose a reason for hiding this comment

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

DataResponse is not a template in the current code base. Remove the parameter or update the docblocks of DataRepsonse to make it a template.

Copy link
Member Author

Choose a reason for hiding this comment

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

#36355 can you review?

apps/user_status/lib/Model/Response/PredefinedStatus.php Outdated Show resolved Hide resolved
apps/user_status/lib/Model/Response/PrivateUserStatus.php Outdated Show resolved Hide resolved
apps/user_status/lib/Model/Response/PredefinedStatus.php Outdated Show resolved Hide resolved
apps/user_status/lib/Model/Response/PredefinedStatus.php Outdated Show resolved Hide resolved
apps/user_status/lib/Model/Response/PublicUserStatus.php Outdated Show resolved Hide resolved
@provokateurin provokateurin force-pushed the feature/user_status-openapi branch 3 times, most recently from 8c790bf to 73f5c87 Compare February 1, 2023 11:34
@blizzz blizzz mentioned this pull request Feb 1, 2023
@provokateurin provokateurin force-pushed the feature/user_status-openapi branch 4 times, most recently from 0253834 to e514beb Compare February 3, 2023 09:10
@provokateurin provokateurin marked this pull request as draft February 3, 2023 10:52
@provokateurin provokateurin force-pushed the feature/user_status-openapi branch 2 times, most recently from cf4adbd to b3a7a60 Compare February 4, 2023 21:38
This was referenced Feb 8, 2023
@skjnldsv skjnldsv deleted the feature/user_status-openapi branch March 14, 2024 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants