Azure / Azure/azure-functions-openapi-extension
StackOverflow Exception on circular reference
- Dominant language
- C#
- Stars
- 388
- Forks
- 202
- PR merge metrics
- No merged PRs in 30d
Description
Here is a code sample to reproduce the issue:
```c#
public class Function1
{
private const string ContentType = "application/json";
public List Lib { get; set; } = new List();
[FunctionName(nameof(AddBook))]
[OpenApiOperation(operationId: nameof(AddBook), Visibility = OpenApiVisibilityType.Important)]
[OpenApiRequestBody(contentType: ContentType, bodyType: typeof(Book), Required = true)]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: ContentType, bodyType: typeof(List))]
public IActionResult AddBook([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)][FromBody] Book req, ILogger log)
{
Lib.Add(req);
return new OkObjectResult(Lib);
}
}
public class Book
{
public string Name { get; set; }
public DateTime PublicationDate { get; set; }
public Author Author { get; set; }
}
public class Author
{
public string Name { get; set; }
public List Books { get; set; }
}
```
It seems like recursion happens in **Visit** method of **ObjectTypeVisitor** class.
The same can be reproduced in Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V3IoC project by adding a new class Owner:
```c#
public class Owner
{
public string Name { get; set; }
public List Pets { get; set; }
}
```
And introducing new property "public Owner Owner { get; set; }" in Pet class
Contributor guide
Research direction
Start with the Visit method in ObjectTypeVisitor and reproduce the circular Book/Author or Pet/Owner model in the Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.V3IoC project. Trace the recursive traversal and use the provided models to verify that circular references no longer cause a stack overflow; the issue also has a merged pull request to review for existing context.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, openapi
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100