1

I am using api-platform 2.6 with symfony 6. I have a model

use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiProperty;

#[ApiResource(
    itemOperations: [
        'get' => [
            'path' => '',
        ],
    ]
)]
class SomeName
{
    #[ApiProperty(identifier: true)]
    public string $pathInfo;

$pathInfo is a identifier and can take values of the form like "/some/path/.../". I would like to use this api method like

/some-name/?pathInfo=/some/path/.../

where $pathInfo is a query (GET) parameter. How can I do this?

I have tried this

    itemOperations: [
        'get' => [
            'path' => '?pathInfo={pathInfo}',
        ],
    ],

but I get error "No route found for..." and I don't like that in OpenApi documentation this api method looks like "/some-name?pathInfo={pathInfo}"

1 Answer 1

0
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiProperty;

#[ApiResource(
    itemOperations: [
        'get' => [
            'path' => '/some-name',
            'openapi_context' => [
                'parameters' => [
                    [
                        'in' => 'query',
                        'name' => 'pathInfo',
                        'required' => true,
                        'schema' => [
                            'type' => 'string',
                        ],
                        'description' => 'The path information',
                    ],
                ],
            ],
        ],
    ]
)]
Sign up to request clarification or add additional context in comments.

2 Comments

This just outputs the second pathInfo field in the Open Api documentation. And the api method itself returns an error "Invalid identifier value or configuration.". But thanks for the answer.
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.