fix(normalizer): support OAS 3.1 annotated enums (oneOf + const) for consistent enum generation (C#)#23869
Open
nagabalaji-b wants to merge 5 commits into
Open
fix(normalizer): support OAS 3.1 annotated enums (oneOf + const) for consistent enum generation (C#)#23869nagabalaji-b wants to merge 5 commits into
nagabalaji-b wants to merge 5 commits into
Conversation
Contributor
There was a problem hiding this comment.
3 issues found across 8 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| if (subSchema.getEnum() == null || subSchema.getEnum().isEmpty()) { | ||
| // Check if this sub-schema has an enum or const value (OpenAPI 3.1 uses const for single-value enums) | ||
| List<Object> subSchemaEnumValues = subSchema.getEnum(); | ||
| if ((subSchemaEnumValues == null || subSchemaEnumValues.isEmpty()) && subSchema.getConst() == null) { |
Contributor
There was a problem hiding this comment.
Rather than doing (subSchemaEnumValues == null || subSchemaEnumValues.isEmpty()) twice, could we extract this to a variable boolean definesEnum = ModelUtils.hasEnum(subSchema) and then have
if (!definesEnum && subSchema.getConst() == null) {This could allow use to skip the comments almost entirely and instead allow the variable/method names be the explanation themselves.
| |sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true| | ||
| |sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true| | ||
| |sourceFolder|source folder for generated code| |OpenAPI/src| | ||
| |sourceFolder|source folder for generated code| |OpenAPI\src| |
Contributor
There was a problem hiding this comment.
Are these path changes intentional?
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
This PR addresses normalization for OpenAPI 3.1 annotated enums, where enum values are expressed using
oneOf+const. The main focus is on ensuring C# behavior aligns with traditional enum handling.Problem
OpenAPI 3.0 typically utilizes enum arrays. In contrast, OpenAPI 3.1 often adopts an annotated enum style with
oneOf+constand per-value descriptions. Prior to this fix, const-based composed schemas were not consistently simplified into enum-like schemas, potentially impacting strong enum generation in C#.Example (OAS 3.1)
Equivalent OAS 3.0 Shape
C# Before vs After
Before Fix (String Property)
The property is a plain string because
oneOf+constwas not normalized to enum semantics.After Fix (Strong Enum)
After normalization, the schema is recognized as an enum and generates a strongly-typed enum with the appropriate JSON converter and member attributes.
Actual Behavior Before
OAS 3.1
oneOf+constwas not consistently normalized to enum semantics. C# output could revert to non-enum-style modeling for this pattern.Expected Behavior
OAS 3.1
oneOf+constshould normalize in the same manner as OAS 3.0 enums. C# should consistently produce strongly typed enum output.Changes in This PR
constas a single enum value when an enum is absent in composed sub-schemas.oneOfandanyOfenum-like paths.C# Result After Fix (Illustrative)
Validation
The targeted normalizer test for OAS 3.1 simplifying
oneOf/anyOfpaths passed. Samples have been regenerated for Java configurations. Documentation for the generator has been exported.Compatibility
This is a bug fix only. No intended breaking behavior changes. The normalization improvement is generator-agnostic; C# is the primary verified use case.
PR Checklist
@muttleyxd @devhl-labs @lucasheim @shibayan (C# generators)
Summary by cubic
Normalize OpenAPI 3.1 annotated enums (
oneOf+const) as true enums. This ensures that C# code generation produces strong enums consistently, matching OAS 3.0 behavior.constas a single enum value when an enum is missing in sub-schemas.oneOf/anyOfenum-like schemas into a single enum in the parent, preserving types and per-value descriptions.Written for commit 51e0b0f. Summary will update with new commits. Review in cubic