OpenAPI readOnly + required property gives 400 error

518 views
Skip to first unread message

Keerthana Srikanth

unread,
Sep 8, 2021, 9:25:43 AM9/8/21
to vert.x
Hello!

I'm using Vert.x OpenAPI (Vert.x 4.1.3). 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.

Is this a bug or is there a way to have the expected validation behaviour?

Thanks,
Keerthana

Thomas SEGISMONT

unread,
Sep 9, 2021, 10:38:15 AM9/9/21
to vert.x
Sounds like a bug, thank you for reporting.

Would you mind filing an issue on GitHub? Ideally with a small reproducer. Thanks very much

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/7cc35d94-f1ea-46fe-bb16-4deb93d8ea58n%40googlegroups.com.

sidz

unread,
Sep 9, 2021, 3:02:59 PM9/9/21
to vert.x
Hi, 

The only way to support this on the OpenAPI specification is that to add  allowReserved property to the specification. But  Vert.x OpenAPI RouterBuilder is not supporting for that. 

"allowReserved Parameter in OpenAPI Spec In Not Working In Vertx" -> Check this thread as well. 

Reply all
Reply to author
Forward
0 new messages