packagist-api icon indicating copy to clipboard operation
packagist-api copied to clipboard

error when requesting additional fields

Open tacman opened this issue 1 year ago • 6 comments

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

image

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

image

I'll submit a PR

tacman avatar Jan 28 '24 17:01 tacman

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

tacman avatar Jan 28 '24 18:01 tacman

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

robbieaverill avatar Mar 14 '24 00:03 robbieaverill

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

tacman avatar Mar 14 '24 00:03 tacman

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'])) {

robbieaverill avatar Mar 14 '24 00:03 robbieaverill

That's what I did in https://github.com/KnpLabs/packagist-api/pull/102, but it wasn't enough.

tacman avatar Mar 14 '24 00:03 tacman