Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for prefixing all generated model type names with a user-specified string (e.g., --model-prefix Api produces ApiUser, ApiAddress, etc.). This is useful when generated types might conflict with existing types in the consuming codebase.
Changes:
- Added
ModelPrefixoption toGeneratorOptionsand threaded it throughNameHelper.ToTypeName,ApplyTypePrefix,TypeResolver, andCSharpCodeEmitterso all generated type declarations and references are consistently prefixed. - Added
ValidateTypeNamePrefixto enforce that the prefix is a valid C# identifier start (letter or underscore, followed by letters/digits/underscores). - Exposed
--model-prefixin the CLI, updated documentation (README, CLI reference, usage guide), and added unit/integration tests.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/OpenApiCodeGenerator/GeneratorOptions.cs |
New ModelPrefix property |
src/OpenApiCodeGenerator/NameHelper.cs |
ToTypeName accepts prefix; new ValidateTypeNamePrefix and ApplyTypePrefix; extracted constants |
src/OpenApiCodeGenerator/TypeResolver.cs |
Passes _options.ModelPrefix to ToTypeName calls |
src/OpenApiCodeGenerator/CSharpCodeEmitter.cs |
Applies prefix in type declarations, references, collision resolution, and inline enums |
src/OpenApiCodeGenerator.Cli/Program.cs |
--model-prefix CLI argument and help text |
tests/.../NameHelperTests.cs |
Tests for prefix application and validation |
tests/.../CSharpCodeEmitterTests.cs |
Test for prefixed type declarations and references |
tests/.../CSharpSchemaGeneratorTests.cs |
End-to-end test with fixture |
tests/.../ApiDirectoryTests.cs |
Updated ToTypeName call signature |
docs/.../cli.md |
CLI reference documentation for --model-prefix |
docs/.../cli-usage.md |
Usage guide section for model prefixing |
README.md |
README updated with new option |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+86
to
94
| public static string ApplyTypePrefix(string typeName, string? prefix) | ||
| { | ||
| if (string.IsNullOrEmpty(prefix)) | ||
| { | ||
| return typeName; | ||
| } | ||
|
|
||
| return ValidateTypeNamePrefix(prefix) + typeName; | ||
| } |
| namespaceName = GetNextArg(args, ref i, "--namespace"); | ||
| break; | ||
| case "--model-prefix": | ||
| modelPrefix = GetNextArg(args, ref i, "--model-prefix"); |
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.
No description provided.