Target Framework: net9.0, net10.0
Extensions and utilities for working with OpenAPI specifications using Microsoft.OpenApi. Provides helper methods for parsing, analyzing, and extracting information from OpenAPI documents and schemas.
Working with OpenAPI specifications programmatically requires extensive knowledge of the object model and common patterns. Atc.OpenApi simplifies this by providing:
- OpenAPI Extension Methods: Convenient extensions for common operations
- Schema Helpers: Extract and analyze schema information
- Data Type Utilities: Determine data types from OpenAPI schemas
- Operation Analysis: Get operation names and response schemas
- Model Extraction: Retrieve model schemas from responses
- Type-Safe Parsing: Strongly-typed access to OpenAPI components
Perfect for:
- API code generators
- OpenAPI documentation tools
- API client generators
- Schema validation tools
- API specification analyzers
- OpenAPI-first development workflows
dotnet add package Atc.OpenApi- .NET 9.0
- Extension methods for
OpenApiOperation - Extension methods for
OpenApiSchema - Schema data type detection and extraction
- Operation name retrieval
- Model schema extraction from responses
- Support for complex schema analysis
- Integration with Microsoft.OpenApi.Readers
- Microsoft.OpenApi.Readers
- Atc (foundation library)
Work with OpenAPI operations:
GetOperationName(): Extracts operation identifierGetModelSchemaFromResponse(): Gets the response model schema
Analyze OpenAPI schemas:
GetDataType(): Determines the data type of a schema- Schema property analysis
- Type detection and mapping
using Atc.OpenApi;
using Microsoft.OpenApi.Models;
// Get operation name
var operationName = openApiOperation.GetOperationName();
Console.WriteLine($"Operation: {operationName}");
// Get model schema from response
var modelSchema = openApiOperation.GetModelSchemaFromResponse();
if (modelSchema != null)
{
Console.WriteLine($"Response Type: {modelSchema.Type}");
}using Atc.OpenApi;
using Microsoft.OpenApi.Models;
OpenApiSchema schema = /* your schema */;
// Get data type information
var dataType = schema.GetDataType();
Console.WriteLine($"Data Type: {dataType}");
// Check schema properties
if (schema.Properties != null)
{
foreach (var property in schema.Properties)
{
Console.WriteLine($"Property: {property.Key}, Type: {property.Value.Type}");
}
}using Microsoft.OpenApi.Readers;
using Atc.OpenApi;
// Read OpenAPI document
var openApiDocument = new OpenApiStringReader().Read(yamlContent, out var diagnostic);
// Analyze operations
foreach (var path in openApiDocument.Paths)
{
foreach (var operation in path.Value.Operations)
{
var operationName = operation.Value.GetOperationName();
var responseSchema = operation.Value.GetModelSchemaFromResponse();
Console.WriteLine($"Path: {path.Key}");
Console.WriteLine($"Method: {operation.Key}");
Console.WriteLine($"Operation: {operationName}");
}
}Contributions are welcome! Please see the main repository README for contribution guidelines.