From 795ad242f8adef3b8eba95839d06512e0125f009 Mon Sep 17 00:00:00 2001 From: ymaillard <12812115+ymaillard@users.noreply.github.com> Date: Tue, 2 Aug 2022 09:55:16 +0200 Subject: [PATCH] Return the data type "string" for the enum PHP class in the JSON Schema document. Actually, the JSON Schema document specifies the data type "object". According to my interpretation of the specification, it should be a string ( https://swagger.io/docs/specification/data-models/enums/ ) --- src/JsonSchema/TypeFactory.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/JsonSchema/TypeFactory.php b/src/JsonSchema/TypeFactory.php index b2595ee6ff0..02e61098f79 100644 --- a/src/JsonSchema/TypeFactory.php +++ b/src/JsonSchema/TypeFactory.php @@ -127,6 +127,13 @@ private function getClassType(?string $className, string $format, ?bool $readabl ]; } + if (is_a($className, \BackedEnum::class, true)) { + return [ + 'type' => 'string', + 'format' => 'enum', + ]; + } + // Skip if $schema is null (filters only support basic types) if (null === $schema) { return ['type' => 'string'];