[csharp] Support null types#23260
Open
devhl-labs wants to merge 2 commits intoOpenAPITools:masterfrom
Open
Conversation
Contributor
There was a problem hiding this comment.
23 issues found across 64 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/NullTypes/src/Org.OpenAPITools/Model/ColorOrNull.cs">
<violation number="1" location="samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Model/ColorOrNull.cs:111">
P2: ColorOrNullJsonConverter only accepts/writes object-shaped JSON, so valid string or null representations for this union will throw or serialize incorrectly.</violation>
</file>
<file name="samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Api/DefaultApi.cs">
<violation number="1" location="samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Api/DefaultApi.cs:236">
P2: Path concatenation can produce a double-slash when BaseAddress.AbsolutePath ends with '/', resulting in a different URL path (e.g., /api//widgets/{id}) that may not match server routes.</violation>
</file>
<file name="samples/client/petstore/csharp/generichost/latest/NullTypes/appveyor.yml">
<violation number="1" location="samples/client/petstore/csharp/generichost/latest/NullTypes/appveyor.yml:3">
P2: AppVeyor image is pinned to Visual Studio 2019, which won’t have the .NET 10 SDK required by this ‘latest’ sample (net10.0 targets). CI will fail to build/test unless a newer image or SDK install step is used.</violation>
</file>
<file name="samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Model/ShapeOrNull.cs">
<violation number="1" location="samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Model/ShapeOrNull.cs:152">
P2: Nullable `Area` is treated as non-nullable in the converter: JSON nulls are read but then rejected, and serialization dereferences `AreaOption.Value!.Value` when `Area` is explicitly null. This makes `area: null` payloads fail despite `double?` being nullable.</violation>
</file>
<file name="samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Client/DateTimeJsonConverter.cs">
<violation number="1" location="samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Client/DateTimeJsonConverter.cs:27">
P2: RFC3339 allows fractional seconds with 1 or more digits, but the parser only accepts up to 7. Valid RFC3339 timestamps with 8+ fractional digits will fail TryParseExact and throw NotSupportedException.</violation>
</file>
<file name="samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/README.md">
<violation number="1" location="samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/README.md:95">
P2: README documents obsolete response types (`ApiResponse<T>`, `T`, `TOrDefault`) that do not match the sample’s generated interface-based API responses, causing misleading integration guidance.</violation>
</file>
<file name="samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Client/DateOnlyNullableJsonConverter.cs">
<violation number="1" location="samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Client/DateOnlyNullableJsonConverter.cs:49">
P2: Invalid date payloads are reported with `NotSupportedException` instead of `JsonException`, misclassifying deserialization errors.</violation>
</file>
<file name="samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Client/ClientUtils.cs">
<violation number="1" location="samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Client/ClientUtils.cs:56">
P2: `TryDeserialize` reports failure when deserializing a valid JSON `null` because it returns `result != null`. `JsonSerializer.Deserialize<T>` can succeed and return `null`, so `TryDeserialize` returns `false` for valid `null` payloads, breaking nullable/null-type handling.</violation>
</file>
<file name="samples/client/petstore/csharp/generichost/latest/NullTypes/docs/scripts/git_push.sh">
<violation number="1" location="samples/client/petstore/csharp/generichost/latest/NullTypes/docs/scripts/git_push.sh:38">
P2: Embedding GIT_TOKEN in the remote URL persists the token in `.git/config`, leaving a long‑lived plaintext credential that can be exposed by git tooling. Prefer credential helpers or prompt-based auth instead of storing tokens in remote URLs.</violation>
</file>
<file name="samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Model/Color.cs">
<violation number="1" location="samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Model/Color.cs:168">
P2: The Color JSON converter accepts array payloads and silently returns an empty Color instance because it only processes property names at object depth. This masks invalid input for an object schema instead of rejecting it.</violation>
<violation number="2" location="samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Model/Color.cs:208">
P1: Nullable RGB fields are treated as non-nullable in custom JSON conversion, causing explicit JSON nulls to throw during read/write.</violation>
</file>
<file name="samples/client/petstore/csharp/generichost/latest/NullTypes/docs/models/ShapeOrNull.md">
<violation number="1" location="samples/client/petstore/csharp/generichost/latest/NullTypes/docs/models/ShapeOrNull.md:7">
P3: ShapeOrNull is marked nullable in the OpenAPI schema, but the generated docs only describe the object fields and never mention that `null` is a valid value, which misleads consumers.</violation>
</file>
<file name="samples/client/petstore/csharp/generichost/latest/NullTypes/docs/scripts/git_push.ps1">
<violation number="1" location="samples/client/petstore/csharp/generichost/latest/NullTypes/docs/scripts/git_push.ps1:22">
P2: Script only checks for any remote but later assumes a valid `origin`; if a different remote exists or `origin` is missing, `git pull/push origin` will fail or use the wrong repo.</violation>
<violation number="2" location="samples/client/petstore/csharp/generichost/latest/NullTypes/docs/scripts/git_push.ps1:29">
P2: `git pull --ff-only` failure is misclassified as missing repository, causing incorrect repo-creation/error paths for valid first-push states.</violation>
<violation number="3" location="samples/client/petstore/csharp/generichost/latest/NullTypes/docs/scripts/git_push.ps1:33">
P2: Auto-creating GitHub repo ignores `GitUserId`, which can create the repo under a different owner than the configured remote URL.</violation>
</file>
<file name="samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Model/Shape.cs">
<violation number="1" location="samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Model/Shape.cs:152">
P2: ShapeJsonConverter still treats `area` as non-nullable: it throws on deserializing explicit null and will throw when serializing a set-but-null AreaOption, so null-type support is broken for this property.</violation>
</file>
<file name="samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Client/DateTimeNullableJsonConverter.cs">
<violation number="1" location="samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Client/DateTimeNullableJsonConverter.cs:55">
P2: Malformed non-null date strings are silently deserialized as null; the nullable converter should throw on parse failure instead of returning null for invalid values.</violation>
<violation number="2" location="samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Client/DateTimeNullableJsonConverter.cs:77">
P2: Serialization uses the `K` format specifier without normalizing `DateTimeKind`. For `DateTimeKind.Unspecified` this emits no offset, producing non‑RFC3339 strings (no timezone) even though the converter is documented for RFC3339 `date-time` values.</violation>
</file>
<file name="samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Model/NullTypeDirect.cs">
<violation number="1" location="samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Model/NullTypeDirect.cs:141">
P2: `alwaysNull` represents a bare `null` type but the converter accepts any JSON value and re-serializes non-null values, so invalid payloads like `{ "alwaysNull": 123 }` are treated as valid.</violation>
<violation number="2" location="samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Model/NullTypeDirect.cs:152">
P1: Nullable `Id` is handled as non-nullable in the custom JSON converter, causing runtime exceptions on null during read/write.</violation>
</file>
<file name="samples/client/petstore/csharp/generichost/latest/NullTypes/docs/models/NullTypeDirect.md">
<violation number="1" location="samples/client/petstore/csharp/generichost/latest/NullTypes/docs/models/NullTypeDirect.md:8">
P3: The docs link `Null.md` for the `Object` type, but no `Null.md` file exists in the models docs directory, so this link is broken.</violation>
</file>
<file name="samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Client/TokenBase.cs">
<violation number="1" location="samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Client/TokenBase.cs:67">
P2: IsRateLimited reads _nextAvailable without synchronization while BeginRateLimit writes it under a lock. The timer thread can observe stale state and raise TokenBecameAvailable early. Guard the read with the same lock (or use a volatile/interlocked read).</violation>
<violation number="2" location="samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Client/TokenBase.cs:81">
P2: Event is checked and invoked via separate reads, creating a race that can throw `NullReferenceException` when subscribers change concurrently.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
samples/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Model/Color.cs
Show resolved
Hide resolved
...nt/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Model/NullTypeDirect.cs
Show resolved
Hide resolved
...lient/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Model/ColorOrNull.cs
Show resolved
Hide resolved
...s/client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Api/DefaultApi.cs
Show resolved
Hide resolved
samples/client/petstore/csharp/generichost/latest/NullTypes/appveyor.yml
Show resolved
Hide resolved
...nt/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Model/NullTypeDirect.cs
Show resolved
Hide resolved
...client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Client/TokenBase.cs
Show resolved
Hide resolved
...client/petstore/csharp/generichost/latest/NullTypes/src/Org.OpenAPITools/Client/TokenBase.cs
Show resolved
Hide resolved
samples/client/petstore/csharp/generichost/latest/NullTypes/docs/models/ShapeOrNull.md
Show resolved
Hide resolved
samples/client/petstore/csharp/generichost/latest/NullTypes/docs/models/NullTypeDirect.md
Show resolved
Hide resolved
This was referenced Mar 15, 2026
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.
Related to #19258 and #5180
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.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)Summary by cubic
Adds C# generator support for OAS 3.1
type: nullby emitting nullableobjectproperties. Adds aNullTypessample and enables it in CI.New Features
openApiType: 'null'toobjectand mark them nullable inAbstractCSharpCodegen.NullTypessample (bin/configs/csharp-generichost-latest-nullTypes.yaml, generated client, tests)..github/workflows/samples-dotnet10.yamlto build and test the new sample.Refactors
Written for commit c92b00a. Summary will update on new commits.