Skip to content

Commit 68ceb58

Browse files
Address code review feedback
- Move schema keywords to class constant for better performance - Remove $ref from keywords list to avoid potential circular dependencies - Add documentation to constant Co-authored-by: DannyvdSluijs <618940+DannyvdSluijs@users.noreply.github.com>
1 parent dc6cb01 commit 68ceb58

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/JsonSchema/SchemaStorage.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ class SchemaStorage implements SchemaStorageInterface
1414
{
1515
public const INTERNAL_PROVIDED_SCHEMA_URI = 'internal://provided-schema/';
1616

17+
/**
18+
* JSON Schema keywords that indicate an object is a schema with validation rules,
19+
* not a pure container (like definitions, properties)
20+
*/
21+
private const SCHEMA_KEYWORDS = [
22+
'type', 'properties', 'items', 'additionalProperties', 'additionalItems',
23+
'required', 'allOf', 'anyOf', 'oneOf', 'not', 'format',
24+
'minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum',
25+
'minLength', 'maxLength', 'pattern', 'minItems', 'maxItems',
26+
'uniqueItems', 'minProperties', 'maxProperties', 'multipleOf',
27+
'$schema', 'id', '$id', 'title', 'description',
28+
'default', 'examples', 'patternProperties', 'dependencies'
29+
];
30+
1731
protected $uriRetriever;
1832
protected $uriResolver;
1933
protected $schemas = [];
@@ -243,18 +257,7 @@ private function findSchemaIdInObject(object $schema): ?string
243257
*/
244258
private function isSchemaObject(object $schema): bool
245259
{
246-
// Common JSON Schema keywords that indicate this is a schema, not a container
247-
$schemaKeywords = [
248-
'type', 'properties', 'items', 'additionalProperties', 'additionalItems',
249-
'required', 'allOf', 'anyOf', 'oneOf', 'not', 'format',
250-
'minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum',
251-
'minLength', 'maxLength', 'pattern', 'minItems', 'maxItems',
252-
'uniqueItems', 'minProperties', 'maxProperties', 'multipleOf',
253-
'$ref', '$schema', 'id', '$id', 'title', 'description',
254-
'default', 'examples', 'patternProperties', 'dependencies'
255-
];
256-
257-
foreach ($schemaKeywords as $keyword) {
260+
foreach (self::SCHEMA_KEYWORDS as $keyword) {
258261
if (property_exists($schema, $keyword)) {
259262
return true;
260263
}

0 commit comments

Comments
 (0)