Skip to content

feat: Support prefixing models#18

Merged
nikcio merged 4 commits intomainfrom
feature/support-prefixing-models
Mar 15, 2026
Merged

feat: Support prefixing models#18
nikcio merged 4 commits intomainfrom
feature/support-prefixing-models

Conversation

@nikcio
Copy link
Contributor

@nikcio nikcio commented Mar 15, 2026

No description provided.

Copy link

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

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 ModelPrefix option to GeneratorOptions and threaded it through NameHelper.ToTypeName, ApplyTypePrefix, TypeResolver, and CSharpCodeEmitter so all generated type declarations and references are consistently prefixed.
  • Added ValidateTypeNamePrefix to enforce that the prefix is a valid C# identifier start (letter or underscore, followed by letters/digits/underscores).
  • Exposed --model-prefix in 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");
@nikcio nikcio merged commit 0a91431 into main Mar 15, 2026
4 checks passed
@nikcio nikcio deleted the feature/support-prefixing-models branch March 15, 2026 20:21
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.

2 participants