Repository navigation
feat(openapi): drop schema defaults their own schema rejects - #13
Merged
Merged
Conversation
API Platform derives `default` from the PHP initializer, so `private string $slug = '';` next to a slug Assert\Regex yields `default: ""` that the property's own `pattern` rejects. Form clients start from that default and show a validation error before anyone typed. InvalidDefaultSchemaDecorator removes such defaults (pattern, minLength, maxLength, enum), walking properties, nested objects and allOf/anyOf/oneOf. On by default, switch off with schema_default_cleanup.enabled: false. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve the conflicts in CHANGELOG.md and ApiPlatformUtilsExtension.php by keeping both sides: relation_labels from master and schema_default_cleanup from this branch. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…rs [*] Definitions and properties are ArrayObjects and the stubbed factory writes into the schema it is handed, like the real one. The uncompilable-pattern test uses [^], which ECMA accepts and PCRE rejects. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
No behaviour change: properties children are still checked and descended into, allOf/anyOf/oneOf branches are still only descended into. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The cleanup descends into items (single schema and tuple form), prefixItems and additionalProperties, and checks the default of every visited sub-schema, combinator branches and the definition root included. A default next to a $ref is kept, because the reference is not resolved. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A pattern that already contained \/ was escaped twice, no longer compiled, and silently kept its invalid default. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
isset() skipped every null default. Presence is now tested with array_key_exists/offsetExists; a null default is judged by enum only. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PCRE lets $ match before a trailing newline, ECMA-262 does not. The D modifier makes the check follow the ECMA reading. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Every buildSchema() call walked all definitions collected so far, which is quadratic over one OpenAPI build. Cleaned definition objects are now remembered in a WeakMap per definitions object; replaced definitions and plain-array definitions are still cleaned. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…up [*] A higher decoration priority sits further inside: the cleanup (5) wraps the relation field decorator (10) and is wrapped by the Hydra, HAL and JSON:API schema factories (0). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ngelog [*] README: option, default, checked keywords, descent and known limits. CHANGELOG: the entry moves to Changed and names what consumers must do. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
InvalidDefaultSchemaDecoratordecoratesapi_platform.json_schema.schema_factoryand removes adefaultfrom the emitted JSON/OpenAPI schemas when the schema it sits in rejects it (pattern,minLength,maxLength,enum). API Platform derivesdefaultfrom the PHP property initializer, soprivate string $slug = '';next to a slug#[Assert\Regex]yieldsdefault: ""that its ownpatternrejects, and form clients show a validation error before anyone typed.Switched by
schema_default_cleanup.enabled, on by default. Released as0.7.0(minor), because the emitted schema changes for every consumer.Review follow-ups in this PR
The branch was brought up to date with
masterby a merge commit (no rebase); the original commit is unchanged. On top of it:items(single schema and tuple form),prefixItemsandadditionalProperties, and checks the default of every visited sub-schema,allOf/anyOf/oneOfbranches and the definition root included.\/is no longer escaped twice (it did not compile and silently kept its default).default: nullis recognised and judged byenumonly: it is removed when anenumexists that does not containnull.$in a pattern matches only at the very end (ECMA reading), not before a trailing newline.buildSchema()call (was quadratic in the number of definitions). Cleaned definition objects are remembered in aWeakMapper definitions object; replaced definitions and plain-array definitions are still cleaned.defaultnext to a$refis kept, because the reference is not resolved.ArrayObjectdefinitions and properties, the stub writes into the schema it is handed); the "PHP cannot compile the pattern" test uses[^].config/services_schema_default_cleanup.yamldescribes the real decoration order.0.7.0section under### Changed.What consumers must do
Check forms that rely on a default that is now removed, among them
default: nullon nullable enum properties whoseenumdoes not containnull, or switch the cleanup off:Known limits
$refis not resolved; a default next to a$refis not checked.Tests
85 tests, 213 assertions on PHP 8.4. Every fix has a test that fails without it.
🤖 Generated with Claude Code