You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When building a JSON-LD only API (no plain JSON format), the OpenAPI specification still generates duplicate schemas and content types. Users have to create custom OpenApiFactory decorators to filter these out.
2. Removes duplicate schemas (keeps only .jsonld versions)
privatefunctionfilterNonJsonSchemas(OpenApi$openApi): OpenApi
{
$schemas = $openApi->getComponents()->getSchemas();
// Collect base names that have .jsonld versions$jsonldSchemas = [];
foreach ($schemasas$name => $schema) {
if (str_ends_with($name, '.jsonld')) {
$jsonldSchemas[substr($name, 0, -7)] = true;
}
}
$filteredSchemas = new \ArrayObject();
foreach ($schemasas$name => $schema) {
$baseName = preg_replace('/\.jsonld$/', '', $name);
// Skip non-.jsonld version when .jsonld existsif (!str_ends_with($name, '.jsonld') && isset($jsonldSchemas[$baseName])) {
continue;
}
$filteredSchemas[$name] = $schema;
}
return$openApi->withComponents($components->withSchemas($filteredSchemas));
}
Proposed Framework Enhancement
Option A: openapi.prefer_format Configuration
Add a configuration option to specify the preferred format for OpenAPI documentation:
api_platform:
openapi:
prefer_format: jsonld # Only show jsonld schemas and content types
Implementation:
In OpenApiFactory, when prefer_format is set:
Only generate schemas for that format (skip others even if configured)
Only include that format's content type in responses
Remove duplicate schemas that exist in multiple format variants
Option B: openapi.formats Configuration
Allow explicit control over which formats appear in OpenAPI (separate from runtime formats):
api_platform:
formats:
jsonld: ['application/ld+json']json: ['application/json'] # Available at runtimeopenapi:
formats:
jsonld: ['application/ld+json'] # Only this in docs
Implementation:
In OpenApiFactory::getMimeTypes():
privatefunctiongetMimeTypes(HttpOperation$operation): array
{
// Use openapi.formats if configured, otherwise fall back to operation formats$responseFormats = $this->openapiFormats
?? $operation->getOutputFormats()
?? [];
// ... rest of method
}
Option C: Automatic Deduplication
When multiple formats produce equivalent schemas (same structure, different naming), automatically deduplicate:
// In OpenApiFactory::collectPaths() or a new dedicated methodprivatefunctiondeduplicateSchemas(\ArrayObject$schemas): \ArrayObject
{
$dominated = [];
// jsonld dominates json (more specific)foreach ($schemasas$name => $schema) {
if (str_ends_with($name, '.jsonld')) {
$baseName = substr($name, 0, -7);
if (isset($schemas[$baseName])) {
$dominated[$baseName] = true;
}
}
}
// Remove dominated schemasforeach ($dominatedas$name => $_) {
unset($schemas[$name]);
}
return$schemas;
}
Recommendation
Option A (prefer_format) is the cleanest because:
Simple, single configuration option
Clear intent: "I want my OpenAPI docs in this format"
Our decorator also adds Accept and Content-Type header parameters to all operations, showing available formats as an enum. This is useful documentation that API Platform could generate automatically.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Activity
stale commentedon Apr 29, 2026
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.