Unitegra.ApiMetadata 1.5.0

dotnet add package Unitegra.ApiMetadata --version 1.5.0
                    
NuGet\Install-Package Unitegra.ApiMetadata -Version 1.5.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Unitegra.ApiMetadata" Version="1.5.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Unitegra.ApiMetadata" Version="1.5.0" />
                    
Directory.Packages.props
<PackageReference Include="Unitegra.ApiMetadata" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Unitegra.ApiMetadata --version 1.5.0
                    
#r "nuget: Unitegra.ApiMetadata, 1.5.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Unitegra.ApiMetadata@1.5.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Unitegra.ApiMetadata&version=1.5.0
                    
Install as a Cake Addin
#tool nuget:?package=Unitegra.ApiMetadata&version=1.5.0
                    
Install as a Cake Tool

Unitegra.ApiMetadata

NuGet balíček pro automatickou extrakci metadat z API endpointů pro Unitegra dokumentaci.

Instalace

dotnet add package Unitegra.ApiMetadata

Nebo přidáním reference v .csproj:

<PackageReference Include="Unitegra.ApiMetadata" Version="1.5.0" />

Použití

1. Konfigurace v appsettings.json

{
  "UnitegraMetadata": {
    "Secret": "<your-secret-here>",
    "IntegrationName": "HegerAPI",
    "CacheDurationMinutes": 30
  }
}

2. Registrace služeb v Program.cs / Startup.cs

using Unitegra.ApiMetadata.Extensions;

// .NET 6+ (Program.cs)
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddUnitegraMetadata(builder.Configuration.GetSection("UnitegraMetadata"));

// .NET Core 3.1 / .NET 5 (Startup.cs)
public void ConfigureServices(IServiceCollection services)
{
    services.AddUnitegraMetadata(Configuration.GetSection("UnitegraMetadata"));
}

Alternativně lze konfigurovat přímo v kódu:

builder.Services.AddUnitegraMetadata(options =>
{
    options.Secret = "<your-secret-here>";
    options.IntegrationName = "Moje API";
    options.CacheDurationMinutes = 60;
});

3. Označení endpointů atributem

using Unitegra.ApiMetadata.Attributes;

[ApiController]
[Route("api/[controller]")]
public class ProductsController : ControllerBase
{
    // GET endpoint = Source (čte data)
    [HttpGet]
    [EndpointMetadata(typeof(Product))]
    public async Task<List<Product>> GetProducts()
    {
        // implementace
    }

    // POST endpoint = Target (zapisuje data)
    [HttpPost]
    [EndpointMetadata(typeof(Product))]
    public async Task<IActionResult> CreateProduct([FromBody] Product product)
    {
        // implementace
    }

    // S popisem a tagy
    [HttpPut("{id}")]
    [EndpointMetadata(typeof(Product), Description = "Aktualizace produktu", Tags = new[] { "products", "update" })]
    public async Task<IActionResult> UpdateProduct(int id, [FromBody] Product product)
    {
        // implementace
    }
}

4. Více entit v jednom endpointu (TargetTypes)

[HttpPost]
[EndpointMetadata(typeof(Order), typeof(OrderItem))]
public async Task<IActionResult> CreateOrder([FromBody] CreateOrderRequest request)
{
    // implementace
}

Endpoint pro metadata

Po registraci služeb bude dostupný endpoint:

GET /api/unitegra-metadata/endpoints
Header: X-Api-Key: <your-secret-here>

Odpověď

{
  "integrationName": "Moje API",
  "mappings": [
    {
      "source": {
        "server": "sql-server-name",
        "database": "MyDatabase",
        "entity": "dbo.Products"
      },
      "target": {
        "server": "Moje API",
        "database": "API",
        "entity": "GET /api/products"
      },
      "columnMapping": [
        {
          "source": { "column": "Id", "type": "int" },
          "target": { "column": "Id", "type": "int" }
        },
        {
          "source": { "column": "Name", "type": "nvarchar" },
          "target": { "column": "Name", "type": "nvarchar" }
        }
      ]
    }
  ]
}

