Skip to content

Commit 102c231

Browse files
committed
fix
1 parent 06d6227 commit 102c231

File tree

4 files changed

+10
-45
lines changed

4 files changed

+10
-45
lines changed

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

Lines changed: 2 additions & 14 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;
@@ -37,8 +36,7 @@ final class SchemaPropertyMetadataFactory implements PropertyMetadataFactoryInte
3736

3837
public function __construct(
3938
ResourceClassResolverInterface $resourceClassResolver,
40-
private readonly ?PropertyMetadataFactoryInterface $decorated = null,
41-
private readonly ?PropertyInfoExtractorInterface $propertyInfo = null,
39+
private readonly ?PropertyMetadataFactoryInterface $decorated = 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/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)