Skip to content

fix(metadata): infer schema for Link URI variables from linked property - #8677

Open
bram123 wants to merge 1 commit into
api-platform:mainfrom
bram123:link-uri-variable-schema-inference
Open

bram123 wants to merge 1 commit into
api-platform:mainfrom
bram123:link-uri-variable-schema-inference

Conversation

@bram123

@bram123 bram123 commented Oct 12, 2026

Copy link
Copy Markdown
Q A
Branch? main for features
Tickets Closes #8646
License MIT
Doc PR

When defining URI variables using Link without an explicit schema, OpenAPI generated path parameters defaulted to generic string types and lost format information (such as UUID/ULID or integer types) from the target property metadata.

This PR infers primitive schema type and format in LinkFactory from the linked property when none is explicitly configured on the Link.

Functional Test

tests/Functional/OpenApiLinkSchemaTest.php

public function testLinkSchemaIsInferredFromLinkedProperty(): void
{
    $response = self::createClient()->request('GET', '/docs', [
        'headers' => ['Accept' => 'application/vnd.openapi+json'],
    ]);
    $this->assertResponseIsSuccessful();

    $json = $response->toArray();
    $parameters = $json['paths']['/link_schema_parents/{parentId}/children/{id}']['get']['parameters'];

    $parentParam = $parameters[0];
    $this->assertSame('path', $parentParam['in']);
    $this->assertTrue($parentParam['required']);
    $this->assertSame(['type' => 'string', 'format' => 'uuid'], $parentParam['schema']);

    $idParam = $parameters[1];
    $this->assertSame('path', $idParam['in']);
    $this->assertTrue($idParam['required']);
    $this->assertSame(['type' => 'integer'], $idParam['schema']);
}

@bram123

bram123 commented Oct 12, 2026 •

Copy link
Copy Markdown
Author

PHPStan/PHPUnit failures seem unrelated?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Metadata] Incorrect api schema for path variable

1 participant