OpenAPITools / OpenAPITools/openapi-generator

[BUG][C#] Generated C# client does not produce nullable response types

Open
#20,477 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?0
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When using the OpenAPI Generator CLI (version 7.10.0) to generate a C# client with the nullableReferenceTypes=true option, methods returning a nullable schema do not generate nullable response types (e.g., Task<MyType?>).

openapi-generator version

7.10.0

OpenAPI declaration file content or url

Example.yaml or Example2.yaml

Generation Details

My Environment:

  • Windows 11 Enterprise
  • openjdk version "23.0.1" 2024-10-15

I installed openapi-generator-cli via:
npm install -g @openapitools/openapi-generator-cli

Configuration file:
config.yaml

Steps to reproduce

In my C:\Temp folder I have only Example.yaml and config.yaml files. I'm running next command to generate api in Console:
openapi-generator-cli generate -c config.yaml

As a result I have C:\Temp\output-directory\src\Org.OpenAPITools\Api\DefaultApi.cs with next code:
public async System.Threading.Tasks.Task<MyType> ExamplePostAsync(...
You can find it in attachment DefaultApi.cs.txt.

However, I expected to have
public async System.Threading.Tasks.Task<MyType?> ExamplePostAsync(...

Related issues/PRs
Suggest a fix

Ensure that the C# generator respects the nullableReferenceTypes=true configuration and generates nullable response types (Task<MyType?>) for schemas defined as nullable: true or oneOf with null.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with Example.yaml and config.yaml using the openapi-generator-cli command, then compare the generated DefaultApi.cs output with the expected Task<MyType?> signature. Trace the C# generator handling of nullableReferenceTypes=true and nullable schemas, and consider the issue done when the generated response types preserve nullability for the reported cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.