Skip to content

Conversation

@lekhmanrus
Copy link
Contributor

  • Enum Descriptions. The code now extracts the description from the System.ComponentModel.Description attribute for each enum value and includes it in the schema under x-enumDescriptions.
  • Backward Compatibility for Enum Names. Supports JSON property names by accepting x-enumNames as well as x-enum-names and x-enum-varnames.
  • Backward Compatibility for Enum Descriptions. Similarly, the schema now accepts both x-enumDescriptions and x-enum-descriptions.

Close #1156

@lekhmanrus lekhmanrus force-pushed the feat/support-description-for-each-x-enum-names-value_ branch 2 times, most recently from 86450b6 to ad2ade4 Compare April 1, 2025 00:02
@lahma
Copy link
Collaborator

lahma commented Jul 27, 2025

Can you rebase and add a test case that shows the change?

@lekhmanrus lekhmanrus force-pushed the feat/support-description-for-each-x-enum-names-value_ branch from ad2ade4 to 4fcde15 Compare July 28, 2025 23:10
- Add test case for enum descriptions with Description attributes
- Add backward compatibility tests for x-enum-names, x-enum-varnames, and x-enum-descriptions
- Fix JSON string assertions to properly check for quoted values
@lekhmanrus
Copy link
Contributor Author

Hi @lahma,
sure, done. 😊

Copy link
Collaborator

@lahma lahma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I switched to verify testing for output to get clearer picture of the output. Thank you!

@RicoSuter
Copy link
Owner

Is there a good reason why it's serialized to "x-enum-descriptions" and not "x-enumDescriptions" like in all other places (e.g. "x-enumNames")?

@lahma
Copy link
Collaborator

lahma commented Sep 18, 2025

I think I googled what is the preferred and most used way and it turned out to be this, might need verification. Maybe Yet Another Configuration Option for preferred name..

@lekhmanrus
Copy link
Contributor Author

OpenAPI 3.0 and 2.0 do not have a way to define custom names/descriptions for enum values, but some tools provide x- extensions like OpenAPI Generator, openapi-typescript-codegen, Scalar support x-enum-varnames and x-enum-descriptions
https://openapi-generator.tech/docs/templating/#enum
NSwag supports x-enumNames https://github.com/RicoSuter/NJsonSchema/wiki/Enums#enum-names-and-descriptions though.
But seems like x-enum-varnames and x-enum-descriptions are just more commonly used.

@lahma
Copy link
Collaborator

lahma commented Sep 28, 2025

Maybe a PR for configurable name would be the best, closed PR usually doesn't carry far.

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.

Is a description for each x-enumNames value supported?

3 participants