Skip to content

Document that System.Text.Json ignores [EnumMember] - #4127

Merged
martincostello merged 2 commits into
domaindrivendev:masterfrom
RaphaelFakhri:docs/3328-enum-member-naming
Sep 29, 2026
Merged

martincostello merged 2 commits into
domaindrivendev:masterfrom
RaphaelFakhri:docs/3328-enum-member-naming

Conversation

@RaphaelFakhri

Copy link
Copy Markdown
Contributor

Fixes #3328.

Adds a Rename Enum Values in Schemas section to the SwaggerGen docs, covering the difference you agreed was worth writing down: System.Text.Json does not implement [EnumMember], Newtonsoft.Json does, and [JsonStringEnumMemberName] is the native option.

I verified all three claims against master rather than trusting the issue, by generating the schema for the same enum through each resolver:

Serializer Attribute enum in the generated schema
System.Text.Json [EnumMember(Value = "X-foo")] Value1, X
System.Text.Json [JsonStringEnumMemberName("X-foo")] Value1, X-foo
Newtonsoft.Json [EnumMember(Value = "X-foo")] Value1, X-foo

The C# examples are plain fenced blocks rather than MarkdownSnippets snippets. JsonStringEnumMemberNameAttribute is .NET 9 and later, and DocumentationSnippets multi-targets down to net8.0, so a compiled snippet would need an #if NET9_0_OR_GREATER around it that would then show up in the rendered page. Happy to switch it to a snippet with the guard, or to a net9.0-and-later snippet project, if you would rather have it compiled.

markdownlint-cli2 with the repo's .markdownlint.json reports 0 issues, and dotnet mdsnippets leaves the file unchanged.

@codecov

codecov Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.24%. Comparing base (d0b1e26) to head (3812750).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4127   +/-   ##
=======================================
  Coverage   95.24%   95.24%           
=======================================
  Files         111      111           
  Lines        4142     4142           
  Branches      848      848           
=======================================
  Hits         3945     3945           
  Misses        197      197           
Flag Coverage Δ
Linux 95.24% <ø> (ø)
Windows 95.24% <ø> (ø)
macOS 95.24% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread docs/configure-and-customize-swaggergen.md
The attribute is not implemented by System.Text.Json, so it renames nothing in
the generated schema, while Newtonsoft.Json does honor it. Point at
[JsonStringEnumMemberName], which System.Text.Json added in .NET 9 and which
does reach the document.
@RaphaelFakhri

Copy link
Copy Markdown
Contributor Author

Agreed. The section is now four lines: one sentence on why the serializer decides the names, and links to the upstream documentation for [JsonStringEnumMemberName] (System.Text.Json) and for [EnumMember] with StringEnumConverter (Newtonsoft.Json). The examples and sample JSON are removed.

@RaphaelFakhri
RaphaelFakhri force-pushed the docs/3328-enum-member-naming branch from 3126a4b to 3812750 Compare September 29, 2026 10:06
@martincostello
martincostello merged commit 00a35eb into domaindrivendev:master Sep 29, 2026
14 checks passed
This was referenced Oct 7, 2026
This was referenced Oct 11, 2026
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.

[docs]: Document that System.Text.Json based serializer doesn't respect [EnumMember]

2 participants