Skip to content

Add support for number enums and enhance request body content handling#58

Merged
shibayan merged 1 commit into
masterfrom
number-enum
Apr 24, 2026
Merged

Add support for number enums and enhance request body content handling#58
shibayan merged 1 commit into
masterfrom
number-enum

Conversation

@shibayan

Copy link
Copy Markdown
Owner

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:

  • Added a new SchemaEnumKind.Number kind 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]
  • Implemented EmitNumberEnumSchema to generate record struct types for number enums, with custom JSON converter classes for serialization/deserialization. (src/OpenApiWeaver/ClientGenerator.Emitter.Schemas.cs [1] [2] [3]
  • Enhanced enum member name and value handling for number enums, including normalization and formatting helpers. (src/OpenApiWeaver/ClientGenerator.Transformer.Schemas.cs [1] [2]

Request body content type improvements:

  • Modified request body handling to include the correct mediaType parameter in calls to JsonContent.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:

  • Added and updated tests to verify number enum generation and correct request content type handling, including cases for decimal and double enums. (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.

@shibayan shibayan self-assigned this Apr 24, 2026
Copilot AI review requested due to automatic review settings April 24, 2026 07:19
@shibayan shibayan added the enhancement New feature or request label Apr 24, 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 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.Number detection/inference and propagate number enum “value type” (decimal/float/double) through the schema model.
  • Emit number enums as strongly-typed readonly record struct types with custom JsonConverter serialization/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.

Comment thread src/OpenApiWeaver/ClientGenerator.Emitter.Schemas.cs
Comment thread src/OpenApiWeaver/ClientGenerator.Transformer.Schemas.cs
@shibayan shibayan merged commit c89a5cc into master Apr 24, 2026
8 checks passed
@shibayan shibayan deleted the number-enum branch April 24, 2026 07:37
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