metosin / malli

High-performance data-driven data specification library for Clojure/Script.
Eclipse Public License 2.0
1.44k stars 204 forks source link

Invalid Swagger JSON with [:or :nil] alternatives #1006

Closed mkreis closed 3 months ago

mkreis commented 5 months ago

Depending on the order of alternative types including :nil, the Swagger JSON can become invalid.

With :nil at the end, it is fine: [:days-paid-leave-sick-child {:optional true} [:or [:int {:min 0 :max 30}] :nil]] becomes

          days-paid-leave-sick-child:
            type: integer
            format: int64
            minimum: 0
            maximum: 30
            x-anyOf:
              - type: integer
                format: int64
                minimum: 0
                maximum: 30
              - type: 'null'

which is valid, but with :nil as first item, it is invalid: [:days-until-sick-leave-notice {:optional true} [:or :nil [:int {:min 1 :max 4}]]] becomes

          days-until-sick-leave-notice:
            type: 'null'
            x-anyOf:
              - type: 'null'
              - type: integer
                format: int64
                minimum: 1
                maximum: 4

which is invalid:

type should be equal to one of the allowed values
allowedValues: array, boolean, integer, number, object, string
ikitommi commented 5 months ago

Ok, this is a bug. :or should select first non-null as the base-type with JSON Schema. PR welcome on this.