Skip to content

Commit

Permalink
feat: create open api spec on build
Browse files Browse the repository at this point in the history
Refs: #64
  • Loading branch information
Phil91 committed Sep 26, 2024
1 parent 7f9308f commit ba852e2
Show file tree
Hide file tree
Showing 12 changed files with 193 additions and 40 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/tags/v1.1.0/docs/api/asr-service.yaml"
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
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:
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
credential:
type: string
authorities:
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:
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:
type: array
items:
type: string
errorId:
type: string
details:
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: [ ]
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.9.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling" Version="2.9.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.9.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.Logging" Version="2.9.0" />
<PackageReference Include="Org.Eclipse.TractusX.Portal.Backend.Framework.Seeding" Version="2.9.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.9.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.9.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 @@ -90,7 +90,7 @@ public async Task GetCredentials_WithCredentialTypeFilters_ReturnsExpected()
public async Task CheckSwagger_ReturnsExpected()
{
// Act
var response = await _client.GetAsync($"{BaseUrl}/swagger/v1/swagger.json");
var response = await _client.GetAsync($"{BaseUrl}/swagger");

// Assert
response.Should().NotBeNull();
Expand Down
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 ba852e2

Please sign in to comment.