Skip to content

Open api union types - #35

Open
tomasvanrijsse wants to merge 2 commits into
crescat-io:masterfrom
Timatic:open-api-union-types
Open

Open api union types#35
tomasvanrijsse wants to merge 2 commits into
crescat-io:masterfrom
Timatic:open-api-union-types

Conversation

@tomasvanrijsse

Copy link
Copy Markdown
Contributor

Support composite OpenAPI types by generating PHP 8.1+ union types for DTOs. This enables better type accuracy for flexible API schemas that use anyOf, oneOf, or allOf constructs.

Changes:

  • Added handleCompositeType() to process composite type schemas
  • Extract PHP types from References and inline Schemas
  • Support nested unions (e.g., anyOf with type: ["string", "null"])
  • Generate FQN for referenced DTOs in union types
  • Deduplicate types in generated unions

Example output: BusinessId|null, Timestamp|null, DiscountSubscription|null

tomasvanrijsse and others added 2 commits January 12, 2026 14:07
Support composite OpenAPI types by generating PHP 8.1+ union types
for DTOs. This enables better type accuracy for flexible API schemas
that use anyOf, oneOf, or allOf constructs.

Changes:
- Added handleCompositeType() to process composite type schemas
- Extract PHP types from References and inline Schemas
- Support nested unions (e.g., anyOf with type: ["string", "null"])
- Generate FQN for referenced DTOs in union types
- Deduplicate types in generated unions

Code quality improvements:
- Extracted buildDtoFqn() helper for DRY
- Extracted extractTypeFromSchema() for type resolution
- Added PHPDoc annotations
- Fixed typo in mapType() (int64\t → int64)
- Use strict comparison operators (===)
- Fixed missing format parameter in array union handling

Example output: BusinessId|null, Timestamp|null, DiscountSubscription|null

Related to Phase 1, PR crescat-io#3 of generator improvements.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Verify that anyOf composite types correctly generate PHP union types
for both primitive types (string|int|null) and DTO references.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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