Comments (10)
I ran into the same issue when typing to adopt the new release.
Fixed in #42
from azurefunctions.extensions.
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.
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:
- Use the
IsOpenApiArray
check to determine if the type is an array. - 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.
@DibranMulder Can you show me the class definition of PagedViewModel<T>
and MessageViewModel
?
from azurefunctions.extensions.
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.
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.
However Generic is still broken.
from azurefunctions.extensions.
@DibranMulder Yes, the generic still needs more work. Thanks for confirming the List<T>
bit!
from azurefunctions.extensions.
@DibranMulder The generics has been fixed and released to NuGet. Thanks for your patience!
from azurefunctions.extensions.
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.
from azurefunctions.extensions.
Related Issues (20)
- Get EnumMember Value HOT 1
- Generic types makes yaml definition non-compliant
- Documentation stale - OpenApiResponseBody should be OpenApiResponseWithBodyAttribute HOT 1
- ReflectionTypeLoadException when running CLI HOT 2
- An item with the same key has already been added.
- StackOverflow Exception HOT 5
- Property description added to field? HOT 3
- Updating Authorization Level and Base URL HOT 5
- Generic delimiter selector
- Can we specify our own swagger.json file? HOT 1
- Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' HOT 2
- Mark an endpoint as deprecated HOT 2
- OpenApiHttpTriggerContext.cs generates a compiler warning when using C#8 nullable reference types HOT 2
- default "Code" query string on all functions HOT 1
- Missing list item type definition HOT 2
- authentication settings HOT 2
- Resolver error for dictionary properties in swagger UI OpenApi 3.1.1 HOT 1
- FileUpload support HOT 2
- Upgrade for dependencies packages
- Support for isolated function and HttpRequestData over HttpRequest? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from azurefunctions.extensions.