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

Silent error when type class is not found #667

Open
igorsantos07 opened this issue Aug 20, 2021 · 4 comments
Open

Silent error when type class is not found #667

igorsantos07 opened this issue Aug 20, 2021 · 4 comments

Comments

@igorsantos07
Copy link

igorsantos07 commented Aug 20, 2021

I guess this is missing an else block?

Sample code:

namespace API {
  class Item {
    public function patch (Types\ItemEdit $item) { [...] }
  }
}

namespace API\Types {
  class ItemEdit {
    /*
     * @var array {@type PriceEdit} {@required true}
     */
    public $prices;
  }

  class PriceEdit {
    /*
     * @var int {@required true}
     */
    public $value;
  }
}

What seems to happen: inside ItemEdit the namespace for PriceEdit is valid (so the IDE won't complain), but since Restler is executing code outside of it, it can't find that class and silently fails. It would need to sniff the parent namespace to gather the correct namespace for the code shown on the linked section? I guess, if sniffing is "too much" to make it natural, the easiest would be to just yell at the dev and say the given class type seems invalid and might need to be a FQN?

@Arul-
Copy link
Member

Arul- commented Aug 23, 2021

Restler requires one class per file so that the autoloader is able to fetch them properly

Otherwise, you need to load the dependency manually.

Can you try both the options and see if it fixes the issue?

Let's see how we can alert the user when the class is not found

@igorsantos07
Copy link
Author

igorsantos07 commented Aug 23, 2021 via email

@Arul-
Copy link
Member

Arul- commented Aug 23, 2021

Can you test this with Restler 6? namespace parsing is rewritten for that. if it detects the relative namespace correctly we can see how we can backport it to Restler 5

@igorsantos07
Copy link
Author

This was actually a bit confusing since there's no docs page for v6 and I had a hard time with Composer trying to install the v6 branch... I went with dev-master instead, I guess it's pretty much the same?

I see a couple of things changed in the way the Explorer interprets API params, since it doesn't show the list of fields of a type anymore?

method
image

v3
image

master
image

Anyhow, the same issue still persists in the master branch. In there, $info->type is still just the bare classname, even when it's defined inside a namespace. In the earlier example, it should complete $info->type into \API\Types\PriceEdit (from \API\Types\ItemEdit::$prices, and not just PriceEdit.

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

No branches or pull requests

2 participants