vertx-web icon indicating copy to clipboard operation
vertx-web copied to clipboard

OpenAPI readOnly + required property gives 400 error

Open KeerthanaSrikanth opened this issue 4 years ago • 0 comments

Version

4.1.3

Context

I'm facing an issue with request validation for properties which are readOnly + required at the same time. For such properties, I'm getting unexpected 400 Bad Request errors.

Sample Schema

SampleObject:

type: object
 description: Sample description
 required:
   - id
   - name
 properties:
   id:
     type: string
   name:
     type: string
     readOnly: true

Expected validation behaviour: Only id should be required in request bodies Actual behaviour: io.vertx.ext.web.validation.BodyProcessorException: [Bad Request] Validation error for body application/json: provided object should contain property name

As per the OpenAPI documentation: readOnly properties are included in responses but not in requests, and writeOnly properties may be sent in requests but not in responses. If a readOnly or writeOnly property is included in the required list, required affects just the relevant scope – responses only or requests only. That is, read-only required properties apply to responses only, and write-only required properties – to requests only.

Do you have a reproducer?

https://github.com/KeerthanaSrikanth/web-and-openapi-howto I have added readOnly property to required property name in the Pet schema.

Steps to reproduce

1. `mvn compile exec:java`
2. `curl -X POST -H "Content-type: application/json" --data '{"id":4}' http://localhost:8080/pets`

It should give no error but it gives 400 Bad request error. {"code":400,"message":"[Bad Request] Validation error for body application/json: provided object should contain property name"}%

KeerthanaSrikanth avatar Sep 28 '21 05:09 KeerthanaSrikanth