Refreshing the documentation page and getting
User Warning: $ref "#/components/schemas/OrderProduct1N" not found for @OAProperty(property="products") in
ErrorException
Show exception properties
ErrorException {#28457 ▼
#severity: E_USER_WARNING
}
in vendor/zircote/swagger-php/src/Loggers/DefaultLogger.php (line 31)
in vendor/psr/log/src/LoggerTrait.php -> log (line 61)
in vendor/zircote/swagger-php/src/Annotations/AbstractAnnotation.php -> warning (line 511)
in vendor/zircote/swagger-php/src/Annotations/Schema.php -> validate (line 517)
in vendor/zircote/swagger-php/src/Annotations/AbstractAnnotation.php -> validate (line 592)
in vendor/zircote/swagger-php/src/Annotations/AbstractAnnotation.php :: _validate (line 598)
in vendor/zircote/swagger-php/src/Annotations/AbstractAnnotation.php :: _validate (line 565)
in vendor/zircote/swagger-php/src/Annotations/Schema.php -> validate (line 517)
in vendor/zircote/swagger-php/src/Annotations/AbstractAnnotation.php -> validate (line 592)
in vendor/zircote/swagger-php/src/Annotations/AbstractAnnotation.php :: _validate (line 598)
in vendor/zircote/swagger-php/src/Annotations/AbstractAnnotation.php :: _validate (line 565)
in vendor/zircote/swagger-php/src/Annotations/AbstractAnnotation.php -> validate (line 592)
in vendor/zircote/swagger-php/src/Annotations/AbstractAnnotation.php :: _validate (line 565)
in vendor/zircote/swagger-php/src/Annotations/OpenApi.php -> validate (line 170)
in vendor/zircote/swagger-php/src/Analysis.php -> validate (line 440)
in vendor/nelmio/api-doc-bundle/src/ApiDocGenerator.php -> validate (line 134)
in vendor/nelmio/api-doc-bundle/src/Render/RenderOpenApi.php -> generate (line 85)
in vendor/nelmio/api-doc-bundle/src/Render/RenderOpenApi.php -> render (line 68)
in vendor/nelmio/api-doc-bundle/src/Controller/SwaggerUiController.php -> renderFromRequest (line 36)
in vendor/symfony/http-kernel/HttpKernel.php -> __invoke (line 183)
in vendor/symfony/http-kernel/HttpKernel.php -> handleRaw (line 76)
in vendor/symfony/http-kernel/Kernel.php -> handle (line 182)
in vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php -> handle (line 35)
in vendor/autoload_runtime.php -> run (line 29)
require_once('/var/www/pmp-api/vendor/autoload_runtime.php')
in public/index.php (line 5)
<?phpuse AppKernel;require_once dirname(__DIR__).'/vendor/autoload_runtime.php';return function (array $context) { return new Kernel($context['APP_ENV'] ?? 'dev', (bool) $context['APP_DEBUG']);};
#[OASchema(
schema: "OrderProduct1N",
)]
How to understand this attribute? https://zircote.github.io/swagger-php/guide/common-techniques.html#enum-schemas here for example it should work if it is in documentation. So only that my object is in different namespace. But does that have something to do with it?
It is symfony 7, php 8.3.
Controller method:
#[Route(
path: '/{version}/sellers/{sellerId}/test',
requirements: ['version' => '%supported_versions%'],
methods: ['GET']
)]
#[OAResponse(
response: 200,
description: 'Successful',
content: new OAJsonContent(
ref: new Model(
type: SellerOrdersList1::class,
),
)
)]
#[OATag(name: 'Orders')]
#[OAGet(summary: 'Get orders belonging to a seller')]
#[Areas(['public'])]
public function test()
{
return $this->json('ok');
}
Models:
<?php
declare(strict_types=1);
namespace AppModelResponseOrder;
use AppEntityOrder1;
use AppOpenApiSchemasSellerOrderListOrder;
use NelmioApiDocBundleAnnotationModel;
use OpenApiAttributes as OA;
class SellerOrdersList1
{
#[OAProperty(
type: 'array',
items: new OAItems(type: 'object', ref: new Model(type: Order1::class)),
)]
protected array $orders;
/**
* @return Order[]
*/
public function getOrders(): array
{
return $this->orders;
}
/**
* @param Order[] $orders
*/
public function setOrders(array $orders): void
{
$this->orders = $orders;
}
}
<?php
namespace AppEntity;
use AppOpenApiSchemasSellerOrderListOrderProduct1N;
use DoctrineCommonCollectionsCollection;
use NelmioApiDocBundleAnnotationModel;
use OpenApiAttributes as OA;
class Order1 implements ClaimEntityInterface
{
#[OAProperty(
type: 'array',
items: new OAItems(ref: new Model(type: OrderProduct1N::class))
)]
private Collection $products;
}
<?php
declare(strict_types=1);
namespace AppOpenApiSchemasSellerOrderList;
use OpenApiAttributes as OA;
#[OASchema(
schema: "OrderProduct1N",
)]
class OrderProduct1N
{
public string $test;
}
Expecting it to not get error at first.
I see here: NelmioApiDocBundle v4.0.0-BETA1, $ref not found
it is written
In your case, you should use ref=@NelmioApiDocBundleAnnotationModel(type=ProductDTO::class instead of ref=”#/components/schemas/ProductDto.
But I do not understand then why in this https://zircote.github.io/swagger-php/guide/common-techniques.html#enum-schemas example it works assuming it working example.
Update
Making field public gets rid of this error.
#[OAProperty(
type: 'array',
items: new OAItems(ref: new Model(type: OrderProduct1N::class))
)]
public Collection $products;
But then it does not matter if schema is existing or not over in this model:
#[OASchema(
schema: "OrderProduct1N",
)]
class OrderProduct1N
{
public string $test;
}
so then what this for? I see in another example it is being used without schema key.
#[OASchema(
it just has properties field:
#[OASchema(
properties: [
new OAProperty(
property: 'limit',
type: 'integer',
example: 40
)
]
)]
class PaginationMeta
{
}
In that place it shows documentation for properties like ‘limit’ even when as we can see PaginationMeta has no properties. So if needing this it can be useful – to declare properties for ducumenation which are not on the class. But then what is schema field in schema attribute for? Renaming? Tried using by schema field – getting errors. Like
#[OAProperty(
type: 'array',
items: new OAItems(ref: new Model(type: '#/components/schemas/OrderProduct1N'))
)]
public Collection $products;
Schema of type “#/components/schemas/OrderProduct1N” can’t be
generated, no describer supports it. Class
“#/components/schemas/OrderProduct1N” does not exist, did you forget
a use statement, or typed it wrong?
LogicException:
Schema of type "#/components/schemas/OrderProduct1N" can't be generated, no describer supports it. Class "#/components/schemas/OrderProduct1N" does not exist, did you forget a use statement, or typed it wrong?
at vendor/nelmio/api-doc-bundle/src/Model/ModelRegistry.php:126
at NelmioApiDocBundleModelModelRegistry->registerSchemas()
(vendor/nelmio/api-doc-bundle/src/ApiDocGenerator.php:131)
at NelmioApiDocBundleApiDocGenerator->generate()
(vendor/nelmio/api-doc-bundle/src/Render/RenderOpenApi.php:85)
at NelmioApiDocBundleRenderRenderOpenApi->render('html', 'public', array('ui_renderer' => 'swaggerui'))
(vendor/nelmio/api-doc-bundle/src/Render/RenderOpenApi.php:68)
at NelmioApiDocBundleRenderRenderOpenApi->renderFromRequest(object(Request), 'html', 'public', array('ui_renderer' => 'swaggerui'))
(vendor/nelmio/api-doc-bundle/src/Controller/SwaggerUiController.php:36)
at NelmioApiDocBundleControllerSwaggerUiController->__invoke(object(Request), 'public')
(vendor/symfony/http-kernel/HttpKernel.php:183)
at SymfonyComponentHttpKernelHttpKernel->handleRaw(object(Request), 1)
(vendor/symfony/http-kernel/HttpKernel.php:76)
at SymfonyComponentHttpKernelHttpKernel->handle(object(Request), 1, true)
(vendor/symfony/http-kernel/Kernel.php:182)
at SymfonyComponentHttpKernelKernel->handle(object(Request))
(vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php:35)
at SymfonyComponentRuntimeRunnerSymfonyHttpKernelRunner->run()
(vendor/autoload_runtime.php:29)
at require_once('/var/www/pmp-api/vendor/autoload_runtime.php')
(public/index.php:5)