🎸Dynamic OpenAPI Schema Naming Based on DTO Namespace
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 30/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- openapi, php
- Lĩnh vực
- api, backend-api-design
Hướng nghiên cứu
Bắt đầu bằng việc xem xét chiến lược đặt tên của OpenApiFactory và vị trí cấu hình được đề xuất trong config/packages/api_platform.yaml. Xác định cách các namespace của DTO và các thư mục context của Model sẽ được phân giải, sau đó xác minh rằng các schema input và output nhận được các khóa EntryPoint.Context.ClassName được yêu cầu mà không xảy ra xung đột.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Feature Request: Dynamic OpenAPI Schema Naming Based on DTO Namespace
📦 Background
By default, API Platform generates OpenAPI schemas using the “short name” of each DTO, which often leads to collisions and unclear schema names when multiple operations share the same class name (e.g. ResetPasswordInput). We have a custom decorator today that post-processes the OpenAPI components and renames schemas at runtime to {EntryPoint}.{Context}.{DTO}, but this requires complex workarounds and still depends on heuristics or introspection of generated schema names.
🚩 Problem
-
Schema collisions when different operations share DTO class names (e.g.
ResetPasswordInputin “request” and “perform” flows). -
Lack of clarity: consumers see only the short class name, not the context (“Request” vs “Reset”) nor the entrypoint.
-
Complex custom decorators required to hack around built‑in naming logic.
🎯 Desired Behavior
When you define DTOs under a folder structure like:
src/ApiResource/
└── Auth
└── ResetPassword
├── Model
│ ├── Request
│ │ └── ResetPasswordInput.php
│ └── Reset
│ └── ResetPasswordInput.php
└── ResetPasswordEntryPoint.php
-
OpenAPI schema key should become
ResetPasswordEntryPoint.Request.ResetPasswordInput.jsonld ResetPasswordEntryPoint.Reset.ResetPasswordInput.jsonld -
It should work automatically for any module/feature/folder under
ApiResource/{Module}/{Feature}/Model/{Context}/{DTO}.php. -
No extra configuration (no manual
_api_operation_nameoverrides) or fragile heuristics based on class metadata.
💡 Proposed Solution
Enhance API Platform’s OpenAPI naming strategy to:
-
Extract the resource entrypoint (folder name + “EntryPoint”).
-
Extract the context folder under
Model(e.g.Request,Reset). -
Use the DTO class name.
-
Compose the OpenAPI schema key as
{EntryPoint}.{Context}.{ClassName}, automatically for all input/output DTOs.
This could live inside the core OpenApiFactory or as a first‑class feature behind a config flag, e.g.:
# config/packages/api_platform.yaml
api_platform:
openapi:
dynamic_schema_naming: true
Benefits:
-
Eliminates custom decorator hacks.
-
Prevents name collisions entirely.
-
Provides clear, self‑documenting schema names.
🔧 Example Before/After
| Before | After |
|---|---|
| components.schemas.ResetPasswordInput.jsonld | components.schemas.ResetPasswordEntryPoint.Request.ResetPasswordInput |
| components.schemas.ResetPasswordInput_1.jsonld | components.schemas.ResetPasswordEntryPoint.Reset.ResetPasswordInput |
Please consider adding this as an official enhancement to API Platform’s OpenAPI generator. It aligns with the directory‑based organization of DTOs and greatly improves developer experience and schema clarity.
Thank you! 🚀
- Ngôn ngữ chính
- PHP
- Star
- 2.6k
- Fork
- 989
- Merge trung bình
- 1 ngày 23 giờ
- Pull request đã merge (30 ngày)
- 102
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của api-platform/core
-
JSON:API: resource schemas (`*.jsonapi`) have `properties` but no `type: object`Có thể đã có người làm @ousamabenyounes đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 Dưới một giờ Mức phù hợp với người mới 80/100
api-platform/core#8701 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
JSON:API: `JsonApiCollectionBaseSchemaNoPagination` declares `data` as `type: array` without `items`Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
api-platform/core#8699 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
api:openapi:export --spec-version=3.0.0 outputs `webhooks`, which is invalid in OpenAPI 3.0Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
api-platform/core#8690 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
api-platform/core#8680 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
api-platform/core#8725 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của api-platform/core
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
grokability/snipe-it#19857 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 92/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Authentication / Authorization Feature: Volunteer
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
bagisto/bagisto-api#51 ·