Repository navigation
Simplify code generation and unify JSON media type detection - #125
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The refactors preserve existing behavior while the intentional media-type change is consistent, documented, and regression-tested.
Review effort: Balanced
Findings: None
What changed in this PR
Simplifies generation internals while consistently recognizing only valid JSON application media types.
Changes:
- Centralizes JSON media-type detection across requests, responses, and generated error handling.
- Deduplicates parameter emission and schema type mapping logic.
- Adds regression tests and documents JSON detection behavior.
| File | Description |
|---|---|
README.md |
Documents recognized JSON media types. |
tests/OpenApiWeaver.Tests/ClientGeneratorTests.Operations.cs |
Adds JSON detection regression coverage. |
src/OpenApiWeaver/OpenApi/SchemaTypeResolver.cs |
Consolidates simple schema mappings. |
src/OpenApiWeaver/Generator/Transforming/ClientGenerator.Transformer.Responses.cs |
Applies strict JSON response detection. |
src/OpenApiWeaver/Generator/Transforming/ClientGenerator.Transformer.RequestBodies.cs |
Removes duplicated media-type helpers. |
src/OpenApiWeaver/Generator/Transforming/ClientGenerator.Transformer.Content.cs |
Centralizes media-type matching and priorities. |
src/OpenApiWeaver/Generator/SupportTypes/ClientGenerator.SupportTypesEmitter.Response.cs |
Generates strict runtime JSON detection. |
src/OpenApiWeaver/CodeGeneration/OperationEmitter.Parameters.cs |
Adds shared optional-parameter emission. |
src/OpenApiWeaver/CodeGeneration/OperationEmitter.cs |
Uses shared parameter emission paths. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Summary
Reduce duplicated generation logic by sharing optional parameter emission and simple schema type mappings, and replace predicate-array content priorities with direct conditions.
Unify JSON media type detection for requests, responses, and generated error handling. Only application/json and application/*+json are recognized, ignoring case and media type parameters. For example, text/plain; profile=json and application/jsonp now use text handling instead of JSON deserialization. Other generated behavior is preserved.
Related issue
None.
Type of change
Validation
Impact checklist
Notes for reviewers
No diagnostics were introduced or changed. JSON media type recognition is the intentional behavior change; the remaining changes simplify existing implementation paths.