Skip to content

Wrong Schema when allOf #5203

Open
Open
@sunchuo

Description

Q&A (please complete the following information)

Content & configuration

Example Swagger/OpenAPI definition:

openapi: 3.1.0
info:
  title: Complex API with Conditional Requirements
  version: "1.0"
  description: An example API demonstrating conditional requirements within a single schema.
servers:
  - url: https://api.example.com/v1
paths:
  /resources:
    get:
      summary: List all resources
      operationId: listResources
      tags:
        - Resources
      security:
        - bearerAuth: []
      responses:
        '200':
          description: An array of resources
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Resource'
    post:
      summary: Create a new resource
      operationId: createResource
      tags:
        - Resources
      security:
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Resource'
      responses:
        '201':
          description: Resource created
  /resources/{resourceId}:
    get:
      summary: Get a specific resource
      operationId: getResource
      tags:
        - Resources
      security:
        - bearerAuth: []
      parameters:
        - name: resourceId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Detailed information about the resource
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Resource'
    put:
      summary: Update a resource
      operationId: updateResource
      tags:
        - Resources
      security:
        - bearerAuth: []
      parameters:
        - name: resourceId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Resource'
      responses:
        '200':
          description: Resource updated
    patch:
      summary: Partially update a resource
      operationId: partiallyUpdateResource
      tags:
        - Resources
      security:
        - bearerAuth: []
      parameters:
        - name: resourceId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Resource'
      responses:
        '200':
          description: Resource partially updated
    delete:
      summary: Delete a resource
      operationId: deleteResource
      tags:
        - Resources
      security:
        - bearerAuth: []
      parameters:
        - name: resourceId
          in: path
          required: true
          schema:
            type: string
      responses:
        '204':
          description: Resource deleted
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
  schemas:
    Address:
      type: object
      properties:
        level1:
          type: string
        level2:
          type: string
        level3:
          type: string
      required: [level1, level2, level3]
    Resource:
      type: object
      properties:
        id:
          type: string
          format: uuid
        type:
          type: string
          enum: [TypeA, TypeB]
        commonField:
          type: string
        address:
          $ref: '#/components/schemas/Address'
      required: [id, type, commonField, address]
      allOf:
        - if:
            properties:
              type:
                const: TypeA
          then:
            properties:
              specificFieldA:
                type: object
                properties:
                  name:
                    type: string
                  age:
                    type: integer
                  address:
                    $ref: '#/components/schemas/Address'
            required: [specificFieldA]
        - if:
            properties:
              type:
                const: TypeB
          then:
            properties:
              specificFieldB:
                type: number
            required: [specificFieldB]

Describe the bug you're encountering

QQ20240725-112412

After pasting the yaml into editor. schema renders the wrong result at the first time.
If you change it in the editor, the schema becomes correct.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions