Skip to content

Commit 2e3fc91

Browse files
committed
fix
1 parent 06d6227 commit 2e3fc91

File tree

5 files changed

+13
-49
lines changed

5 files changed

+13
-49
lines changed

src/JsonSchema/Metadata/Property/Factory/SchemaPropertyMetadataFactory.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use ApiPlatform\Metadata\Util\ResourceClassInfoTrait;
2222
use Doctrine\Common\Collections\ArrayCollection;
2323
use Ramsey\Uuid\UuidInterface;
24-
use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface;
2524
use Symfony\Component\PropertyInfo\Type;
2625
use Symfony\Component\Uid\Ulid;
2726
use Symfony\Component\Uid\Uuid;
@@ -38,7 +37,6 @@ final class SchemaPropertyMetadataFactory implements PropertyMetadataFactoryInte
3837
public function __construct(
3938
ResourceClassResolverInterface $resourceClassResolver,
4039
private readonly ?PropertyMetadataFactoryInterface $decorated = null,
41-
private readonly ?PropertyInfoExtractorInterface $propertyInfo = null,
4240
) {
4341
$this->resourceClassResolver = $resourceClassResolver;
4442
}
@@ -270,17 +268,7 @@ private function getClassType(?string $className, bool $nullable, ?bool $readabl
270268
];
271269
}
272270

273-
if (!$this->propertyInfo) {
274-
return ['type' => 'object'];
275-
}
276-
277-
$properties = $this->propertyInfo->getProperties($className, ['serializer_groups' => null]);
278-
$propertiesSchema = [];
279-
foreach ($properties as $property) {
280-
$propertiesSchema[$property] = $this->create($className, $property)->getSchema();
281-
}
282-
283-
return ['type' => 'object', 'properties' => $propertiesSchema];
271+
return ['type' => Schema::UNKNOWN_TYPE];
284272
}
285273

286274
/**

src/JsonSchema/SchemaFactory.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ private function buildPropertySchema(Schema $schema, string $definitionName, str
183183
$propertySchemaType = $propertySchema['type'] ?? false;
184184

185185
$isUnknown = Schema::UNKNOWN_TYPE === $propertySchemaType
186-
|| ('array' === $propertySchemaType && Schema::UNKNOWN_TYPE === ($propertySchema['items']['type'] ?? null));
186+
|| ('array' === $propertySchemaType && Schema::UNKNOWN_TYPE === ($propertySchema['items']['type'] ?? null))
187+
|| ('object' === $propertySchemaType && Schema::UNKNOWN_TYPE === ($propertySchema['additionalProperties']['type'] ?? null));
187188

188189
if (
189190
!$isUnknown && (
@@ -241,8 +242,9 @@ private function buildPropertySchema(Schema $schema, string $definitionName, str
241242
}
242243

243244
if ($isCollection) {
244-
$propertySchema['items']['$ref'] = $subSchema['$ref'];
245-
unset($propertySchema['items']['type']);
245+
$key = ($propertySchema['type'] ?? null) === 'object' ? 'additionalProperties' : 'items';
246+
$propertySchema[$key]['$ref'] = $subSchema['$ref'];
247+
unset($propertySchema[$key]['type']);
246248
break;
247249
}
248250

src/OpenApi/Factory/OpenApiFactory.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
use ApiPlatform\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface;
3434
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
3535
use ApiPlatform\OpenApi\Attributes\Webhook;
36-
use ApiPlatform\OpenApi\Model;
3736
use ApiPlatform\OpenApi\Model\Components;
3837
use ApiPlatform\OpenApi\Model\Contact;
3938
use ApiPlatform\OpenApi\Model\ExternalDocumentation;
@@ -512,11 +511,11 @@ private function buildOpenApiResponse(array $existingResponses, int|string $stat
512511
}
513512

514513
/**
515-
* @return \ArrayObject<Model\MediaType>
514+
* @return \ArrayObject<MediaType>
516515
*/
517516
private function buildContent(array $responseMimeTypes, array $operationSchemas): \ArrayObject
518517
{
519-
/** @var \ArrayObject<Model\MediaType> $content */
518+
/** @var \ArrayObject<MediaType> $content */
520519
$content = new \ArrayObject();
521520

522521
foreach ($responseMimeTypes as $mimeType => $format) {
@@ -603,11 +602,11 @@ private function getPathDescription(string $resourceShortName, string $method, b
603602
/**
604603
* @see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#linkObject.
605604
*
606-
* @return \ArrayObject<Model\Link>
605+
* @return \ArrayObject<Link>
607606
*/
608607
private function getLinks(ResourceMetadataCollection $resourceMetadataCollection, HttpOperation $currentOperation): \ArrayObject
609608
{
610-
/** @var \ArrayObject<Model\Link> $links */
609+
/** @var \ArrayObject<Link> $links */
611610
$links = new \ArrayObject();
612611

613612
// Only compute get links for now

src/Symfony/Bundle/Resources/config/json_schema.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
<service id="api_platform.json_schema.metadata.property.metadata_factory.schema" decorates="api_platform.metadata.property.metadata_factory" decoration-priority="10" class="ApiPlatform\JsonSchema\Metadata\Property\Factory\SchemaPropertyMetadataFactory" public="false">
3737
<argument type="service" id="api_platform.resource_class_resolver" />
3838
<argument type="service" id="api_platform.json_schema.metadata.property.metadata_factory.schema.inner" />
39-
<argument type="service" id="api_platform.property_info" on-invalid="null" />
4039
</service>
4140

4241
<service id="api_platform.json_schema.backward_compatible_schema_factory" decorates="api_platform.json_schema.schema_factory" decoration-priority="-2" class="ApiPlatform\JsonSchema\BackwardCompatibleSchemaFactory">

tests/JsonSchema/Command/JsonSchemaGenerateCommandTest.php

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -377,15 +377,7 @@ public static function arrayPropertyTypeSyntaxProvider(): \Generator
377377
[
378378
'type' => 'array',
379379
'items' => [
380-
'type' => 'object',
381-
'properties' => [
382-
'bar' => [
383-
'type' => 'string',
384-
],
385-
'baz' => [
386-
'type' => 'integer',
387-
],
388-
],
380+
'$ref' => '#/definitions/Foo.jsonld',
389381
],
390382
],
391383
];
@@ -394,15 +386,7 @@ public static function arrayPropertyTypeSyntaxProvider(): \Generator
394386
[
395387
'type' => 'array',
396388
'items' => [
397-
'type' => 'object',
398-
'properties' => [
399-
'bar' => [
400-
'type' => 'string',
401-
],
402-
'baz' => [
403-
'type' => 'integer',
404-
],
405-
],
389+
'$ref' => '#/definitions/Foo.jsonld',
406390
],
407391
],
408392
];
@@ -411,15 +395,7 @@ public static function arrayPropertyTypeSyntaxProvider(): \Generator
411395
[
412396
'type' => 'object',
413397
'additionalProperties' => [
414-
'type' => 'object',
415-
'properties' => [
416-
'bar' => [
417-
'type' => 'string',
418-
],
419-
'baz' => [
420-
'type' => 'integer',
421-
],
422-
],
398+
'$ref' => '#/definitions/Foo.jsonld',
423399
],
424400
],
425401
];

0 commit comments

Comments
 (0)