镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/JsonSchema/SchemaFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ private function buildPropertySchema(Schema $schema, string $definitionName, str
continue;
}

$childSerializerContext = $serializerContext + [self::FORCE_SUBSCHEMA => true, 'gen_id' => $propertyMetadata->getGenId() ?? true];
$childSerializerContext = [self::FORCE_SUBSCHEMA => true, 'gen_id' => $propertyMetadata->getGenId() ?? ($serializerContext['gen_id'] ?? true)] + $serializerContext;
if (isset($serializerContext[AbstractNormalizer::ATTRIBUTES])) {
$attributes = $serializerContext[AbstractNormalizer::ATTRIBUTES];
if (\is_array($attributes) && \array_key_exists($normalizedPropertyName, $attributes) && \is_array($attributes[$normalizedPropertyName])) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\JsonSchemaGenIdChain;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use Symfony\Component\Serializer\Attribute\Groups;

#[ApiResource(operations: [
new Get(
uriTemplate: '/json_schema_gen_id_chain/inverse_middles/{id}',
normalizationContext: ['groups' => ['chain:read']],
provider: [self::class, 'provide'],
),
])]
class GenIdChainInverseMiddle
{
#[ApiProperty(identifier: true)]
#[Groups(['chain:read'])]
public ?int $id = null;

#[ApiProperty(genId: false)]
#[Groups(['chain:read'])]
public ?GenIdChainLeaf $second = null;

public static function provide(): ?self
{
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\JsonSchemaGenIdChain;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use Symfony\Component\Serializer\Attribute\Groups;

#[ApiResource(operations: [
new Get(
uriTemplate: '/json_schema_gen_id_chain/inverse_roots/{id}',
normalizationContext: ['groups' => ['chain:read']],
provider: [self::class, 'provide'],
),
])]
class GenIdChainInverseRoot
{
#[ApiProperty(identifier: true)]
#[Groups(['chain:read'])]
public ?int $id = null;

#[ApiProperty(genId: true)]
#[Groups(['chain:read'])]
public ?GenIdChainInverseMiddle $first = null;

public static function provide(): ?self
{
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\JsonSchemaGenIdChain;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use Symfony\Component\Serializer\Attribute\Groups;

#[ApiResource(operations: [
new Get(
uriTemplate: '/json_schema_gen_id_chain/leaves/{id}',
normalizationContext: ['groups' => ['chain:read']],
provider: [self::class, 'provide'],
),
])]
class GenIdChainLeaf
{
#[ApiProperty(identifier: true)]
#[Groups(['chain:read'])]
public ?int $id = null;

#[Groups(['chain:read'])]
public ?string $label = null;

public static function provide(): ?self
{
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\JsonSchemaGenIdChain;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use Symfony\Component\Serializer\Attribute\Groups;

#[ApiResource(operations: [
new Get(
uriTemplate: '/json_schema_gen_id_chain/middles/{id}',
normalizationContext: ['groups' => ['chain:read']],
provider: [self::class, 'provide'],
),
])]
class GenIdChainMiddle
{
#[ApiProperty(identifier: true)]
#[Groups(['chain:read'])]
public ?int $id = null;

#[ApiProperty(genId: true)]
#[Groups(['chain:read'])]
public ?GenIdChainLeaf $second = null;

public static function provide(): ?self
{
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\JsonSchemaGenIdChain;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use Symfony\Component\Serializer\Attribute\Groups;

#[ApiResource(operations: [
new Get(
uriTemplate: '/json_schema_gen_id_chain/null_middles/{id}',
normalizationContext: ['groups' => ['chain:read']],
provider: [self::class, 'provide'],
),
])]
class GenIdChainNullMiddle
{
#[ApiProperty(identifier: true)]
#[Groups(['chain:read'])]
public ?int $id = null;

#[Groups(['chain:read'])]
public ?GenIdChainLeaf $second = null;

public static function provide(): ?self
{
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\JsonSchemaGenIdChain;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use Symfony\Component\Serializer\Attribute\Groups;

#[ApiResource(operations: [
new Get(
uriTemplate: '/json_schema_gen_id_chain/null_roots/{id}',
normalizationContext: ['groups' => ['chain:read']],
provider: [self::class, 'provide'],
),
])]
class GenIdChainNullRoot
{
#[ApiProperty(identifier: true)]
#[Groups(['chain:read'])]
public ?int $id = null;

#[ApiProperty(genId: false)]
#[Groups(['chain:read'])]
public ?GenIdChainNullMiddle $first = null;

public static function provide(): ?self
{
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\JsonSchemaGenIdChain;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use Symfony\Component\Serializer\Attribute\Groups;

#[ApiResource(operations: [
new Get(
uriTemplate: '/json_schema_gen_id_chain/roots/{id}',
normalizationContext: ['groups' => ['chain:read']],
provider: [self::class, 'provide'],
),
])]
class GenIdChainRoot
{
#[ApiProperty(identifier: true)]
#[Groups(['chain:read'])]
public ?int $id = null;

#[ApiProperty(genId: false)]
#[Groups(['chain:read'])]
public ?GenIdChainMiddle $first = null;

public static function provide(): ?self
{
return null;
}
}
Loading
Loading