Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ec15ee8
Add openAPI package
seantleonard Apr 12, 2023
6773bdd
Initial openapi service, controller, and mapped swagger ui viewer end…
seantleonard Apr 13, 2023
33dafd3
Add runtimeconfig to openapidocumentor.
seantleonard Apr 14, 2023
55a78e1
Automate Component Schema creation for Full Entity (with primary key).
seantleonard Apr 14, 2023
8894daf
additional GET path documenting
seantleonard Apr 24, 2023
9f2c700
add openapidoc creation at startup, refine error messages 409 and 500…
seantleonard Apr 27, 2023
1488636
Consolidated code paths, reduced code verbosity/duplication. Comments.
seantleonard Apr 27, 2023
c783106
updated response codes and formatting of number in openapi doc.
seantleonard Apr 28, 2023
81ceda1
updated openapicontroller route and updated swaggerUI uri to point to…
seantleonard Apr 28, 2023
accb50e
Remove swagger package, keep swaggerui.
seantleonard Apr 28, 2023
63f0b95
added constants and new suberrorcode.
seantleonard Apr 28, 2023
ca3ca2d
Merge branch 'main' into dev/seantleonard/openapiv3_initial
seantleonard Apr 28, 2023
2c25653
updated media type set as application/json for GET endpoint. updated …
seantleonard Apr 28, 2023
93bebc8
prevent entities from being openapi documented if they explicitly dis…
seantleonard Apr 28, 2023
3489ff9
Consolidated code paths, reduced code verbosity/duplication. Comments…
seantleonard May 3, 2023
ab5d9de
Merge branch 'main' into dev/seantleonard/openapiv3_initial
seantleonard May 3, 2023
9941fb7
Moved placement of swaggerUI setup, to fix HTTP400 errors
seantleonard May 3, 2023
058c53d
Remove ability to POST on openapicontroller since creation occurs on …
seantleonard May 3, 2023
12d25fb
remove unnecessary usings
seantleonard May 3, 2023
e79f905
updated comments to correctly reflect operations and expected results.
seantleonard May 3, 2023
28b4120
updating function comments in interface, updating documentor usage of…
seantleonard May 5, 2023
dbcf3b5
Merge branch 'main' into dev/seantleonard/openapiv3_initial
seantleonard May 5, 2023
cf7fbe3
updated custom REST route handling for swagger and openapi, moved ope…
seantleonard May 5, 2023
988faaf
updated with dotnet format.
seantleonard May 5, 2023
de2026f
fixed tests and controller logic
seantleonard May 5, 2023
f1e06b9
list to hashset to track columns
seantleonard May 5, 2023
f77b304
allow building notice file in dev.
seantleonard May 5, 2023
aaaee4d
allow building notice file remove conditions.
seantleonard May 6, 2023
69c5fb0
Merge branch 'main' into dev/seantleonard/openapiv3_initial
abhishekkumams May 8, 2023
d30b776
Merge branch 'main' into dev/seantleonard/openapiv3_initial
seantleonard May 8, 2023
32da9c4
updated tests, updated restservice/controller handling of swaggerendp…
seantleonard May 9, 2023
6aee930
added back condition to notice file generation task in ci/cd pipeline
seantleonard May 9, 2023
d25b15b
updated logic and tests for RestPath retrieval to use existing functions
seantleonard May 9, 2023
dd3ead5
reuse constants for default rest path /api
seantleonard May 9, 2023
834615d
updated hashset name to nonAutoGeneratedPKColumnNames
seantleonard May 10, 2023
b05b812
Merge branch 'main' into dev/seantleonard/openapiv3_initial
seantleonard May 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/Config/DataApiBuilderException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,19 @@ public enum SubStatusCodes
/// <summary>
/// Error encountered while doing data type conversions.
/// </summary>
ErrorProcessingData
ErrorProcessingData,
/// <summary>
/// Attempting to generate OpenAPI document when one already exists.
/// </summary>
OpenApiDocumentAlreadyExists,
/// <summary>
/// Attempting to generate OpenAPI document failed.
/// </summary>
OpenApiDocumentGenerationFailure,
/// <summary>
/// Global REST endpoint disabled in runtime configuration.
/// </summary>
GlobalRestEndpointDisabled
}

