OpenAPITools / OpenAPITools/openapi-diff

[bug] [polymorphism] Changes in child schema are ignored when only parent schema is directly referenced

Đang mở
#571 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Java
Star
1.1k
Fork
190
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

When using AllOf for polymorphism, when a property references a parent schema using ref and a change is done to a child schema which is not referenced directly anywhere in the OAS file, changes done to child schema are ignored in the differ output.

Example schema:

openapi: 3.0.0
servers:
  - url: 'http://petstore.swagger.io/v2'
info:
  description: >-
    This is a sample server Petstore server.  You can find out more about
    Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net,
    #swagger](http://swagger.io/irc/).  For this sample, you can use the api key
    `special-key` to test the authorization filters.
  version: 1.0.0
  title: Swagger Petstore
  termsOfService: 'http://swagger.io/terms/'
  contact:
    email: apiteam@swagger.io
  license:
    name: Apache 2.0
    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
tags:
  - name: pet
    description: Everything about your Pets
    externalDocs:
      description: Find out more
      url: 'http://swagger.io'
  - name: store
    description: Access to Petstore orders
  - name: user
    description: Operations about user
    externalDocs:
      description: Find out more about our store
      url: 'http://swagger.io'
paths:
  /pet/findByStatus:
    get:
      tags:
        - pet
      summary: Finds Pets by status
      description: Multiple status values can be provided with comma separated strings
      operationId: findPetsByStatus
      parameters:
        - name: status
          in: query
          description: Status values that need to be considered for filter
          required: true
          explode: true
          schema:
            type: array
            items:
              type: string
              enum:
                - available
                - pending
                - sold
              default: available
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  pets:
                    type: array
                    items:
                      $ref: '#/components/schemas/Pet'
        '400':
          description: Invalid status value
      security:
        - petstore_auth:
            - 'write:pets'
            - 'read:pets'
externalDocs:
  description: Find out more about Swagger
  url: 'http://swagger.io'
components:
  requestBodies:
    Pet:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Pet'
      description: Pet object that needs to be added to the store
      required: true
  securitySchemes:
    petstore_auth:
      type: oauth2
      flows:
        implicit:
          authorizationUrl: 'http://petstore.swagger.io/oauth/dialog'
          scopes:
            'write:pets': modify pets in your account
            'read:pets': read your pets
    api_key:
      type: apiKey
      name: api_key
      in: header
  schemas:
    BasePet:
      type: object
      properties:
        pet_color:
          type: string
    Pet:
      allOf:
      - $ref: '#/components/schemas/BasePet'
      type: object
      discriminator:
        propertyName: pet_type
        mapping:
          dog: '#/components/schemas/Dog'
          cat: '#/components/schemas/Cat'
      required:
      - pet_type
      properties:
        pet_type:
          nullable: false
          allOf:
          - type: string
    Cat:
      description: Cat class
      allOf:
      - $ref: '#/components/schemas/Pet'
      type: object
      discriminator:
        propertyName: pet_type
        mapping:
          dog: '#/components/schemas/Cat'
      properties:
        name:
          type: string
        toy:
          $ref: '#/components/schemas/Toy'
    Dog:
      description: Dog class
      allOf:
      - $ref: '#/components/schemas/Pet'
      type: object
      discriminator:
        propertyName: pet_type
        mapping:
          dog: '#/components/schemas/Cat'
      properties:
        bark:
          type: string
    Toy:
      description: Toy class
      type: object
      discriminator:
        propertyName: toy_type
        mapping:
          ball: '#/components/schemas/Ball'
      properties:
        toy_type:
          type: string
        price:
          type: number
    Ball:
      description: Ball class
      allOf:
        - $ref: '#/components/schemas/Toy'
        - type: object
          properties:
            size:
              type: string
      discriminator:
        propertyName: toy_type
        mapping:
          ball: '#/components/schemas/Ball'

If I add new property material to Ball, I would expect to see changes in GET /pet/findByStatus operation, while the actual situation is, that the changes are ignored.

Tested with 2.1.0-SNAPSHOT.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện trường hợp đã được báo cáo với tài liệu OpenAPI được cung cấp và so sánh đầu ra của differ sau khi thêm Ball.material. Theo dõi cách tham chiếu GET /pet/findByStatus đi đến các schema đa hình và xác nhận rằng các thay đổi trong các schema con được tham chiếu gián tiếp cũng được bao gồm. Được xem là hoàn tất khi đầu ra báo cáo thay đổi của Ball và một bài kiểm thử hồi quy bao phủ kịch bản này.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
java, openapi
Lĩnh vực
api
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
38/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.