Problem with schema descriptions
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 42/100
Research direction
Start by tracing OpenAPI schema generation for custom enum properties and compare it with the existing PHPDoc description handling for scalar properties. Done means the generated OpenAPI specification includes the property's PHPDoc description without requiring an explicit description in the ApiProperty schema.
Written by the indexing model from the issue text.
Description
API Platform version(s) affected: 4.1.8
Description
When using a custom enum as a property type, the OpenAPI description must be explicitly defined using the #[ApiProperty(schema: ['description' => '...'])] attribute.
In contrast, for scalar or other non-enum types, the description can be extracted automatically from the PHPDoc comment block.
This inconsistency can lead to confusion and additional boilerplate when using enums.
How to reproduce
class ChecklistQuestionTypeType extends Type implements TypeNameInterface {
case ACTIVE = 'active';
case INACTIVE = 'inactive';
public const array MAPPED_VALUES = [
1 => self::ACTIVE,
2 => self::INACTIVE,
];
public const array VALUES = [...self::MAPPED_VALUES];
public function getValues(): array
{
return self::VALUES;
}
public function getMappedValues(): array
{
return self::MAPPED_VALUES;
}
}
final class ExampleResource
{
/**
* The current status of the resource.
*/
#[ApiProperty(schema: ['type' => 'string', 'enum' => Status::VALUES])]
public string $status;
}
Expected: The OpenAPI spec should include the description from the PHPDoc (The current status of the resource.).
Actual: The description is missing unless explicitly added in the ApiProperty attribute like so:
#[ApiProperty(schema: ['description' => 'The current status of the resource.', ...])]
Additional Context
- The inconsistency suggests that PHPDoc parsing is skipped or not supported for enum types.
- It would improve DX if enum properties behaved consistently with scalar types regarding description inference.
- Dominant language
- PHP
- Stars
- 2.6k
- Forks
- 989
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 104
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from api-platform/core
-
JSON:API: resource schemas (`*.jsonapi`) have `properties` but no `type: object`Possibly taken @ousamabenyounes claimed this 1 day ago. Open
Difficulty 2/5 Under an hour Newbie friendliness 80/100
api-platform/core#8701 ·
Maintainers usually reply within 1 day
-
JSON:API: `JsonApiCollectionBaseSchemaNoPagination` declares `data` as `type: array` without `items`Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
api-platform/core#8699 ·
Maintainers usually reply within 1 day
-
api:openapi:export --spec-version=3.0.0 outputs `webhooks`, which is invalid in OpenAPI 3.0Possibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
api-platform/core#8690 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
api-platform/core#8680 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
api-platform/core#8725 ·
Maintainers usually reply within 1 day
All issues in api-platform/core
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
Maintainers usually reply within 1 day
-
Authentication / Authorization Feature: Volunteer
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
WordPress/mcp-adapter#399 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 80/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
freescout-help-desk/freescout#5750 · 1 comment ·
Maintainers usually reply within 1 day