Commit 417840c
authored
[csharp][generichost] Deserialize present-but-null nullable enums (#23912)
For a property that is both `required` and `nullable` with an enum type, the
generated JsonConverter only assigned the backing Option when the raw JSON
string was non-null. An explicit `null` therefore left the Option unset, and the
required-property check then threw `ArgumentException: Property is required` —
even though the property was present (just null).
Assign the Option unconditionally for nullable enums, mapping a null raw value
to a null enum value. Non-nullable enums keep the existing guard, so their
generated output is unchanged. Regenerated all generichost samples.
Adds CSharpClientCodegenTest#testGenericHostNullableEnumDeserializesPresentNull,
which generates the generichost client and asserts the RequiredClass converter
uses the null-tolerant read for the required+nullable enum while the non-nullable
enum keeps the guard.1 parent da8c31c commit 417840c
38 files changed
Lines changed: 154 additions & 220 deletions
File tree
- modules/openapi-generator/src
- main/resources/csharp/libraries/generichost
- test/java/org/openapitools/codegen/csharpnetcore
- samples/client/petstore/csharp/generichost
- latest/UseDateTimeOffset/src/Org.OpenAPITools/Model
- net10
- FormModels/src/Org.OpenAPITools/Model
- NullReferenceTypes/src/Org.OpenAPITools/Model
- Petstore/src/Org.OpenAPITools/Model
- SourceGeneration/src/Org.OpenAPITools/Model
- net4.7
- FormModels/src/Org.OpenAPITools/Model
- Petstore/src/Org.OpenAPITools/Model
- net4.8
- FormModels/src/Org.OpenAPITools/Model
- Petstore/src/Org.OpenAPITools/Model
- net8
- FormModels/src/Org.OpenAPITools/Model
- NullReferenceTypes/src/Org.OpenAPITools/Model
- Petstore/src/Org.OpenAPITools/Model
- SourceGeneration/src/Org.OpenAPITools/Model
- net9
- FormModels/src/Org.OpenAPITools/Model
- NullReferenceTypes/src/Org.OpenAPITools/Model
- Petstore/src/Org.OpenAPITools/Model
- SourceGeneration/src/Org.OpenAPITools/Model
- standard2.0/Petstore/src/Org.OpenAPITools/Model
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
| 233 | + | |
233 | 234 | | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
234 | 239 | | |
235 | 240 | | |
| 241 | + | |
236 | 242 | | |
237 | 243 | | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
238 | 248 | | |
239 | 249 | | |
| 250 | + | |
240 | 251 | | |
241 | 252 | | |
242 | 253 | | |
| |||
Lines changed: 33 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
43 | 76 | | |
44 | 77 | | |
45 | 78 | | |
| |||
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
753 | 753 | | |
754 | 754 | | |
755 | 755 | | |
756 | | - | |
757 | | - | |
| 756 | + | |
758 | 757 | | |
759 | 758 | | |
760 | 759 | | |
| |||
Lines changed: 4 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1915 | 1915 | | |
1916 | 1916 | | |
1917 | 1917 | | |
1918 | | - | |
1919 | | - | |
| 1918 | + | |
1920 | 1919 | | |
1921 | 1920 | | |
1922 | 1921 | | |
1923 | | - | |
1924 | | - | |
| 1922 | + | |
1925 | 1923 | | |
1926 | 1924 | | |
1927 | 1925 | | |
| |||
1949 | 1947 | | |
1950 | 1948 | | |
1951 | 1949 | | |
1952 | | - | |
1953 | | - | |
| 1950 | + | |
1954 | 1951 | | |
1955 | 1952 | | |
1956 | 1953 | | |
1957 | 1954 | | |
1958 | 1955 | | |
1959 | 1956 | | |
1960 | | - | |
1961 | | - | |
| 1957 | + | |
1962 | 1958 | | |
1963 | 1959 | | |
1964 | 1960 | | |
| |||
samples/client/petstore/csharp/generichost/net10/FormModels/src/Org.OpenAPITools/Model/EnumTest.cs
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
281 | 281 | | |
282 | 282 | | |
283 | 283 | | |
284 | | - | |
285 | | - | |
| 284 | + | |
286 | 285 | | |
287 | 286 | | |
288 | 287 | | |
| |||
Lines changed: 8 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
845 | 845 | | |
846 | 846 | | |
847 | 847 | | |
848 | | - | |
849 | | - | |
| 848 | + | |
850 | 849 | | |
851 | 850 | | |
852 | 851 | | |
853 | | - | |
854 | | - | |
| 852 | + | |
855 | 853 | | |
856 | 854 | | |
857 | 855 | | |
858 | | - | |
859 | | - | |
| 856 | + | |
860 | 857 | | |
861 | 858 | | |
862 | 859 | | |
863 | | - | |
864 | | - | |
| 860 | + | |
865 | 861 | | |
866 | 862 | | |
867 | 863 | | |
| |||
883 | 879 | | |
884 | 880 | | |
885 | 881 | | |
886 | | - | |
887 | | - | |
| 882 | + | |
888 | 883 | | |
889 | 884 | | |
890 | 885 | | |
891 | | - | |
892 | | - | |
| 886 | + | |
893 | 887 | | |
894 | 888 | | |
895 | 889 | | |
896 | | - | |
897 | | - | |
| 890 | + | |
898 | 891 | | |
899 | 892 | | |
900 | 893 | | |
901 | 894 | | |
902 | 895 | | |
903 | 896 | | |
904 | | - | |
905 | | - | |
| 897 | + | |
906 | 898 | | |
907 | 899 | | |
908 | 900 | | |
| |||
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
761 | 761 | | |
762 | 762 | | |
763 | 763 | | |
764 | | - | |
765 | | - | |
| 764 | + | |
766 | 765 | | |
767 | 766 | | |
768 | 767 | | |
| |||
0 commit comments