Skip to content

Commit

Permalink
feat: Add method to get property keys
Browse files Browse the repository at this point in the history
  • Loading branch information
tymondesigns committed Jan 18, 2025
1 parent 95d64fa commit 7d50d41
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Types/Concerns/HasProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ public function propertyNames(Schema $schema): static
return $this;
}

/**
* @return array<int, string>
*/
public function getPropertyKeys(): array
{
return array_keys($this->properties);
}

/**
* Add properties to schema array
*
Expand Down
10 changes: 10 additions & 0 deletions tests/Unit/Support/DocParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,13 @@
expect($variable->types)->toBe(['string', 'int']);
expect($variable->description)->toBe('The nickname of the user');
});

it('can parse a multiline description', function (): void {
$docblock = '/** This is a test docblock
* with multiple lines
* and a new line
*/';
$parser = new DocParser($docblock);

expect($parser->description())->toBe("This is a test docblock\nwith multiple lines\nand a new line");
});
1 change: 1 addition & 0 deletions tests/Unit/Targets/ObjectSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
expect($schemaArray)->toHaveKey('properties.age.minimum', 18);
expect($schemaArray)->toHaveKey('properties.age.maximum', 150);
expect($schemaArray)->toHaveKey('required', ['name', 'email']);
expect($schema->getPropertyKeys())->toBe(['name', 'email', 'age']);

// Validation tests
expect(fn() => $schema->validate([
Expand Down

0 comments on commit 7d50d41

Please sign in to comment.