diff --git a/features/openapi/docs.feature b/features/openapi/docs.feature index 18f09998c8b..8eead22bfcc 100644 --- a/features/openapi/docs.feature +++ b/features/openapi/docs.feature @@ -100,7 +100,7 @@ Feature: Documentation support { "owl:maxCardinality": 1, "type": "string", - "format": "iri-reference" + "format": "iri-template" } """ # Enable these tests when SF 4.4 / PHP 7.1 support is dropped diff --git a/src/JsonSchema/Tests/TypeFactoryTest.php b/src/JsonSchema/Tests/TypeFactoryTest.php index f2518d54079..f8a955cf538 100644 --- a/src/JsonSchema/Tests/TypeFactoryTest.php +++ b/src/JsonSchema/Tests/TypeFactoryTest.php @@ -57,12 +57,12 @@ public static function typeProvider(): iterable yield [['nullable' => true, 'type' => 'string', 'format' => 'date-time'], new Type(Type::BUILTIN_TYPE_OBJECT, true, \DateTimeImmutable::class)]; yield [['type' => 'string', 'format' => 'duration'], new Type(Type::BUILTIN_TYPE_OBJECT, false, \DateInterval::class)]; yield [['type' => 'string', 'format' => 'binary'], new Type(Type::BUILTIN_TYPE_OBJECT, false, \SplFileInfo::class)]; - yield [['type' => 'string', 'format' => 'iri-reference'], new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::class)]; - yield [['nullable' => true, 'type' => 'string', 'format' => 'iri-reference'], new Type(Type::BUILTIN_TYPE_OBJECT, true, Dummy::class)]; + yield [['type' => 'string', 'format' => 'iri-template'], new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::class)]; + yield [['nullable' => true, 'type' => 'string', 'format' => 'iri-template'], new Type(Type::BUILTIN_TYPE_OBJECT, true, Dummy::class)]; yield ['enum' => ['type' => 'string', 'enum' => ['male', 'female']], new Type(Type::BUILTIN_TYPE_OBJECT, false, GenderTypeEnum::class)]; yield ['nullable enum' => ['type' => 'string', 'enum' => ['male', 'female', null], 'nullable' => true], new Type(Type::BUILTIN_TYPE_OBJECT, true, GenderTypeEnum::class)]; - yield ['enum resource' => ['type' => 'string', 'format' => 'iri-reference'], new Type(Type::BUILTIN_TYPE_OBJECT, false, GamePlayMode::class)]; - yield ['nullable enum resource' => ['type' => 'string', 'format' => 'iri-reference', 'nullable' => true], new Type(Type::BUILTIN_TYPE_OBJECT, true, GamePlayMode::class)]; + yield ['enum resource' => ['type' => 'string', 'format' => 'iri-template'], new Type(Type::BUILTIN_TYPE_OBJECT, false, GamePlayMode::class)]; + yield ['nullable enum resource' => ['type' => 'string', 'format' => 'iri-template', 'nullable' => true], new Type(Type::BUILTIN_TYPE_OBJECT, true, GamePlayMode::class)]; yield [['type' => 'array', 'items' => ['type' => 'string']], new Type(Type::BUILTIN_TYPE_STRING, false, null, true)]; yield 'array can be itself nullable' => [ ['nullable' => true, 'type' => 'array', 'items' => ['type' => 'string']], @@ -185,12 +185,12 @@ public static function jsonSchemaTypeProvider(): iterable yield [['type' => ['string', 'null'], 'format' => 'date-time'], new Type(Type::BUILTIN_TYPE_OBJECT, true, \DateTimeImmutable::class)]; yield [['type' => 'string', 'format' => 'duration'], new Type(Type::BUILTIN_TYPE_OBJECT, false, \DateInterval::class)]; yield [['type' => 'string', 'format' => 'binary'], new Type(Type::BUILTIN_TYPE_OBJECT, false, \SplFileInfo::class)]; - yield [['type' => 'string', 'format' => 'iri-reference'], new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::class)]; - yield [['type' => ['string', 'null'], 'format' => 'iri-reference'], new Type(Type::BUILTIN_TYPE_OBJECT, true, Dummy::class)]; + yield [['type' => 'string', 'format' => 'iri-template'], new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::class)]; + yield [['type' => ['string', 'null'], 'format' => 'iri-template'], new Type(Type::BUILTIN_TYPE_OBJECT, true, Dummy::class)]; yield ['enum' => ['type' => 'string', 'enum' => ['male', 'female']], new Type(Type::BUILTIN_TYPE_OBJECT, false, GenderTypeEnum::class)]; yield ['nullable enum' => ['type' => ['string', 'null'], 'enum' => ['male', 'female', null]], new Type(Type::BUILTIN_TYPE_OBJECT, true, GenderTypeEnum::class)]; - yield ['enum resource' => ['type' => 'string', 'format' => 'iri-reference'], new Type(Type::BUILTIN_TYPE_OBJECT, false, GamePlayMode::class)]; - yield ['nullable enum resource' => ['type' => ['string', 'null'], 'format' => 'iri-reference'], new Type(Type::BUILTIN_TYPE_OBJECT, true, GamePlayMode::class)]; + yield ['enum resource' => ['type' => 'string', 'format' => 'iri-template'], new Type(Type::BUILTIN_TYPE_OBJECT, false, GamePlayMode::class)]; + yield ['nullable enum resource' => ['type' => ['string', 'null'], 'format' => 'iri-template'], new Type(Type::BUILTIN_TYPE_OBJECT, true, GamePlayMode::class)]; yield [['type' => 'array', 'items' => ['type' => 'string']], new Type(Type::BUILTIN_TYPE_STRING, false, null, true)]; yield 'array can be itself nullable' => [ ['type' => ['array', 'null'], 'items' => ['type' => 'string']], @@ -306,12 +306,12 @@ public static function openAPIV2TypeProvider(): iterable yield [['type' => 'string', 'format' => 'date-time'], new Type(Type::BUILTIN_TYPE_OBJECT, true, \DateTimeImmutable::class)]; yield [['type' => 'string', 'format' => 'duration'], new Type(Type::BUILTIN_TYPE_OBJECT, false, \DateInterval::class)]; yield [['type' => 'string', 'format' => 'binary'], new Type(Type::BUILTIN_TYPE_OBJECT, false, \SplFileInfo::class)]; - yield [['type' => 'string', 'format' => 'iri-reference'], new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::class)]; - yield [['type' => 'string', 'format' => 'iri-reference'], new Type(Type::BUILTIN_TYPE_OBJECT, true, Dummy::class)]; + yield [['type' => 'string', 'format' => 'iri-template'], new Type(Type::BUILTIN_TYPE_OBJECT, false, Dummy::class)]; + yield [['type' => 'string', 'format' => 'iri-template'], new Type(Type::BUILTIN_TYPE_OBJECT, true, Dummy::class)]; yield ['enum' => ['type' => 'string', 'enum' => ['male', 'female']], new Type(Type::BUILTIN_TYPE_OBJECT, false, GenderTypeEnum::class)]; yield ['nullable enum' => ['type' => 'string', 'enum' => ['male', 'female', null]], new Type(Type::BUILTIN_TYPE_OBJECT, true, GenderTypeEnum::class)]; - yield ['enum resource' => ['type' => 'string', 'format' => 'iri-reference'], new Type(Type::BUILTIN_TYPE_OBJECT, false, GamePlayMode::class)]; - yield ['nullable enum resource' => ['type' => 'string', 'format' => 'iri-reference'], new Type(Type::BUILTIN_TYPE_OBJECT, true, GamePlayMode::class)]; + yield ['enum resource' => ['type' => 'string', 'format' => 'iri-template'], new Type(Type::BUILTIN_TYPE_OBJECT, false, GamePlayMode::class)]; + yield ['nullable enum resource' => ['type' => 'string', 'format' => 'iri-template'], new Type(Type::BUILTIN_TYPE_OBJECT, true, GamePlayMode::class)]; yield [['type' => 'array', 'items' => ['type' => 'string']], new Type(Type::BUILTIN_TYPE_STRING, false, null, true)]; yield 'array can be itself nullable, but ignored in OpenAPI V2' => [ ['type' => 'array', 'items' => ['type' => 'string']], diff --git a/src/JsonSchema/TypeFactory.php b/src/JsonSchema/TypeFactory.php index 05e695a707b..f228bb9c312 100644 --- a/src/JsonSchema/TypeFactory.php +++ b/src/JsonSchema/TypeFactory.php @@ -139,7 +139,7 @@ private function getClassType(?string $className, bool $nullable, string $format if (true !== $readableLink && $this->isResourceClass($className)) { return [ 'type' => 'string', - 'format' => 'iri-reference', + 'format' => 'iri-template', ]; }