Open Frankyfrankly opened 3 years ago
@Frankyfrankly Thanks for the issue. I looked at the issue, but if you change the models' structure it will solve your issue:
public class Book
{
...
public string AuthorId { get; set; }
}
public class Author
{
...
public List<Book> Books { get; set; }
}
To me, the circular reference issue is about how data structure looks like, rather than the issue of this extension. If you still want to keep the Author
in your Book
class, I would recommend adding the [OpenApiIgnore()]
decorator on top of it like:
public class Book
{
...
public string AuthorId { get; set; }
[OpenApiIgnore()]
public Author Author { get; set; }
}
By doing so, you will avoid the circular reference issue.
@Frankyfrankly I'll close the issue for now. If you'd like to discuss more on this, please open a new issue.
Hi @justinyoo ,
I run into same problem as is described https://github.com/aliencube/AzureFunctions.Extensions/issues/134
In my case I use health check library in Azure function project. And the response type HealthReport contains additional types including Exception type.
I guess this is root cause of a bug and circular reference.
As you see, these types cannot be changed as you suggest above.
Also I attached call stack when exception is thrown
I am open to help in investigation of the issue.
...
[OpenApiIgnore()] public Author Author { get; set; } }
By doing so, you will avoid the circular reference issue.
This is not working for me as OpenApiIgnoreAttibute seems to only be valid for AttributeTargets.Method
.
@john-patterson Oops my bad. I meant JsonIgnore
.
@justinyoo ah. Okay, yeah I see in the code where that gets selected out. Unfortunately JsonIgnore
isn't a great general solution as my other serializers handle my class just fine (my class Reviewer
has an array of reviewers for whom they vote, based on the Azure DevOps type IdentityRefWithVote
).
Is there opposition to a PR that generalizes OpenApiIgnore
a bit to target properties and fields as well along with a patch to the RecursiveObjectTypeVisitor
, ObjectTypeVisitor
, and TypeExtensions
? This should be backward compatible as JsonIgnore
will still result in ignoring the attribute and OpenApiIgnore
on methods will continue to behave the same.
If this works from a product management perspective, I can get a PR thrown together later today.
@vlaskal Thanks for your suggestion! What I'm suspecting where the StackOverflowException or CircularReferenceException occurs is these two parts:
Adding the reference schemas should also be done before traversing each type's properties.
It would be great if you can have a look. Once it's fixed, @john-patterson you wouldn't need to extend the OpenApiIgnore
decorator.
@justinyoo Thanks for hints. I will try too look at it and will reach you back.
I have the same issue and a possible solution in #467
I'm also getting this error without any luck using the IgnoreJson
attribute on circular references.
Here is a code sample to reproduce the issue:
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:
And introducing new property "public Owner Owner { get; set; }" in Pet class