loopbackio / loopbackio/loopback-next

@param.array {type: 'object'} throws 400

Đang mở
#7,777 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.

bug OpenAPI REST
Ngôn ngữ chính
TypeScript
Star
5.1k
Fork
1.1k
Merge trung bình
2 ngày 21 giờ
Pull request đã merge (30 ngày)
27

Mô tả

Steps to reproduce

In explorer, make a GET request to a controller that has an array of type: 'object': @param.array('objectArray', 'query', {type: 'object'})

Current Behavior

When making a GET request to a controller with an array of objects parameter @param.array('objectArray', 'query', {type: 'object'}), it will throw a 400 [{path: "/0", code: "type", message: "must be object", info: {type: "object"}}] because it doesn't parse the JSON string.

Example:
/getWithObjectArray?objectArray=%7B%22name%22%3A%22hello%22%7D
essentially parses to:
['{"name":"hello"}']

Expected Behavior

The request should parse the json string in each array item so the request does not fail.

Link to reproduction sandbox

Added a test to show it broken: https://github.com/kyle-apex/loopback-next/commit/3d9d8e602f8a747e63ced1cf443f92a59998f35f

Added some code to show it "fixed": https://github.com/kyle-apex/loopback-next/commit/0a69964708fe2f135acd47900d86636dc199a515

My "fix" may be too broad. In openapi-v3/../parameter.decorator.ts, @param.query.param forces content: { 'application/json': { schema, }, } so coerce-parameter.ts knows to parse the JSON. @param.array doesn't have a similar capability, so it's tough for coerce-parameter.ts to know if it should parse the object represented as a string as JSON or not.

Any ideas for best approach?

Additional information

darwin x64 12.18.1

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 việc tái hiện một yêu cầu GET sử dụng @param.array với type: 'object', sau đó kiểm tra openapi-v3/../parameter.decorator.ts và coerce-parameter.ts để hiểu cách nội dung JSON được chọn. Hoàn thành khi mỗi chuỗi đối tượng JSON trong mảng được phân tích, để yêu cầu không còn thất bại với phản hồi 400.

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

Đánh giá

Công nghệ
typescript
Lĩnh vực
api
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 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
42/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.