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

error when requesting additional fields #101

Open
tacman opened this issue Jan 28, 2024 · 6 comments
Open

error when requesting additional fields #101

tacman opened this issue Jan 28, 2024 · 6 comments
Labels

Comments

@tacman
Copy link
Contributor

tacman commented Jan 28, 2024

$client->all(['fields' => ['abandoned','repository','type']);

image

Generates an error because source isn't set in $version:

image

I'll submit a PR

tacman added a commit to tacman/packagist-api that referenced this issue Jan 28, 2024
@tacman
Copy link
Contributor Author

tacman commented Jan 28, 2024

Actually, my PR isn't sufficient.

The problem is that the return value when passing 'fields' to list.json is an array of those fields.

    public function createPackageResults(array $package): Package
    {
        dd($package);

returns

image

@robbieaverill
Copy link
Collaborator

Hi @tacman, would you be interested in submitting another PR to fix this?

@tacman
Copy link
Contributor Author

tacman commented Mar 14, 2024

Can you point me in the right direction? For the project I was working on, I simply filtered them after retrieving.

@robbieaverill
Copy link
Collaborator

It seems like the error is caused by the code expecting the 'source' key to exist. In your example you're filtering fields and 'source' isn't one of those included. Perhaps a change like this might be sufficient to fix the issue:

- if ($version['source']) {
+ if (!empty($version['source'])) {

@tacman
Copy link
Contributor Author

tacman commented Mar 14, 2024

That's what I did in #102, but it wasn't enough.

@tacman
Copy link
Contributor Author

tacman commented Nov 20, 2024

So the key issue here is that depending on the parameters to list.json, it returns either a list of strings (package names), or if "fields" is present, a list of objects keyed by package names.

So we need some sort of test to see what the result is. It's kinda ugly. I guess we can get the result back and check for is_array or array_is_list.

Even better would be a real API, like API Platform. composer/packagist#1491

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 a pull request may close this issue.

2 participants