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

chore: make Forms OpenAPI compliant #2358

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft

chore: make Forms OpenAPI compliant #2358

wants to merge 9 commits into from

Conversation

Chartman123
Copy link
Collaborator

This fixes #2356

@Chartman123 Chartman123 added the 2. developing Work in progress label Oct 7, 2024
@Chartman123 Chartman123 added this to the 5.0 milestone Oct 7, 2024
@Chartman123 Chartman123 self-assigned this Oct 7, 2024
@Chartman123 Chartman123 force-pushed the chore/OpenAPI branch 2 times, most recently from 4ec727e to 1527af4 Compare October 7, 2024 20:24
@Chartman123 Chartman123 changed the title Chore/open api chore: make Forms OpenAPI compliant Oct 7, 2024
Copy link

codecov bot commented Oct 15, 2024

Codecov Report

Attention: Patch coverage is 32.07547% with 72 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@39bd5df). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2358   +/-   ##
=======================================
  Coverage        ?   42.88%           
  Complexity      ?      851           
=======================================
  Files           ?       72           
  Lines           ?     3211           
  Branches        ?        0           
=======================================
  Hits            ?     1377           
  Misses          ?     1834           
  Partials        ?        0           

@Chartman123 Chartman123 force-pushed the chore/OpenAPI branch 3 times, most recently from 5f0053f to 190bc42 Compare October 21, 2024 21:43
lib/Controller/ShareApiController.php Outdated Show resolved Hide resolved
lib/Controller/ShareApiController.php Outdated Show resolved Hide resolved
lib/Controller/ShareApiController.php Outdated Show resolved Hide resolved
@Chartman123 Chartman123 force-pushed the chore/OpenAPI branch 3 times, most recently from 4b1572c to 700fe5e Compare October 22, 2024 19:05
@provokateurin
Copy link
Member

@Chartman123 as it seems you are pretty much free to change the API however you like, would you like to have a review by me of the whole API to point out improvements?

@Chartman123
Copy link
Collaborator Author

@provokateurin yes, that would be nice :) Would you recommend to first do this review and then make it OpenAPI compliant?

@provokateurin
Copy link
Member

I think it is easier to first make it all work and then review and refactor it.

@Chartman123
Copy link
Collaborator Author

Ok, I think I should be ready by the weekend

@Chartman123 Chartman123 force-pushed the chore/OpenAPI branch 7 times, most recently from 6bbddcb to aadf1d3 Compare October 26, 2024 16:44
@Chartman123 Chartman123 force-pushed the chore/OpenAPI branch 5 times, most recently from 9c1f80a to 841aed3 Compare October 29, 2024 16:05
@Chartman123
Copy link
Collaborator Author

@provokateurin I've fixed most of the psalm errors now... but I just can't seem to find a way to fix the remaining ones.

fix any problems reported by nextcloud/openapi-extractor#168

how can I do this? do I have to apply the patch manually to the files in the vendor-bin directory?

@provokateurin
Copy link
Member

I've fixed most of the psalm errors now... but I just can't seem to find a way to fix the remaining ones.

I can try to take a look, but I'm already busy with similar problems this week so I might lack the headspace for it this week.

how can I do this? do I have to apply the patch manually to the files in the vendor-bin directory?

You can clone the repo, do a composer i in it an then call generate-spec using the path so something like ../../openapi-extractor/generate-spec.

@provokateurin
Copy link
Member

I fixed everything. The main problem was that you didn't type the lower-level methods and then psalm wasn't inferring the types correctly anymore.
I also fixed the array syntaxes from the PR I mentioned above and uncovered some more problems that I fixed as well.

Now you should take a look if everything is to your liking and change anything you want and then I can give this an API design review 🎉

@provokateurin
Copy link
Member

Uh ok I made the tests unhappy, can you fix that for me?

@provokateurin
Copy link
Member

Now you should take a look if everything is to your liking and change anything you want

To be more precise: I had to change some of your type declarations to match the real code. Please check that everything you want to have exposed through the API is as intended (both missing information and too much information e.g. for security).

@Chartman123
Copy link
Collaborator Author

Thank you very much 😇 I'll have a look at it tomorrow or on the weekend.

@Chartman123 Chartman123 force-pushed the chore/OpenAPI branch 5 times, most recently from ee70205 to 96954fd Compare November 4, 2024 22:22
@Chartman123
Copy link
Collaborator Author

@provokateurin I was able to fix the unit tests (switched back to associative array in Question.php). Now there's only one error left in the integration tests, that might be related to this \stdClass / array thing for the extraSettings...

