dotnet / dotnet/aspnetcore

OpenAPI does not produce example for XML root which is a collection

Open
#65,755 0 comments 0 reactions 0 assignees View on GitHub
area-minimal feature-openapi
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

OpenAPI does not produce json that can be used in Swagger UI to render XML data when the root object is a Collection. In Swagger it shows
```

```

### Expected Behavior

For the endpoint `/WeatherForecast/forecasts` when selecting the `application/vnd.example.forecasts+xml` request / response it should generate the sample XML of
```


2026-03-12T12:07:50.801Z
string
0

```

### Steps To Reproduce

https://github.com/ajohnstone-ks/OpenApiIssue

Run the app, open a browser to https://localhost:7118/swagger/index.html and expand the `POST /WeatherForecast/forecasts` node. Change `Request Body` or `Response Body` to `application/vnd.example.forecasts+xml` and observe that you see

```

```

for the example when it should be

```


2026-03-12T12:11:41.824Z
string
0

```

### Exceptions (if any)

_No response_

### .NET Version

10.0.2

### Anything else?

VS Version: 18.2.1
Asp.Net core: 10

Packages
`Microsoft.AspNetCore.OpenApi` 10.0.4
`Swashbuckle.AspNetCore.SwaggerUI` 10.1.5

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.