Skip to content

BREAKING: Arrayable schemas, new Schema/* namespace, support schemas return raw arrays (#2)#46

Merged
edevsh merged 3 commits intocorebranch:1.xfrom
edevsh:1.x
Oct 13, 2025
Merged

BREAKING: Arrayable schemas, new Schema/* namespace, support schemas return raw arrays (#2)#46
edevsh merged 3 commits intocorebranch:1.xfrom
edevsh:1.x

Conversation

@edevsh
Copy link
Member

@edevsh edevsh commented Oct 13, 2025

Summary

This pull request introduces full arrayable support across all schema-interface–based classes and ensures consistent test coverage for serialization behavior.


Tasks

  • Implement toArray() method on SchemaInteger
  • Make all SchemaInterface-based classes implement arrayable behavior
  • (IN PROGRESS) Add and improve unit tests for all schema-interface–based classes to cover:
    • Field access and type validation
    • Array conversion (toArray) and consistency checks

Breaking Changes

1. SchemaInterface contract update

  • Added SchemaInterface::toArray(): array.
    → Any external implementations must add this method.

2. Namespace & layout refactor

  • All schemas moved from Blugen\Service\Lexicon\V1\TypeSpecificSchema\*Blugen\Service\Lexicon\V1\Schema\*.

  • New structure:

    • Concrete → primitive field schemas (e.g., StringSchema, BooleanSchema)
    • Container → structural types (ArraySchema, ObjectSchema)
    • Meta → compositional/indirect types (RefSchema, UnionSchema, UnknownSchema, TokenSchema)
    • Support → auxiliary schemas (InputSchema, OutputSchema, MessageSchema, ErrorsSchema)
    • Primary → root schemas (QuerySchema, ProcedureSchema, RecordSchema, SubscriptionSchema, HTTPAbstract)
      → Any code importing old TypeSpecificSchema\... namespaces will break.

3. Support schemas – type() and description() behavior

  • Now use SupportSchemaTrait, which throws BadMethodCallException in type() (and description() unless overridden).
  • Previously, these returned a concrete type string.
    → Code calling type() on support schemas will fail.

4. InputSchema / OutputSchema return type changes

  • schema() now returns raw ?array from IOAbstract (was schema object).
  • Default empty schema behavior removed.
    → Callers expecting schema objects (e.g., ObjectSchema, UnionSchema, RefSchema) will break.

5. ErrorsSchema collection semantics

  • Now yields ErrorSchema objects instead of arrays.

  • Implements read-only ArrayAccess:

    • offsetSet() / offsetUnset() throw BadMethodCallException.
    • offsetGet() throws OutOfBoundsException for invalid indexes.
      → Previously it accepted arbitrary array access.

6. ObjectSchema::properties() contract update

  • Return type changed: now returns an array of schema instances (via SchemaFactory) instead of Property objects.
  • Throws MissingRequiredFieldException if properties is invalid or missing.
  • Property metadata (e.g. name, nullable, required) must now be derived via schema arrays.
    → Code depending on Property objects will break.

7. New core exception introduced

  • Blugen\Service\Lexicon\V1\Exceptions\MissingRequiredFieldException
    → Thrown in ObjectSchema::properties() and potentially other locations.

8. Generator & factory updates

  • SchemaFactory refactored to point to new Schema\{Concrete,Container,Meta} classes.
  • Generators now build schemas via SchemaFactory.
    → Any custom generator or class references to old TypeSpecificSchema paths must be updated.

9. Legacy class removals

  • Deleted:

    • V1/TypeSpecificSchema/Support/{ErrorsSchema,InputSchema,MessageSchema,OutputSchema}
    • V1/TypeSpecificSchema/Field/ObjectSchema
  • Replacements exist under new V1/Schema/{Support,Container,...} but with changed behaviors above.

10. Explicit breaking commit reference

  • 16a45c4BREAKING CHANGE: Refactor(TypeSpecificSchema/Support) to use traits and return raw schema arrays.

@edevsh edevsh self-assigned this Oct 13, 2025
@edevsh edevsh added enhancement New feature or request breaking change Indicates a change that breaks backward compatibility and requires updates in dependent code labels Oct 13, 2025
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting

Comment on lines +17 to +22
public function description(): string
{
throw new BadMethodCallException(sprintf(
'%s::description() is not supported for support schemas.',
static::class
));

Choose a reason for hiding this comment

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

P0 Badge Support schemas declare incompatible description() return type

The SupportSchemaTrait declares description(): string and just throws, but SchemaInterface now requires description(): ?string. Classes such as Schema/Support/MessageSchema and Schema/Support/ErrorsSchema use this trait without overriding the method, so their generated method signature is string, which is incompatible with the interface. Attempting to load any of those classes will trigger a fatal "Declaration must be compatible" error. The trait’s signature should be updated to ?string (or the classes should override it) so the codebase remains instantiable.

Useful? React with 👍 / 👎.

Comment on lines +95 to +100
foreach($properties as $propertyName => $property) {
$property = new Property(
$propertyName,
new Schema($property->toArray()),
in_array($property, $nullable, true),
in_array($property, $required, true)

Choose a reason for hiding this comment

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

P1 Badge Procedure input generator ignores nullable/required flags

When generating an input class for procedure schemas, each property is wrapped in Property with in_array($property, $nullable, true) and in_array($property, $required, true). The $nullable/$required arrays from ObjectSchema contain property names, not schema instances, so these strict comparisons always return false. As a result, every generated field is treated as non-nullable and optional even when the schema marks it required, which will produce incorrect client code. The checks should compare $propertyName against those arrays instead.

Useful? React with 👍 / 👎.

@codecov
Copy link

codecov bot commented Oct 13, 2025

Codecov Report

❌ Patch coverage is 75.13812% with 45 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...con/V1/DefGenerator/Primary/ProcedureGenerator.php 0.00% 16 Missing ⚠️
...ponentGenerator/Field/ObjectComponentGenerator.php 0.00% 12 Missing ⚠️
...exicon/V1/DefGenerator/Primary/RecordGenerator.php 0.00% 12 Missing ⚠️
src/Service/Lexicon/V1/Definition.php 0.00% 5 Missing ⚠️

❌ Your patch status has failed because the patch coverage (75.13%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.
❌ Your project status has failed because the head coverage (48.50%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Files with missing lines Coverage Δ Complexity Δ
...mponentGenerator/Field/ArrayComponentGenerator.php 0.00% <ø> (ø) 19.00 <0.00> (ø)
...omponentGenerator/Field/BlobComponentGenerator.php 0.00% <ø> (ø) 16.00 <0.00> (ø)
...onentGenerator/Field/BooleanComponentGenerator.php 0.00% <ø> (ø) 26.00 <0.00> (ø)
...mponentGenerator/Field/BytesComponentGenerator.php 0.00% <ø> (ø) 13.00 <0.00> (ø)
...onentGenerator/Field/CidLinkComponentGenerator.php 0.00% <ø> (ø) 12.00 <0.00> (ø)
...onentGenerator/Field/IntegerComponentGenerator.php 0.00% <ø> (ø) 26.00 <0.00> (ø)
...omponentGenerator/Field/NullComponentGenerator.php 0.00% <ø> (ø) 4.00 <0.00> (ø)
...ponentGenerator/Field/ParamsComponentGenerator.php 0.00% <ø> (ø) 8.00 <0.00> (ø)
...ComponentGenerator/Field/RefComponentGenerator.php 0.00% <ø> (ø) 18.00 <0.00> (ø)
...ponentGenerator/Field/StringComponentGenerator.php 0.00% <ø> (ø) 30.00 <0.00> (ø)
... and 48 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@edevsh edevsh merged commit bcfa4c6 into corebranch:1.x Oct 13, 2025
5 of 7 checks passed
@edevsh edevsh linked an issue Oct 13, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Indicates a change that breaks backward compatibility and requires updates in dependent code enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing CHANGELOG.md file in the repository

1 participant