Skip to content
Draft
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
12 changes: 6 additions & 6 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

<ItemGroup>
<!-- Test libraries -->
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="10.0.14" />
<PackageVersion Include="Microsoft.Extensions.ApiDescription.Server" Version="10.0.14" />
<PackageVersion Include="Swashbuckle.AspNetCore.SwaggerUi" Version="10.3.1" />

<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.8.0" />
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="NUnit" Version="4.6.1" />
Expand All @@ -22,8 +26,8 @@
<PackageVersion Include="coverlet.collector" Version="10.0.1" />

<!-- Asp.Net Core Framework dependency -->
<FrameworkReference Update="Microsoft.AspNetCore.App" Version="$(dotnetVersion)" />

<FrameworkReference Update="Microsoft.AspNetCore.App" Version="$(dotnetVersion)" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="$(dotnetVersion)" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="$(dotnetVersion)" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="$(dotnetVersion)" />
Expand Down Expand Up @@ -51,13 +55,9 @@
<PackageVersion Include="Microsoft.Identity.Web.DownstreamApi" Version="4.0.0" />

<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="10.0.400" />

<PackageVersion Include="Newtonsoft.Json" Version="13.0.4" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="10.2.3" />

<PackageVersion Include="Castle.Windsor" Version="6.0.0" />
<PackageVersion Include="Castle.Core" Version="5.2.1" />

<!-- Dependencies for drivers and adapters -->
<PackageVersion Include="System.IO.Ports" Version="10.0.0" />
<PackageVersion Include="MQTTnet" Version="5.0.1.1416" />
Expand All @@ -73,4 +73,4 @@
<!--Dependency for SBOM generation-->
<PackageVersion Include="Microsoft.Sbom.Targets" Version="4.1.5" />
</ItemGroup>
</Project>
</Project>
3 changes: 2 additions & 1 deletion MORYX-Framework.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
</Folder>
<Folder Name="/Runtime/">
<Project Path="src/Moryx.AspNetCore.Mqtt/Moryx.AspNetCore.Mqtt.csproj" />
<Project Path="src/Moryx.AspNetCore.OpenApi/Moryx.AspNetCore.OpenApi.csproj" />
<Project Path="src/Moryx.AspNetCore/Moryx.AspNetCore.csproj" />
<Project Path="src/Moryx.CommandCenter.Web/Moryx.CommandCenter.Web.csproj" />
<Project Path="src/Moryx.Runtime.Endpoints/Moryx.Runtime.Endpoints.csproj" />
Expand Down Expand Up @@ -186,5 +187,5 @@
<Project Path="src/Moryx.Container/Moryx.Container.csproj" />
<Project Path="src/Moryx.Launcher/Moryx.Launcher.csproj" />
<Project Path="src/Moryx/Moryx.csproj" />
<Project Path="src/StartProject.Asp/StartProject.Asp.csproj" DefaultStartup="true"/>
<Project Path="src/StartProject.Asp/StartProject.Asp.csproj" DefaultStartup="true" />
</Solution>
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Moryx.AbstractionLayer.Recipes;
using Moryx.Tools;
using Moryx.Serialization;
using Moryx.AbstractionLayer.Products.Endpoints.Models;
using Moryx.AbstractionLayer.Products.Endpoints.Properties;
using Moryx.AbstractionLayer.Recipes;
using Moryx.AspNetCore;
using Moryx.Configuration;
using Moryx.Runtime.Modules;
using Moryx.Serialization;
using Moryx.Tools;

namespace Moryx.AbstractionLayer.Products.Endpoints;

Expand Down Expand Up @@ -43,6 +43,9 @@ public ProductManagementController(IProductManagement productManagement,
}

#region importers
/// <summary>
/// Loads dataset of existing products, recipes and importers for the UI
/// </summary>
[HttpGet]
[Route("configuration")]
[Authorize(Policy = ProductPermissions.CanViewTypes)]
Expand Down Expand Up @@ -78,6 +81,11 @@ private RecipeDefinitionModel[] GetRecipeTypes()
return typeModels.ToArray();
}

