Skip to content

Improve optional argument #692

@camlafit

Description

@camlafit

Hi

Looks possible to improve optional argument and reduce case with error.
I've found an old issue at SO : https://stackoverflow.com/questions/21241675/service-with-many-optional-parameters-with-restler

In validator.ph at https://github.com/Luracast/Restler/blob/master/src/Data/Validator.php#L512

I propose to add this patch :

	    if (!$info->required && isset($info->default) && empty($input)) {
	    	$input = $info->default;
	    }

After default value is checked as any other input and must be compliant with other annotation/configuration set.

In this case annotation must be set with :

@param string $state {@required false} {@default defaultvalue}

If this idea is not too bad I can propose a related pull request

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions