in program cs und example values
This commit is contained in:
@@ -147,12 +147,13 @@ builder.Services.AddSwaggerGen(c =>
|
||||
new string[] {} // Keine spezifischen "Scopes" f<>r JWT (leer lassen)
|
||||
}
|
||||
});
|
||||
|
||||
// 3. Optional: Filtern und Anzeigen von Autorisierungsinformationen (Rollen)
|
||||
// Damit Swagger die "Authorize"-Informationen von Ihren Controllern anzeigt.
|
||||
c.OperationFilter<AuthorizeOperationFilter>();
|
||||
c.OperationFilter<LoginExampleOperationFilter>();
|
||||
|
||||
c.SchemaFilter<AddExampleSchemaFilter>();
|
||||
|
||||
c.OperationFilter<LoginExampleOperationFilter>();
|
||||
c.OperationFilter<PaymentMethodExampleOperationFilter>();
|
||||
c.OperationFilter<SupplierExampleOperationFilter>();
|
||||
});
|
||||
|
||||
// --- ENDE: DIENSTE ZUM CONTAINER HINZUF<55>GEN ---
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
// src/Webshop.Api/SwaggerFilters/PaymentMethodExampleOperationFilter.cs
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
using Microsoft.OpenApi.Any;
|
||||
using Webshop.Domain.Enums;
|
||||
using System.Net.Mime; // Für MediaTypeNames
|
||||
|
||||
namespace Webshop.Api.SwaggerFilters
|
||||
{
|
||||
public class PaymentMethodExampleOperationFilter : IOperationFilter
|
||||
{
|
||||
public void Apply(OpenApiOperation operation, OperationFilterContext context)
|
||||
{
|
||||
// Überprüfe, ob dies die "CreatePaymentMethod"-Methode im "AdminPaymentMethodsController" ist
|
||||
if (context.MethodInfo.DeclaringType == typeof(Controllers.Admin.AdminPaymentMethodsController) &&
|
||||
context.MethodInfo.Name == "CreatePaymentMethod")
|
||||
{
|
||||
if (operation.RequestBody == null ||
|
||||
!operation.RequestBody.Content.TryGetValue(MediaTypeNames.Application.Json, out var mediaType))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (mediaType.Examples == null)
|
||||
{
|
||||
mediaType.Examples = new Dictionary<string, OpenApiExample>();
|
||||
}
|
||||
mediaType.Examples.Clear();
|
||||
|
||||
// Beispiel 1: Banküberweisung
|
||||
mediaType.Examples["BankTransfer"] = new OpenApiExample
|
||||
{
|
||||
Summary = "Beispiel: Banküberweisung",
|
||||
Value = new OpenApiObject
|
||||
{
|
||||
["name"] = new OpenApiString("Banküberweisung (Vorkasse)"),
|
||||
["description"] = new OpenApiString("Bitte überweisen Sie den Betrag auf unser Konto."),
|
||||
["isActive"] = new OpenApiBoolean(true),
|
||||
["paymentGatewayType"] = new OpenApiString(PaymentGatewayType.BankTransfer.ToString()),
|
||||
["configuration"] = new OpenApiString("{\"IBAN\":\"DE123456789\",\"BIC\":\"ABCDEFGH\",\"BankName\":\"Beispielbank AG\"}"),
|
||||
["processingFee"] = new OpenApiDouble(0)
|
||||
}
|
||||
};
|
||||
|
||||
// Beispiel 2: Stripe
|
||||
mediaType.Examples["Stripe"] = new OpenApiExample
|
||||
{
|
||||
Summary = "Beispiel: Kreditkarte (Stripe)",
|
||||
Value = new OpenApiObject
|
||||
{
|
||||
["name"] = new OpenApiString("Kreditkarte (via Stripe)"),
|
||||
["description"] = new OpenApiString("Sichere Zahlung mit Ihrer Kreditkarte."),
|
||||
["isActive"] = new OpenApiBoolean(true),
|
||||
["paymentGatewayType"] = new OpenApiString(PaymentGatewayType.Stripe.ToString()),
|
||||
["configuration"] = new OpenApiString("{\"PublicKey\":\"pk_test_YOUR_KEY\",\"SecretKey\":\"sk_test_YOUR_SECRET\"}"),
|
||||
["processingFee"] = new OpenApiDouble(1.5)
|
||||
}
|
||||
};
|
||||
|
||||
// Beispiel 3: PayPal
|
||||
mediaType.Examples["PayPal"] = new OpenApiExample
|
||||
{
|
||||
Summary = "Beispiel: PayPal",
|
||||
Value = new OpenApiObject
|
||||
{
|
||||
["name"] = new OpenApiString("PayPal"),
|
||||
["description"] = new OpenApiString("Zahlen Sie schnell und sicher mit PayPal."),
|
||||
["isActive"] = new OpenApiBoolean(true),
|
||||
["paymentGatewayType"] = new OpenApiString(PaymentGatewayType.PayPal.ToString()),
|
||||
["configuration"] = new OpenApiString("{\"ClientId\":\"YOUR_PAYPAL_CLIENT_ID\",\"ClientSecret\":\"YOUR_PAYPAL_SECRET\"}"),
|
||||
["processingFee"] = new OpenApiDouble(2.5)
|
||||
}
|
||||
};
|
||||
|
||||
// Beispiel 4: Rechnung
|
||||
mediaType.Examples["Invoice"] = new OpenApiExample
|
||||
{
|
||||
Summary = "Beispiel: Kauf auf Rechnung",
|
||||
Value = new OpenApiObject
|
||||
{
|
||||
["name"] = new OpenApiString("Kauf auf Rechnung"),
|
||||
["description"] = new OpenApiString("Nur für registrierte Geschäftskunden."),
|
||||
["isActive"] = new OpenApiBoolean(true),
|
||||
["paymentGatewayType"] = new OpenApiString(PaymentGatewayType.Invoice.ToString()),
|
||||
["configuration"] = new OpenApiString("{\"PaymentTerms\":\"14 Tage netto\"}"),
|
||||
["processingFee"] = new OpenApiDouble(0)
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
61
Webshop.Api/SwaggerFilters/SupplierExampleOperationFilter.cs
Normal file
61
Webshop.Api/SwaggerFilters/SupplierExampleOperationFilter.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
// src/Webshop.Api/SwaggerFilters/SupplierExampleOperationFilter.cs
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
using Microsoft.OpenApi.Any;
|
||||
using System.Net.Mime; // Für MediaTypeNames
|
||||
|
||||
namespace Webshop.Api.SwaggerFilters
|
||||
{
|
||||
public class SupplierExampleOperationFilter : IOperationFilter
|
||||
{
|
||||
public void Apply(OpenApiOperation operation, OperationFilterContext context)
|
||||
{
|
||||
// Überprüfe, ob dies die "CreateSupplier"-Methode im "AdminSuppliersController" ist
|
||||
if (context.MethodInfo.DeclaringType == typeof(Controllers.Admin.AdminSuppliersController) &&
|
||||
context.MethodInfo.Name == "CreateSupplier")
|
||||
{
|
||||
if (operation.RequestBody == null ||
|
||||
!operation.RequestBody.Content.TryGetValue(MediaTypeNames.Application.Json, out var mediaType))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (mediaType.Examples == null)
|
||||
{
|
||||
mediaType.Examples = new Dictionary<string, OpenApiExample>();
|
||||
}
|
||||
mediaType.Examples.Clear();
|
||||
|
||||
// Beispiel 1: Lokaler Lieferant
|
||||
mediaType.Examples["LocalSupplier"] = new OpenApiExample
|
||||
{
|
||||
Summary = "Beispiel: Lokaler Lieferant",
|
||||
Value = new OpenApiObject
|
||||
{
|
||||
["name"] = new OpenApiString("Lokale Manufaktur GmbH"),
|
||||
["contactPerson"] = new OpenApiString("Hans Meier"),
|
||||
["email"] = new OpenApiString("hans.meier@manufaktur-lokal.de"),
|
||||
["phoneNumber"] = new OpenApiString("+49 89 1234567"),
|
||||
["addressId"] = new OpenApiNull(),
|
||||
["notes"] = new OpenApiString("Handgefertigte Produkte, kurze Lieferzeiten.")
|
||||
}
|
||||
};
|
||||
|
||||
// Beispiel 2: Internationaler Großhändler
|
||||
mediaType.Examples["InternationalSupplier"] = new OpenApiExample
|
||||
{
|
||||
Summary = "Beispiel: Internationaler Großhändler",
|
||||
Value = new OpenApiObject
|
||||
{
|
||||
["name"] = new OpenApiString("Global Imports Inc."),
|
||||
["contactPerson"] = new OpenApiString("John Smith"),
|
||||
["email"] = new OpenApiString("john.smith@global-imports.com"),
|
||||
["phoneNumber"] = new OpenApiString("+1 555 987 6543"),
|
||||
["addressId"] = new OpenApiNull(),
|
||||
["notes"] = new OpenApiString("Container-Lieferungen, 4-6 Wochen Vorlaufzeit.")
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user