Code Monkey home page Code Monkey logo

Comments (10)

glennular avatar glennular commented on June 5, 2024 1

I ran into the same issue when typing to adopt the new release.

Fixed in #42

from azurefunctions.extensions.

justinyoo avatar justinyoo commented on June 5, 2024 1

And also for lists it doesn't work. So any List doesn't add a schema definition.

[OpenApiResponseBody(HttpStatusCode.OK, "application/json", typeof(List<T>))]

However when T is added as root response body then it works again.

[OpenApiResponseBody(HttpStatusCode.OK, "application/json", typeof(T))]

This has been fixed in 1.5.3. Can you double check at your end?

from azurefunctions.extensions.

DibranMulder avatar DibranMulder commented on June 5, 2024

I think the bug is in GetOpenApiSchemas, it filters out Array's. But what if my type is only used in lists? Then it isn't part of the schema. In my opinion these things have to be fixed:

  1. Use the IsOpenApiArray check to determine if the type is an array.
  2. If its an Array then the ElementType or the Generic SubType has to be selected. Just like in the ToOpenApiSchema method. (type.GetElementType() ?? type.GetGenericArguments()[0])
public Dictionary<string, OpenApiSchema> GetOpenApiSchemas(List<MethodInfo> elements)
{
    var requests = elements.SelectMany(p => p.GetCustomAttributes<OpenApiRequestBodyAttribute>(inherit: false))
                            .Select(p => p.BodyType);
    var responses = elements.SelectMany(p => p.GetCustomAttributes<OpenApiResponseBodyAttribute>(inherit: false))
                            .Select(p => p.BodyType);
    var types = requests.Union(responses)
                        .Distinct()
                        .Where(p => p != typeof(JObject))
                        .Where(p => p != typeof(JToken))
                        .Where(p => !typeof(Array).IsAssignableFrom(p))
                        .Where(p => !p.IsGenericType)
                        ;
    var schemas = types.ToDictionary(p => p.Name, p => p.ToOpenApiSchema());

    return schemas;
}

from azurefunctions.extensions.

justinyoo avatar justinyoo commented on June 5, 2024

@DibranMulder Can you show me the class definition of PagedViewModel<T> and MessageViewModel?

from azurefunctions.extensions.

justinyoo avatar justinyoo commented on June 5, 2024

Apparently @glennular 's PR #42 has sorted out the issue at a certain level, but I'm not sure whether it's solved your issue or not.

from azurefunctions.extensions.

DibranMulder avatar DibranMulder commented on June 5, 2024

Apparently @glennular 's PR #42 has sorted out the issue at a certain level, but I'm not sure whether it's solved your issue or not.

public class PagedViewModel<T>
{
    public int PageIndex { get; set; }
    public int TotalResults { get; set; }
    public IEnumerable<T> Results { get; set; }
}

public class MessageViewModel
{
    public int Id { get; set; }
    public short Severity { get; set; }
    public string Type { get; set; }
    public string Message { get; set; }
    public string ProductId { get; set; }
    public DateTime TimeStamp { get; set; }
    public bool Read { get; set; }
}

And also for lists it doesn't work. So any List doesn't add a schema definition.

[OpenApiResponseBody(HttpStatusCode.OK, "application/json", typeof(List<T>))]

However when T is added as root response body then it works again.

[OpenApiResponseBody(HttpStatusCode.OK, "application/json", typeof(T))]

I think this is because all generic types are filtered out.

from azurefunctions.extensions.

DibranMulder avatar DibranMulder commented on June 5, 2024

Can confirm that Lists work.
image

However Generic is still broken.
image
image

from azurefunctions.extensions.

justinyoo avatar justinyoo commented on June 5, 2024

@DibranMulder Yes, the generic still needs more work. Thanks for confirming the List<T> bit!

from azurefunctions.extensions.

justinyoo avatar justinyoo commented on June 5, 2024

@DibranMulder The generics has been fixed and released to NuGet. Thanks for your patience!

from azurefunctions.extensions.

Dan-Williams93 avatar Dan-Williams93 commented on June 5, 2024

Hi @justinyoo, it looks like the response type with generics described by @DibranMulder is still an issue in the latest release. I am currently trying to make use of the OpenApiResponseBody attribute in the same way, using the example as below

    public class GenericModel<T>
    {
        public IEnumerable<T> Results { get; set; }
    }

    public class MyExampleType
    {
        public string SomeValue { get; set; }
    }

    [OpenApiResponseBody(HttpStatusCode.OK, "application/json", typeof(GenericModel<MyExampleType>))]

However, when looking at the definition, the generic model is shown as the response type but it fails to show the internal generic enumerable as it is not defined in the schema definition.

image

image

from azurefunctions.extensions.

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.