Refactor error handling and update inline schema management#48
Merged
Conversation
…agement in DocumentTransformer
Contributor
There was a problem hiding this comment.
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
_inlineSchemaNameswith_inlineSchemasByIdentityfor 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.
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.
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
_inlineSchemaNameswith a more robust_inlineSchemasByIdentitydictionary for managing inline schemas, and updating the error thrown for empty HTTP responses to a more informative custom exception.Inline Schema Management Improvements:
_inlineSchemaNamesdictionary (which mapped schema identity to type names) with_inlineSchemasByIdentity, which maps schema identity directly to the correspondingInlineSchemaInfoobject. This change simplifies and strengthens the logic for registering and resolving inline schemas. [1] [2]_inlineSchemasByIdentityfor more direct and reliable lookups of inline schemas. [1] [2]Error Handling Enhancements:
InvalidOperationExceptionto a customOpenApiExceptionthat includes status code, reason phrase, and content type for better diagnostics. Updated both implementation and related test expectations. [1] [2]