Skip to content

Commit

Permalink
feat(api-hub): create open api spec on build (#66)
Browse files Browse the repository at this point in the history
Refs: #64
Reviewed-By: Evelyn Gurschler <[email protected]>
  • Loading branch information
Phil91 authored Sep 30, 2024
1 parent 7f9308f commit edc06c1
Show file tree
Hide file tree
Showing 14 changed files with 213 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unit.tests-formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ jobs:
- name: Check Format
run: dotnet format src --verify-no-changes --no-restore
- name: Test
run: dotnet test src --no-restore --verbosity normal
run: dotnet test src --no-build --no-restore --configuration Release --verbosity normal
2 changes: 2 additions & 0 deletions .tractusx
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@

product: "SSI Authority & Schema Registry"
leadingRepository: "https://github.com/eclipse-tractusx/ssi-authority-schema-registry"
openApiSpecs:
- "https://raw.githubusercontent.com/eclipse-tractusx/ssi-authority-schema-registry/refs/heads/main/docs/api/asr-service.yaml"
8 changes: 4 additions & 4 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ nuget/nuget/-/Serilog.Sinks.File/5.0.0, Apache-2.0, approved, #11116
nuget/nuget/-/Serilog/3.1.1, Apache-2.0, approved, #13978
nuget/nuget/-/SharpZipLib/1.4.2, MIT AND GFDL-1.3-or-later AND (Apache-2.0 AND MIT) AND WTFPL AND bzip2-1.0.6 AND LicenseRef-Permissive-license-with-conditions AND LicenseRef-Permission-Notice, approved, #10058
nuget/nuget/-/SshNet.Security.Cryptography/1.3.0, MIT, approved, clearlydefined
nuget/nuget/-/Swashbuckle.AspNetCore.Swagger/6.5.0, MIT AND Apache-2.0, approved, #7160
nuget/nuget/-/Swashbuckle.AspNetCore.SwaggerGen/6.5.0, MIT AND Apache-2.0, approved, #7156
nuget/nuget/-/Swashbuckle.AspNetCore.SwaggerUI/6.5.0, MIT AND Apache-2.0, approved, #7158
nuget/nuget/-/Swashbuckle.AspNetCore/6.5.0, MIT AND Apache-2.0, approved, #7159
nuget/nuget/-/Swashbuckle.AspNetCore.Swagger/6.8.0, MIT AND Apache-2.0, approved, #16262
nuget/nuget/-/Swashbuckle.AspNetCore.SwaggerGen/6.8.0, MIT AND Apache-2.0, approved, #16259
nuget/nuget/-/Swashbuckle.AspNetCore.SwaggerUI/6.8.0, MIT AND Apache-2.0, approved, #16261
nuget/nuget/-/Swashbuckle.AspNetCore/6.8.0, MIT AND Apache-2.0, approved, #16260
nuget/nuget/-/Testcontainers.PostgreSql/3.8.0, MIT, approved, #15169
nuget/nuget/-/Testcontainers/3.8.0, MIT, approved, #15178
nuget/nuget/-/xunit.abstractions/2.0.3, Apache-2.0, approved, clearlydefined
Expand Down
159 changes: 159 additions & 0 deletions docs/api/asr-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
openapi: 3.0.1

Check warning on line 1 in docs/api/asr-service.yaml

View workflow job for this annotation

GitHub Actions / Analyze

[MEDIUM] Global Server Object Uses HTTP

Global server object URL should use 'https' protocol instead of 'http'
info:
title: Org.Eclipse.TractusX.SsiAuthoritySchemaRegistry.Service
version: v1.0.0
paths:
/api/registry/credentials:
get:
tags:
- 'Org.Eclipse.TractusX.SsiAuthoritySchemaRegistry.Service, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
summary: Gets all credentials with optional filter possibilities
description: 'Example: GET: api/registry/credentials'
parameters:
- name: bpnl
in: query
schema:
type: string
- name: credentialTypeId
in: query
schema:
$ref: '#/components/schemas/CredentialTypeId'
responses:
'200':
description: OK
content:
application/json:
schema:

Check warning on line 26 in docs/api/asr-service.yaml

View workflow job for this annotation

GitHub Actions / Analyze

[MEDIUM] Array Without Maximum Number of Items (v3)

Array schema should have the field 'maxItems' set
type: array
items:
$ref: '#/components/schemas/CredentialData'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal Server Error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/api/schema/validate:
post:
tags:
- 'Org.Eclipse.TractusX.SsiAuthoritySchemaRegistry.Service, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
summary: Gets all credentials with optional filter possibilities
description: 'Example: POST: api/schema/validate'
parameters:
- name: schemaType
in: query
required: true
schema:
$ref: '#/components/schemas/CredentialSchemaType'
requestBody:
content:
application/json:
schema: { }
required: true
responses:
'200':
description: OK
content:
application/json:
schema:
type: boolean
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
'500':
description: Internal Server Error
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
components:
schemas:
CredentialData:
type: object
properties:
credentialName:
type: string

Check warning on line 84 in docs/api/asr-service.yaml

View workflow job for this annotation

GitHub Actions / Analyze

[MEDIUM] Pattern Undefined (v3)

String schema should have 'pattern' defined.
credential:
type: string

Check warning on line 86 in docs/api/asr-service.yaml

View workflow job for this annotation

GitHub Actions / Analyze

[MEDIUM] Pattern Undefined (v3)

String schema should have 'pattern' defined.
authorities:

Check warning on line 87 in docs/api/asr-service.yaml

View workflow job for this annotation

GitHub Actions / Analyze

[MEDIUM] Array Without Maximum Number of Items (v3)

Array schema should have the field 'maxItems' set
type: array
items:
type: string
additionalProperties: false
CredentialSchemaType:
enum:
- BusinessPartnerCredential
- DismantlerCredential
- FrameworkCredential
- MembershipCredential
type: string
CredentialTypeId:
enum:
- BusinessPartnerNumber
- Membership
- Framework
- CompanyRole
type: string
ErrorDetails:
type: object
properties:
errorCode:
type: string
type:
type: string
message:
type: string
parameters:

Check warning on line 115 in docs/api/asr-service.yaml

View workflow job for this annotation

GitHub Actions / Analyze

[MEDIUM] Array Without Maximum Number of Items (v3)

Array schema should have the field 'maxItems' set

Check warning on line 115 in docs/api/asr-service.yaml

View workflow job for this annotation

GitHub Actions / Analyze

[MEDIUM] Parameter Object Without Schema

The Parameter Object should have the attribute 'schema' defined
type: array
items:
$ref: '#/components/schemas/ErrorParameter'
additionalProperties: false
ErrorParameter:
type: object
properties:
name:
type: string
value:
type: string
additionalProperties: false
ErrorResponse:
type: object
properties:
type:
type: string
title:
type: string
status:
type: integer
format: int32
errors:
type: object
additionalProperties:

Check warning on line 140 in docs/api/asr-service.yaml

View workflow job for this annotation

GitHub Actions / Analyze

[MEDIUM] Array Without Maximum Number of Items (v3)

Array schema should have the field 'maxItems' set
type: array
items:
type: string
errorId:
type: string
details:

Check warning on line 146 in docs/api/asr-service.yaml

View workflow job for this annotation

GitHub Actions / Analyze

[MEDIUM] Array Without Maximum Number of Items (v3)

Array schema should have the field 'maxItems' set
type: array
items:
$ref: '#/components/schemas/ErrorDetails'
nullable: true
additionalProperties: false
securitySchemes:
Bearer:
type: apiKey
description: "JWT Authorization header using the Bearer scheme. \r\n\r\n Enter 'Bearer' [space] and then your token in the text input below.\r\n\r\nExample: \"Bearer 12345abcdef\""
name: Authorization
in: header
security:
- Bearer: [ ]
17 changes: 17 additions & 0 deletions docs/technical-documentation/release-process/Release Process.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The release process for a new version can roughly be divided into the following
- [1. Aggregate migrations](#1-aggregate-migrations)
- [2. Version bump](#2-version-bump)
- [3. Update README (on chart level)](#3-update-readme-on-chart-level)
- [4. Update .tractusx](#4-update-tractusx)
- [Update CHANGELOG.md](#update-changelogmd)
- [Merge release branch](#merge-release-branch)
- [RC: provide successive rc branch and change base of open PRs](#rc-provide-successive-rc-branch-and-change-base-of-open-prs)
Expand Down Expand Up @@ -52,6 +53,22 @@ Example for commit message:

_build: update readme for vx.x.x_

### 4. Update .tractusx

Adjust links of the open api specifications in the .tractusx file.

All stable releases should be listed. In case of a pre-release version (rc, alpha, etc.), only the latest one should be listed.

```md
openApiSpecs:
- "https://raw.githubusercontent.com/eclipse-tractusx/ssi-authority-schema-registry/blob/v1.0.0/docs/api/asr-service.yaml"
- "https://raw.githubusercontent.com/eclipse-tractusx/ssi-authority-schema-registry/blob/v1.1.0/docs/api/asr-service.yaml"
```

Example for commit message:

_build: update open api spec for vx.x.x_

## Update CHANGELOG.md

The changelog file tracks all notable changes since the last released version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="8.0.7" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.4" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.DependencyInjection" Version="2.4.2" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling" Version="2.4.2" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.DependencyInjection" Version="2.10.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling" Version="2.10.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.4" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.Linq" Version="2.4.2" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.Logging" Version="2.4.2" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.Seeding" Version="2.4.2" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.Linq" Version="2.10.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.Logging" Version="2.10.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.Seeding" Version="2.10.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {
"swashbuckle.aspnetcore.cli": {
"version": "6.8.0",
"commands": [
"swagger"
],
"rollForward": false
}
}
}
5 changes: 3 additions & 2 deletions src/registry/SsiAuthoritySchemaRegistry.Service/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/

using Org.Eclipse.TractusX.Portal.Backend.Framework.Models.Extensions;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Web;
using Org.Eclipse.TractusX.SsiAuthoritySchemaRegistry.DbAccess.DependencyInjection;
using Org.Eclipse.TractusX.SsiAuthoritySchemaRegistry.Service.Controllers;
using System.Text.Json.Serialization;

const string Version = "v1";
var version = AssemblyExtension.GetApplicationVersion();

await WebApplicationBuildRunner
.BuildAndRunWebApplicationAsync<Program>(args, "registry", Version, ".Registry",
.BuildAndRunWebApplicationAsync<Program>(args, "registry", version, ".Registry",
builder =>
{
builder.Services.AddEndpointsApiExplorer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@
<UserSecretsId>0e157b48-9f59-4c9b-b8fc-40ed582cdcf0</UserSecretsId>
</PropertyGroup>

<Target Name="openapi" AfterTargets="Build">
<Message Text="generating openapi v$(Version)" Importance="high" />
<Exec Command="dotnet tool restore" />
<Exec Command="dotnet tool run swagger tofile --yaml --output ../../../docs/api/asr-service.yaml $(OutputPath)$(AssemblyName).dll v$(Version)" EnvironmentVariables="DOTNET_ROLL_FORWARD=LatestMajor;SKIP_CONFIGURATION_VALIDATION=true" />
</Target>

<ItemGroup>
<PackageReference Include="JsonSchema.Net" Version="7.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.6" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.6" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.Web" Version="2.4.2" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.Web" Version="2.10.0" />
<PackageReference Include="System.Json" Version="4.7.1" />
<PackageReference Include="System.Linq" Version="4.3.0" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<PackageReference Include="FakeItEasy" Version="8.2.0" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.DateTimeProvider" Version="2.4.2" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.DateTimeProvider" Version="2.10.0" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
<PackageReference Include="Testcontainers.PostgreSql" Version="3.8.0" />
<PackageReference Include="xunit" Version="2.7.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,4 @@ public async Task GetCredentials_WithCredentialTypeFilters_ReturnsExpected()
}

#endregion

#region Swagger

[Fact]
public async Task CheckSwagger_ReturnsExpected()
{
// Act
var response = await _client.GetAsync($"{BaseUrl}/swagger/v1/swagger.json");

// Assert
response.Should().NotBeNull();
response.StatusCode.Should().Be(HttpStatusCode.OK);
}

#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ public class IntegrationTestFactory : WebApplicationFactory<RegistryBusinessLogi

protected override void ConfigureWebHost(IWebHostBuilder builder)
{
var projectDir = Directory.GetCurrentDirectory();
var configPath = Path.Combine(projectDir, "appsettings.IntegrationTests.json");

var config = new ConfigurationBuilder().AddJsonFile(configPath, true).Build();
builder.UseConfiguration(config);
Environment.SetEnvironmentVariable("SKIP_CONFIGURATION_VALIDATION", "true");
builder.ConfigureTestServices(services =>
{
services.ConfigureHttpJsonOptions(options =>
Expand Down

This file was deleted.

0 comments on commit edc06c1

Please sign in to comment.