Refactor ClientGenerator to Enhance Type Handling and Naming Conventions#53
Merged
Conversation
shibayan
commented
Apr 18, 2026
Owner
- Removed the _generatedEnumTypeNames field to streamline enum type management.
- Introduced TypeShape enum to categorize schema types more effectively.
- Created TypeUsage class to encapsulate type information, including nullable handling.
- Updated ParameterInfo, SchemaPropertyDefinition, and RequestBodyInfo classes to utilize TypeUsage for type definitions.
- Enhanced naming conventions for generated classes and methods to avoid collisions by implementing unique name allocation strategies.
- Improved response handling to correctly manage nullable types and binary responses.
- Added tests to ensure unique naming for tags, methods, parameters, and schemas that normalize to the same identifier.
- Refined schema resolution logic to support nullable properties and enhance overall type safety.
- Removed the _generatedEnumTypeNames field to streamline enum type management. - Introduced TypeShape enum to categorize schema types more effectively. - Created TypeUsage class to encapsulate type information, including nullable handling. - Updated ParameterInfo, SchemaPropertyDefinition, and RequestBodyInfo classes to utilize TypeUsage for type definitions. - Enhanced naming conventions for generated classes and methods to avoid collisions by implementing unique name allocation strategies. - Improved response handling to correctly manage nullable types and binary responses. - Added tests to ensure unique naming for tags, methods, parameters, and schemas that normalize to the same identifier. - Refined schema resolution logic to support nullable properties and enhance overall type safety.
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the OpenAPI client generator to improve type/nullability handling and to enforce collision-resistant naming across schemas, tags, operations, and parameters.
Changes:
- Introduces
TypeUsage/TypeShapeto centrally model C# type naming, shape classification, and nullability rules. - Adds deterministic unique-name allocation for schemas, schema properties, tag clients, operation methods, parameters, and request body parameters.
- Improves response handling for nullable referenced schemas and referenced binary payload schemas; adds regression tests for these behaviors.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/OpenApiWeaver.Tests/ClientGeneratorTests.Schemas.cs | Adds tests for schema/type and schema-property name collisions, plus required nullable referenced properties. |
| tests/OpenApiWeaver.Tests/ClientGeneratorTests.Operations.cs | Adds tests for tag/method/parameter collision handling and referenced nullable/binary response behaviors. |
| src/OpenApiWeaver/ClientGenerator.Transformer.Schemas.cs | Implements schema/type-name allocation, unique property naming, TypeUsage-based type resolution, and nullable reference resolution. |
| src/OpenApiWeaver/ClientGenerator.Transformer.RequestBodies.cs | Uses TypeUsage and allocates unique request-body and form property names to avoid collisions. |
| src/OpenApiWeaver/ClientGenerator.Transformer.Operations.cs | Allocates unique tag client names, method names, and parameter names; refactors response typing around TypeUsage. |
| src/OpenApiWeaver/ClientGenerator.Transformer.Naming.cs | Adds identifier normalization helpers and a shared unique-name allocator. |
| src/OpenApiWeaver/ClientGenerator.Model.cs | Introduces TypeShape and TypeUsage; updates model types to carry structured type/nullability info and renamed “wire” fields. |
| src/OpenApiWeaver/ClientGenerator.Emitter.cs | Removes enum-type tracking state that’s no longer needed with TypeUsage. |
| src/OpenApiWeaver/ClientGenerator.Emitter.Schemas.cs | Emits schema properties and nested schemas using TypeUsage and updated model field names. |
| src/OpenApiWeaver/ClientGenerator.Emitter.RequestBodies.cs | Emits request body assignments and form fields using allocated request-body parameter names and updated wire fields. |
| src/OpenApiWeaver/ClientGenerator.Emitter.Operations.cs | Emits operation signatures/bodies using TypeUsage, unique parameter/body names, and updated response nullability handling. |
| src/OpenApiWeaver/ClientGenerator.Emitter.Naming.cs | Removes old “requires non-null response” logic superseded by TypeUsage.RequiresNonNullJsonResponse. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.