AspNet.Evaluation.OpenAPI 0.0.2

dotnet add package AspNet.Evaluation.OpenAPI --version 0.0.2                
NuGet\Install-Package AspNet.Evaluation.OpenAPI -Version 0.0.2                
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="AspNet.Evaluation.OpenAPI" Version="0.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AspNet.Evaluation.OpenAPI --version 0.0.2                
#r "nuget: AspNet.Evaluation.OpenAPI, 0.0.2"                
#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.
// Install AspNet.Evaluation.OpenAPI as a Cake Addin
#addin nuget:?package=AspNet.Evaluation.OpenAPI&version=0.0.2

// Install AspNet.Evaluation.OpenAPI as a Cake Tool
#tool nuget:?package=AspNet.Evaluation.OpenAPI&version=0.0.2                

OpenAPI.Evaluation.AspNet

Adds ASP.NET support for OpenAPI.Evaluation.

Continuous Delivery

Installation

dotnet add package AspNet.Evaluation.OpenAPI

https://www.nuget.org/packages/AspNet.Evaluation.OpenAPI/

Getting Started

Load and register the OpenAPI specification, see OpenAPI.Evaluation for more details.

var builder = WebApplication.CreateBuilder(args);
using var openApiStream = File.OpenRead("path/to/openapi-specification.json");
var specification = OpenAPI.Evaluation.Specification.OpenAPI.Parse(JsonNode.Parse(openApiStream));
builder.Services.AddOpenApiEvaluation(specification);
var app = builder.Build();
// Register evaluation into the request pipeline
app.UseOpenApiEvaluation();
// Register route handlers
...

Evaluating From a Route Handler

HttpContext has some extension methods which can be used to evaluate the current request and response.

app.Run(context =>
{
    var requestEvaluationResult = context.EvaluateRequest();
    ...
    var responseCode = ...
    IHeaderDictionary responseHeaders = ...
    var responseContent = ...
    var responseEvaluation = context.EvaluateResponse(responseCode, responseHeaders, responseContent);
    ...
    return Task.CompletedTask;
});

Response Evaluation Caviat

Be aware that once response headers have been sent over the wire the response can no longer be changed. If you want to evaluate using the response make sure it's buffered. It's recommended to evaluate the response before setting it in the http context that way if evaluation fails it's possible to return a proper response or abort the request without leaking invalid information to the client.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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 was computed.  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. 
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
0.0.2 376 11/14/2023
0.0.2-pre-86f234d2 161 11/3/2023
0.0.2-pre-05fe66fd 116 11/14/2023
0.0.1 173 10/20/2023
0.0.1-pre-cc8c3194 151 10/20/2023
0.0.1-pre-4f831d12 126 10/19/2023