`oneOf` in path params is causing validation errors when using OAS 3.0

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

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

Đánh giá

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

Hướng nghiên cứu

The bug is in path parameter handling: lib/openapi_first/validators/request_parameters.rb around line 15 receives the path as a string when the schema uses oneOf, but as an integer when it uses type: integer. Start by reproducing with the spec in the issue and checking how the path value is coerced before validation. Done means GET /accounts/1 passes for a oneOf integer/enum path parameter, with a regression test added to the request validation specs.

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

Mô tả

I have the following spec:

openapi: 3.0.1
paths:
  /accounts/{id}:
    get:
      operationId: getAccountId
      summary: Get the details of an account
      parameters:
        - name: id
          in: path
          required: true
          schema:
            oneOf:
              - type: integer
              - type: string
                enum: [current]

When validating e.g. GET /accounts/1 request, I get an Path segment is invalid: value at '/id' is not an integer. value at '/id' is not one of: ["current"] error.
The following schema for the path parameter already reproduces the issue:

oneOf:
  - type: integer

The following schema does not give a validation error:

type: integer

The parsed_request in /lib/openapi_first/validators/request_parameters.rb:15 in the case of a schema using oneOf:
#<data OpenapiFirst::ParsedRequest path={"id"=>"1"}, ...>, without oneOf: #<data OpenapiFirst::ParsedRequest path={"id"=>1}, ...>, that could cause the path param to be invalid.

I believe the spec above using the schema with the oneOf is valid and should not give validation errors for requests like GET /accounts/1.

Ngôn ngữ chính
Ruby
Star
222
Fork
27
Merge trung bình
17 giờ 15 phút
Pull request đã merge (30 ngày)
6

Chuẩn bị môi trường

  • Có Dockerfile hoặc tệp Docker Compose
  • Không có mẫu pull request
  • Không có 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.

Issue khác của ahx/openapi_first

Tất cả issue của ahx/openapi_first

Issue tương tự

Thêm issue về Ruby

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.