Skip to content

fix: handle empty description in class generator#2677

Merged
myakove merged 1 commit intomainfrom
fix-empty-description
Mar 17, 2026
Merged

fix: handle empty description in class generator#2677
myakove merged 1 commit intomainfrom
fix-empty-description

Conversation

@rnetser
Copy link
Collaborator

@rnetser rnetser commented Mar 17, 2026

Problem

When the OpenAPI schema has an empty description field (e.g., LlamaStackDistribution), running class-generator --kind <Kind> --overwrite produces an empty class docstring (""" """), replacing any previously correct fallback text.

The root cause: dict.get("description", MISSING_DESCRIPTION_STR) returns "" (empty string) when the key exists but is empty, instead of falling back to the default.

Fix

Changed _kind_schema.get("description", MISSING_DESCRIPTION_STR) to _kind_schema.get("description") or MISSING_DESCRIPTION_STR in explain_parser.py.

Using or ensures both missing keys and empty/falsy values fall back to "No field description from API".

Reproduction

oc explain LlamaStackDistribution
# DESCRIPTION: <empty>

class-generator --update-schema-for LlamaStackDistribution
class-generator --kind LlamaStackDistribution --overwrite
# Before fix: class docstring becomes """ """
# After fix: class docstring shows "No field description from API"

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of missing or empty descriptions to consistently display fallback descriptions instead of empty fields, providing better consistency across the application.

When API schema has description: "" (empty string), dict.get()
returns the empty string instead of falling back to
MISSING_DESCRIPTION_STR, causing empty class docstrings.

Use 'or' instead of get() default to handle both missing and
empty/falsy description values.
@rh-bot-1
Copy link

Report bugs in Issues

Welcome! 🎉

This pull request will be automatically processed with the following features:

🔄 Automatic Actions

  • Reviewer Assignment: Reviewers are automatically assigned based on the OWNERS file in the repository root
  • Size Labeling: PR size labels (XS, S, M, L, XL, XXL) are automatically applied based on changes
  • Issue Creation: Disabled for this repository
  • Branch Labeling: Branch-specific labels are applied to track the target branch
  • Auto-verification: Auto-verified users have their PRs automatically marked as verified
  • Labels: All label categories are enabled (default configuration)

📋 Available Commands

PR Status Management

  • /wip - Mark PR as work in progress (adds WIP: prefix to title)
  • /wip cancel - Remove work in progress status
  • /hold - Block PR merging (approvers only)
  • /hold cancel - Unblock PR merging
  • /verified - Mark PR as verified
  • /verified cancel - Remove verification status
  • /reprocess - Trigger complete PR workflow reprocessing (useful if webhook failed or configuration changed)
  • /regenerate-welcome - Regenerate this welcome message

Review & Approval

  • /lgtm - Approve changes (looks good to me)
  • /approve - Approve PR (approvers only)
  • /automerge - Enable automatic merging when all requirements are met (maintainers and approvers only)
  • /assign-reviewers - Assign reviewers based on OWNERS file
  • /assign-reviewer @username - Assign specific reviewer
  • /check-can-merge - Check if PR meets merge requirements

Testing & Validation

  • /retest tox - Run Python test suite with tox
  • /retest python-module-install - Test Python package installation
  • /retest conventional-title - Validate commit message format
  • /retest all - Run all available tests

Cherry-pick Operations

  • /cherry-pick <branch> - Schedule cherry-pick to target branch when PR is merged
    • Multiple branches: /cherry-pick branch1 branch2 branch3

Label Management

  • /<label-name> - Add a label to the PR
  • /<label-name> cancel - Remove a label from the PR

✅ Merge Requirements

This PR will be automatically approved when the following conditions are met:

  1. Approval: /approve from at least one approver
  2. Status Checks: All required status checks must pass
  3. No Blockers: No wip, hold, has-conflicts labels and PR must be mergeable (no conflicts)
  4. Verified: PR must be marked as verified

📊 Review Process

Approvers and Reviewers

Approvers:

  • myakove
  • rnetser

Reviewers:

  • myakove
  • rnetser
Available Labels
  • hold
  • verified
  • wip
  • lgtm
  • approve
  • automerge

💡 Tips

  • WIP Status: Use /wip when your PR is not ready for review
  • Verification: The verified label is automatically removed on each new commit
  • Cherry-picking: Cherry-pick labels are processed when the PR is merged
  • Permission Levels: Some commands require approver permissions
  • Auto-verified Users: Certain users have automatic verification and merge privileges

For more information, please refer to the project documentation or contact the maintainers.

@coderabbitai
Copy link

coderabbitai bot commented Mar 17, 2026

Caution

Review failed

Pull request was closed or merged during review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d78317cd-fe60-4c8b-a975-3405c491fb09

📥 Commits

Reviewing files that changed from the base of the PR and between 16ded46 and 1f8ad88.

📒 Files selected for processing (1)
  • class_generator/parsers/explain_parser.py

Walkthrough

The explain_parser description retrieval now applies a fallback default description when the description is missing or evaluates as falsy (e.g., empty string), instead of only when the key is absent from the schema.

Changes

Cohort / File(s) Summary
Parser Enhancement
class_generator/parsers/explain_parser.py
Modified description retrieval logic to use fallback default when description is missing or falsy, expanding the conditions for applying the default from key absence to include empty or falsy values.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: fixing how empty descriptions are handled in the class generator.
Description check ✅ Passed The description comprehensively covers the problem, solution, and reproduction steps, though it doesn't follow the exact template structure with all section headings.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-empty-description
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@rnetser
Copy link
Collaborator Author

rnetser commented Mar 17, 2026

/verified

@myakove
Copy link
Collaborator

myakove commented Mar 17, 2026

/lgtm
/approve

@myakove myakove enabled auto-merge (squash) March 17, 2026 14:58
@myakove myakove merged commit 4f1322f into main Mar 17, 2026
6 of 7 checks passed
@myakove myakove deleted the fix-empty-description branch March 17, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants