dotnet / dotnet/runtime

OpenAPI: spec for collections inside polymorphic objects inside polymorphic objects are not generated correctly

Open
#128,155 5 comments 3 reactions 0 assignees View on GitHub
area-System.Text.Json bug
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

**Describe the bug**
I have a polymorphic object that has collection properties (List) that is used inside another polymorphic object. This results in the library generating stuff like:

```
"$ref": "#/components/schemas/polymorphicClass/anyOf/0/properties/polymorphicClassThatIsAProperty/anyOf/8/properties/intList"
```

Instead of
```
"type": [
"null",
"array"
],
"items": {
"type": "number",
"format": "int32"
}
```

### Expected Behavior

Correct array spec should be generated

### Steps To Reproduce

Simply create this structure and expose class A via a controller and generate OpenAPI specs for it:

```
[JsonPolymorphic(TypeDiscriminatorPropertyName = "type")]
[JsonDerivedType(typeof(B), typeDiscriminator: "test")]
public abstract class A
{
public C TestProperty { get; set; }
}

public class B : A
{
}

[JsonPolymorphic(TypeDiscriminatorPropertyName = "otherType")]
[JsonDerivedType(typeof(D), typeDiscriminator: "test1")]
public abstract class C
{
}

public class D : C
{
public List TestInts { get; set; }
}
```

### Exceptions (if any)

_No response_

### .NET Version

10.0.101

### Anything else?

.NET SDK:
Version: 10.0.101
Commit: fad253f51b
Workload version: 10.0.100-manifests.c57ac48b
MSBuild version: 18.0.6+fad253f51

Runtime Environment:
OS Name: Mac OS X
OS Version: 26.4
OS Platform: Darwin
RID: osx-arm64
Base Path: /usr/local/share/dotnet/sdk/10.0.101/

.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.

Host:
Version: 10.0.1
Architecture: arm64
Commit: fad253f51b

.NET SDKs installed:
9.0.303 [/usr/local/share/dotnet/sdk]
9.0.308 [/usr/local/share/dotnet/sdk]
10.0.101 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 9.0.7 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 9.0.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.11 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
None

Environment variables:
DOTNET_ROOT [/usr/local/share/dotnet]

global.json file:
Not found

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.