Skip to content

Refactor ClientGenerator methods for improved readability and efficiency#56

Merged
shibayan merged 1 commit into
masterfrom
optimize
Apr 19, 2026
Merged

Refactor ClientGenerator methods for improved readability and efficiency#56
shibayan merged 1 commit into
masterfrom
optimize

Conversation

@shibayan

Copy link
Copy Markdown
Owner

This pull request refactors and simplifies several internal methods across the codebase, focusing on improving maintainability, reducing code duplication, and clarifying logic for request body handling, escaping, and identifier normalization. The changes also introduce helper methods and reorganize priority logic for media type selection.

Refactoring and Code Simplification:

  • Extracted common escaping logic into reusable EscapeByLookup method, and updated EscapeXmlDocumentationText, EscapeXmlDocumentationAttribute, and EscapeStringLiteral to use it, reducing code duplication and improving maintainability. [1] [2] [3] [4]
  • Replaced the EmitSecuritySchemeInitialization helper method with inline code for simplicity.

Request Body and Schema Handling Improvements:

  • Refactored request body value kind classification by introducing ClassifyValueKind and related helpers, improving clarity and error reporting for unsupported schema types and array items. [1] [2] [3]
  • Replaced hardcoded content type mappings with a static array, and improved logic for resolving request body kind from content type.

Media Type Selection and Prioritization:

  • Centralized content priority logic into a new GetContentPriority method with predicate arrays, improving flexibility and reducing repetition in media type selection.
  • Inlined and simplified the preferred content selection logic, removing the separate SelectPreferredContent method.

Identifier Normalization:

  • Consolidated Pascal and camel identifier normalization into a single helper, NormalizeIdentifier, reducing duplication and clarifying intent.

Minor Cleanups:

  • Removed an unused ResolveTypeName method.
  • Minor adjustment to documentation line splitting to avoid unnecessary empty lines.

@shibayan shibayan requested a review from Copilot April 19, 2026 15:42
@shibayan shibayan self-assigned this Apr 19, 2026
@shibayan shibayan added the enhancement New feature or request label Apr 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 refactors several internal ClientGenerator transformer/emitter helpers to reduce duplication and simplify logic in the OpenAPI → client-model → emitted-source pipeline.

Changes:

  • Consolidates repeated escaping/identifier-normalization logic into reusable helper methods.
  • Refactors request body value-kind classification and content-type mapping to improve clarity and error reporting.
  • Centralizes response media-type prioritization logic to reduce repetition.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/OpenApiWeaver/ClientGenerator.cs Removes redundant OpenAPI-document filtering inside TryCreateInput (filtering already happens in the incremental pipeline).
src/OpenApiWeaver/ClientGenerator.Transformer.Schemas.cs Removes unused helpers and slightly restructures nullability logic for readability.
src/OpenApiWeaver/ClientGenerator.Transformer.RequestBodies.cs Refactors request-body kind/value-kind classification and replaces hardcoded content-type mapping with a static table.
src/OpenApiWeaver/ClientGenerator.Transformer.Operations.cs Centralizes media-type priority logic used for selecting preferred response/error content.
src/OpenApiWeaver/ClientGenerator.Transformer.Naming.cs Consolidates Pascal/camel identifier normalization into a shared helper.
src/OpenApiWeaver/ClientGenerator.Emitter.cs Inlines security scheme initialization in the constructor emitter.
src/OpenApiWeaver/ClientGenerator.Emitter.Naming.cs Refactors string literal escaping to reuse the shared escape helper.
src/OpenApiWeaver/ClientGenerator.Emitter.DocComments.cs Refactors XML escaping via a lookup helper and slightly adjusts doc-line splitting.

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

Comment thread src/OpenApiWeaver/ClientGenerator.Transformer.Operations.cs
@shibayan shibayan merged commit a4bd342 into master Apr 19, 2026
8 checks passed
@shibayan shibayan deleted the optimize branch April 19, 2026 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants