Skip to content

Initial attempt at adding Swagger annotations#204

Closed
snake14 wants to merge 3 commits into5.x-devfrom
PG-4407-swagger-annotation-poc
Closed

Initial attempt at adding Swagger annotations#204
snake14 wants to merge 3 commits into5.x-devfrom
PG-4407-swagger-annotation-poc

Conversation

@snake14
Copy link
Copy Markdown
Contributor

@snake14 snake14 commented Aug 5, 2025

Description

POC adding annotations for php-swagger.

If you check out this branch and the new plugin PR, you can test generating the documentation by running the following console command: openapidocs:generate-doc-file --plugin=CustomAlerts. I have been pasting that output into https://editor.swagger.io/ to view how it presents.

Comment thread API.php
namespace Piwik\Plugins\CustomAlerts;

use Exception;
use OpenApi\Annotations as OA;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This isn't technically required for the documentation to be generated, but it's nice for autocomplete.

@snake14
Copy link
Copy Markdown
Contributor Author

snake14 commented Aug 5, 2025

@AltamashShaikh @james-hill-matomo Can you please take an initial look at this and let me know what you think?

Copy link
Copy Markdown
Contributor

@AltamashShaikh AltamashShaikh left a comment

Choose a reason for hiding this comment

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

@snake14 Good work

I see errors when I paste the JSON

image

Also not important, we should make this screen better if possible

image

@AltamashShaikh
Copy link
Copy Markdown
Contributor

@snake14 Overall looks good to me

@snake14
Copy link
Copy Markdown
Contributor Author

snake14 commented Aug 5, 2025

@snake14 Good work

I see errors when I paste the JSON

Yeah. I forgot to mention that. I did what the openmost swagger plugin does and included the method query parameter in the paths. This is necessary to keep the paths unique, since without the query parameters, all paths are /index.php. One option is to map them as actual RESTful paths like /CustomAlerts/addAlert and /CustomAlerts/getAlert, but I'm hesitant to do that as it would be misleading to customers.

Also not important, we should make this screen better if possible

UI was completely out of scope for this ticket. I was simply using editor.swagger.io so that I could compare the presentation to the openmost swagger plugin UI. That said, it's displaying the necessary data about the token_auth parameter used to authenticate with the API. The main thing that we might want to change is making api_key a more UI friendly name like MatomoAuthToken. Anything more than that is purely superficial, but we'll see what it looks like once we've implemented a UI and selected a theme.

Comment thread API.php
*
* @method static \Piwik\Plugins\CustomAlerts\API getInstance()
*
* @OA\Schema(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It would be really nice if we could define the schema as part of a DTO or at least the model similar to this example.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Agree - I'm not sure where you're linking to, but I'd love to have response objects (and possibly input data objects) defined as their own classes and re-used. RESTy.

We don't have the budget to big bang upgrade everything, but moving in that direction makes sense to me.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's annoying that the link didn't work. I was linking to https://zircote.github.io/swagger-php/guide/examples.html#product-php, but had the Annotation option selected.

@snake14
Copy link
Copy Markdown
Contributor Author

snake14 commented Aug 13, 2025

Closing in favour of #205

@snake14 snake14 closed this Aug 13, 2025
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.

3 participants