Skip to content

[OpenAPI] Missing @context, @type, @id in nested resource #5967

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

Closed
pmontoya opened this issue Nov 13, 2023 · 2 comments
Closed

[OpenAPI] Missing @context, @type, @id in nested resource #5967

pmontoya opened this issue Nov 13, 2023 · 2 comments

Comments

@pmontoya
Copy link

API Platform version(s) affected: 3.2.x

Description
When I generate openapi documentation (using the api:openapi:export command) the output response has been updated from 3.1 version. A nested resource doesn't have its jsonld properties (as @id)

How to reproduce

category class

<?php

namespace App\Catalog\Infrastructure\ApiPlatform\Resource;

use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use Symfony\Component\Serializer\Annotation\Groups;

#[Get(uriTemplate: '/categories/{id}', uriVariables: ['id'])]
#[GetCollection(uriTemplate: '/categories')]
class Category
{
    public function __construct(
        #[Groups(['get'])]
        private readonly string $name,
    )
    {
    }

    public function getName(): string
    {
        return $this->name;
    }
}

Product class

<?php

namespace App\Catalog\Infrastructure\ApiPlatform\Resource;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use App\Catalog\Infrastructure\ApiPlatform\Provider\GetProductCollectionProvider;
use App\Catalog\Infrastructure\ApiPlatform\Provider\GetProductItemProvider;
use Symfony\Component\Serializer\Annotation\Groups;

#[Get(
    uriTemplate: '/products/{sku}',
    uriVariables: ['sku'],
    normalizationContext: ['groups' => ['get']],
    provider: GetProductItemProvider::class
)]
class Product
{
    public function __construct(
        #[ApiProperty(identifier: true)]
        #[Groups(['get'])]
        public readonly string   $sku,
        #[Groups(['get'])]
        public readonly string   $title,
        #[Groups(['get'])]
        public readonly Category $category,
    )
    {

    }
}

the openapi json contains an entry Category.jsonld with @id, @type and @context and an entry Category.jsonld-get without. The product has a property

     "category": {
         "owl:maxCardinality": 1,
         "$ref": "#/components/schemas/Category.jsonld-get"
      }

Before 3.2, Category.jsonld-get had @id, @type and @context attributes

Thank you for your help

@j-schumann
Copy link

Duplicate of #5950?

@pmontoya
Copy link
Author

Yes it is thank you.

@pmontoya pmontoya closed this as not planned Won't fix, can't repro, duplicate, stale Nov 14, 2023
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

No branches or pull requests

2 participants