Skip to content

Fix Rule::enum on array items replacing array type in OpenAPI spec#1123

Open
dbrekelmans wants to merge 1 commit into
dedoc:mainfrom
dbrekelmans:fix/enum-rule-array-items
Open

Fix Rule::enum on array items replacing array type in OpenAPI spec#1123
dbrekelmans wants to merge 1 commit into
dedoc:mainfrom
dbrekelmans:fix/enum-rule-array-items

Conversation

@dbrekelmans
Copy link
Copy Markdown
Contributor

@dbrekelmans dbrekelmans commented Mar 27, 2026

Follow-up to #1119 (comment), applies the same fix to Rule::enum.

When Rule::enum is used on array items (e.g. ['array', Rule::enum(StatusEnum::class)]), the EnumRule transformer ignores the previous type and returns the enum type directly, discarding the array entirely.

Before (incorrect):

  {
    "$ref": "#/components/schemas/StatusEnum"
  }

After (correct):

  {
    "type": "array",
    "items": {
      "$ref": "#/components/schemas/StatusEnum"
    }
  }

Note on test skips

The only() and except() array tests use ->skip(! method_exists(Enum::class, 'only')) / ->skip(! method_exists(Enum::class, 'except')), because these methods were only added in Laravel 11. This matches the existing skip conditions on the non-array only/except tests.

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