Skip to content

Commit

Permalink
feat(api-hub): generate open api specs for portal services (#1030)
Browse files Browse the repository at this point in the history
* adjust ms build processes to generate open api file for web service projects
* add documentation for the process of generating the open api files
* adjust validation of settings
* add possibility to skip the settings validation on startup for test projects
* update framework version

---------

Refs: #1021
Co-authored-by: Norbert Truchsess <[email protected]>
Reviewed-by: Norbert Truchsess <[email protected]>
Reviewed-by: Evelyn Gurschler <[email protected]>
  • Loading branch information
Phil91 and ntruchsess authored Sep 27, 2024
1 parent f8c155c commit 67cc761
Show file tree
Hide file tree
Showing 108 changed files with 17,103 additions and 1,249 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pre-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
- name: Check Format
run: dotnet format src --verify-no-changes --no-restore
- name: Test
run: dotnet test src --filter FullyQualifiedName\!~Org.Eclipse.TractusX.Portal.Backend.EndToEnd.Tests --no-restore --verbosity normal
run: dotnet test src --filter FullyQualifiedName\!~Org.Eclipse.TractusX.Portal.Backend.EndToEnd.Tests --no-build --no-restore --configuration Release --verbosity normal

checkFramework:
name: Check nuget packages
Expand Down
10 changes: 5 additions & 5 deletions .tractusx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

leadingRepository: "https://github.com/eclipse-tractusx/portal"
openApiSpecs:
- "https://raw.githubusercontent.com/eclipse-tractusx/portal-backend/9f2b0e92eb28bd75f916acaae5a4d1f3f0ac610c/docs/api/administration-service.yaml"
- "https://raw.githubusercontent.com/eclipse-tractusx/portal-backend/9f2b0e92eb28bd75f916acaae5a4d1f3f0ac610c/docs/api/apps-service.yaml"
- "https://raw.githubusercontent.com/eclipse-tractusx/portal-backend/9f2b0e92eb28bd75f916acaae5a4d1f3f0ac610c/docs/api/notifications-service.yaml"
- "https://raw.githubusercontent.com/eclipse-tractusx/portal-backend/9f2b0e92eb28bd75f916acaae5a4d1f3f0ac610c/docs/api/registration-service.yaml"
- "https://raw.githubusercontent.com/eclipse-tractusx/portal-backend/9f2b0e92eb28bd75f916acaae5a4d1f3f0ac610c/docs/api/services-service.yaml"
- "https://raw.githubusercontent.com/eclipse-tractusx/portal-backend/refs/tags/v2.3.0-alpha.2/docs/api/administration-service.yaml"
- "https://raw.githubusercontent.com/eclipse-tractusx/portal-backend/refs/tags/v2.3.0-alpha.2/docs/api/apps-service.yaml"
- "https://raw.githubusercontent.com/eclipse-tractusx/portal-backend/refs/tags/v2.3.0-alpha.2/docs/api/notifications-service.yaml"
- "https://raw.githubusercontent.com/eclipse-tractusx/portal-backend/refs/tags/v2.3.0-alpha.2/docs/api/registration-service.yaml"
- "https://raw.githubusercontent.com/eclipse-tractusx/portal-backend/refs/tags/v2.3.0-alpha.2/docs/api/services-service.yaml"
10 changes: 5 additions & 5 deletions DEPENDENCIES
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ 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/-/Stubble.Core/1.10.8, MIT AND BSD-2-Clause, approved, #9297
nuget/nuget/-/SwashBuckle.AspNetCore/6.5.0, MIT AND Apache-2.0, approved, #7159
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/6.8.0, MIT AND Apache-2.0, approved, #16260
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.7.0, MIT, approved, #13960
nuget/nuget/-/Testcontainers/3.7.0, MIT, approved, #13982
nuget/nuget/-/Xunit.Extensions.AssemblyFixture/2.4.1, MIT, approved, #3502
Expand Down
45 changes: 45 additions & 0 deletions docs/api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# OpenAPI Provisioning

The provisioning of the open api files for each service of the portal is done via the ms build process of each Service project.

## Setup to generate open api files

The following setup was done for all existing services of the portal which currently are:

- `Adminstiration Service`
- `Apps Service`
- `Notification Service`
- `Registration Service`
- `Services Service`

### Setup dotnet tool

To be able to run the `dotnet tool run swagger tofile` command it needs to be installed for the project. Therefor a `dotnet-tools.json` file was created within a `.config` directory. This file includes a reference to a nuget package which is needed to execute the command.

### Setup csproj

To execute the generation of the open api document the .csproj file of the project was adjusted as follows:

```xml
<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/$(AssemblyName).yaml $(OutputPath)$(AssemblyName).dll v$(Version)" EnvironmentVariables="DOTNET_ROLL_FORWARD=LatestMajor;SKIP_CONFIGURATION_VALIDATION=true;MVC_ROUTING_BASEPATH=api/administration" />
</Target>
```

The configuration runs after the build of the project, it executes a `dotnet tool restore` which is needed to than run the command to generate the open api file.

The `dotnet tool run swagger tofile` is executed with the following parameters:

1. `--yaml` sets the filetype to yaml, an alternative would be to remove the parameter, the file would than be generated as a json

2. `--ouput ../../../docs/api/$(AssemblyName).yaml $(OutputPath)$(AssemblyName).dll v$(Version)` sets the ouput path for the file and specifies the version of the swagger file that should be taken

> **IMPORTANT**: the version set for the output must(!) match with the version which is specified in the `Program.cs` more under [Setup Program](#setup-program)
1. `EnvironmentVariables="DOTNET_ROLL_FORWARD=LatestMajor;SKIP_CONFIGURATION_VALIDATION=true"` sets the environment variables to start up the program. With the variable `SKIP_CONFIGURATION_VALIDATION` the configuration validation is skipped when starting the application

## Setup Program

To get the version of the assembly which is used in the csproj file with `$(Version)` an extension was introduced. By calling `AssemblyExtension.GetApplicationVersion()` in the Program.cs the entry assembly will be taken, and the `InformationalVersion` will be taken.
Loading

0 comments on commit 67cc761

Please sign in to comment.