/// <summary>
/// Run the product importer with the given parameters
/// </summary>
/// <param name="importerName">Name of the importer</param>
/// <param name="importParameters">Parameters for the importer</param>
[HttpPost]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
Expand Down Expand Up @@ -111,6 +119,11 @@ private object ConvertParametersBack(string importerName, Entry currentParameter

#endregion
#region product type
/// <summary>
/// Store the product type in the database
/// </summary>
/// <param name="newTypeModel">Model of the new product</param>
/// <returns>The assigned database id of the product</returns>
[HttpPost]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
Expand All @@ -129,6 +142,10 @@ public async Task<ActionResult<long>> SaveType(ProductModel newTypeModel)
return await _productManagement.SaveTypeAsync(newType);
}

/// <summary>
/// Retrieves all product types, if no identity is specified. Otherwise the model identified by that id is returned
/// </summary>
/// <param name="identity">Optional. The id to look for</param>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
Expand Down Expand Up @@ -160,6 +177,11 @@ await _productConverter.ConvertProduct(productType, false)
};
}

/// <summary>
/// Query the product type database
/// </summary>
/// <param name="query">Query parameters</param>
/// <returns>The products models matching the query</returns>
[HttpPost]
[Route("types/query")]
[Authorize(Policy = ProductPermissions.CanViewTypes)]
Expand All @@ -174,6 +196,10 @@ public async Task<ActionResult<ProductModel[]>> GetTypes(ProductQuery query)
return productModels.ToArray();
}

/// <summary>
/// Get's a product type using the database id
/// </summary>
/// <param name="id">Database id</param>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
Expand All @@ -197,6 +223,11 @@ public async Task<ActionResult<ProductModel>> GetTypeById(long id)
return await _productConverter.ConvertProduct(productType, false);
}

/// <summary>
/// Deletes the product type with the given id
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpDelete]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
Expand All @@ -210,6 +241,11 @@ public async Task<ActionResult<bool>> DeleteType(long id)
return result;
}

/// <summary>
/// Updates the existing product type
/// </summary>
/// <param name="id">Database id of the product type</param>
/// <param name="modifiedType">New product model</param>
[HttpPut]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
Expand All @@ -226,6 +262,11 @@ public async Task<ActionResult<long>> UpdateType(long id, ProductModel modifiedT
return await _productManagement.SaveTypeAsync(type);
}

/// <summary>
/// Create a clone of the product type identified with the id with the new identitiy
/// </summary>
/// <param name="id">Database id of the existing product type</param>
/// <param name="newIdentity">Product identifier of the new product</param>
[HttpPost]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
Expand Down Expand Up @@ -256,6 +297,11 @@ public async Task<ActionResult<ProductModel>> Duplicate(long id, [FromBody] stri
return await _productConverter.ConvertProduct(newProductType, false);
}

/// <summary>
/// Loads the recipe attached to the product type with the id
/// </summary>
/// <param name="id">Database id</param>
/// <param name="classification">Recipe classification <see cref="RecipeClassification"/></param>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
Expand All @@ -275,6 +321,11 @@ public async Task<ActionResult<RecipeModel[]>> GetRecipes(long id, int classific
#endregion

#region product instances
/// <summary>
/// Get's the product instance with the given id
/// </summary>
/// <param name="id">Database id of the product instance</param>
/// <returns></returns>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
Expand All @@ -291,6 +342,10 @@ public async Task<ActionResult<ProductInstanceModel>> GetInstance(long id)
return ProductConverter.ConvertProductInstance(productInstance);
}

/// <summary>
/// Loads multiple product instances at once
/// </summary>
/// <param name="ids">A list of product instance ids</param>
[HttpGet]
[Route("instances")]
[Authorize(Policy = ProductPermissions.CanViewInstances)]
Expand All @@ -303,6 +358,12 @@ public async Task<ActionResult<ProductInstanceModel[]>> GetInstances([FromQuery]
return modelList.ToArray();
}

/// <summary>
/// Create a new product instace of the product type identified via the identifier and revision
/// </summary>
/// <param name="identifier">Product identifier</param>
/// <param name="revision">Revision of the product</param>
/// <param name="save">If save is false, the new instance won't be stored in the db</param>
[HttpPost]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
Expand All @@ -318,6 +379,10 @@ public async Task<ActionResult<ProductInstanceModel>> CreateInstance(string iden
return ProductConverter.ConvertProductInstance(instance);
}

/// <summary>
/// Save the instance in the product db
/// </summary>
/// <param name="instanceModel">Model of the product instance</param>
[HttpPut]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
Expand All @@ -339,6 +404,11 @@ public async Task<ActionResult> SaveInstance(ProductInstanceModel instanceModel)

