swagger-api / swagger-editor

Swagger Editor
https://editor.swagger.io
Apache License 2.0
8.8k stars 2.24k forks source link

Wrong Schema when multiple anyOf/oneOf are inside allOf #5144

Open alexby opened 1 month ago

alexby commented 1 month ago

Q&A

Example Swagger/OpenAPI definition:

openapi: 3.1.0
info:
  version: 0.0.42
  title: some title
paths:
  /v1/user:
    get:
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                allOf:
                  - anyOf:
                    - type: object
                      properties:
                        firstA:
                          type: string
                    - type: object
                      properties:
                        firstB:
                          type: string
                  - anyOf:
                    - type: object
                      properties:
                        secondA:
                          type: string
                    - type: object
                      properties:
                        secondB:
                          type: string

Describe the bug you're encountering

Having multiple anyOf (or oneOf) inside the allOf will make the both conditions to be joined in a single anyOf (oneOf). In other words the condition (firstA OR firstB) AND (secondA OR secondB) is rendered like firstA OR firstB OR secondA OR secondB.

Expected behavior

image

Actual behavior

image

Additional context or thoughts

Having different conditions (oneOf & anyOf) under the same allOf will be resulted in a correct Schema.