OpenAPITools / OpenAPITools/openapi-generator

[REQ] CodeGen Nullable Configuration Directive

Open
#9,456 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Problem Description

We're trying to move from Swagger CodeGen to OpenAPI CodeGen but, as has been mentioned elsewhere, one of the problems is that OpenAPI CodeGen doesn't behave the same way regarding nullable types - properties and parameters.

I've read about the use of x-nullable but this - as far as I'm aware - would have to be added to each property, etc and we don't have control over the publication of the OpenAPI Definitions. A script to insert this would be possible but extremely laborious and pron to error.

We just tried v5.1.1 of CodeGen and, apart from this issue, the version is very stable and consistent and has generated easily the cleanest C# code we've had from a generator. (The Swagger CodeGens tended to miss types, throw errors and often required manual code clean-up.)

So ... would it be possible to add in a config directive such as useNullable or something so that the generator behaves closer to the Swagger CodeGen (eg v2.3.1 which was the most dependable from our POV).

Suggested Solution

The addition of a configuration directive such as useNullable.

Alternatives Considered

We've looked into modifying the API definitions with a script (we do this for other aspects such as tagging), modifying the resultant C# and have considered pulling a code fork to modify but none of these are very practicable. And we also think that there are likely to be others out there who would like this functionality. (In fact, some have posted to this effect.)

Context

This feature would mainly be of use to users who have no/little control of the publication of API definitions.

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

The issue names no files, tests, or entry points. Start by locating the C# generator's nullable-type handling and configuration path, then determine how a global directive should affect properties and parameters. Done means the directive is documented and its nullable output is covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, java, openapi
Domain
api, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.