libopenapi-validator icon indicating copy to clipboard operation
libopenapi-validator copied to clipboard

Ability to handle Schema objects FIXED FIELDs eg readOnly, writeOnly

Open jojobrem opened this issue 1 year ago • 6 comments

libopenapi-validator currently is unable to handle fixed fields in schema objects, an example being writeOnly. This property specifies that the schema object may appear in a request but not to come back in the response, as noted https://spec.openapis.org/oas/v3.0.3#fixed-fields-19 However libopenapi-validator has no reference to these fields and this behaviour. Is there a plan to implement this?

jojobrem avatar Jul 24 '24 10:07 jojobrem

You found a gap! Nice. This needs to be added.

daveshanley avatar Aug 02 '24 11:08 daveshanley

Hi @daveshanley - Any thoughts on this? my fear is that this may may be an issue with the underlying jsonschema module....

JemDay avatar Sep 03 '24 15:09 JemDay

I have not looked any deeper into this yet. It may be a gap down there, or it could be something that can be controlled by libopenapi I don't know yet.

daveshanley avatar Sep 03 '24 15:09 daveshanley

I have not looked any deeper into this yet. It may be a gap down there, or it could be something that can be controlled by libopenapi I don't know yet.

Thanks - the support of this construct is spotty across a variety of tools (eg Spectral gets tripped up as well). It would seem to me that at a very basic level when a payload is checked against a schema it needs to be in the context of a request or a response, without that the schema validator couldn't assess readOnly/writeOnly.

JemDay avatar Sep 03 '24 15:09 JemDay

I've looked at this in the swaggest package, which similarly defers to the jsonschema lib for validation. The conclusion I've come to is that the jsonschema spec differs meaningfully from the OpenAPI spec when required is handled together with readOnly and writeOnly, and that this behavior can't be deferred to a library designed to validate jsonschema.

This means that this lib will have to do its own schema walk and implement its own handling.

tstirrat15 avatar May 19 '25 22:05 tstirrat15

The more I think about this the more I believe (to your point) that you really need to generate different schemas that simulate these OAS constructs.

If memory serves I think there is a way in JSONSchema to declare a property must not be present.

JemDay avatar May 20 '25 01:05 JemDay