Skip to content

Commit bda0d65

Browse files
OpenAPI - Distinguish between stored procedure parameters and result set columns (#1551)
## Why make this change? - Closes #1509 ## What is this change? - The OpenApiDocumentor service now correctly distinguishes between input parameters and result set columns when documenting a stored procedures REST endpoint. Previously, only the result set columns were resolved. As a result, the OpenApi document that is generated now shows input parameters as fields to be used in the request bodies of POST, PUT, and PATCH. (GET and DELETE have no request bodies). ## How was this tested? - [x] Integration Tests - Added tests with additional stored procedures in our sql deployment script which demonstrates how parameters and output result set columns (and their JSON data types) are resolved and included in the open api doc. ## OpenAPI document example An example OpenAPI document which helps visualize how the parsing works. Irrelevant fields were removed. ```json { "openapi": "3.0.1", "paths": { "/sp1": { "get": {"..."}, "post": { "tags": [ "sp1" ], "description": "Executes a stored procedure.", "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/sp1_sp_request" } } }, "required": true }, "responses": { "201": { "description": "Created", "content": { "application/json": { "schema": { "properties": { "value": { "type": "array", "items": { "$ref": "#/components/schemas/sp1_sp_response" } } } } } } }, "400": { "description": "BadRequest" } } } } }, "components": { "schemas": { "sp1_sp_request": { "type": "object", "properties": { "inputName": { "type": "string", "format": "" } } }, "sp1_sp_response": { "type": "object", "properties": { "outputName": { "type": "string", "format": "" } } } } } } ``` --------- Co-authored-by: Aniruddh Munde <[email protected]>
1 parent 7c20fe2 commit bda0d65

File tree

9 files changed

+457
-42
lines changed

9 files changed

+457
-42
lines changed

src/Core/Services/OpenAPI/IOpenApiDocumentor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using System.Diagnostics.CodeAnalysis;
55

6-
namespace Azure.DataApiBuilder.Core.Services.OpenAPI
6+
namespace Azure.DataApiBuilder.Core.Services
77
{
88
/// <summary>
99
/// Interface for the service which generates and provides the OpenAPI description document

src/Core/Services/OpenAPI/OpenApiDocumentor.cs

Lines changed: 107 additions & 36 deletions
Large diffs are not rendered by default.

src/Directory.Packages.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
2626
<PackageVersion Include="Microsoft.OData.Edm" Version="7.12.5" />
2727
<PackageVersion Include="Microsoft.OData.Core" Version="7.12.5" />
28-
<PackageVersion Include="Microsoft.OpenApi" Version="1.6.3" />
28+
<PackageVersion Include="Microsoft.OpenApi" Version="1.6.5" />
29+
<PackageVersion Include="Microsoft.OpenApi.Readers" Version="1.6.5" />
2930
<PackageVersion Include="Moq" Version="4.18.2" />
3031
<PackageVersion Include="MSTest.TestAdapter" Version="3.0.2" />
3132
<PackageVersion Include="MSTest.TestFramework" Version="3.0.2" />

src/Service.Tests/Azure.DataApiBuilder.Service.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" />
1919
<PackageReference Include="Microsoft.AspNetCore.TestHost" />
2020
<PackageReference Include="Microsoft.NET.Test.Sdk" />
21+
<PackageReference Include="Microsoft.OpenApi" />
22+
<PackageReference Include="Microsoft.OpenApi.Readers" />
2123
<PackageReference Include="Moq" />
2224
<PackageReference Include="MSTest.TestAdapter" />
2325
<PackageReference Include="MSTest.TestFramework" />
@@ -77,6 +79,7 @@
7779
<ItemGroup>
7880
<ProjectReference Include="..\Auth\Azure.DataApiBuilder.Auth.csproj" />
7981
<ProjectReference Include="..\Config\Azure.DataApiBuilder.Config.csproj" />
82+
<ProjectReference Include="..\Core\Azure.DataApiBuilder.Core.csproj" />
8083
<ProjectReference Include="..\Service\Azure.DataApiBuilder.Service.csproj" />
8184
</ItemGroup>
8285

src/Service.Tests/Configuration/ConfigurationTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
using Azure.DataApiBuilder.Service.Controllers;
2828
using Azure.DataApiBuilder.Service.Exceptions;
2929
using Azure.DataApiBuilder.Service.Tests.Authorization;
30+
using Azure.DataApiBuilder.Service.Tests.OpenApiIntegration;
3031
using Azure.DataApiBuilder.Service.Tests.SqlTests;
3132
using HotChocolate;
3233
using Microsoft.AspNetCore.TestHost;
@@ -1709,7 +1710,7 @@ public async Task OpenApi_EntityLevelRestEndpoint()
17091710
using TestServer server = new(Program.CreateWebHostBuilder(args));
17101711
using HttpClient client = server.CreateClient();
17111712
// Setup and send GET request
1712-
HttpRequestMessage readOpenApiDocumentRequest = new(HttpMethod.Get, $"{RestRuntimeOptions.DEFAULT_PATH}/{Core.Services.OpenAPI.OpenApiDocumentor.OPENAPI_ROUTE}");
1713+
HttpRequestMessage readOpenApiDocumentRequest = new(HttpMethod.Get, $"{RestRuntimeOptions.DEFAULT_PATH}/{OpenApiDocumentor.OPENAPI_ROUTE}");
17131714
HttpResponseMessage response = await client.SendAsync(readOpenApiDocumentRequest);
17141715

17151716
// Parse response metadata

src/Service.Tests/OpenApiDocumentor/CLRtoJsonValueTypeUnitTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using Azure.DataApiBuilder.Service.Models;
1010
using Microsoft.VisualStudio.TestTools.UnitTesting;
1111

12-
namespace Azure.DataApiBuilder.Service.Tests.OpenApiDocumentor;
12+
namespace Azure.DataApiBuilder.Service.Tests.OpenApiIntegration;
1313

1414
/// <summary>
1515
/// Validates TypeHelper converters return expected results.

src/Service.Tests/OpenApiDocumentor/OpenApiDocumentorConstants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
namespace Azure.DataApiBuilder.Service.Tests
4+
namespace Azure.DataApiBuilder.Service.Tests.OpenApiIntegration
55
{
66
public class OpenApiDocumentorConstants
77
{

src/Service.Tests/OpenApiDocumentor/StoredProcedureGeneration.cs

Lines changed: 340 additions & 0 deletions
Large diffs are not rendered by default.

src/Service/Controllers/RestController.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using Azure.DataApiBuilder.Config.ObjectModel;
99
using Azure.DataApiBuilder.Core.Models;
1010
using Azure.DataApiBuilder.Core.Services;
11-
using Azure.DataApiBuilder.Core.Services.OpenAPI;
1211
using Azure.DataApiBuilder.Service.Exceptions;
1312
using Microsoft.AspNetCore.Http;
1413
using Microsoft.AspNetCore.Http.Extensions;

0 commit comments

Comments
 (0)