oneOf not honoring discriminator value (regression 2.12.x)

Issue #334 new
Former user created an issue

I notice when i upgraded to version 2.18.0 from 2.11.0 one of my test failed.

Reason:

When you have a oneOf like below it accepts any input that validates one of the oneOf values even when the productId does not match.

So given:

  X:    
      required:
        - JustAId
        - startDate
        - list
      type: object
      properties:
        JustAId:
          description: "Unique identifier of the intermediary. "
          type: string           
        startDate:       
          type: string
          format: date   
        list:
          type: array
          minItems: 1 
          maxItems: 100
          items:
            $ref: "#/components/schemas/Item"
    Item:    
      oneOf:
        - $ref: "#/components/schemas/P"
        - $ref: "#/components/schemas/Q"
        - $ref: "#/components/schemas/R"
        - $ref: "#/components/schemas/Z"
      discriminator:
        propertyName: productId   
        mapping:
          p: "#/components/schemas/P"
          q: "#/components/schemas/Q"
          r: "#/components/schemas/R"
          z: "#/components/schemas/Z"     

The following code below is valid. But if you change productId to Q it should fail as Q requires other properties which are mandatory. But in 2.18.0 it also accepts this input.

 { 
  "JustAId": "10000",
  "startDate": "2020-02-02", 
  "list": [ 
    { "productId": "P", "t": "X", "p": "X", } 
  ] 
}

Comments (2)

  1. Log in to comment