Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(JsonSchema): fix reDoc json sample values #5638

Merged
merged 4 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion features/openapi/docs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Feature: Documentation support
"""
{
"type": "string",
"format": "iri-reference"
"format": "iri-template"
}
"""
# Enable these tests when SF 4.4 / PHP 7.1 support is dropped
Expand Down
24 changes: 12 additions & 12 deletions src/JsonSchema/Tests/TypeFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@
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)];

Check warning on line 61 in src/JsonSchema/Tests/TypeFactoryTest.php

View check run for this annotation

Codecov / codecov/patch

src/JsonSchema/Tests/TypeFactoryTest.php#L60-L61

Added lines #L60 - L61 were not covered by tests
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)];

Check warning on line 65 in src/JsonSchema/Tests/TypeFactoryTest.php

View check run for this annotation

Codecov / codecov/patch

src/JsonSchema/Tests/TypeFactoryTest.php#L64-L65

Added lines #L64 - L65 were not covered by tests
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']],
Expand Down Expand Up @@ -185,12 +185,12 @@
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)];

Check warning on line 189 in src/JsonSchema/Tests/TypeFactoryTest.php

View check run for this annotation

Codecov / codecov/patch

src/JsonSchema/Tests/TypeFactoryTest.php#L188-L189

Added lines #L188 - L189 were not covered by tests
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)];

Check warning on line 193 in src/JsonSchema/Tests/TypeFactoryTest.php

View check run for this annotation

Codecov / codecov/patch

src/JsonSchema/Tests/TypeFactoryTest.php#L192-L193

Added lines #L192 - L193 were not covered by tests
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']],
Expand Down Expand Up @@ -306,12 +306,12 @@
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)];

Check warning on line 310 in src/JsonSchema/Tests/TypeFactoryTest.php

View check run for this annotation

Codecov / codecov/patch

src/JsonSchema/Tests/TypeFactoryTest.php#L309-L310

Added lines #L309 - L310 were not covered by tests
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)];

Check warning on line 314 in src/JsonSchema/Tests/TypeFactoryTest.php

View check run for this annotation

Codecov / codecov/patch

src/JsonSchema/Tests/TypeFactoryTest.php#L313-L314

Added lines #L313 - L314 were not covered by tests
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']],
Expand Down
2 changes: 1 addition & 1 deletion src/JsonSchema/TypeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Copy link
Member

@soyuka soyuka Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've a problem with that it's not in the specification: https://json-schema.org/understanding-json-schema/reference/string#resource-identifiers isn't redoc wrong?

we should fix this by introducing an example section instead imo

];
}

Expand Down
Loading