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

Respect string type when parsing validation rules' examples #315

Merged

Conversation

joligoms
Copy link
Contributor

This PR implements @Tryfciu 's code that fixes the problem mentioned here.

Now, when we have an @example doc specification with a numeric value, it treats this value according to the type specified for it right at the body request example. So, if this numeric value is a string, it will have quotation marks and won't be parsed into a number.

Here's a practical example:

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            // @example decade00-0000-4000-a000-000000000000
            'id' => 'uuid|required',
            // @example 700100201
            'phone_number' => 'string|digits:9',
            // @example +1
            'some_value' => 'string',
        ];
    }

Notice that phone_number and some_value both have numeric values but should be treated as strings because of the validation type.

So instead of being parsed right into numbers, they will be actual strings:
image

This also fixes the fact that if we have a string like "+1", it won't be parsed into just 1 like before :)

Now of course, if we specify that they are numbers, it treats them as so:

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            // @example decade00-0000-4000-a000-000000000000
            'id' => 'uuid|required',
            // @example 700100201
            'phone_number' => 'integer|digits:9',
            // @example +1
            'some_value' => 'integer',
        ];
    }

image

@romalytvynenko romalytvynenko changed the title fix(#145): treat numeric strings as strings Respect string type when parsing validation rules' examples Mar 3, 2024
@romalytvynenko romalytvynenko merged commit f59ade3 into dedoc:main Mar 3, 2024
6 checks passed
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

Successfully merging this pull request may close these issues.

2 participants