Frage

I have service using many optional parameters :

/**
 * Change user settings
 *
 * @smart-auto-routing false
 * @url POST settings/
 * @param string $name New name of the user {@min 2}{@max 64}
 * @param string $surname New surname of the user {@min 2}{@max 64}
 * @param bool $sex 0 for man, 1 for girl
 * @param string $email New email address of the user {@type email}
 * @param bool $emailing 1 if user want to receive email from ilerter, 0 else
 * @param string $phone_number New phone number of the user {@min 4}
 * @param int $height {@from body}
 * @param int $weight {@from body}
 * @param int $eyes_color {@from body}
 * @param int $hair_color {@from body}
 * @param string $avatar {@from body}
 * @param string $description {@from body}
 * @return bool
 * @throws \Luracast\Restler\RestException
 */
public function settings($name, $surname, $sex, $email, $emailing, $phone_number,
$height = "", $weight = "", $eyes_color = "", $hair_color = "", $avatar = "",
$description = ""){

The problem is when I decide to send only 'avatar' among the optional parameters, my service take it in $height and return

Bad Request: invalid value specified for `height`. Expecting integer value

Is there a way with Restler to catch the only good optional value when it's not the first optional parameter ?

War es hilfreich?

Lösung

When there are so many routes overlapping each other, it is hard to tell which value is mapped to which parameter

Restler 3 tries to match parameters by type, since height, weight, eyes_color, hair_color are typed as integer so they should not interfere when a string value is given, so avatar can pick it up as the first in line

But since you messed the type by assigning string parameters to height, weight etc. They are now considered as strings by Restler and thus ends up with the above problem

Try assigning zero as the default for int values.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top