open-api icon indicating copy to clipboard operation
open-api copied to clipboard

Not validating extra parameters in responses

Open HFR1994 opened this issue 5 years ago • 1 comments

When validating both a request and response. Extra parameters are ignored even if they are not defined in the spec.

Ej:

{
  validateArgs: {
    parameters: [],
    requestBody: {
      description: 'a test body',
      content: {
        'application/json': {
          schema: {
            $ref: '#/definitions/Test1',
          },
        },
      },
    },
    schemas: {
      Test1: {
        properties: {
          foo: {
            type: 'string',
          },
          bar: {
            type: 'string',
          }
        },
      },
    },
  },
  request: {
    body: {
      baz: 'asdf',
    },
    headers: {
      'content-type': 'application/json',
    },
  }
}

This should throw an error because baz is not part of the spec

HFR1994 avatar Jul 22 '20 21:07 HFR1994

I think there is something wrong with the tests, that is why it is not throwing.

If you want it to throw an error when using the module, you can add additionalProperties: false to the schema definition. By default additionalProperties is set to true, that is why it is allowed.

zishone avatar Jan 28 '21 22:01 zishone