fix: admit empty-object allOf members instead of crashing#214
Open
nottmey wants to merge 1 commit into
Open
Conversation
cd373a1 to
44b4a77
Compare
`allOf: [$ref JsonObject, {type: object, properties: {...}}]` crashed with
`FormatException: allOf only supports objects` because `JsonObject` (an open
empty object: `type: object, properties: {}, additionalProperties: {}`)
resolves to `ResolvedEmptyObject`, not `ResolvedObject`, and the resolver
rejected any non-`ResolvedObject` allOf member.
An empty open object intersects trivially — every JSON object satisfies it —
so it is a valid allOf member that simply contributes no properties to the
merged object the renderer builds. The render pass already only merges
`RenderObject` members (`case ResolvedAllOf` in render_tree.dart), so a
`ResolvedEmptyObject` member is already a no-op there; this just makes the
resolver stop crashing on the way there.
Backstage's catalog spec uses exactly this shape for
`RecursivePartialEntityMeta`:
https://github.com/backstage/backstage/blob/master/plugins/catalog-backend/src/schema/openapi.yaml
After this fix, space_gen generates the full Backstage catalog client from
the remote spec without patches.
Co-authored-by: Cursor <cursoragent@cursor.com>
44b4a77 to
7e20da6
Compare
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.
Summary
allOf: [{$ref: JsonObject}, {type: object, properties: {...}}]crashes withFormatException: allOf only supports objectsbecauseJsonObject(an open empty object:type: object, properties: {}, additionalProperties: {}) resolves toResolvedEmptyObject, notResolvedObject, and the resolver rejected any non-ResolvedObjectallOf member.Fix
Allow
ResolvedEmptyObjectas an allOf member (alongsideResolvedObject) in the type-check atresolver.dart. An empty open object intersects trivially — every JSON object satisfies it — so it is a valid allOf member that simply contributes no properties to the merged object the renderer builds.The render pass already only merges
RenderObjectmembers (case ResolvedAllOfinrender_tree.dart), so aResolvedEmptyObjectmember is already a no-op there; this just makes the resolver stop crashing on the way there. The allOf is preserved (not collapsed), so the parent schema keeps its name — important for test emission and downstream naming.This mirrors the spirit of PR #138's
comment_referenceshandling: spec prose / spec shapes that trip Dart's tooling should be sanitized at the generator boundary rather than crashing.Spec that surfaced this
Backstage's catalog OpenAPI spec uses this exact shape for
RecursivePartialEntityMeta:https://github.com/backstage/backstage/blob/master/plugins/catalog-backend/src/schema/openapi.yaml
Schema excerpt:
With this fix, space_gen generates the full Backstage catalog client from the remote spec with no patches or vendoring required.
Test plan
allOf admits empty-object memberstotest/resolver_test.dart— verifies anallOfcontaining an open empty object plus a real object resolves to aResolvedAllOfwith both members preserved (no crash, no collapse).dart test test/resolver_test.dart— all resolver tests pass.dart test(full suite) — 548 tests pass, no regressions.bin/space_gen.dartagainst the remote Backstage catalog spec URL; full client generated successfully (name: devhub_client, alllib/emitted,RecursivePartialEntityMetamodel present, 138 generated round-trip tests pass).