-
Notifications
You must be signed in to change notification settings - Fork 262
Closed as not planned
Closed as not planned
Copy link
Description
Describe the bug
Generating OpenApi Json from a Class with multiple List<T> Properties result in only the first one getting a proper Type. All other Properties don't have a Type and result in Any.
OpenApi File To Reproduce
using Microsoft.AspNetCore.Mvc;
[ApiController]
[Route("[controller]")]
public class CustomerController : ControllerBase
{
[HttpGet(Name = "GetCustomer")]
[Produces<CustomerModel>]
public IActionResult Get()
{
return Ok(new CustomerModel {
Name = "Contoso",
PropA =
[
new OptionRef { RefId = "1", DisplayText = "Type A" },
new OptionRef { RefId = "2", DisplayText = "Type B" }
],
PropB =
[
new OptionRef { RefId = "1", DisplayText = "Branch A" },
new OptionRef { RefId = "2", DisplayText = "Branch B" }
],
PropC =
[
new OptionRef { RefId = "1", DisplayText = "Storage A" },
new OptionRef { RefId = "2", DisplayText = "Storage B" }
],
});
}
}
public class CustomerModel
{
public string Name { get; set; } = string.Empty;
public List<OptionRef> PropB { get; set; } = [];
public List<OptionRef> PropC { get; set; } = [];
public List<OptionRef> PropA { get; set; } = [];
}
public class OptionRef
{
public string RefId { get; set; } = string.Empty;
public string DisplayText { get; set; } = string.Empty;
}
{
"openapi": "3.0.1",
"info": {
"title": "corner4-OpenApiTest | v1",
"version": "1.0.0"
},
"servers": [
{
"url": "http://localhost:5227/"
}
],
"paths": {
"/Customer": {
"get": {
"tags": [
"Customer"
],
"operationId": "GetCustomer",
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"$ref": "#/components/schemas/CustomerModel"
}
},
"application/json": {
"schema": {
"$ref": "#/components/schemas/CustomerModel"
}
},
"text/json": {
"schema": {
"$ref": "#/components/schemas/CustomerModel"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"CustomerModel": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"propB": {
"type": "array",
"items": {
"$ref": "#/components/schemas/OptionRef"
}
},
"propC": {
"type": "array",
"items": {}
},
"propA": {
"type": "array",
"items": {}
}
}
},
"OptionRef": {
"type": "object",
"properties": {
"refId": {
"type": "string"
},
"displayText": {
"type": "string"
}
}
}
}
},
"tags": [
{
"name": "Customer"
}
]
}
Expected behavior
That propC and propA have items ref properly set.
Screenshots/Code Snippets


Additional context
Tested with Microsoft.AspNetCore.OpenApi 9.0.6 with Default WebApi Project with OpenApi Support.
Maybe related to: https://stackoverflow.com/a/79414849 ?
Metadata
Metadata
Assignees
Labels
No labels