Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support unevaluatedProperties OpenAPI 3.1 #1504

Open
minardus opened this issue Nov 29, 2023 · 2 comments
Open

Support unevaluatedProperties OpenAPI 3.1 #1504

minardus opened this issue Nov 29, 2023 · 2 comments

Comments

@minardus
Copy link

minardus commented Nov 29, 2023

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

json-schema-org/json-schema-spec#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 minardus changed the title Support unevaluatedProperties Support unevaluatedProperties OpenAPI 3.1 Nov 29, 2023
@minardus
Copy link
Author

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

@DerManoMann
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants