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

Wrong Schema when allOf #5203

Open
sunchuo opened this issue Jul 25, 2024 · 0 comments
Open

Wrong Schema when allOf #5203

sunchuo opened this issue Jul 25, 2024 · 0 comments

Comments

@sunchuo
Copy link

sunchuo commented Jul 25, 2024

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.

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