Skip to content

Flatten the schema namespace - #3

Merged
ChiragAgg5k merged 1 commit into
mainfrom
refactor/flatten-schema-namespace
Aug 14, 2026
Merged

Flatten the schema namespace#3
ChiragAgg5k merged 1 commit into
mainfrom
refactor/flatten-schema-namespace

Conversation

@ChiragAgg5k

Copy link
Copy Markdown
Member

Every schema class sat under Model\Schema, which stuttered on the base class and repeated itself on each kind:

use Utopia\OpenAPI\Model\Schema\Schema;
use Utopia\OpenAPI\Model\Schema\ArraySchema;
use Utopia\OpenAPI\Model\Schema\ObjectSchema;

The segment carries no information the class names do not already carry. This moves the classes up beside the models they are part of:

use Utopia\OpenAPI\Model\Schema;
use Utopia\OpenAPI\Model\ArraySchema;
use Utopia\OpenAPI\Model\ObjectSchema;

Why not drop the suffix instead

The tidier-looking option — Model\Schema\Array, Model\Schema\Object — is not available. Those names are reserved in PHP:

Object   Cannot use "Object" as a class name as it is reserved
String   Cannot use "String" as a class name as it is reserved
Never    Cannot use "Never" as a class name as it is reserved
Array    declares, but is unusable as a type hint (parsed as the array type)

Integer  usable        Boolean  usable

So Schema\Array and its neighbours cannot exist, and dropping the suffix only where the language permits would leave Schema\Integer sitting beside Schema\ArraySchema. Removing the namespace segment keeps every kind named consistently while taking the redundancy out of the path.

Model is a flat namespace of value objects, so schemas now sit next to Parameter, Response and MediaType rather than one level below them.

Scope

No behaviour change — the classes, their properties and their relationships are untouched. 13 file renames, 23 files changed, +47 / -53.

composer check is green: pint, Rector, and 44 tests / 363 assertions.

Downstream

This is a breaking change for consumers. The migration is mechanical:

Utopia\OpenAPI\Model\Schema\  ->  Utopia\OpenAPI\Model\

appwrite/sdk-generator is the only consumer I know of; it has 22 files importing these names and pins a commit in composer.lock, so it is unaffected until it updates. I will land the rename there alongside the version bump.

Every schema class sat under Model\Schema, which stuttered on the base
class and repeated itself on the kinds:

    Utopia\OpenAPI\Model\Schema\Schema
    Utopia\OpenAPI\Model\Schema\ArraySchema
    Utopia\OpenAPI\Model\Schema\ObjectSchema

The segment carried no information the class names did not already
carry, and a consumer importing a base type and two kinds read Schema
three times per line. The classes move up beside the models they are
part of, so the base is Model\Schema and a kind is Model\ArraySchema.

Dropping the suffix instead is not possible. Array, Object, String and
Never are reserved and cannot name a class in PHP, so Model\Schema\Array
and its neighbours cannot exist, and dropping the suffix only where the
language allows would leave Schema\Integer beside Schema\ArraySchema.
Removing the namespace segment keeps every kind named consistently while
taking the redundancy out of the path.

Model is a flat namespace of value objects, so schemas sit naturally
next to Parameter, Response and MediaType rather than one level below
them. No behaviour changes: the classes, their properties and their
relationships are untouched.
@greptile-apps

greptile-apps Bot commented Aug 14, 2026

Copy link
Copy Markdown

Greptile Summary

The PR flattens all schema model classes from Utopia\OpenAPI\Model\Schema into Utopia\OpenAPI\Model.

  • Renames schema source files and updates their namespace declarations.
  • Updates parser, specification, model, test, and README imports.
  • Preserves the existing class structures and relationships while intentionally changing their public FQCNs.

Confidence Score: 5/5

The PR appears safe to merge; the namespace migration is internally consistent and its intentional downstream breaking impact is documented.

The renamed classes, internal imports, tests, and documentation consistently use the flattened namespace, Composer’s PSR-4 mapping resolves the new file locations, and no stale old-namespace references or symbol collisions were found.

Important Files Changed

Filename Overview
src/Model/Schema.php Moves the common schema base class into the flat model namespace; its implementation is otherwise unchanged.
src/Parser/Schema/Reader.php Updates all schema model imports to the flattened namespace without changing parsing behavior.
src/Parser/OpenAPI2.php Updates ObjectSchema to its new FQCN while preserving parser behavior.
src/Specification.php Updates the schema base-class import used by the public specification model.
README.md Documents the flattened schema namespace and updates the reference-schema example.
tests/Schema/ReaderTest.php Updates test imports so existing schema-reader coverage exercises the renamed model classes.

Reviews (1): Last reviewed commit: "refactor: flatten the schema namespace" | Re-trigger Greptile

@ChiragAgg5k
ChiragAgg5k merged commit 5962baf into main Aug 14, 2026
5 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the refactor/flatten-schema-namespace branch August 14, 2026 07:11
ChiragAgg5k added a commit to appwrite/sdk-generator that referenced this pull request Aug 14, 2026
utopia-php/openapi#3 moved the schema classes up beside the models they
are part of, so the base is Model\Schema and a kind is Model\ArraySchema
rather than Model\Schema\Schema and Model\Schema\ArraySchema. The
segment repeated what the class names already said, and a file importing
a base type and two kinds read Schema three times per line.

The rename is mechanical across 22 files. It also collapses what used to
be two Utopia namespaces into one, so those import blocks sort as a
single run; six that had drifted out of alphabetical order are sorted,
one of them because this rename moved a name past its neighbour.

No behaviour change. Generating all 19 SDKs before and after gives
16716 byte-identical files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant