Skip to content

feat: add opt-out for JsonPropertyName attributes#47

Merged
nikcio merged 4 commits intoNikcio-labs:mainfrom
geirsagberg-udir:feat/json-property-name-opt-out
Apr 20, 2026
Merged

feat: add opt-out for JsonPropertyName attributes#47
nikcio merged 4 commits intoNikcio-labs:mainfrom
geirsagberg-udir:feat/json-property-name-opt-out

Conversation

@geirsagberg-udir
Copy link
Copy Markdown
Contributor

Summary

  • Adds GenerateJsonPropertyNameAttributes option (default true) to GeneratorOptions so [JsonPropertyName] emission can be suppressed.
  • Exposes the toggle through the CLI as --no-json-property-name-attributes.
  • Useful when the consuming serializer already applies the desired naming policy and the attributes would just be noise.

Test plan

  • CSharpCodeEmitterTests covers the opt-out path
  • CSharpSchemaGeneratorTests verifies generated output omits the attribute when disabled
  • GeneratorOptionsTests confirms the default remains true (no behavior change for existing users)

Replaces #45 — re-opened from a dedicated feature branch so my fork's main can track upstream cleanly.

@geirsagberg-udir
Copy link
Copy Markdown
Contributor Author

full disclosure: Coded by Claude, but I verified it works manually by compiling and running the tool on our own spec

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new generator option to suppress emitting System.Text.Json.Serialization.JsonPropertyName attributes, with corresponding CLI/docs updates, to support consumers that rely on serializer naming policies instead of per-property attributes.

Changes:

  • Added GeneratorOptions.GenerateJsonPropertyNameAttributes (default true) to control [JsonPropertyName] emission.
  • Wired the option through the CLI via --no-json-property-name-attributes and updated help text / docs.
  • Added unit + integration tests covering the opt-out behavior and confirming the default remains enabled.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/OpenApiCodeGenerator.Tests/GeneratorOptionsTests.cs Asserts the new option defaults to true.
tests/OpenApiCodeGenerator.Tests/CSharpSchemaGeneratorTests.cs Integration coverage ensuring generated code omits [JsonPropertyName] and serializes correctly with a naming policy when disabled.
tests/OpenApiCodeGenerator.Tests/CSharpCodeEmitterTests.cs Unit coverage ensuring emitter skips property attributes when disabled.
src/OpenApiCodeGenerator/GeneratorOptions.cs Introduces GenerateJsonPropertyNameAttributes option with docs and default.
src/OpenApiCodeGenerator/CSharpCodeEmitter.cs Gates [JsonPropertyName] emission behind the new option.
src/OpenApiCodeGenerator.Cli/Program.cs Adds --no-json-property-name-attributes flag and passes it into GeneratorOptions.
docs/src/content/docs/reference/cli.md Documents the new CLI flag and adds it to examples.
docs/src/content/docs/guides/configuration.md Documents the library option + CLI mapping, plus guidance and examples.
README.md Updates CLI options list to include the new flag.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@geirsagberg-udir geirsagberg-udir force-pushed the feat/json-property-name-opt-out branch from c440c1e to 506e8be Compare April 15, 2026 19:13
@geirsagberg-udir
Copy link
Copy Markdown
Contributor Author

fixed merge conflicts

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/OpenApiCodeGenerator.Cli/Program.cs Outdated
Comment thread src/OpenApiCodeGenerator.Cli/Program.cs
Comment thread src/OpenApiCodeGenerator/GeneratorOptions.cs Outdated
Comment thread docs/src/content/docs/guides/configuration.md Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/OpenApiCodeGenerator.Cli/Program.cs
Comment thread src/OpenApiCodeGenerator/GeneratorOptions.cs
@nikcio nikcio merged commit abcb807 into Nikcio-labs:main Apr 20, 2026
5 checks passed
@nikcio nikcio linked an issue Apr 20, 2026 that may be closed by this pull request
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.

Opt-out for [JsonPropertyName] attribute emission

3 participants