SH.Framework.OpenApi.Implementation
1.0.1
dotnet add package SH.Framework.OpenApi.Implementation --version 1.0.1
NuGet\Install-Package SH.Framework.OpenApi.Implementation -Version 1.0.1
<PackageReference Include="SH.Framework.OpenApi.Implementation" Version="1.0.1" />
<PackageVersion Include="SH.Framework.OpenApi.Implementation" Version="1.0.1" />
<PackageReference Include="SH.Framework.OpenApi.Implementation" />
paket add SH.Framework.OpenApi.Implementation --version 1.0.1
#r "nuget: SH.Framework.OpenApi.Implementation, 1.0.1"
#:package SH.Framework.OpenApi.Implementation@1.0.1
#addin nuget:?package=SH.Framework.OpenApi.Implementation&version=1.0.1
#tool nuget:?package=SH.Framework.OpenApi.Implementation&version=1.0.1
SH.Framework.OpenApi.Implementation
A comprehensive implementation layer for OpenAPI integration in ASP.NET Core projects. This package provides extension methods and helpers for customizing OpenAPI schema generation, including friendly schema reference IDs and configuration registration. It extends the default OpenAPI experience with practical utilities for schema naming and configuration.
๐ Features
- ๐ Extension Methods: Easily register OpenAPI configuration in your DI container
- ๐ Friendly Schema Reference IDs: Custom logic for readable and unique schema IDs
- ๐ง Flexible Configuration: Customize OpenAPI options for your project
- ๐ฆ .NET 10 Support: Modern .NET compatibility
- ๐ก๏ธ Type Safety: Strongly-typed extension points
- ๐ฏ Clean Architecture: Promotes maintainable and scalable API documentation
๐ฆ Installation
dotnet add package SH.Framework.OpenApi.Implementation
Note: This package automatically includes required dependencies for OpenAPI integration.
๐ ๏ธ Quick Start
1. Register OpenAPI Configuration
using SH.Framework.Library.OpenApi.Implementation;
var builder = WebApplication.CreateBuilder(args);
// Register OpenAPI configuration
builder.Services.AddOpenApiConfiguration();
var app = builder.Build();
2. Customize Schema Reference IDs
The package provides a helper for generating friendly schema reference IDs:
using SH.Framework.Library.OpenApi.Implementation;
string schemaId = OpenApiExtensions.CreateFriendlyId(typeof(List<string>));
// Output: ListOfString
3. Use in ASP.NET Core Projects
Integrate with your API project for improved OpenAPI documentation:
public static class RegisterOpenApiConfiguration
{
public static IServiceCollection AddOpenApiConfiguration(this IServiceCollection services) {
services.AddOpenApi(options =>
{
options.CreateSchemaReferenceId = context =>
{
return OpenApiExtensions.CreateFriendlyId(context.Type);
};
});
return services;
}
}
๐๏ธ Architecture Components
Friendly Schema Reference ID
Generates readable and unique schema IDs for OpenAPI documents:
public static string CreateFriendlyId(Type type)
{
if (type.IsArray)
return $"{CreateFriendlyId(type.GetElementType()!)}Array";
if (type.IsGenericType)
{
var nameBuilder = new StringBuilder();
var cleanName = type.Name.Split('`')[0];
nameBuilder.Append(cleanName);
nameBuilder.Append("Of");
var args = type.GetGenericArguments();
for (int i = 0; i < args.Length; i++)
nameBuilder.Append(CreateFriendlyId(args[i]));
return nameBuilder.ToString();
}
if (type.IsNested && type.DeclaringType != null)
return $"{CreateFriendlyId(type.DeclaringType)}{type.Name}";
var id = type.Name;
return id.Replace("[]", "Array").Replace("[", "").Replace("]", "").Replace(",", "").Replace("+", "");
}
Extension Registration
public static IServiceCollection AddOpenApiConfiguration(this IServiceCollection services)
{
services.AddOpenApi(options =>
{
options.CreateSchemaReferenceId = context =>
{
return OpenApiExtensions.CreateFriendlyId(context.Type);
};
});
return services;
}
๐ง Advanced Usage
Custom Schema Naming
You can extend or override the schema ID generation logic for your own types:
options.CreateSchemaReferenceId = context =>
{
// Custom logic
return MyCustomSchemaIdGenerator(context.Type);
};
Integration with Other OpenAPI Tools
This package is compatible with other OpenAPI/Swagger tools and can be used to enhance schema documentation and naming conventions.
๐ Response Patterns
OpenAPI schema IDs generated by this package will be readable and unique, improving the clarity of your API documentation.
๐ฏ Best Practices
- Use friendly schema IDs for better documentation
- Register OpenAPI configuration early in your DI setup
- Customize options as needed for your API
- Leverage extension methods to keep your startup code clean
- Follow clean architecture principles for scalable API projects
๐ Dependencies
- Microsoft.AspNetCore.OpenApi: OpenAPI integration for ASP.NET Core
- Microsoft.Extensions.DependencyInjection: DI support
- .NET 10.0: Target framework
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ข Company
Strawhats Company
Created by Muharrem Kaรงkฤฑn
โญ If you find this library helpful, please consider giving it a star on GitHub!
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net10.0
- Microsoft.AspNetCore.OpenApi (>= 10.0.5)
- Microsoft.Extensions.DependencyInjection (>= 10.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v1.0.0:
- Initial release with custom schema reference ID and OpenAPI configuration extensions.