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

Add types to responses #38802

Merged
merged 1 commit into from Jun 30, 2023
Merged

Add types to responses #38802

merged 1 commit into from Jun 30, 2023

Conversation

provokateurin
Copy link
Member

@provokateurin provokateurin commented Jun 14, 2023

From #36666

Summary

Sadly the methods have to be overridden in all the subclasses, but the code for that is always mostly the same.

Checklist

@provokateurin
Copy link
Member Author

The addHeader is not being override due to the lack of one feature and the existence of one (might be even two) bug(s) in psalm. The method is not used much in the server code where it would be relevant for the OpenAPI changes. This PR should be merged regardless of this missing piece.

@provokateurin
Copy link
Member Author

I think the addHeader method should be deprecated to solve the issue

@nickvergessen
Copy link
Member

I think the addHeader method should be deprecated to solve the issue

Deprecation means we can remove it in 3 years. So it won't solve your issue any time soon.

@provokateurin
Copy link
Member Author

I know, I will have to add some comments about this in the OpenAPI tutorial/guidelines.

@ChristophWurst
Copy link
Member

Is there any mechanism is place to ensure this doesn't fall apart with future modifications of the code? How does a developer check if they need to annotate changed/new APIs?

@provokateurin
Copy link
Member Author

Is there any mechanism is place to ensure this doesn't fall apart with future modifications of the code?

Do you mean the code of the response classes? Those are validated by psalm

How does a developer check if they need to annotate changed/new APIs?

Developers don't need to add any new annotations because of these changes.

Copy link
Member

@nickvergessen nickvergessen left a comment

Choose a reason for hiding this comment

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

You mean internal, right? We are not planning to remove the function

lib/public/AppFramework/Http/NotFoundResponse.php Outdated Show resolved Hide resolved
lib/public/AppFramework/Http/RedirectResponse.php Outdated Show resolved Hide resolved
lib/public/AppFramework/Http/TooManyRequestsResponse.php Outdated Show resolved Hide resolved
@provokateurin
Copy link
Member Author

@come-nc @nickvergessen I will wait for your approvals as well, just to be sure everything is alright

Copy link
Member

@nickvergessen nickvergessen left a comment

Choose a reason for hiding this comment

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

but fine either way

lib/public/AppFramework/Http/DataDisplayResponse.php Outdated Show resolved Hide resolved
lib/public/AppFramework/Http/DataResponse.php Outdated Show resolved Hide resolved
lib/public/AppFramework/Http/FileDisplayResponse.php Outdated Show resolved Hide resolved
Copy link
Member

@nickvergessen nickvergessen left a comment

Choose a reason for hiding this comment

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

Missed one last type, but fine by me

lib/public/AppFramework/Http/TemplateResponse.php Outdated Show resolved Hide resolved
Signed-off-by: jld3103 <jld3103yt@gmail.com>
@provokateurin provokateurin merged commit 90a78d7 into master Jun 30, 2023
37 checks passed
@provokateurin provokateurin deleted the feature/type-responses branch June 30, 2023 08:12
@provokateurin
Copy link
Member Author

🎉

@ChristophWurst
Copy link
Member

Mail's Psalm shows that all responses have to be type-annotated now due to vimeo/psalm#6870 (comment). Example: https://github.com/nextcloud/mail/blob/b7b84f452ac6951d0d2e6d96e33b9eec91ac6098/lib/Http/AttachmentDownloadResponse.php https://psalm.dev/r/92dc4c7871

ERROR: MissingTemplateParam - lib/Http/AttachmentDownloadResponse.php:29:7 - OCA\Mail\Http\AttachmentDownloadResponse has missing template params when extending OCP\AppFramework\Http\DownloadResponse, expecting 3 (see https://psalm.dev/182)
class AttachmentDownloadResponse extends DownloadResponse {

It means those responses have to specify a type for the template (for static headers and status code) https://psalm.dev/r/68242bdab6.

If I spec the type for server master I'll get an error for stable27 and older: https://psalm.dev/r/7038ef2ed1

Could there be any trick to allow responses to have types but with a default?

@provokateurin
Copy link
Member Author

For subclasses you either need to implement the template parameters which should be quite easy or you just supress the error. Implementing the template parameters should be quite easy and afterwards you don't need to add the parameters when you use the type (like in return annotations), you can just leave them empty and it will use the "default" parameters.

@ChristophWurst
Copy link
Member

If I spec the type for server master I'll get an error for stable27 and older: https://psalm.dev/r/7038ef2ed1

@provokateurin
Copy link
Member Author

Well, then suppress until you support only 28+?

paulijar added a commit to owncloud/music that referenced this pull request Apr 8, 2024
Every call to the Subsonic XML API caused and error 'Undefined array
key "" at /var/www/html/lib/private/AppFramework/Http.php#128' to be
logged to the nextcloud.log.

This happened because the XmlResponse object had no response status
set. Setting this used to happen automatically, but after the Nextcloud
PR nextcloud/server#38802, the automatic setting
has not happened without a call to the parent class constructor from
the derived class. However, we can't call the parent constructor because
it doesn't exist on ownCloud. To overcome the problem, we now set the
status code explicitly in the constructor of XmlResponse.

refs #1142
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants