Skip to content

feat: expose open string enum branches - #5

Merged
ChiragAgg5k merged 1 commit into
mainfrom
feat/open-string-enum-query
Aug 20, 2026
Merged

feat: expose open string enum branches#5
ChiragAgg5k merged 1 commit into
mainfrom
feat/open-string-enum-query

Conversation

@ChiragAgg5k

Copy link
Copy Markdown
Member

What

Expose the enum-bearing branch when an anyOf combines exactly one string enum with one or more enum-free string branches.

This shape documents the values callers commonly use without closing the accepted string set:

{
  "anyOf": [
    {
      "type": "string",
      "enum": ["network.requests", "network.inbound"]
    },
    { "type": "string" }
  ]
}

Consumers can now use the canonical model directly:

$enum = $schema->openStringEnumBranch();

instead of duplicating composition and branch inspection.

Behavior

The query is deliberately narrow and returns null unless:

  • the composition is anyOf;
  • every member is a StringSchema;
  • exactly one member carries enum values; and
  • at least one other string member has no enum values.

Branch order does not matter. oneOf, allOf, mixed-type unions, closed enums, and unions containing multiple enums remain unchanged.

Context

This semantic query is needed by appwrite/sdk-generator#1816. Keeping it in the canonical OpenAPI model prevents individual generators from maintaining their own schema-shape parsers and lets them focus on language-specific rendering.

Test plan

  • branch order is ignored;
  • oneOf and allOf are rejected;
  • missing enum or open branches are rejected;
  • multiple enum branches are rejected;
  • integer enum and mixed string/integer unions are rejected;
  • full composer check passes: 48 tests, 382 assertions.

An anyOf can combine a string enum with an enum-free string branch to document common values without closing the accepted set. Consumers currently have to repeat that structural interpretation themselves.\n\nExpose the enum-bearing branch from CompositeSchema when the union has exactly that shape. Keep oneOf, mixed-type unions, and unions with multiple enums unchanged.
@greptile-apps

greptile-apps Bot commented Aug 20, 2026

Copy link
Copy Markdown

Greptile Summary

The PR adds a narrowly scoped semantic query for retrieving the enum-bearing branch from an open string anyOf.

  • Adds CompositeSchema::openStringEnumBranch() with composition, type, and branch-count checks.
  • Documents the public API and its exclusions.
  • Adds tests for branch ordering, unsupported compositions, missing branches, multiple enums, and mixed schema types.

Confidence Score: 5/5

The PR appears safe to merge with no actionable defects identified.

The helper enforces the documented anyOf, direct string-member, unique enum, and open-branch constraints, and the tests exercise the important accepted and rejected shapes.

Important Files Changed

Filename Overview
src/Model/CompositeSchema.php Adds the open-string-enum branch query with behavior consistent with the stated direct-StringSchema contract.
tests/Schema/ReaderTest.php Covers the principal successful shape and the documented rejection cases.
README.md Documents usage and the major boundaries of the new semantic query.

Reviews (1): Last reviewed commit: "feat: expose open string enum branches" | Re-trigger Greptile

@ChiragAgg5k
ChiragAgg5k merged commit 84115cc into main Aug 20, 2026
5 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the feat/open-string-enum-query branch August 20, 2026 13:35
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