OpenAPITools / OpenAPITools/openapi-generator

[bug][symfony] AnyType is not defined

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

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

Issue: Bug
Ngôn ngữ chính
Java
Star
26.8k
Fork
7.7k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

AnyType is not defined in symfony server generated code.
In some situations, schemas return any, this is handled in other languages where that is translated into something the language understands, examples:

  • Java: Object
  • C#: `Object
  • Rust: serde_json:Value

However, this translation is not made for symfony, and the generators write AnyType in such situations, leading to type errors:
AnyType is not defined anywhere.

image

openapi-generator version

7.2.0

some_data:
      type: object
      additionalProperties: true

or

some_data:
      type: object
      additionalProperties: {}

when a request is made with some data , this exception is thrown by JMSSerializer in vendor/jms/metadata/src/MetadataFactory.php

curl --location --request POST 'http://localhost:8000/myservice' \
--header 'Content-Type: application/json' \
--data-raw '{
  "some_data": {
    "additionalProp1": "string",
    "additionalProp2": "string",
    "additionalProp3": "string"
  }
}'

Uncaught PHP Exception ReflectionException: "Class "AnyType" does not exist" at MetadataFactory.php line 175

image

Generation Details
openapi-generator-cli \                        
    generate \
    -i openapi.yaml \
    -g php-symfony \
    -o .
Steps to reproduce
Related issues/PRs

its the same issue as this one was for typescript https://github.com/OpenAPITools/openapi-generator/issues/6332

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 chạy lệnh openapi-generator được cung cấp với generator php-symfony và schema ví dụ sử dụng additionalProperties. Theo dõi kiểu được tạo qua quá trình xử lý request đến vendor/jms/metadata/src/MetadataFactory.php. Hoàn thành khi mã Symfony được tạo không còn tham chiếu đến AnyType chưa được định nghĩa và payload POST được nêu có thể được xử lý thành công.

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

Đánh giá

Công nghệ
php, symfony
Lĩnh vực
api, backend
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
48/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.