Skip to content

Pattern validation not applied to individual values in case of comma separated query params #54

@KPranith

Description

@KPranith

Steps to recreate the issue

  1. Change query.json /pets petId parameter like below
    {
    "name": "petId",
    "in": "query",
    "required": true,
    "description": "The id of the pet to retrieve",
    "schema": {
    "type": "array",
    "items": {
    "type": "string",
    "pattern": "^[A-Z0-9]+-[0-9]{4}"
    }
    }
    }
  2. change the test case should coerce query parameter to an array in query.spec.ts as below

it('should coerce query parameter to an array', () => {
const queryMeta = {
method: 'get',
query: {
petId:'ACD-2016,ACD-213'
}
};
expect(chowchow.validateRequest('/pets', queryMeta)).toEqual(expect.objectContaining({
query: {
petId: ['ACD-2016,ACD-213']
}
}));
expect(queryMeta.query.petId).toEqual('ACD-2016,ACD-213');
});

As the string ACD-213 is not matching the pattern it should fail but it doesn't
image

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