Warm tip: This article is reproduced from serverfault.com, please click

What happens when we pass extra field in request body(JSON) in a OpenAPI POST endpoint

发布于 2020-11-13 04:53:46

I was working on Swagger generated OpenAPI specification and I noticed that if we pass some extra fields in PUT/POST API endpoint, then the server doesn't throw any error, even though it process all valid/necessary field. So my doubt is that

  1. Should the server throw error in this case?
  2. Is it the OpenAPI standard to allow unknown fields and then ignore them?
Questioner
Aman Chourasiya
Viewed
0
aman 2021-02-03 13:08:55

In Swagger specification 2.0 there is no option to reject the extra fields passed in the request body. Server will only accept those fields that are allowed in the request definition and other fields will be ignored. If you want to disallow extra fields then you can handle these in the backend manually.