Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Centralize Input/Output and Data Class Logic in Metadata

Aperta
#7,907 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Refactoring
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
php

Direzione di ricerca

Inizia confrontando la logica di fallback in ObjectMapperProvider, SerializerContextBuilder e OpenApiFactory con le classi Metadata, Operation e ApiResource. Determina come dovrebbe essere centralizzato il comportamento dei dati di input, output e delle classi dati opzionali, quindi verifica che i consumer interessati utilizzino fallback coerenti e che la decisione relativa alla compatibilità o alla release sia documentata.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Currently, across the codebase (e.g., in ObjectMapperProvider, SerializerContextBuilder, OpenApiFactory), we frequently encounter the pattern of checking for a custom input/output class and falling back to the resource class if not defined:

$class = $operation->getInput()['class'] ?? $operation->getClass();
// or
$class = $operation->getOutput()['class'] ?? $operation->getClass();

To simplify the codebase and avoid repetitive logic, I propose introducing helper methods directly in the Metadata (and thus Operation and ApiResource) classes to handle these fallbacks.

Proposed Changes

The idea is to add the following methods:

  1. getInputClass(): ?string: Returns the custom input class if defined, otherwise falls back to getClass().
  2. getOutputClass(): ?string: Returns the custom output class if defined, otherwise falls back to getClass().
  3. getDataClass(): ?string: (Optional/For discussion) A method to handle the mapped entity class with a similar fallback mechanism, specifically useful when working with DTOs and Data Mappers.
Benefits
  • Dry Code: Centralizes the logic in one place.
  • Simplification: Reduces boilerplate in providers, processors, and factories.
  • Consistency: Ensures the fallback logic is applied identically everywhere.
Considerations

This changes metadata handling significantly. Cleaner API, but assess whether it requires a major (breaking) release or can remain optional.

Lingua principale
PHP
Stelle
2.6k
Fork
982
Merge medio
1g 16h
PR unite (30g)
59

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di api-platform/core

Tutte le issue di api-platform/core

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.