From fde7d4d21e8121b446f83bac42c4805544458130 Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Thu, 1 Feb 2024 11:20:50 +0300 Subject: [PATCH 1/3] Generate expand for operations that return a collection --- .../Operation/EdmOperationOperationHandler.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/EdmOperationOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/EdmOperationOperationHandler.cs index ad19be745..c6b86f36a 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/EdmOperationOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/EdmOperationOperationHandler.cs @@ -249,6 +249,12 @@ private void AppendSystemQueryOptions(IEdmFunction function, OpenApiOperation op { operation.Parameters.AppendParameter(orderbyParameter); } + + // $expand + if (Context.CreateExpand(function, entityType) is OpenApiParameter expandParameter) + { + operation.Parameters.AppendParameter(expandParameter); + } } } } From 9092c0145877dbc40e94715aee8ce8e0af4b8e55 Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Thu, 1 Feb 2024 11:21:12 +0300 Subject: [PATCH 2/3] Update tests --- .../Resources/TripService.OpenApi.V2.json | 144 +++++++++++++ .../Resources/TripService.OpenApi.V2.yaml | 104 ++++++++++ .../Resources/TripService.OpenApi.json | 194 ++++++++++++++++++ .../Resources/TripService.OpenApi.yaml | 144 +++++++++++++ 4 files changed, 586 insertions(+) diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.V2.json b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.V2.json index 614be48e7..d9be7bed6 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.V2.json +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.V2.json @@ -7082,6 +7082,21 @@ ], "type": "string" } + }, + { + "in": "query", + "name": "$expand", + "description": "Expand related entities", + "type": "array", + "items": { + "enum": [ + "*", + "Friends", + "BestFriend", + "Trips" + ], + "type": "string" + } } ], "responses": { @@ -7630,6 +7645,19 @@ ], "type": "string" } + }, + { + "in": "query", + "name": "$expand", + "description": "Expand related entities", + "type": "array", + "items": { + "enum": [ + "*", + "PlanItems" + ], + "type": "string" + } } ], "responses": { @@ -11102,6 +11130,21 @@ ], "type": "string" } + }, + { + "in": "query", + "name": "$expand", + "description": "Expand related entities", + "type": "array", + "items": { + "enum": [ + "*", + "Friends", + "BestFriend", + "Trips" + ], + "type": "string" + } } ], "responses": { @@ -12042,6 +12085,21 @@ ], "type": "string" } + }, + { + "in": "query", + "name": "$expand", + "description": "Expand related entities", + "type": "array", + "items": { + "enum": [ + "*", + "Friends", + "BestFriend", + "Trips" + ], + "type": "string" + } } ], "responses": { @@ -15441,6 +15499,19 @@ ], "type": "string" } + }, + { + "in": "query", + "name": "$expand", + "description": "Expand related entities", + "type": "array", + "items": { + "enum": [ + "*", + "PlanItems" + ], + "type": "string" + } } ], "responses": { @@ -16042,6 +16113,21 @@ ], "type": "string" } + }, + { + "in": "query", + "name": "$expand", + "description": "Expand related entities", + "type": "array", + "items": { + "enum": [ + "*", + "Friends", + "BestFriend", + "Trips" + ], + "type": "string" + } } ], "responses": { @@ -23441,6 +23527,21 @@ ], "type": "string" } + }, + { + "in": "query", + "name": "$expand", + "description": "Expand related entities", + "type": "array", + "items": { + "enum": [ + "*", + "Friends", + "BestFriend", + "Trips" + ], + "type": "string" + } } ], "responses": { @@ -24063,6 +24164,19 @@ ], "type": "string" } + }, + { + "in": "query", + "name": "$expand", + "description": "Expand related entities", + "type": "array", + "items": { + "enum": [ + "*", + "PlanItems" + ], + "type": "string" + } } ], "responses": { @@ -28079,6 +28193,21 @@ ], "type": "string" } + }, + { + "in": "query", + "name": "$expand", + "description": "Expand related entities", + "type": "array", + "items": { + "enum": [ + "*", + "Friends", + "BestFriend", + "Trips" + ], + "type": "string" + } } ], "responses": { @@ -29139,6 +29268,21 @@ ], "type": "string" } + }, + { + "in": "query", + "name": "$expand", + "description": "Expand related entities", + "type": "array", + "items": { + "enum": [ + "*", + "Friends", + "BestFriend", + "Trips" + ], + "type": "string" + } } ], "responses": { diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.V2.yaml b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.V2.yaml index aaac5390b..095fb4536 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.V2.yaml +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.V2.yaml @@ -4925,6 +4925,17 @@ paths: - Features - Features desc type: string + - in: query + name: $expand + description: Expand related entities + type: array + items: + enum: + - '*' + - Friends + - BestFriend + - Trips + type: string responses: '200': description: Success @@ -5310,6 +5321,15 @@ paths: - EndsAt - EndsAt desc type: string + - in: query + name: $expand + description: Expand related entities + type: array + items: + enum: + - '*' + - PlanItems + type: string responses: '200': $ref: '#/responses/GetFriendsTripsResponse' @@ -7742,6 +7762,17 @@ paths: - Features - Features desc type: string + - in: query + name: $expand + description: Expand related entities + type: array + items: + enum: + - '*' + - Friends + - BestFriend + - Trips + type: string responses: '200': description: Success @@ -8414,6 +8445,17 @@ paths: - Features - Features desc type: string + - in: query + name: $expand + description: Expand related entities + type: array + items: + enum: + - '*' + - Friends + - BestFriend + - Trips + type: string responses: '200': description: Success @@ -10781,6 +10823,15 @@ paths: - EndsAt - EndsAt desc type: string + - in: query + name: $expand + description: Expand related entities + type: array + items: + enum: + - '*' + - PlanItems + type: string responses: '200': $ref: '#/responses/GetFriendsTripsResponse' @@ -11209,6 +11260,17 @@ paths: - Features - Features desc type: string + - in: query + name: $expand + description: Expand related entities + type: array + items: + enum: + - '*' + - Friends + - BestFriend + - Trips + type: string responses: '200': description: Success @@ -16432,6 +16494,17 @@ paths: - Features - Features desc type: string + - in: query + name: $expand + description: Expand related entities + type: array + items: + enum: + - '*' + - Friends + - BestFriend + - Trips + type: string responses: '200': description: Success @@ -16872,6 +16945,15 @@ paths: - EndsAt - EndsAt desc type: string + - in: query + name: $expand + description: Expand related entities + type: array + items: + enum: + - '*' + - PlanItems + type: string responses: '200': $ref: '#/responses/GetFriendsTripsResponse' @@ -19709,6 +19791,17 @@ paths: - Features - Features desc type: string + - in: query + name: $expand + description: Expand related entities + type: array + items: + enum: + - '*' + - Friends + - BestFriend + - Trips + type: string responses: '200': description: Success @@ -20471,6 +20564,17 @@ paths: - Features - Features desc type: string + - in: query + name: $expand + description: Expand related entities + type: array + items: + enum: + - '*' + - Friends + - BestFriend + - Trips + type: string responses: '200': description: Success diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.json b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.json index 635ce3f41..2270b453b 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.json +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.json @@ -7761,6 +7761,26 @@ "type": "string" } } + }, + { + "name": "$expand", + "in": "query", + "description": "Expand related entities", + "style": "form", + "explode": false, + "schema": { + "uniqueItems": true, + "type": "array", + "items": { + "enum": [ + "*", + "Friends", + "BestFriend", + "Trips" + ], + "type": "string" + } + } } ], "responses": { @@ -8373,6 +8393,24 @@ "type": "string" } } + }, + { + "name": "$expand", + "in": "query", + "description": "Expand related entities", + "style": "form", + "explode": false, + "schema": { + "uniqueItems": true, + "type": "array", + "items": { + "enum": [ + "*", + "PlanItems" + ], + "type": "string" + } + } } ], "responses": { @@ -12183,6 +12221,26 @@ "type": "string" } } + }, + { + "name": "$expand", + "in": "query", + "description": "Expand related entities", + "style": "form", + "explode": false, + "schema": { + "uniqueItems": true, + "type": "array", + "items": { + "enum": [ + "*", + "Friends", + "BestFriend", + "Trips" + ], + "type": "string" + } + } } ], "responses": { @@ -13223,6 +13281,26 @@ "type": "string" } } + }, + { + "name": "$expand", + "in": "query", + "description": "Expand related entities", + "style": "form", + "explode": false, + "schema": { + "uniqueItems": true, + "type": "array", + "items": { + "enum": [ + "*", + "Friends", + "BestFriend", + "Trips" + ], + "type": "string" + } + } } ], "responses": { @@ -17073,6 +17151,24 @@ "type": "string" } } + }, + { + "name": "$expand", + "in": "query", + "description": "Expand related entities", + "style": "form", + "explode": false, + "schema": { + "uniqueItems": true, + "type": "array", + "items": { + "enum": [ + "*", + "PlanItems" + ], + "type": "string" + } + } } ], "responses": { @@ -17753,6 +17849,26 @@ "type": "string" } } + }, + { + "name": "$expand", + "in": "query", + "description": "Expand related entities", + "style": "form", + "explode": false, + "schema": { + "uniqueItems": true, + "type": "array", + "items": { + "enum": [ + "*", + "Friends", + "BestFriend", + "Trips" + ], + "type": "string" + } + } } ], "responses": { @@ -26010,6 +26126,26 @@ "type": "string" } } + }, + { + "name": "$expand", + "in": "query", + "description": "Expand related entities", + "style": "form", + "explode": false, + "schema": { + "uniqueItems": true, + "type": "array", + "items": { + "enum": [ + "*", + "Friends", + "BestFriend", + "Trips" + ], + "type": "string" + } + } } ], "responses": { @@ -26714,6 +26850,24 @@ "type": "string" } } + }, + { + "name": "$expand", + "in": "query", + "description": "Expand related entities", + "style": "form", + "explode": false, + "schema": { + "uniqueItems": true, + "type": "array", + "items": { + "enum": [ + "*", + "PlanItems" + ], + "type": "string" + } + } } ], "responses": { @@ -31230,6 +31384,26 @@ "type": "string" } } + }, + { + "name": "$expand", + "in": "query", + "description": "Expand related entities", + "style": "form", + "explode": false, + "schema": { + "uniqueItems": true, + "type": "array", + "items": { + "enum": [ + "*", + "Friends", + "BestFriend", + "Trips" + ], + "type": "string" + } + } } ], "responses": { @@ -32424,6 +32598,26 @@ "type": "string" } } + }, + { + "name": "$expand", + "in": "query", + "description": "Expand related entities", + "style": "form", + "explode": false, + "schema": { + "uniqueItems": true, + "type": "array", + "items": { + "enum": [ + "*", + "Friends", + "BestFriend", + "Trips" + ], + "type": "string" + } + } } ], "responses": { diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.yaml b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.yaml index 2f1e6be26..898d710af 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.yaml +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.yaml @@ -5385,6 +5385,21 @@ paths: - Features - Features desc type: string + - name: $expand + in: query + description: Expand related entities + style: form + explode: false + schema: + uniqueItems: true + type: array + items: + enum: + - '*' + - Friends + - BestFriend + - Trips + type: string responses: '200': description: Success @@ -5813,6 +5828,19 @@ paths: - EndsAt - EndsAt desc type: string + - name: $expand + in: query + description: Expand related entities + style: form + explode: false + schema: + uniqueItems: true + type: array + items: + enum: + - '*' + - PlanItems + type: string responses: '200': $ref: '#/components/responses/GetFriendsTripsResponse' @@ -8479,6 +8507,21 @@ paths: - Features - Features desc type: string + - name: $expand + in: query + description: Expand related entities + style: form + explode: false + schema: + uniqueItems: true + type: array + items: + enum: + - '*' + - Friends + - BestFriend + - Trips + type: string responses: '200': description: Success @@ -9219,6 +9262,21 @@ paths: - Features - Features desc type: string + - name: $expand + in: query + description: Expand related entities + style: form + explode: false + schema: + uniqueItems: true + type: array + items: + enum: + - '*' + - Friends + - BestFriend + - Trips + type: string responses: '200': description: Success @@ -11879,6 +11937,19 @@ paths: - EndsAt - EndsAt desc type: string + - name: $expand + in: query + description: Expand related entities + style: form + explode: false + schema: + uniqueItems: true + type: array + items: + enum: + - '*' + - PlanItems + type: string responses: '200': $ref: '#/components/responses/GetFriendsTripsResponse' @@ -12356,6 +12427,21 @@ paths: - Features - Features desc type: string + - name: $expand + in: query + description: Expand related entities + style: form + explode: false + schema: + uniqueItems: true + type: array + items: + enum: + - '*' + - Friends + - BestFriend + - Trips + type: string responses: '200': description: Success @@ -18129,6 +18215,21 @@ paths: - Features - Features desc type: string + - name: $expand + in: query + description: Expand related entities + style: form + explode: false + schema: + uniqueItems: true + type: array + items: + enum: + - '*' + - Friends + - BestFriend + - Trips + type: string responses: '200': description: Success @@ -18621,6 +18722,19 @@ paths: - EndsAt - EndsAt desc type: string + - name: $expand + in: query + description: Expand related entities + style: form + explode: false + schema: + uniqueItems: true + type: array + items: + enum: + - '*' + - PlanItems + type: string responses: '200': $ref: '#/components/responses/GetFriendsTripsResponse' @@ -21774,6 +21888,21 @@ paths: - Features - Features desc type: string + - name: $expand + in: query + description: Expand related entities + style: form + explode: false + schema: + uniqueItems: true + type: array + items: + enum: + - '*' + - Friends + - BestFriend + - Trips + type: string responses: '200': description: Success @@ -22621,6 +22750,21 @@ paths: - Features - Features desc type: string + - name: $expand + in: query + description: Expand related entities + style: form + explode: false + schema: + uniqueItems: true + type: array + items: + enum: + - '*' + - Friends + - BestFriend + - Trips + type: string responses: '200': description: Success From 429ee7720cae9c3d0574f1366b4ee55e5db1b509 Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Thu, 1 Feb 2024 11:27:32 +0300 Subject: [PATCH 3/3] Update release note --- .../Microsoft.OpenAPI.OData.Reader.csproj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj b/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj index fab1671d9..c9dfa666a 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj +++ b/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj @@ -15,7 +15,7 @@ netstandard2.0 Microsoft.OpenApi.OData true - 1.6.0-preview.4 + 1.6.0-preview.5 This package contains the codes you need to convert OData CSDL to Open API Document of Model. © Microsoft Corporation. All rights reserved. Microsoft OpenApi OData EDM @@ -25,6 +25,7 @@ - Updates the format of the request body schema of a collection of complex property #423 - Adds a delete operation and a required @id query parameter to collection-valued navigation property paths with $ref #453 - Fixes inconsistency of nullability of schemas of properties that are a collection of structured types #467 +- Generates $expand query parameter for operations whose return type is a collection #481 Microsoft.OpenApi.OData.Reader ..\..\tool\Microsoft.OpenApi.OData.snk