Is there an existing issue for this?
Describe the bug
The default CreateSchemaReferenceId on OpenApiOptions generates schema reference IDs containing [] for array types. For example, a return type of ItemResult<string[]> produces the schema key ItemResultOfString[].
The [] characters are invalid in OpenAPI schema keys, which must match ^[a-zA-Z0-9\.\-_]+$. This causes OpenApiDocument.LoadAsync to report a validation error:
The key 'ItemResultOfString[]' in 'schemas' of components MUST match the regular expression '^[a-zA-Z0-9\.\-_]+$'. [#/components]
Expected Behavior
Array types should have valid schema reference IDs, e.g. ItemResultOfStringArray instead of ItemResultOfString[].
Steps To Reproduce
#:sdk Microsoft.NET.Sdk.Web
#:property TargetFramework=net10.0
#:property PublishAot=false
#:package Microsoft.AspNetCore.OpenApi@10.0.5
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenApi();
var app = builder.Build();
app.MapOpenApi();
app.MapGet("/api/test", () => new ItemResult<string[]>());
await app.StartAsync();
using var client = new HttpClient();
using var stream = await (await client.GetAsync("http://localhost:5000/openapi/v1.json")).Content.ReadAsStreamAsync();
var result = await Microsoft.OpenApi.OpenApiDocument.LoadAsync(stream, "json");
Console.Error.WriteLine(result.Diagnostic.Errors.Count > 0
? $"Errors:\n{string.Join("\n", result.Diagnostic.Errors.Select(e => $" {e.Message}"))}"
: "No errors (unexpected).");
await app.StopAsync();
public class ItemResult<T>
{
public bool WasSuccessful { get; set; }
public T? Object { get; set; }
}
Run the above file-based app. Observe error in output:
Errors:
The key 'ItemResultOfString[]' in 'schemas' of components MUST match the regular expression '^[a-zA-Z0-9\.\-_]+$'.
Exceptions (if any)
No response
.NET Version
10.0.201
Anything else?
No response
Is there an existing issue for this?
Describe the bug
The default
CreateSchemaReferenceIdonOpenApiOptionsgenerates schema reference IDs containing[]for array types. For example, a return type ofItemResult<string[]>produces the schema keyItemResultOfString[].The
[]characters are invalid in OpenAPI schema keys, which must match^[a-zA-Z0-9\.\-_]+$. This causesOpenApiDocument.LoadAsyncto report a validation error:Expected Behavior
Array types should have valid schema reference IDs, e.g.
ItemResultOfStringArrayinstead ofItemResultOfString[].Steps To Reproduce
Run the above file-based app. Observe error in output:
Exceptions (if any)
No response
.NET Version
10.0.201
Anything else?
No response