OpenAPITools / OpenAPITools/openapi-generator
[BUG] [ASPNETCORE] nullable array does not generate a nullable property
Open
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 (example)?
- [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)
openapi-generator version
7.8.0
Description
When an array is makred as nullable in the openapi spec the generated property is NOT nullable
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
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; }
Generation Details
openapi-generator-cli generate -i src/petstore.yaml -g aspnetcore --additional-properties nullableReferenceTypes=true,aspnetCoreVersion=8.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/petstore.yaml and the ASP.NET Core generation command, then trace how the nullable array schema becomes the RoleTypes property. Done means nullableReferenceTypes=true generates List? for roleTypes while preserving the shown DataMember attributes; add or run the relevant generator regression coverage if available.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100