swagger-php icon indicating copy to clipboard operation
swagger-php copied to clipboard

Support unevaluatedProperties OpenAPI 3.1

Open minardus opened this issue 2 years ago • 2 comments

unevaluatedProperties is in 3.1 spec, it is the same as additionalProperties, but it can see through $refs.

Example:

Request:
  required:
    - id
  properties:
    id:
      description: Id
      type: integer
  type: object
  unevaluatedProperties: false
ExtendedRequest:
  required:
      - extra_id
  allOf:
        -
          $ref: '#/components/schemas/Request'
        -
          properties:
            extra_id:
              description: 'Extra ID'
              type: integer
    unevaluatedProperties: false

Request can only accept id ExtendedRequest can only accept id AND extra_id

It is now not checked by the validator, so I can send extra parameters like 'extra_parameter' and it's still valid. If I use additionalProperties: false, it will read Request first, and then it will immediately give error extra_id is not allowed

This is maybe because 3.1 is not fully supported yet? Because Attribute/Annotations should also support it then

If I use additionalProperties instead I get this

Keyword validation failed: Data has additional properties (extra_id) which are not allowed Field

And as I read it, this is not supported by additionalProperties, but is supported by unevaluatedProperties

https://json-schema.org/understanding-json-schema/reference/object#unevaluated-properties

Also the problem is described here

https://github.com/json-schema-org/json-schema-spec/issues/661

The only solution is to 'unroll' the properties into ExtendedRequest, so no inheritance takes place and I can use additionalProperties. Maybe the code could support generating it like that? That would also solve my issue for now. So not reffing but copying the properties.

minardus avatar Nov 29 '23 12:11 minardus

I have found out I can bypass it by using Traits (I was extending). This will make a copy instead of using allOf: - $ref

minardus avatar Nov 29 '23 13:11 minardus

Have you tried and verified that unevaluatedProperties is supported by tools like swagger-ui? Just asking as I do not have time to track things at that level.

DerManoMann avatar Nov 29 '23 22:11 DerManoMann