Skip to content
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
4 changes: 2 additions & 2 deletions src/Parser/Schema/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
private const array PARAMETER_FIELDS = [
'type', 'format', 'items', 'default', 'enum', 'maximum', 'exclusiveMaximum',
'minimum', 'exclusiveMinimum', 'maxLength', 'minLength', 'pattern',
'maxItems', 'minItems', 'uniqueItems', 'multipleOf', 'description', 'x-nullable',
'maxItems', 'minItems', 'uniqueItems', 'multipleOf', 'description',
];

public function __construct(private Dialect $dialect) {}
Expand Down Expand Up @@ -161,7 +161,7 @@ private function common(array $data): array
return [
'title' => Value::optionalString($data, 'title'),
'description' => Value::optionalString($data, 'description') ?? '',
'nullable' => (bool) ($data['nullable'] ?? $data['x-nullable'] ?? false),
'nullable' => (bool) ($data['nullable'] ?? false),
'default' => $data['default'] ?? null,
'enum' => $enum,
'format' => Value::optionalString($data, 'format'),
Expand Down
2 changes: 1 addition & 1 deletion tests/CrossVersionFixtureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function test_equivalent_documents_produce_equivalent_canonical_behavior(
self::assertSame('int64', $pet->properties['id']->format);
self::assertInstanceOf(StringSchema::class, $pet->properties['name']);
self::assertSame(1, $pet->properties['name']->minLength);
self::assertTrue($pet->properties['nickname']->nullable);
self::assertFalse($pet->properties['nickname']->nullable);
self::assertInstanceOf(ReferenceSchema::class, $pet->properties['parent']);
self::assertSame($this->petReference($version), $pet->properties['parent']->reference);
self::assertSame(['available', 'adopted'], $pet->properties['status']->enum);
Expand Down
3 changes: 1 addition & 2 deletions tests/Fixtures/openapi-2.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@
"minLength": 1
},
"nickname": {
"type": "string",
"x-nullable": true
"type": "string"
},
"parent": {
"$ref": "#/definitions/Pet"
Expand Down
3 changes: 1 addition & 2 deletions tests/Fixtures/openapi-3.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@
"minLength": 1
},
"nickname": {
"type": "string",
"nullable": true
"type": "string"
},
"parent": {
"$ref": "#/components/schemas/Pet"
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/openapi-3.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"minLength": 1
},
"nickname": {
"type": ["string", "null"]
"type": "string"
},
"parent": {
"$ref": "#/components/schemas/Pet"
Expand Down
15 changes: 11 additions & 4 deletions tests/Schema/ReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,20 @@ public function test_an_explicit_enum_wins_over_const(): void
self::assertSame(['a', 'b'], $this->reader(Version::V3_1)->read(['type' => 'string', 'const' => 'c', 'enum' => ['a', 'b']], '#/x')->enum);
}

public function test_nullability_is_read_from_either_keyword(): void
public function test_nullability_is_read_from_the_nullable_keyword(): void
{
self::assertTrue($this->reader(Version::V3_0)->read(['type' => 'string', 'nullable' => true], '#/x')->nullable);
self::assertTrue($this->reader(Version::V2)->read(['type' => 'string', 'x-nullable' => true], '#/x')->nullable);
self::assertFalse($this->reader(Version::V3_0)->read(['type' => 'string'], '#/x')->nullable);
}

public function test_x_nullable_remains_an_uninterpreted_extension(): void
{
$schema = $this->reader(Version::V2)->read(['type' => 'string', 'x-nullable' => true], '#/x');

self::assertFalse($schema->nullable);
self::assertSame(['x-nullable' => true], $schema->extensions);
}

public function test_references_are_left_unexpanded_so_recursive_graphs_terminate(): void
{
$schema = $this->reader(Version::V3_1)->read(['$ref' => '#/components/schemas/Pet'], '#/x');
Expand Down Expand Up @@ -245,8 +252,8 @@ public function test_parameter_fields_are_lifted_into_a_schema_and_non_schema_ke

self::assertInstanceOf(IntegerSchema::class, $schema);
self::assertSame(1, $schema->minimum);
self::assertTrue($schema->nullable);
self::assertSame(['x-nullable' => true], $schema->extensions, "'x-nullable' is read as nullability and still kept as an extension");
self::assertFalse($schema->nullable);
self::assertSame([], $schema->extensions);
}

public function test_extensions_are_carried_onto_the_schema(): void
Expand Down
Loading