Azure / Azure/azure-functions-openapi-extension

Stack overflow in System.Globalization.CompareInfo

Open
#576 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
388
Forks
202
PR merge metrics
No merged PRs in 30d

Description

**Describe the issue**
Creating a simple azure function produces a stack overflow exception when loading the swagger ui page.

**To Reproduce**
Steps to reproduce the behavior:
1. Create a new Azure Function App with a single function.
2. Run in the debugger and click the generated Swagger UI page link.
3. Swagger UI page fails to load => Stack Overflow Exception

**Expected behavior**
Swagger UI page opens displaying the available function endpoint.

**Code**
```csharp
public class ClientsCreate
{
private ECMLDataContext Context { get; set; }
private ILogger Log { get; set; }

public ClientsCreate(ILogger log)
{
//Context = new ECMLDataContext();
Log = log;
}

[OpenApiOperation(nameof(ClientsCreate),
tags: new[] { "Ecml" },
Description = "Creates a new Client record")]
[OpenApiRequestBody(
contentType: "application/json",
bodyType: typeof(Client),
Required = true,
Description = "The body of the request")]
[OpenApiResponseWithBody(
statusCode: HttpStatusCode.OK,
contentType: "application/json",
bodyType: typeof(string),
Description = "Indicates success and returns a user-friendly message")]
[OpenApiResponseWithBody(
HttpStatusCode.BadRequest,
contentType: "application/json",
bodyType: typeof(string),
Description = "Indicates failure and returns a user-friendly message")]
[FunctionName(nameof(ClientsCreate))]
public async Task Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "clients")] HttpRequest req)
{
var requestBody = await new StreamReader(req.Body).ReadToEndAsync();
var client = JsonConvert.DeserializeObject(requestBody);
Context.Clients.Add(client);
await Context.SaveChangesAsync();
return new OkObjectResult(client);
}
}
```

**Environment (please complete the following information, if applicable):**
- OS: Windows 11
- Browser Edge
- Version 113.0.1774.35 (Official build) (64-bit)

**Call Stack**
```
[Managed to Native Transition]
> System.Private.CoreLib.dll!System.Globalization.CompareInfo.IcuCompareString(System.ReadOnlySpan string1, System.ReadOnlySpan string2, System.Globalization.CompareOptions options) Line 50 C#
System.Private.CoreLib.dll!System.Globalization.CompareInfo.Compare(System.ReadOnlySpan string1, System.ReadOnlySpan string2, System.Globalization.CompareOptions options) Line 448 C#
System.Private.CoreLib.dll!System.Globalization.CompareInfo.Compare(string string1, string string2, System.Globalization.CompareOptions options) Line 300 C#
System.Private.CoreLib.dll!string.Equals(string value, System.StringComparison comparisonType) Line 665 C#
Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.dll!Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions.TypeExtensions.IsArrayType(System.Type type) Unknown
Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.dll!Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Visitors.ObjectTypeVisitor.IsVisitable(System.Type type) Unknown
Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.dll!Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Visitors.OpenApiSchemaAcceptor.Accept(Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Visitors.VisitorCollection collection, Newtonsoft.Json.Serialization.NamingStrategy namingStrategy) Unknown
Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.dll!Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Visitors.ObjectTypeVisitor.ProcessProperties(Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Visitors.IOpenApiSchemaAcceptor instance, string schemaName, System.Collections.Generic.Dictionary properties, Newtonsoft.Json.Serialization.NamingStrategy namingStrategy) Unknown
Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.dll!Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Visitors.ObjectTypeVisitor.Visit(Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions.IAcceptor acceptor, System.Collections.Generic.KeyValuePair type, Newtonsoft.Json.Serialization.NamingStrategy namingStrategy, System.Attribute[] attributes) Unknown
Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.dll!Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Visitors.OpenApiSchemaAcceptor.Accept(Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Visitors.VisitorCollection collection, Newtonsoft.Json.Serialization.NamingStrategy namingStrategy) Unknown
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with a new Azure Function and the generated Swagger UI, then read the call-stack entry points TypeExtensions.IsArrayType, ObjectTypeVisitor.IsVisitable, and OpenApiSchemaAcceptor.Accept. Trace the recursive schema processing shown in the stack and verify the fix by confirming Swagger UI loads and displays the function endpoint without a stack overflow.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp, openapi
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.