Skip to content

Generate descriptions for undocumented enum cases - #1323

Merged
romalytvynenko merged 2 commits into
mainfrom
feat/add-enum_cases_auto_description_strategy
Nov 6, 2026
Merged

romalytvynenko merged 2 commits into
mainfrom
feat/add-enum_cases_auto_description_strategy

Conversation

@romalytvynenko

@romalytvynenko romalytvynenko commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Added enum_cases_auto_description_strategy config option which allows to automatically document enum cases using their names.

For example:

enum CompanySize: string
{
    case SINGLE = '1';
    case SMALL = '2-10';
    case MEDIUM = '11-50';
    case LARGE = '51+';
}

As is, this enum will be documented as this JSON schema:

{
  "type": "string",
  "enum": ["1", "2-10", "11-50", "51+"], 
  "title": "CompanySize"
}

While this is a valid JSON schema, it lacks enum names. So you can add them via PHPDoc:

enum CompanySize: string
{
    /** Single */
    case SINGLE = '1';
    /** Small */
    case SMALL = '2-10';
    /** Medium */
    case MEDIUM = '11-50';
    /** Large */
    case LARGE = '51+';
}

Given enum_cases_description_strategy option is set to 'description':

{
  "type": "string",
  "enum": ["1", "2-10", "11-50", "51+"],
  "x-enumDescriptions": {
    "1": "Single",
    "2-10": "Small",
    "11-50": "Medium",
    "51+": "Large"
  },
  "title": "CompanySize"
}

But providing description that is literally the same as the enum case name is a bit... repetitive.

The new config option, enum_cases_auto_description_strategy, allows to get the description automatically from enum names without adding repetitive PHPDoc.

Available options:

  • title: enum named LARGE_COMPANY gets Large Company description in OpenAPI
  • sentence: enum named LARGE_COMPANY gets Large company description in OpenAPI
  • as_is: enum named LARGE_COMPANY remains LARGE_COMPANY description in OpenAPI

In case you provide PHPDoc for the case, just content of PHPDoc will be used.

@romalytvynenko
romalytvynenko merged commit 3e50b35 into main Nov 6, 2026
1 of 6 checks passed
@romalytvynenko
romalytvynenko deleted the feat/add-enum_cases_auto_description_strategy branch November 6, 2026 15:34
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