Skip to content

Refactor error handling and update inline schema management#48

Merged
shibayan merged 1 commit into
masterfrom
consistent-exception
Apr 16, 2026
Merged

Refactor error handling and update inline schema management#48
shibayan merged 1 commit into
masterfrom
consistent-exception

Conversation

@shibayan

Copy link
Copy Markdown
Owner

This pull request refactors the handling of inline schema registration and error handling in the OpenApiWeaver source generator. The main improvements include replacing the use of _inlineSchemaNames with a more robust _inlineSchemasByIdentity dictionary for managing inline schemas, and updating the error thrown for empty HTTP responses to a more informative custom exception.

Inline Schema Management Improvements:

  • Replaced the _inlineSchemaNames dictionary (which mapped schema identity to type names) with _inlineSchemasByIdentity, which maps schema identity directly to the corresponding InlineSchemaInfo object. This change simplifies and strengthens the logic for registering and resolving inline schemas. [1] [2]
  • Updated all usages in schema registration and type resolution to use _inlineSchemasByIdentity for more direct and reliable lookups of inline schemas. [1] [2]

Error Handling Enhancements:

  • Changed the exception thrown when an HTTP response body is empty from a generic InvalidOperationException to a custom OpenApiException that includes status code, reason phrase, and content type for better diagnostics. Updated both implementation and related test expectations. [1] [2]

@shibayan shibayan requested a review from Copilot April 16, 2026 15:58
@shibayan shibayan self-assigned this Apr 16, 2026
@shibayan shibayan added the enhancement New feature or request label Apr 16, 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 inline schema registration in the OpenApiWeaver source generator by replacing the identity→typename map with an identity→InlineSchemaInfo map, and updates generated client code to throw OpenApiException (instead of InvalidOperationException) when a JSON response body deserializes to null.

Changes:

  • Replace _inlineSchemaNames with _inlineSchemasByIdentity for direct inline-schema lookups.
  • Update inline schema registration/type resolution to use the new dictionary.
  • Change generated client non-null JSON response guard to throw OpenApiException, and update the related test assertion.

Reviewed changes

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

File Description
tests/OpenApiWeaver.Tests/OpenApiWeaverSourceGeneratorTests.Schemas.cs Updates expected generated source to match new exception type for empty JSON body.
src/OpenApiWeaver/OpenApiWeaverSourceGenerator.DocumentTransformer.cs Replaces inline-schema tracking field with identity→InlineSchemaInfo dictionary.
src/OpenApiWeaver/OpenApiWeaverSourceGenerator.DocumentTransformer.Schemas.cs Refactors inline schema registration and resolution to use the new dictionary.
src/OpenApiWeaver/OpenApiWeaverSourceGenerator.ClientEmitter.Operations.cs Updates generated operation code to throw OpenApiException when JSON body is null.

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

@shibayan shibayan merged commit b00504d into master Apr 16, 2026
8 checks passed
@shibayan shibayan deleted the consistent-exception branch April 16, 2026 16:08
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