#endregion
#region recipes
/// <summary>
/// Get's a recipe by it's db id
/// </summary>
/// <param name="id">Database id of the recipe</param>
/// <returns></returns>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
Expand All @@ -355,6 +425,11 @@ public async Task<ActionResult<RecipeModel>> GetRecipe(long id)
return _productConverter.ConvertRecipe(recipe);
}

/// <summary>
/// Saves a new recipe in the database
/// </summary>
/// <param name="recipe">Model of the recipe</param>
/// <returns>The database id of the newly created recipe</returns>
[HttpPost]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
Expand All @@ -373,6 +448,11 @@ public async Task<ActionResult<long>> SaveRecipe(RecipeModel recipe)
return await _productManagement.SaveRecipeAsync(await _productConverter.ConvertRecipeBack(recipe, productRecipe, null));
}

/// <summary>
/// Updates the existing recipes
/// </summary>
/// <param name="id">Database id of the recipe</param>
/// <param name="recipeModel">Updated recipe model</param>
[HttpPut]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
Expand Down
25 changes: 25 additions & 0 deletions src/Moryx.AspNetCore.OpenApi/Moryx.AspNetCore.OpenApi.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Description>Extensions for the integration of MORYX in ASP.NET Core</Description>
<PackageTags>MORYX;ASP</PackageTags>
<IsPackable>true</IsPackable>
<RootNamespace>Moryx.AspNetCore.OpenApi</RootNamespace>
</PropertyGroup>


<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Moryx.AspNetCore\Moryx.AspNetCore.csproj" />
</ItemGroup>

</Project>
70 changes: 70 additions & 0 deletions src/Moryx.AspNetCore.OpenApi/MoryxOpenApiDocumentTransformer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) 2026 Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using Microsoft.AspNetCore.OpenApi;
using Microsoft.OpenApi;

namespace Moryx.AspNetCore.OpenApi;

/// <summary>
/// Document transformer to improve our API documentation
/// </summary>
internal class MoryxOpenApiDocumentTransformer : IOpenApiDocumentTransformer
{
/// <inheritdoc />
public async Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransformerContext context, CancellationToken cancellationToken)
{
SortPathEntries(document);

EnsureSseItemBaseExists(document);
}

/// <summary>
/// Sort path entries by tag
/// </summary>
/// <param name="document"></param>
private static void SortPathEntries(OpenApiDocument document)
{
var path = new OpenApiPaths();
var sortLookup = new Dictionary<string, int>();
document.Tags = document.Tags.OrderBy(t => t.Name).ToHashSet();

var sorted = document.Paths.OrderBy((p) =>
{
if (p.Value.Operations.Count == 0)
{
return "";
}

var op = p.Value.Operations.First().Value;
return op.Tags.FirstOrDefault()?.Name ?? "";
});

foreach (var item in sorted)
{
path.Add(item.Key, item.Value);
}

document.Paths = path;
}

private static void EnsureSseItemBaseExists(OpenApiDocument document)
{
var sseItemBaseSchema = new OpenApiSchema()
{
Type = JsonSchemaType.Object,
Properties = new Dictionary<string, IOpenApiSchema>()
{
{ "type", new OpenApiSchema() { Type = JsonSchemaType.String } },
{ "eventId", new OpenApiSchema() { Type = JsonSchemaType.String } },
{ "reconnectInterval", new OpenApiSchema()
{
Type = JsonSchemaType.String,
Pattern = "^-?(\\d+\\.)?\\d{2}:\\d{2}:\\d{2}(\\.\\d{1,7})?$",
}
}
}
};
document.AddComponent(MoryxSseOperationTransformer.SseItemBaseSchemaId, sseItemBaseSchema);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2026 Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.OpenApi;
using Microsoft.OpenApi;

namespace Moryx.AspNetCore.OpenApi;

internal class MoryxOperationIdOperationTransformer : IOpenApiOperationTransformer
{
public async Task TransformAsync(OpenApiOperation operation, OpenApiOperationTransformerContext context, CancellationToken cancellationToken)
{
if (context.Description.ActionDescriptor is ControllerActionDescriptor controllerActionDescriptor)
{
operation.OperationId = controllerActionDescriptor.MethodInfo.Name; // TODO: This keeps the old behavior, but it's actually violating guidelines regrading uniqueness
}
}
}
Loading
Loading