cdimascio / express-openapi-validator

🦋 Auto-validates api requests, responses, and securities using ExpressJS and an OpenAPI 3.x specification

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Request body is marked as invalid, using `oneOf` inside `allOf`

jmechevarria opened this issue · comments

Describe the bug
I try to use oneOf inside allOf in my schema, but validator says request body is invalid

To Reproduce

This is the schema:

  RequestDTO:
    type: object
    additionalProperties: false
    allOf:
      - oneOf:
          - type: object
            additionalProperties: false
            properties:
              prop1:
                type: string
          - type: object
            additionalProperties: false
            properties:
              prop2:
                type: string
                enum: [this, that]
                default: this
      - type: object
        additionalProperties: false
        properties:
          prop3:
            type: string

Actual behavior
When submitting the following request body:

{ "prop1": "a value", "prop3": "another value" }

Error:
request/body must NOT have additional properties, request/body must NOT have additional properties, request/body must NOT have additional properties, request/body must match exactly one schema in oneOf, request/body must NOT have additional properties, request/body must NOT have additional properties, request/body must NOT have additional properties

Expected behavior
I would expect that request to be validated OK by that schema.

Additional information

The intent here is to have a schema that allows sending either prop1 and prop3 or prop2 and prop3

This is what I see in the OpenAPI SwaggerUI preview window (in VSCode), which looks OK:

Screenshot 2024-02-06 at 9 45 32 p m

Also, I'm using openapi-typescript-codegen to generate my TS clients and that also looks OK:

/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

export type RequestDTO = (
  | {
      prop1?: string;
    }
  | {
      prop2?: RequestDTO.prop2;
    }
) & {
  prop3?: string;
};

export namespace RequestDTO {
  export enum prop2 {
    THIS = "this",
    THAT = "that",
  }
}

Am I assuming something wrong about how my schema should behave with this input?