Resolves response schemas of actions/functions that return collection (#117)

* Update response schema of action/functions that return a collection

* Update Title to use entity type name for the previous segment

* Update test files data appropriately
This commit is contained in:
Irvine Sunday 2021-09-21 12:05:41 +03:00 committed by GitHub
parent 3cce51566f
commit da7f51abbf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 365 additions and 163 deletions

View file

@ -172,6 +172,28 @@ namespace Microsoft.OpenApi.OData.Operation
}
else
{
OpenApiSchema schema;
if (EdmOperation.ReturnType.TypeKind() == EdmTypeKind.Collection)
{
// Get the entity type of the previous segment
IEdmEntityType entityType = Path.Segments.Reverse().Skip(1).Take(1).FirstOrDefault().EntityType;
schema = new OpenApiSchema
{
Title = $"Collection of {entityType.Name}",
Type = "object",
Properties = new Dictionary<string, OpenApiSchema>
{
{
"value", Context.CreateEdmTypeSchema(EdmOperation.ReturnType)
}
}
};
}
else
{
schema = Context.CreateEdmTypeSchema(EdmOperation.ReturnType);
}
// function should have a return type.
OpenApiResponse response = new OpenApiResponse
{
@ -182,7 +204,7 @@ namespace Microsoft.OpenApi.OData.Operation
Constants.ApplicationJsonMediaType,
new OpenApiMediaType
{
Schema = Context.CreateEdmTypeSchema(EdmOperation.ReturnType)
Schema = schema
}
}
}

View file

@ -1169,9 +1169,15 @@
"200": {
"description": "Success",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip"
"title": "Collection of Person",
"type": "object",
"properties": {
"value": {
"type": "array",
"items": {
"$ref": "#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip"
}
}
}
}
},
@ -1221,9 +1227,15 @@
"200": {
"description": "Success",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person"
"title": "Collection of Person",
"type": "object",
"properties": {
"value": {
"type": "array",
"items": {
"$ref": "#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person"
}
}
}
}
},
@ -1636,9 +1648,15 @@
"200": {
"description": "Success",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person"
"title": "Collection of Trip",
"type": "object",
"properties": {
"value": {
"type": "array",
"items": {
"$ref": "#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person"
}
}
}
}
},
@ -2814,9 +2832,15 @@
"200": {
"description": "Success",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip"
"title": "Collection of Person",
"type": "object",
"properties": {
"value": {
"type": "array",
"items": {
"$ref": "#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip"
}
}
}
}
},
@ -2874,9 +2898,15 @@
"200": {
"description": "Success",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person"
"title": "Collection of Person",
"type": "object",
"properties": {
"value": {
"type": "array",
"items": {
"$ref": "#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person"
}
}
}
}
},
@ -3353,9 +3383,15 @@
"200": {
"description": "Success",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person"
"title": "Collection of Trip",
"type": "object",
"properties": {
"value": {
"type": "array",
"items": {
"$ref": "#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person"
}
}
}
}
},
@ -4563,9 +4599,15 @@
"200": {
"description": "Success",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip"
"title": "Collection of Person",
"type": "object",
"properties": {
"value": {
"type": "array",
"items": {
"$ref": "#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip"
}
}
}
}
},
@ -4623,9 +4665,15 @@
"200": {
"description": "Success",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person"
"title": "Collection of Person",
"type": "object",
"properties": {
"value": {
"type": "array",
"items": {
"$ref": "#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person"
}
}
}
}
},
@ -5102,9 +5150,15 @@
"200": {
"description": "Success",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person"
"title": "Collection of Trip",
"type": "object",
"properties": {
"value": {
"type": "array",
"items": {
"$ref": "#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person"
}
}
}
}
},

View file

@ -801,9 +801,13 @@ paths:
'200':
description: Success
schema:
type: array
items:
$ref: '#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip'
title: Collection of Person
type: object
properties:
value:
type: array
items:
$ref: '#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip'
default:
$ref: '#/responses/error'
x-ms-docs-operation-type: function
@ -836,9 +840,13 @@ paths:
'200':
description: Success
schema:
type: array
items:
$ref: '#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person'
title: Collection of Person
type: object
properties:
value:
type: array
items:
$ref: '#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person'
default:
$ref: '#/responses/error'
x-ms-docs-operation-type: action
@ -1127,9 +1135,13 @@ paths:
'200':
description: Success
schema:
type: array
items:
$ref: '#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person'
title: Collection of Trip
type: object
properties:
value:
type: array
items:
$ref: '#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person'
default:
$ref: '#/responses/error'
x-ms-docs-operation-type: function
@ -1952,9 +1964,13 @@ paths:
'200':
description: Success
schema:
type: array
items:
$ref: '#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip'
title: Collection of Person
type: object
properties:
value:
type: array
items:
$ref: '#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip'
default:
$ref: '#/responses/error'
x-ms-docs-operation-type: function
@ -1993,9 +2009,13 @@ paths:
'200':
description: Success
schema:
type: array
items:
$ref: '#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person'
title: Collection of Person
type: object
properties:
value:
type: array
items:
$ref: '#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person'
default:
$ref: '#/responses/error'
x-ms-docs-operation-type: action
@ -2332,9 +2352,13 @@ paths:
'200':
description: Success
schema:
type: array
items:
$ref: '#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person'
title: Collection of Trip
type: object
properties:
value:
type: array
items:
$ref: '#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person'
default:
$ref: '#/responses/error'
x-ms-docs-operation-type: function
@ -3181,9 +3205,13 @@ paths:
'200':
description: Success
schema:
type: array
items:
$ref: '#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip'
title: Collection of Person
type: object
properties:
value:
type: array
items:
$ref: '#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip'
default:
$ref: '#/responses/error'
x-ms-docs-operation-type: function
@ -3222,9 +3250,13 @@ paths:
'200':
description: Success
schema:
type: array
items:
$ref: '#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person'
title: Collection of Person
type: object
properties:
value:
type: array
items:
$ref: '#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person'
default:
$ref: '#/responses/error'
x-ms-docs-operation-type: action
@ -3561,9 +3593,13 @@ paths:
'200':
description: Success
schema:
type: array
items:
$ref: '#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person'
title: Collection of Trip
type: object
properties:
value:
type: array
items:
$ref: '#/definitions/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person'
default:
$ref: '#/responses/error'
x-ms-docs-operation-type: function

