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

Request body is marked as invalid, using oneOf inside allOf #902

Open
jmechevarria opened this issue Feb 7, 2024 · 0 comments
Open

Request body is marked as invalid, using oneOf inside allOf #902

jmechevarria opened this issue Feb 7, 2024 · 0 comments

Comments

@jmechevarria
Copy link

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?

@jmechevarria jmechevarria changed the title Schema is marked as invalid, using oneOf inside allOf Request body is marked as invalid, using oneOf inside allOf Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant