Document `#[NotExposed]` for nested DTOs in design.md and dto.md

Open Beginner friendly
#2,284 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
85/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Quiet
Tech stack
php
Domain
documentation

Research direction

Read core/dto.md and core/design.md, then compare the existing NotExposed reference in core/jsonapi.md. Add the requested explanation, PHP example, and cross-link; done means users can discover how nested DTO metadata is documented without exposing public endpoints.

Written by the indexing model from the issue text.

Description

Context

#[NotExposed] is currently documented only in jsonapi.md (for JSON:API relations) and briefly mentioned in openapi.md. It is missing from the two pages most users land on when designing DTOs:

Problem

API Platform's metadata pipeline (Hydra docs, OpenAPI, JSON Schema, property security, etc.) walks #[ApiResource] classes only. Nested POPOs referenced via property typehints are invisible to the doc generators. Users hit this repeatedly (e.g. https://github.com/api-platform/core/issues/8187, https://github.com/api-platform/core/issues/8087) and the typical answer — "mark the nested DTO with #[NotExposed]" — is not discoverable from the DTO docs.

Suggested addition

Short subsection in dto.md (and a mention in design.md) covering:

  • Nested DTOs referenced from an output DTO are not introspected for docs unless they are themselves resources
  • Use #[NotExposed] on a nested DTO to register its metadata (Hydra/OpenAPI/property factories) without exposing public endpoints
  • Brief example:
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\NotExposed;

#[ApiResource(operations: [new Get(/* ... */)])]
class Response
{
    /** @var Nested[] */
    public array $data = [];
}

#[NotExposed]
class Nested
{
    public function __construct(public int $id) {}
}
  • Cross-link to the existing NotExposed reference in jsonapi.md
Dominant language
No language data
Stars
181
Forks
1.1k
Avg merge
1d 10h
Merged PRs (30d)
24

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from api-platform/docs

All issues in api-platform/docs

Similar issues

More Documentation issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.