OpenAPI.NET.OData
OpenAPI.NET.OData copied to clipboard
Add support for @odata.context and @odata.count
We have paging support and can specify $count=true
to get the count of all elements.
Unfortunately there's no way to get @odata.count
value from a response.
Without this OData paging features are kind of unusable. In order to add it I modified the document approximately like this:
foreach (var path in document.Paths.Values)
{
foreach (var operation in path.Operations.Values)
{
if (operation.OperationId.Contains(".List", StringComparison.Ordinal))
{
var props = operation.Responses["200"].Content["application/json"].Schema.Properties;
props.Add("@odata.context", new OpenApiSchema()
{
Type = "string"
});
props.Add("@odata.count", new OpenApiSchema()
{
Type = "integer",
Format = "int32"
});
}
}
}
Thanks for reporting this gap @sherlock1982 . @CarolKigoonya @irvinesunday I added this to the backlog (p3).
To provide more context on this one, we have recently moved to using component schemas for this to avoid duplication across endpoints.
I believe we should introduce a base type to avoid duplication of properties.
+ microsoft.graph.baseCollectionResponse:
+ title: Collection response
+ type: object
+ properties:
+ '@odata.nextLink':
+ type: string
+ '@odata.context':
+ type: string
+ '@odata.count':
+ type: int64
microsoft.graph.userCollectionResponse:
+ allOf:
+ - '#/components/schemas/microsoft.graph.baseCollectionResponse'
+ - schema:
+ type: object
+ properties:
+ value:
+ type: array
+ items:
+ $ref: '#/components/schemas/microsoft.graph.user'
title: Collection of user
type: object
- properties:
- value:
- type: array
- items:
- $ref: '#/components/schemas/microsoft.graph.user'
- '@odata.nextLink':
- type: string
@sherlock1982 Do you have a need for @odata.context? I understand how count and nextlink are useful but to date the only tooling that I have seen that uses @odata.context is native OData tooling and therefore does not seem useful in an OpenAPI description.
It's ok without @odata.context
.
Thought to add it just because it exists :-)
I'm not sure though how nextLink
can be natively supported.