Skip to content

Params validation #315

Open
Open
@Zack-Heisnberg

Description

@Zack-Heisnberg

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

^4.0.0

Plugin version

No response

Node.js version

19

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

20.04

Description

the required for param validation doesn't work and allow empty strings

Steps to Reproduce

            fastify.get<{
              Params: {
                model: string;
              },
              Querystring: {
                sort: string;
                asc: number;
              }
            }>('/listAll/:model/', {
              schema: {
                params: {
                  type: 'object',
                  properties: {
                    model: { type: 'string' },
                  },
                  required: ['model'],
                },
                querystring: {
                  type: 'object',
                  properties: {
                    sort: { type: 'string' },
                    asc: { type: 'number' },
                  },
                  required: ['sort'],
                },
              },
            }, async function (request, reply) {
              return 'db endpoint for => ' + request.params.model;
            });

i undestand this can be fixed with

           params: {
                  type: 'object',
                  properties: {
                    model: { type: 'string' },
                    minLength: 1, 
                  },
                  required: ['model'],
                },

but i think the required on a string should do it for params

Current Behavior

CURL /listAll/t?sort=p => this is ok

CURL /listAll/t=> validation works , sort is required

CURL /listAll//?sort=p => get ok 200 , validation doesn't works , and allow the model to be empty

Expected Behavior

CURL /listAll/t?sort=p => this is ok

CURL /listAll/t=> validation works , sort is required

CURL /listAll//?sort=p => validation works , and doesn't allow the model to be empty

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