public HttpStatusCode StatusCode { get; }
Expand Down
4 changes: 3 additions & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.14" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="6.0.14" />
<PackageVersion Include="Microsoft.Azure.Cosmos" Version="3.20.0" />
<!--When updating Microsoft.Data.SqlClient, update license URL in scripts/notice-generation.ps1-->
<!--When updating Microsoft.Data.SqlClient, update license URL in scripts/notice-generation.ps1-->
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.0.1" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageVersion Include="Microsoft.OData.Edm" Version="7.12.5" />
<PackageVersion Include="Microsoft.OData.Core" Version="7.12.5" />
<PackageVersion Include="Microsoft.OpenApi" Version="1.6.3" />
<PackageVersion Include="Moq" Version="4.18.2" />
<PackageVersion Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageVersion Include="MSTest.TestFramework" Version="2.2.10" />
Expand All @@ -32,6 +33,7 @@
<PackageVersion Include="Npgsql" Version="7.0.1" />
<PackageVersion Include="Polly" Version="7.2.3" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.1.118" />
<PackageVersion Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.5.0" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="System.Drawing.Common" Version="6.0.0" />
<PackageVersion Include="System.IO.Abstractions" Version="17.2.3" />
Expand Down
2 changes: 2 additions & 0 deletions src/Service/Azure.DataApiBuilder.Service.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Json" />
<PackageReference Include="Microsoft.OData.Edm" />
<PackageReference Include="Microsoft.OData.Core" />
<PackageReference Include="Microsoft.OpenApi" />
<PackageReference Include="MSTest.TestFramework" />
<PackageReference Include="MySqlConnector" />
<PackageReference Include="Newtonsoft.Json" />
Expand All @@ -69,6 +70,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" />
<PackageReference Include="System.CommandLine" />
<PackageReference Include="System.IO.Abstractions" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All"/>
Expand Down
67 changes: 67 additions & 0 deletions src/Service/Controllers/OpenApiController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Azure.DataApiBuilder.Service.Exceptions;
using Azure.DataApiBuilder.Service.Services;
using Microsoft.AspNetCore.Mvc;

namespace Azure.DataApiBuilder.Service.Controllers
{
/// <summary>
///
/// </summary>
[Route("[controller]")]
[ApiController]
public class OpenApiController : ControllerBase
{
private IOpenApiDocumentor _apiDocumentor;

public OpenApiController(IOpenApiDocumentor openApiDocumentor)
{
_apiDocumentor = openApiDocumentor;
}

/// <summary>
///
/// </summary>
/// <returns></returns>
[HttpGet]
public IActionResult Get()
{
return _apiDocumentor.TryGetDocument(out string? document) ? Ok(document) : NotFound();
}

/// <summary>
///
/// </summary>
/// <returns></returns>
[HttpPost]
public IActionResult Post()
{
try
{
_apiDocumentor.CreateDocument();

if (_apiDocumentor.TryGetDocument(out string? document))
{
return new CreatedResult(location:"/openapi" ,value: document);
}

return NotFound();
}
catch (DataApiBuilderException dabException)
{
Response.StatusCode = (int)dabException.StatusCode;
return new JsonResult(new
{
error = new
{
code = dabException.SubStatusCode.ToString(),
message = dabException.Message,
status = (int)dabException.StatusCode
}
});
}
}
}
}
13 changes: 13 additions & 0 deletions src/Service/Services/IOpenApiDocumentor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Diagnostics.CodeAnalysis;

namespace Azure.DataApiBuilder.Service.Services
{
public interface IOpenApiDocumentor
{
public bool TryGetDocument([NotNullWhen(true)] out string? document);
public void CreateDocument();
}
}
Loading