Add support for number enums and enhance request body content handling#58
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR enhances the OpenAPI client generator by adding first-class support for number enums (including typeless number enums) and by ensuring generated JSON request bodies set an explicit Content-Type media type.
Changes:
- Add
SchemaEnumKind.Numberdetection/inference and propagate number enum “value type” (decimal/float/double) through the schema model. - Emit number enums as strongly-typed
readonly record structtypes with customJsonConverterserialization/deserialization. - Include the selected request body content type in
JsonContent.Create(..., mediaType: ...)and update tests accordingly.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/OpenApiWeaver/ClientGenerator.Models.cs | Adds SchemaEnumKind.Number and stores request body ContentType in the model. |
| src/OpenApiWeaver/ClientGenerator.Transformer.Schemas.cs | Detects/infers number enums and normalizes enum member naming/value handling. |
| src/OpenApiWeaver/ClientGenerator.Emitter.Schemas.cs | Emits number enums as record structs with JSON converters and number literal formatting. |
| src/OpenApiWeaver/ClientGenerator.Transformer.RequestBodies.cs | Captures the selected request body content type for downstream emission. |
| src/OpenApiWeaver/ClientGenerator.Emitter.RequestBodies.cs | Emits JsonContent.Create with an explicit mediaType. |
| tests/OpenApiWeaver.Tests/ClientGeneratorTests.SpecCompliance.cs | Adds coverage for number enums and JSON-family content type handling. |
| tests/OpenApiWeaver.Tests/ClientGeneratorTests.Operations.cs | Updates expectations to include mediaType: in JSON request body emission. |
💡 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 adds support for OpenAPI number enums (i.e., enums with floating-point values) to the code generator, alongside improvements to request body content type handling. Now, number enums are generated as strongly-typed record structs with appropriate serialization, and JSON request bodies include the correct media type. The changes also include updates to tests to verify these enhancements.
Support for number enums in schema generation:
SchemaEnumKind.Numberkind and logic to detect and handle number enums in OpenAPI schemas, including proper inference and merging with integer enums. (src/OpenApiWeaver/ClientGenerator.Models.cs[1]src/OpenApiWeaver/ClientGenerator.Transformer.Schemas.cs[2] [3] [4] [5]EmitNumberEnumSchemato generate record struct types for number enums, with custom JSON converter classes for serialization/deserialization. (src/OpenApiWeaver/ClientGenerator.Emitter.Schemas.cs[1] [2] [3]src/OpenApiWeaver/ClientGenerator.Transformer.Schemas.cs[1] [2]Request body content type improvements:
mediaTypeparameter in calls toJsonContent.Create, ensuring the generated code sets the appropriate content type header. (src/OpenApiWeaver/ClientGenerator.Emitter.RequestBodies.cs[1]src/OpenApiWeaver/ClientGenerator.Models.cs[2]src/OpenApiWeaver/ClientGenerator.Transformer.RequestBodies.cs[3]Test coverage:
tests/OpenApiWeaver.Tests/ClientGeneratorTests.SpecCompliance.cs[1] [2]tests/OpenApiWeaver.Tests/ClientGeneratorTests.Operations.cs[3] [4]These changes improve the generator's standards compliance and type safety, especially for OpenAPI schemas using number enums.