View file

@ -1331,14 +1331,20 @@
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip"
"title": "Collection of Person",
"type": "object",
"properties": {
"value": {
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip"
}
],
"nullable": true
}
],
"nullable": true
}
}
}
}
@ -1386,14 +1392,20 @@
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person"
"title": "Collection of Person",
"type": "object",
"properties": {
"value": {
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person"
}
],
"nullable": true
}
],
"nullable": true
}
}
}
}
@ -1841,14 +1853,20 @@
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person"
"title": "Collection of Trip",
"type": "object",
"properties": {
"value": {
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person"
}
],
"nullable": true
}
],
"nullable": true
}
}
}
}
@ -3162,14 +3180,20 @@
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip"
"title": "Collection of Person",
"type": "object",
"properties": {
"value": {
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip"
}
],
"nullable": true
}
],
"nullable": true
}
}
}
}
@ -3229,14 +3253,20 @@
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person"
"title": "Collection of Person",
"type": "object",
"properties": {
"value": {
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person"
}
],
"nullable": true
}
],
"nullable": true
}
}
}
}
@ -3768,14 +3798,20 @@
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person"
"title": "Collection of Trip",
"type": "object",
"properties": {
"value": {
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person"
}
],
"nullable": true
}
],
"nullable": true
}
}
}
}
@ -5129,14 +5165,20 @@
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip"
"title": "Collection of Person",
"type": "object",
"properties": {
"value": {
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip"
}
],
"nullable": true
}
],
"nullable": true
}
}
}
}
@ -5196,14 +5238,20 @@
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person"
"title": "Collection of Person",
"type": "object",
"properties": {
"value": {
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person"
}
],
"nullable": true
}
],
"nullable": true
}
}
}
}
@ -5735,14 +5783,20 @@
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person"
"title": "Collection of Trip",
"type": "object",
"properties": {
"value": {
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person"
}
],
"nullable": true
}
],
"nullable": true
}
}
}
}

View file

@ -894,11 +894,15 @@ paths:
content:
application/json:
schema:
type: array
items:
anyOf:
- $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip'
nullable: true
title: Collection of Person
type: object
properties:
value:
type: array
items:
anyOf:
- $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip'
nullable: true
default:
$ref: '#/components/responses/error'
x-ms-docs-operation-type: function
@ -929,11 +933,15 @@ paths:
content:
application/json:
schema:
type: array
items:
anyOf:
- $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person'
nullable: true
title: Collection of Person
type: object
properties:
value:
type: array
items:
anyOf:
- $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person'
nullable: true
default:
$ref: '#/components/responses/error'
x-ms-docs-operation-type: action
@ -1243,11 +1251,15 @@ paths:
content:
application/json:
schema:
type: array
items:
anyOf:
- $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person'
nullable: true
title: Collection of Trip
type: object
properties:
value:
type: array
items:
anyOf:
- $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person'
nullable: true
default:
$ref: '#/components/responses/error'
x-ms-docs-operation-type: function
@ -2152,11 +2164,15 @@ paths:
content:
application/json:
schema:
type: array
items:
anyOf:
- $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip'
nullable: true
title: Collection of Person
type: object
properties:
value:
type: array
items:
anyOf:
- $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip'
nullable: true
default:
$ref: '#/components/responses/error'
x-ms-docs-operation-type: function
@ -2195,11 +2211,15 @@ paths:
content:
application/json:
schema:
type: array
items:
anyOf:
- $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person'
nullable: true
title: Collection of Person
type: object
properties:
value:
type: array
items:
anyOf:
- $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person'
nullable: true
default:
$ref: '#/components/responses/error'
x-ms-docs-operation-type: action
@ -2567,11 +2587,15 @@ paths:
content:
application/json:
schema:
type: array
items:
anyOf:
- $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person'
nullable: true
title: Collection of Trip
type: object
properties:
value:
type: array
items:
anyOf:
- $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person'
nullable: true
default:
$ref: '#/components/responses/error'
x-ms-docs-operation-type: function
@ -3504,11 +3528,15 @@ paths:
content:
application/json:
schema:
type: array
items:
anyOf:
- $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip'
nullable: true
title: Collection of Person
type: object
properties:
value:
type: array
items:
anyOf:
- $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Trip'
nullable: true
default:
$ref: '#/components/responses/error'
x-ms-docs-operation-type: function
@ -3547,11 +3575,15 @@ paths:
content:
application/json:
schema:
type: array
items:
anyOf:
- $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person'
nullable: true
title: Collection of Person
type: object
properties:
value:
type: array
items:
anyOf:
- $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person'
nullable: true
default:
$ref: '#/components/responses/error'
x-ms-docs-operation-type: action
@ -3919,11 +3951,15 @@ paths:
content:
application/json:
schema:
type: array
items:
anyOf:
- $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person'
nullable: true
title: Collection of Trip
type: object
properties:
value:
type: array
items:
anyOf:
- $ref: '#/components/schemas/Microsoft.OData.Service.Sample.TrippinInMemory.Models.Person'
nullable: true
default:
$ref: '#/components/responses/error'
x-ms-docs-operation-type: function