Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filtering not done as expected #1624

Closed
caixingyue opened this issue Jul 8, 2024 · 4 comments · Fixed by #1625
Closed

Filtering not done as expected #1624

caixingyue opened this issue Jul 8, 2024 · 4 comments · Fixed by #1625

Comments

@caixingyue
Copy link

caixingyue commented Jul 8, 2024

image

When all interfaces in a tag are filtered out, the tag should also be removed because it does not have any effect when displayed here.

As shown by the blue line in the figure, no api appears when I click to expand, so it should not continue to exist.

new Processors\PathFilter([], ['/api/']),
new Processors\CleanUnusedComponents(true),
@DerManoMann
Copy link
Collaborator

This might be something to be added to the new AugmentTags processor...

@momala454
Copy link
Contributor

momala454 commented Jul 15, 2024

it still doesn't work. I see tags from removed path still listed
image

my config

'pathFilter' => [
        'paths' => ['/^\/admin\/.+/'],
    ],
    'cleanUnusedComponents' => ['enabled' => true],

@DerManoMann
Copy link
Collaborator

What can I say.
Any chance you could post a single file reproducer?

@momala454
Copy link
Contributor

Test.php

#[\OpenApi\Attributes\OpenApi(
    info: new \OpenApi\Attributes\Info(
        title: 'test',
        description: 'test',
        version: '2.0.0'
    ),
)]
class Test
{
    #[\OpenApi\Attributes\Get(path: '/world/', tags: ['tag world'], responses: [new \OpenApi\Attributes\Response(response: '200', description: 'success')])]
    #[\OpenApi\Attributes\Get(path: '/hello/', tags: ['tag hello'], responses: [new \OpenApi\Attributes\Response(response: '200', description: 'success')])]
    public function hello(): void
    {
    }
}

testrun.php

require("vendor/autoload.php");

spl_autoload_register(function ($string): void {
    if ($string === 'Test') {
        require __DIR__ . '/Test.php';
    }
});

$openapi = (new \OpenApi\Generator())->setVersion('3.0.0')->setConfig([
    'pathFilter' => [
        'paths' => ['/^\/hello\//'],
    ],
    'cleanUnusedComponents' => ['enabled' => true],
])->generate(\OpenApi\Util::finder([__DIR__ . '/Test.php']));
$json = json_decode($openapi->toJson(), true);
echo json_encode($json, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR);

Output, with both tags instead of a single one

{
    "openapi": "3.0.0",
    "info": {
        "title": "test",
        "description": "test",
        "version": "2.0.0"
    },
    "paths": {
        "\/hello\/": {
            "get": {
                "tags": [
                    "tag hello"
                ],
                "operationId": "d334274659cc0b24fab8ee0a76559fdf",
                "responses": {
                    "200": {
                        "description": "success"
                    }
                }
            }
        }
    },
    "tags": [
        {
            "name": "tag world",
            "description": "tag world"
        },
        {
            "name": "tag hello",
            "description": "tag hello"
        }
    ]
}

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

Successfully merging a pull request may close this issue.

3 participants