{
  "reqId": "MjuGvNE73yn63SvGLLMK",
  "level": 3,
  "time": "2024-11-04T22:25:29+00:00",
  "remoteAddr": "192.168.1.132",
  "user": "admin",
  "app": "no app in context",
  "method": "POST",
  "url": "/nextcloud/ocs/v2.php/apps/forms/api/v3/forms/148/submissions",
  "message": "Cannot use object of type stdClass as array in file '/home/chris/workspace/Github/forms/lib/Service/SubmissionService.php' line 383",
  "userAgent": "Mozilla/5.0 (X11; Linux x86_64; rv:131.0) Gecko/20100101 Firefox/131.0",
  "version": "30.0.1.2",
  "exception": {
    "Exception": "Exception",
    "Message": "Cannot use object of type stdClass as array in file '/home/chris/workspace/Github/forms/lib/Service/SubmissionService.php' line 383",
    "Code": 0,
    "Trace": [
      {
        "file": "/srv/www/htdocs/nextcloud/lib/private/AppFramework/App.php",
        "line": 161,
        "function": "dispatch",
        "class": "OC\\AppFramework\\Http\\Dispatcher",
        "type": "->"
      },
      {
        "file": "/srv/www/htdocs/nextcloud/lib/private/Route/Router.php",
        "line": 302,
        "function": "main",
        "class": "OC\\AppFramework\\App",
        "type": "::"
      },
      {
        "file": "/srv/www/htdocs/nextcloud/ocs/v1.php",
        "line": 43,
        "function": "match",
        "class": "OC\\Route\\Router",
        "type": "->"
      },
      {
        "file": "/srv/www/htdocs/nextcloud/ocs/v2.php",
        "line": 7,
        "args": [
          "/srv/www/htdocs/nextcloud/ocs/v1.php"
        ],
        "function": "require_once"
      }
    ],
    "File": "/srv/www/htdocs/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
    "Line": 146,
    "Previous": {
      "Exception": "Error",
      "Message": "Cannot use object of type stdClass as array",
      "Code": 0,
      "Trace": [
        {
          "file": "/home/chris/workspace/Github/forms/lib/Controller/ApiController.php",
          "line": 1254,
          "function": "validateSubmission",
          "class": "OCA\\Forms\\Service\\SubmissionService",
          "type": "->"
        },
        {
          "file": "/srv/www/htdocs/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
          "line": 208,
          "function": "newSubmission",
          "class": "OCA\\Forms\\Controller\\ApiController",
          "type": "->"
        },
        {
          "file": "/srv/www/htdocs/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
          "line": 114,
          "function": "executeController",
          "class": "OC\\AppFramework\\Http\\Dispatcher",
          "type": "->"
        },
        {
          "file": "/srv/www/htdocs/nextcloud/lib/private/AppFramework/App.php",
          "line": 161,
          "function": "dispatch",
          "class": "OC\\AppFramework\\Http\\Dispatcher",
          "type": "->"
        },
        {
          "file": "/srv/www/htdocs/nextcloud/lib/private/Route/Router.php",
          "line": 302,
          "function": "main",
          "class": "OC\\AppFramework\\App",
          "type": "::"
        },
        {
          "file": "/srv/www/htdocs/nextcloud/ocs/v1.php",
          "line": 43,
          "function": "match",
          "class": "OC\\Route\\Router",
          "type": "->"
        },
        {
          "file": "/srv/www/htdocs/nextcloud/ocs/v2.php",
          "line": 7,
          "args": [
            "/srv/www/htdocs/nextcloud/ocs/v1.php"
          ],
          "function": "require_once"
        }
      ],
      "File": "/home/chris/workspace/Github/forms/lib/Service/SubmissionService.php",
      "Line": 383
    },
    "message": "Cannot use object of type stdClass as array in file '/home/chris/workspace/Github/forms/lib/Service/SubmissionService.php' line 383",
    "exception": [],
    "CustomMessage": "Cannot use object of type stdClass as array in file '/home/chris/workspace/Github/forms/lib/Service/SubmissionService.php' line 383"
  },
  "id": "67294e0e3a54b"
}

@provokateurin
Copy link
Member

I'll take a look. I think my mistake was to do the conversion too early, it should only take place in the Controllers.

Chartman123 and others added 9 commits November 7, 2024 21:48
Signed-off-by: Christian Hartmann <[email protected]>
Signed-off-by: Christian Hartmann <[email protected]>
Signed-off-by: Christian Hartmann <[email protected]>
@provokateurin
Copy link
Member

Hi, I just wanted to say that I haven't forgotten this PR.
I was busy with other tasks and didn't work last week.
I hope I come around to this again this week.

@Chartman123
Copy link
Collaborator Author

Hi, I just wanted to say that I haven't forgotten this PR. I was busy with other tasks and didn't work last week. I hope I come around to this again this week.

Everything fine, I also don't have much time at the moment :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2. developing Work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

chore: add OpenAPI support
3 participants