Understanding SchemaFactory behavior on openapiContext on type string #6503
-
Hi, I've got a property in an entity/resource which is an nullable enum of strings. I found out that I needed to specify on #[ApiProperty(openapiContext: ['type' => 'string', 'format' => 'enum', nullable' => true])]
private ?CustomEnum $value = null; But I took a look into ApiPlatform\JsonSchema\SchemaFactory and found out this condition, and this line: if (
!$isUnknown && (
[] === $types
|| ($propertySchema['$ref'] ?? $propertySchema['anyOf'] ?? $propertySchema['allOf'] ?? $propertySchema['oneOf'] ?? false)
# this line below
|| (\is_array($propertySchemaType) ? \array_key_exists('string', $propertySchemaType) : 'string' !== $propertySchemaType)
|| ($propertySchema['format'] ?? $propertySchema['enum'] ?? false)
)
) {
$schema->getDefinitions()[$definitionName]['properties'][$normalizedPropertyName] = new \ArrayObject($propertySchema);
return;
} I'm trying to understand why there's a special case against |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Use |
Beta Was this translation helpful? Give feedback.
-
Wow thanks. I knew that |
Beta Was this translation helpful? Give feedback.
Use
schema
notopenApiContext
it'll set https://github.com/api-platform/core/blob/main/src/JsonSchema/SchemaFactory.php#L84 and shouldn't be changed.