Další endpointy

  • GET /api/unitegra-metadata/endpoints/raw (header X-Api-Key) - Raw metadata (pro debugging)
  • GET /api/unitegra-metadata/health - Health check (bez autentizace)

Konfigurace

Vlastnost Popis Výchozí hodnota
Secret Tajný klíč pro přístup k endpointu null (bez autentizace)
IntegrationName Název API integrace "Unknown API"
CacheDurationMinutes Doba cache v minutách 30
HideFromSwagger Skrýt endpoint ze Swagger UI true
RoutePrefix Prefix cesty pro endpoint "api/unitegra-metadata"
ServerNameOverride Přepsání názvu serveru null (z connection stringu)
DatabaseNameOverride Přepsání názvu databáze null (z connection stringu)

Jak to funguje

  1. Balíček prohledá assembly pomocí reflexe
  2. Najde všechny controller metody s atributem [EndpointMetadata]
  3. Pro každý entity typ zkusí najít metadata v registrovaných DbContext
  4. Pokud DbContext neexistuje, vytvoří základní metadata z typu
  5. Vygeneruje mappingy ve formátu kompatibilním s Unitegra

Explicitní mapování sloupců

MapColumn - explicitní mapování

Pokud se názvy sloupců liší mezi DTO a entitou, použijte [MapColumn]:

[HttpPost]
[EndpointMetadata(
    SourceType = typeof(InvoiceDTO),
    TargetTypes = new[] { typeof(Invoice), typeof(User) },
    Description = "Import faktur")]
// Mapování pro entitu Invoice
[MapColumn("BankPaymentIdentification", "Id", TargetType = typeof(Invoice))]
// Mapování pro entitu User (z vnořeného UserDTO)
[MapColumn("UserId", "Id", TargetType = typeof(User), SourceType = typeof(UserDTO))]
[MapColumn("FirstName", "FirstName", TargetType = typeof(User), SourceType = typeof(UserDTO))]
public async Task<IActionResult> PostInvoices(List<InvoiceDTO> invoices)

IgnoreColumn - ignorování sloupců

Pro sloupce, které se nemají mapovat (computed columns, navigation properties):

[HttpPost]
[EndpointMetadata(SourceType = typeof(ProductDTO), TargetTypes = new[] { typeof(Product) })]
[IgnoreColumn("SynchronizationStatus", TargetType = typeof(Product))]
[IgnoreColumn("SynchronizationStatusMessage", TargetType = typeof(Product))]
public async Task<IActionResult> PostProducts(List<ProductDTO> products)

Automatická detekce vnořených DTO (v1.3.0+)

Od verze 1.3.0 knihovna automaticky detekuje vnořené DTO objekty:

// InvoiceDTO obsahuje vnořené objekty:
public class InvoiceDTO
{
    public string InvoiceId { get; set; }
    public UserDTO User { get; set; }           // Vnořený objekt
    public List<InvoiceItemDTO> Items { get; set; }  // Kolekce
}

// Knihovna automaticky najde:
// - UserDTO pro target entitu User
// - InvoiceItemDTO pro target entitu InvoiceItem
// Není potřeba explicitní MapColumn pro všechny properties

Automatická detekce funguje pro:

  • Kolekce (List<T>, IEnumerable<T>, pole)
  • Vnořené objekty (single properties jako User typu UserDTO)
  • Rekurzivní hledání (1 úroveň do hloubky)

Mapování probíhá podle normalizovaného názvu (odstraní se sufixy Dto, Entity, Model, Post, Get, Request, Response).

Integrace s EF Core

Pokud vaše API používá Entity Framework Core, balíček automaticky:

  • Najde název tabulky a schématu
  • Extrahuje server a databázi z connection stringu
  • Získá informace o sloupcích včetně datových typů
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.5.0 104 2/16/2026
1.4.0 100 2/4/2026
1.3.0 106 1/28/2026
1.2.1 100 1/27/2026
1.2.0 100 1/27/2026
1.1.0 104 1/26/2026
1.0.0 106 1/26/2026