diff --git a/.tractusx b/.tractusx index a92aaa5cef..cc291344b1 100644 --- a/.tractusx +++ b/.tractusx @@ -18,3 +18,9 @@ ############################################################### leadingRepository: "https://github.com/eclipse-tractusx/portal" +openApiSpecs: +- "https://github.com/eclipse-tractusx/portal-backend/tree/v2.2.0/docs/api/Org.Eclipse.TractusX.Portal.Backend.Administration.Service.yaml" +- "https://github.com/eclipse-tractusx/portal-backend/tree/v2.2.0/docs/api/Org.Eclipse.TractusX.Portal.Backend.Apps.Service.yaml" +- "https://github.com/eclipse-tractusx/portal-backend/tree/v2.2.0/docs/api/Org.Eclipse.TractusX.Portal.Backend.Notifications.Service.yaml" +- "https://github.com/eclipse-tractusx/portal-backend/tree/v2.2.0/docs/api/Org.Eclipse.TractusX.Portal.Backend.Registration.Service.yaml" +- "https://github.com/eclipse-tractusx/portal-backend/tree/v2.2.0/docs/api/Org.Eclipse.TractusX.Portal.Backend.Services.Service.yaml" diff --git a/docs/api/README.md b/docs/api/README.md new file mode 100644 index 0000000000..3f4488d4e5 --- /dev/null +++ b/docs/api/README.md @@ -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 + + + + + +``` + +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) + +3. `EnvironmentVariables="DOTNET_ROLL_FORWARD=LatestMajor;ASPNETCORE_ENVIRONMENT=Swagger"` sets the environment variables to start up the program. The environment of the application is set to swagger to skip the application configuration validation + +## 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. diff --git a/src/administration/Administration.Service/Program.cs b/src/administration/Administration.Service/Program.cs index 1c9a2852f3..e73de7bc7d 100644 --- a/src/administration/Administration.Service/Program.cs +++ b/src/administration/Administration.Service/Program.cs @@ -23,6 +23,7 @@ using Org.Eclipse.TractusX.Portal.Backend.Bpdm.Library.DependencyInjection; using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling.Service; using Org.Eclipse.TractusX.Portal.Backend.Framework.Models; +using Org.Eclipse.TractusX.Portal.Backend.Framework.Models.Extensions; using Org.Eclipse.TractusX.Portal.Backend.IssuerComponent.Library.DependencyInjection; using Org.Eclipse.TractusX.Portal.Backend.Notifications.Library; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess; @@ -36,9 +37,8 @@ using Org.Eclipse.TractusX.Portal.Backend.Provisioning.Library.Service; using Org.Eclipse.TractusX.Portal.Backend.Web.Initialization; using Org.Eclipse.TractusX.Portal.Backend.Web.PublicInfos.DependencyInjection; -using System.Reflection; -var version = $"v{Assembly.GetExecutingAssembly().GetCustomAttribute()?.InformationalVersion.Split("+")[0]}"; +var version = AssemblyExtension.GetApplicationVersion(); await WebAppHelper .BuildAndRunWebApplicationAsync(args, "administration", version, builder => diff --git a/src/framework/Framework.Models/Extensions/AssemblyExtension.cs b/src/framework/Framework.Models/Extensions/AssemblyExtension.cs new file mode 100644 index 0000000000..f5c1b9d43b --- /dev/null +++ b/src/framework/Framework.Models/Extensions/AssemblyExtension.cs @@ -0,0 +1,9 @@ +using System.Reflection; + +namespace Org.Eclipse.TractusX.Portal.Backend.Framework.Models.Extensions; + +public static class AssemblyExtension +{ + public static string GetApplicationVersion() => + $"v{Assembly.GetCallingAssembly().GetCustomAttribute()?.InformationalVersion.Split("+")[0]}"; +} diff --git a/src/marketplace/Apps.Service/Program.cs b/src/marketplace/Apps.Service/Program.cs index ebe105140c..97352ec2ab 100644 --- a/src/marketplace/Apps.Service/Program.cs +++ b/src/marketplace/Apps.Service/Program.cs @@ -21,6 +21,7 @@ using Org.Eclipse.TractusX.Portal.Backend.Dim.Library.DependencyInjection; using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling.Service; using Org.Eclipse.TractusX.Portal.Backend.Framework.Models; +using Org.Eclipse.TractusX.Portal.Backend.Framework.Models.Extensions; using Org.Eclipse.TractusX.Portal.Backend.Notifications.Library; using Org.Eclipse.TractusX.Portal.Backend.Offers.Library.DependencyInjection; using Org.Eclipse.TractusX.Portal.Backend.Offers.Library.Service; @@ -31,9 +32,8 @@ using Org.Eclipse.TractusX.Portal.Backend.Provisioning.Library; using Org.Eclipse.TractusX.Portal.Backend.Web.Initialization; using Org.Eclipse.TractusX.Portal.Backend.Web.PublicInfos.DependencyInjection; -using System.Reflection; -var version = $"v{Assembly.GetExecutingAssembly().GetCustomAttribute()?.InformationalVersion.Split("+")[0]}"; +var version = AssemblyExtension.GetApplicationVersion(); await WebAppHelper .BuildAndRunWebApplicationAsync(args, "apps", version, builder => diff --git a/src/marketplace/Services.Service/Program.cs b/src/marketplace/Services.Service/Program.cs index b53cbc61c6..a23b545670 100644 --- a/src/marketplace/Services.Service/Program.cs +++ b/src/marketplace/Services.Service/Program.cs @@ -20,6 +20,7 @@ using Org.Eclipse.TractusX.Portal.Backend.Dim.Library.DependencyInjection; using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling.Service; using Org.Eclipse.TractusX.Portal.Backend.Framework.Models; +using Org.Eclipse.TractusX.Portal.Backend.Framework.Models.Extensions; using Org.Eclipse.TractusX.Portal.Backend.Notifications.Library; using Org.Eclipse.TractusX.Portal.Backend.Offers.Library.DependencyInjection; using Org.Eclipse.TractusX.Portal.Backend.Offers.Library.Web.DependencyInjection; @@ -31,9 +32,8 @@ using Org.Eclipse.TractusX.Portal.Backend.Services.Service.DependencyInjection; using Org.Eclipse.TractusX.Portal.Backend.Web.Initialization; using Org.Eclipse.TractusX.Portal.Backend.Web.PublicInfos.DependencyInjection; -using System.Reflection; -var version = $"v{Assembly.GetExecutingAssembly().GetCustomAttribute()?.InformationalVersion.Split("+")[0]}"; +var version = AssemblyExtension.GetApplicationVersion(); await WebAppHelper .BuildAndRunWebApplicationAsync(args, "services", version, builder => diff --git a/src/notifications/Notifications.Service/Program.cs b/src/notifications/Notifications.Service/Program.cs index d04f5d1afe..3db0332178 100644 --- a/src/notifications/Notifications.Service/Program.cs +++ b/src/notifications/Notifications.Service/Program.cs @@ -18,13 +18,13 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ +using Org.Eclipse.TractusX.Portal.Backend.Framework.Models.Extensions; using Org.Eclipse.TractusX.Portal.Backend.Notifications.Service.BusinessLogic; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess; using Org.Eclipse.TractusX.Portal.Backend.Web.Initialization; using Org.Eclipse.TractusX.Portal.Backend.Web.PublicInfos.DependencyInjection; -using System.Reflection; -var version = $"v{Assembly.GetExecutingAssembly().GetCustomAttribute()?.InformationalVersion.Split("+")[0]}"; +var version = AssemblyExtension.GetApplicationVersion(); await WebAppHelper .BuildAndRunWebApplicationAsync(args, "notification", version, builder => diff --git a/src/registration/Registration.Service/Program.cs b/src/registration/Registration.Service/Program.cs index 5c599d50c8..8fd05cab41 100644 --- a/src/registration/Registration.Service/Program.cs +++ b/src/registration/Registration.Service/Program.cs @@ -19,7 +19,7 @@ ********************************************************************************/ using Org.Eclipse.TractusX.Portal.Backend.Bpdm.Library.DependencyInjection; -using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling; +using Org.Eclipse.TractusX.Portal.Backend.Framework.Models.Extensions; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess; using Org.Eclipse.TractusX.Portal.Backend.Processes.ApplicationChecklist.Config; using Org.Eclipse.TractusX.Portal.Backend.Processes.Mailing.Library.DependencyInjection; @@ -28,9 +28,8 @@ using Org.Eclipse.TractusX.Portal.Backend.Registration.Service.BusinessLogic; using Org.Eclipse.TractusX.Portal.Backend.Web.Initialization; using Org.Eclipse.TractusX.Portal.Backend.Web.PublicInfos.DependencyInjection; -using System.Reflection; -var version = $"v{Assembly.GetExecutingAssembly().GetCustomAttribute()?.InformationalVersion.Split("+")[0]}"; +var version = AssemblyExtension.GetApplicationVersion(); await WebAppHelper .BuildAndRunWebApplicationAsync(args, "registration", version, builder =>