Skip to content

fix: drop unmappable types in nested and union schemas#2028

Open
alleknalle wants to merge 1 commit into
zircote:masterfrom
alleknalle:bugfix-invalid-nested-types
Open

fix: drop unmappable types in nested and union schemas#2028
alleknalle wants to merge 1 commit into
zircote:masterfrom
alleknalle:bugfix-invalid-nested-types

Conversation

@alleknalle

Copy link
Copy Markdown

swagger-php only dropped types with no OpenAPI representation (callable, resource, ...) at the top level, so nested and union positions emitted an invalid type (e.g. items: {type: callable}). Drop them in setSchemaType, leaving the schema open instead.

Summary

swagger-php only applies its "drop unmappable type" sanity check to the top-level schema, so nested and union positions leak the raw PHP type name and emit invalid output:

Input Before After
list<callable> items: {type: callable} items: {}
array<string, callable> additionalProperties: {type: callable} additionalProperties: {}
int|callable type: [callable, integer] type: [integer]

The fix drops these in setSchemaType, where the type is known to be a BuiltinType (callable, resource, iterable, …) rather than a class — so object/class types still resolve to $refs as before. mapNativeType id: it must keep passing class-name strings through for later $ref resolution.

Out of scope: the rare non-all-builtin union where the builtin member itself is unmappable (e.g. Foo|callable); happy to extend if wanted.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Related Issues

None.

Test Plan

Resolver-level cases in tests/Type/TypeResolverTest (list<callable>, array<string, callable>) and an end-to-end case in tests/Processors/AugmentPropertiesTest(via theAugmentPropertiesprocessor).composer test+composer analyse` green.

  • Unit tests added/updated
  • Integration tests added/updated

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code where necessary
  • I have updated the documentation accordingly
  • My changes generate no new warnings
  • New and existing tests pass locally
  • Any dependent changes have been merged and published

swagger-php only dropped types with no OpenAPI representation (callable, resource, ...) at the top level, so nested and union positions emitted an invalid type (e.g. items: {type: callable}). Drop them in setSchemaType, leaving the schema open instead.
@alleknalle alleknalle force-pushed the bugfix-invalid-nested-types branch from f3446e7 to 291f3cb Compare June 23, 2026 22:00
} else {
if ($type instanceof BuiltinType) {
if (!$type->isIdentifiedBy(TypeIdentifier::MIXED)) {
// Only set a type that has an OpenAPI representation; mixed, callable, resource, iterable etc. stay open instead of emitting an invalid type.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

could this comment be moved (and adjusted) to the method docblock in stead, please?
Checks that the given type ...

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.

2 participants