[Metadata] Incorrect api schema for path variable · Issue #8646 · api-platform/core · GitHub
Skip to content

[Metadata] Incorrect api schema for path variable #8646

Open

Description

@bram123

API Platform version(s) affected: 5.0.2

Description
I noticed that all path variables have the default schema ['type' => 'string'], even when the variable is linked to a class property that does have a type / format.
This means that the swagger-ui will display it as a string input field, and miss the correct validation.

How to reproduce

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\Get;

#[Get('entities/{id}')]
readonly class Entity
{
    public function __construct(
        #[ApiProperty(identifier: true)]
        public int $id,
    ) {
    }
}
SwaggerUI Image

Possible Solution
The ApiPlatform\Metadata\Resource\Factory\LinkFactory class is used to generate Link instances based on things like the Operation's uriTemplate.
Here I can use the propertyMetadataFactory to get the schema of the linked property.

Questions
Is this something that should be fixed/implemented at all? For me this would save me from having to add the uriVariables parameter with Link classes everytime.

Is this considered a bug (pull request towards 5.0 branch), or a missing feature (pull request towards main branch?

Activity

  1. changed the title [-][Metadata] Incorrect path variable schemas[/-] [+][Metadata] Incorrect api schema for path variable[/+] on Oct 6, 2026
  2. soyuka commented on Oct 13, 2026

    @soyuka
    Member

    This is a missing feature, not a bug, so it'd target main. Changing the OpenAPI document in a patch release already bit us with #8600.

    Today you can declare it with new Link(schema: ['type' => 'integer']), the default string comes from https://github.com/api-platform/core/blob/5.0/src/OpenApi/Factory/OpenApiFactory.php#L309. I'd rather infer it there than in the LinkFactory so the Link metadata stays untouched: when the Link has no schema and a single identifier, use the identifier property's schema (type/format only, so integer or string + uuid), and keep string for composite identifiers. Note that the Link schema isn't used for validation on uri variables, so this is documentation only.

    Do you want to open a PR?

  3. bram123 commented on Oct 16, 2026

    @bram123
    ContributorAuthor

    4. This is a missing feature, not a bug, so it'd target main. Changing the OpenAPI document in a patch release already bit us with #8600.
    Today you can declare it with new Link(schema: ['type' => 'integer']), the default string comes from https://github.com/api-platform/core/blob/5.0/src/OpenApi/Factory/OpenApiFactory.php#L309. I'd rather infer it there than in the LinkFactory so the Link metadata stays untouched: when the Link has no schema and a single identifier, use the identifier property's schema (type/format only, so integer or string + uuid), and keep string for composite identifiers. Note that the Link schema isn't used for validation on uri variables, so this is documentation only.
    Do you want to open a PR?

    Yes ofc, I'm working on it in #8677

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions