Skip to content

Enum generation descriptions - allow for nulls/empty strings #2393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

simon-curtis
Copy link

@simon-curtis simon-curtis commented Aug 8, 2025

Changes

Expands the condition for skipping enum descriptions to also ignore null and empty strings.

Details

Since NSwag.AspNetCore v14.5, it seems that a descriptions array is always generated for enums, with null values for any undefined entries. This appears to be intended to maintain positional alignment with enum values, and there’s no built-in way to override it due to being a private field. This change ensures such null or empty entries are not appended.

I can't see anything in the spec that would suggest that null is an invalid value for a description but at the moment you get a null reference exception:

file:///D:/git/cma/main/Technical/SourceCode/TestHarness%202.0/TestHarness.UI/node_modules/openapi-typescript/dist/lib/ts.mjs:271
    " ".concat(metadata.description.trim()),
                                    ^

TypeError: Cannot read properties of null (reading 'trim')
    at tsEnumMember (file:///D:/git/cma/main/Technical/SourceCode/TestHarness%202.0/TestHarness.UI/node_modules/openapi-typescript/dist/lib/ts.mjs:271:37)

How to Review

Give it an openapi spec like this and check that the process runs to completion with no errors and that no descriptions are generated.

{
  "schemas": {
    "ProjectType": {
      "type": "integer",
      "description": "",
      "x-enumNames": [
        "Normal",
        "Snapshot"
      ],
      "x-enum-descriptions": [
        null,
        null,
      ],
      "enum": [
        0,
        1
      ]
    }
  }
}

Checklist

  • Unit tests updated
  • docs/ updated (if necessary)
  • pnpm run update:examples run (only applicable for openapi-typescript)

@simon-curtis simon-curtis requested a review from a team as a code owner August 8, 2025 17:02
@simon-curtis simon-curtis requested a review from drwpow August 8, 2025 17:02
Copy link

netlify bot commented Aug 8, 2025

👷 Deploy request for openapi-ts pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 62295ff

Copy link

changeset-bot bot commented Aug 8, 2025

⚠️ No Changeset found

Latest commit: 4314339

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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