fix: enable enum description for API parameters#1075
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for preserving individual enum variant descriptions when generating OpenAPI specifications. The implementation ensures that when enums have JSDoc comments on individual properties, these descriptions are maintained in the generated oneOf schemas rather than being consolidated.
- Preserves per-variant comments in keyof-based enums through the IR
- Prevents consolidation of enum values that have individual descriptions
- Extracts enum descriptions from array items to parameter level when appropriate
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/openapi-generator/test/openapi/comments.test.ts | Adds two test cases verifying enum description preservation: one with individual variant descriptions (oneOf) and one with a single enum description |
| packages/openapi-generator/src/knownImports.ts | Updates keyof handler to preserve comments from object properties when creating enum schemas |
| packages/openapi-generator/src/optimize.ts | Modifies simplifyUnion to skip consolidation of enum literals that have associated comments |
| packages/openapi-generator/src/openapi.ts | Adds logic to extract descriptions from array items and move them to the parameter level for better API documentation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Implement support for individual enum variant descriptions using the x-enumDescriptions OpenAPI extension. This provides cleaner OpenAPI specs compared to the oneOf approach and is better supported by documentation tools like README.com. Changes: - Add enumDescriptions property to Primitive schema type - Update keyof handler to detect individual enum descriptions - Generate x-enumDescriptions extension in OpenAPI output - Preserve enum descriptions during optimization - Add comprehensive tests for both scenarios: * Enums with descriptions use x-enumDescriptions extension * Enums without descriptions use standard enum format All tests passing (188/188)
211379e to
836e43c
Compare
|
🎉 This PR is included in version @api-ts/openapi-generator@5.11.0 🎉 The release is available on npm package (@latest dist-tag) Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ticket: DX-1373