OpenAPITools / OpenAPITools/openapi-generator

[BUG] [ASPNETCORE] nullable array does not generate a nullable property

Open
#21,431 3 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
  • [x ] Have you provided a full/minimal spec to reproduce the issue?
  • [ x] Have you validated the input using an OpenAPI validator?
  • [ x] Have you tested with the latest master to confirm the issue still exists?
  • [ x] Have you searched for related issues/PRs?
  • [ x] What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Nullable arrays in OpenAPI Spec are not generated as nullable types

openapi-generator version

7.13.0

OpenAPI declaration file content
openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
servers: []
paths: {}
components:
  schemas:
    Pet:
      type: object
      properties:
        roleTypes:
          type: array
          items:
            type: string
          nullable: true
Generation Details

java -jar .\openapi-generator-cli.jar generate -i test.yaml -g aspnetcore -o ./tmp/ --additional-properties=useSwashbuckle=true --additional-properties=aspnetCoreVersion=5.0 --additional-properties=useNewtonsoft=false --additional-properties=buildTarget=library

Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/19516

Generated Code:
        [DataMember(Name="roleTypes", EmitDefaultValue=true)]
        public List<string> RoleTypes { get; set; }
expected outcome:
        [DataMember(Name="roleTypes", EmitDefaultValue=true)]
        public List<string>? RoleTypes { get; set; }

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

Start by reproducing the ASPNETCORE generation command with the provided test.yaml declaration and compare the generated RoleTypes property with the expected nullable form. Check the related issue 19516 for context. Done means the generated C# property for a nullable array includes the nullable marker while preserving the existing DataMember output.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, openapi
Domain
backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.