Skip to content

Commit e7f9586

Browse files
Ocramiusteohhanhui
authored andcommitted
Rolling back to mapping unknown object types as JSON-Schema {"type": "string"}
To avoid BC breaks, we defer this fix to api-platform/core#3403 > **API Platform version(s) affected**: 2.5.x > > **Description** > > In our tests for `TypeFactory`: > > ``` > > yield [['type' => 'string'], new Type(Type::BUILTIN_TYPE_OBJECT)]; > yield [['type' => 'string'], new Type(Type::BUILTIN_TYPE_OBJECT, true)]; > > // ... > > yield [['type' => 'string'], new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::class)]; > yield [['type' => 'string'], new Type(Type::BUILTIN_TYPE_OBJECT, true, Dummy::class)]; > ``` > > While reviewing #3402, @dunglas found a potential BC break with objects that may be used in URIs as `string`s (therefore not `objects`): > > * [#3402 (comment)](api-platform/core#3402 (comment)) > > * [#3402 (comment)](api-platform/core#3402 (comment)) > > > **How to reproduce** > > The test should instead convert `object` to `object`: > > ``` > > yield [['type' => 'object'], new Type(Type::BUILTIN_TYPE_OBJECT)]; > yield [['type' => 'object'], new Type(Type::BUILTIN_TYPE_OBJECT, true)]; > > // ... > > yield [['type' => 'object'], new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::class)]; > yield [['type' => 'object'], new Type(Type::BUILTIN_TYPE_OBJECT, true, Dummy::class)]; > ```
1 parent 4dd589e commit e7f9586

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

TypeFactory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private function makeBasicType(Type $type, string $format = 'json', ?bool $reada
117117
private function getClassType(?string $className, string $format, ?bool $readableLink, ?array $serializerContext, ?Schema $schema): array
118118
{
119119
if (null === $className) {
120-
return ['type' => 'object'];
120+
return ['type' => 'string'];
121121
}
122122

123123
if (is_a($className, \DateTimeInterface::class, true)) {
@@ -141,7 +141,7 @@ private function getClassType(?string $className, string $format, ?bool $readabl
141141

142142
// Skip if $schema is null (filters only support basic types)
143143
if (null === $schema) {
144-
return ['type' => 'object'];
144+
return ['type' => 'string'];
145145
}
146146

147147
if ($this->isResourceClass($className) && true !== $readableLink) {

0 commit comments

Comments
 (0)