Giter Site home page Giter Site logo

Comments (10)

justinyoo avatar justinyoo commented on May 26, 2024

@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.

from azure-functions-openapi-extension.

justinyoo avatar justinyoo commented on May 26, 2024

@Frankyfrankly I'll close the issue for now. If you'd like to discuss more on this, please open a new issue.

from azure-functions-openapi-extension.

justinyoo avatar justinyoo commented on May 26, 2024

Related to: aliencube/AzureFunctions.Extensions#134

from azure-functions-openapi-extension.

vlaskal avatar vlaskal commented on May 26, 2024

Hi @justinyoo ,

I run into same problem as is described aliencube/AzureFunctions.Extensions#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
image
I am open to help in investigation of the issue.

from azure-functions-openapi-extension.

john-patterson avatar john-patterson commented on May 26, 2024

...

    [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.

from azure-functions-openapi-extension.

justinyoo avatar justinyoo commented on May 26, 2024

@john-patterson Oops my bad. I meant JsonIgnore.

from azure-functions-openapi-extension.

john-patterson avatar john-patterson commented on May 26, 2024

@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.

from azure-functions-openapi-extension.

justinyoo avatar justinyoo commented on May 26, 2024

@vlaskal Thanks for your suggestion! What I'm suspecting where the StackOverflowException or CircularReferenceException occurs is these two parts:

foreach (var schema in schemasToBeAdded.Where(p => p.Key != "jObject" && p.Key != "jToken"))
{
if (instance.RootSchemas.ContainsKey(schema.Key))
{
continue;
}
instance.RootSchemas.Add(schema.Key, schema.Value);
}

Adding the reference schemas should also be done before traversing each type's properties.

var instance = acceptor as OpenApiSchemaAcceptor;
if (instance.IsNullOrDefault())
{
return;
}
// Processes properties.
var properties = type.Value
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Where(p => !p.ExistsCustomAttribute<JsonIgnoreAttribute>())
.ToDictionary(p => p.GetJsonPropertyName(namingStrategy), p => p);
this.ProcessProperties(instance, name, properties, namingStrategy);

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.

from azure-functions-openapi-extension.

vlaskal avatar vlaskal commented on May 26, 2024

@justinyoo Thanks for hints. I will try too look at it and will reach you back.

from azure-functions-openapi-extension.

AndeyLapkoMobiDev avatar AndeyLapkoMobiDev commented on May 26, 2024

I have the same issue and a possible solution in #467

from azure-functions-openapi-extension.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.