Add integer enum tests to existing composed enum tests#24348
Conversation
There was a problem hiding this comment.
1 issue found across 90 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="samples/client/petstore/csharp/generichost/latest/ComposedEnum/src/Org.OpenAPITools/Model/TypeIntegerWithOneOf.cs">
<violation number="1" location="samples/client/petstore/csharp/generichost/latest/ComposedEnum/src/Org.OpenAPITools/Model/TypeIntegerWithOneOf.cs:31">
P1: The generated `TypeIntegerWithOneOf` model class cannot actually represent the integer enum values (1, 2, 4) defined in the spec. Unlike the existing string enums (`AreaCode`, `StateTerritoryCode`, `MarineAreaCode`) in the same project — which generate a proper C# `enum` type with a `ValueConverter` and correct serialize/deserialize behavior — this model is an empty class with no value property.
**What goes wrong:**
- The `Read` method requires `StartObject`/`StartArray` tokens, so a plain integer like `1` (the correct JSON wire format for `type: integer, format: int32`) throws `JsonException`.
- Even when reading an object, the `Read` method discards parsed data and returns `new TypeIntegerWithOneOf()` — the actual value is never captured. See the switch statement with only `default: break;`.
- `WriteProperties` is empty, so serialization always produces `{}` — all value information is lost on write.
- The class has no property or field to hold the integer value at all.
This means the type cannot roundtrip any value through JSON serialization, making it functionally incomplete as an integer enum representation. The existing string-based enums in this project (e.g., `AreaCode` with `AreaCodeValueConverter`, proper `JsonConverter<AreaCode>`) provide the correct pattern. Consider whether the generator template for `oneOf`/`const` on integer types needs to produce a model class with a value property and corresponding converter logic, similar to how the string enums work.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| /// TypeIntegerWithOneOf | ||
| /// </summary> | ||
| public partial class Parent : IValidatableObject | ||
| public partial class TypeIntegerWithOneOf : IValidatableObject |
There was a problem hiding this comment.
P1: The generated TypeIntegerWithOneOf model class cannot actually represent the integer enum values (1, 2, 4) defined in the spec. Unlike the existing string enums (AreaCode, StateTerritoryCode, MarineAreaCode) in the same project — which generate a proper C# enum type with a ValueConverter and correct serialize/deserialize behavior — this model is an empty class with no value property.
What goes wrong:
- The
Readmethod requiresStartObject/StartArraytokens, so a plain integer like1(the correct JSON wire format fortype: integer, format: int32) throwsJsonException. - Even when reading an object, the
Readmethod discards parsed data and returnsnew TypeIntegerWithOneOf()— the actual value is never captured. See the switch statement with onlydefault: break;. WritePropertiesis empty, so serialization always produces{}— all value information is lost on write.- The class has no property or field to hold the integer value at all.
This means the type cannot roundtrip any value through JSON serialization, making it functionally incomplete as an integer enum representation. The existing string-based enums in this project (e.g., AreaCode with AreaCodeValueConverter, proper JsonConverter<AreaCode>) provide the correct pattern. Consider whether the generator template for oneOf/const on integer types needs to produce a model class with a value property and corresponding converter logic, similar to how the string enums work.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/csharp/generichost/latest/ComposedEnum/src/Org.OpenAPITools/Model/TypeIntegerWithOneOf.cs, line 31:
<comment>The generated `TypeIntegerWithOneOf` model class cannot actually represent the integer enum values (1, 2, 4) defined in the spec. Unlike the existing string enums (`AreaCode`, `StateTerritoryCode`, `MarineAreaCode`) in the same project — which generate a proper C# `enum` type with a `ValueConverter` and correct serialize/deserialize behavior — this model is an empty class with no value property.
**What goes wrong:**
- The `Read` method requires `StartObject`/`StartArray` tokens, so a plain integer like `1` (the correct JSON wire format for `type: integer, format: int32`) throws `JsonException`.
- Even when reading an object, the `Read` method discards parsed data and returns `new TypeIntegerWithOneOf()` — the actual value is never captured. See the switch statement with only `default: break;`.
- `WriteProperties` is empty, so serialization always produces `{}` — all value information is lost on write.
- The class has no property or field to hold the integer value at all.
This means the type cannot roundtrip any value through JSON serialization, making it functionally incomplete as an integer enum representation. The existing string-based enums in this project (e.g., `AreaCode` with `AreaCodeValueConverter`, proper `JsonConverter<AreaCode>`) provide the correct pattern. Consider whether the generator template for `oneOf`/`const` on integer types needs to produce a model class with a value property and corresponding converter logic, similar to how the string enums work.</comment>
<file context>
@@ -26,45 +26,29 @@
+ /// TypeIntegerWithOneOf
/// </summary>
- public partial class Parent : IValidatableObject
+ public partial class TypeIntegerWithOneOf : IValidatableObject
{
/// <summary>
</file context>
a follow up pr to #23869
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
Summary by cubic
Add integer enum coverage to the C#
generichostcomposed-enum tests. AddsTypeIntegerWithOneOf(int32 oneOf/const) and folds the old annotated enum sample intoComposedEnum.TypeIntegerWithOneOfto the 3.0 composed-enum spec and generated sample; registeredTypeIntegerWithOneOfJsonConverter.bin/configs/csharp-generichost-latest-annotatedEnum.yamland theAnnotatedEnumsample; tests now live underComposedEnum..github/workflows/samples-dotnet10.yamlto remove the deletedAnnotatedEnumsample from the CI matrix.Written for commit d465c96. Summary will update on new commits.