0

I would like to specify in my rswag schema definition to only allow the properties that are defined in the schema, and strictly fail with a 500 similar to how it fails if required properties are missing.

So in this example it will fail with a 500 if foo or bar is not present since they are both required; baz is optional.

  type: :object,
  properties: {
    foo: { type: :string },
    bar: { type: :string },
    baz: { type: :string },
  },
  required: %i[foo bar]
},

If other properties are in the payload (qux for example) rswag doesn't complain. I would like to strictly enforce that only specified properties are allowed to make it more obvious to future developers that the schema must be kept up to date with any API changes.

So something like the following.

  type: :object,
  properties: {
    foo: { type: :string },
    bar: { type: :string },
    baz: { type: :string },
  },
  required: %i[foo bar],
  strict: true # <-- Is something like this possible?
},
bigtunacan
  • 4,873
  • 8
  • 40
  • 73
  • 1
    [additionalProperties: false](https://json-schema.org/understanding-json-schema/reference/object.html#additional-properties) – Helen Sep 16 '22 at 20:54

0 Answers0