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
<PackageReference Include="AspNet.Evaluation.OpenAPI" Version="0.0.2" />
paket add AspNet.Evaluation.OpenAPI --version 0.0.2
#r "nuget: AspNet.Evaluation.OpenAPI, 0.0.2"
// 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.
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
Product | Versions 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. |
-
net7.0
- Evaluation.OpenAPI (>= 0.2.1 && < 1.0.0)
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 |
## [v0.0.2](https://github.com/Fresa/OpenAPI.Evaluation.AspNet/compare/6369e848d55dd77409ef3789a42c94613e50dd10...491442e90563916687670d3b1e3d9131ce432b51) (2023-11-14)
### Bug Fixes
* enable request content buffering to be able to evaluate and deserialize separately ([86f234d](https://github.com/Fresa/OpenAPI.Evaluation.AspNet/commit/86f234d2eea6a0247b8425ec1d19cb550e7a582e))