Evaluation.OpenAPI 0.2.1

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

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

OpenAPI.Evaluation

Evaluates API requests and responses against OpenAPI 3.1 specifications. Comes with a custom System.Net.Http.DelegatingHandler that can be used to intercept requests and responses when using an HttpClient.

Continuous Delivery

Installation

dotnet add package Evaluation.OpenAPI

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

Getting Started

Load the OpenAPI specification.

var stream = File.OpenRead("path/to/openapi-specification.json");
var document = JsonNode.Parse(stream);               
var specification = Specification.OpenAPI.Parse(document);

The OpenAPI class has extension methods that can evaluate HttpRequestMessage and HttpResponseMessage or by manually specifying request uri and method and provide content and headers.

Evaluating using HttpClient

See above how to load an OpenAPI specification.

var specification = ...
var evaluationOptions = new EvaluationOptions();
var client = new HttpClient(
    new OpenApiEvaluationHandler(
        specification,
        evaluationOptions,
        new HttpClientHandler()));

When sending a request the HttpResponseMessage will be wrapped by a EvaluationHttpResponseMessage that contains the evaluation results in the property EvaluationResults. If the HttpRequestMessage fails evaluation the handler will return a EvaluationHttpResponseMessage with a BadRequest response and never send the request to the server.

If you rather prefer failed evaluations to throw an exception, this can be configured with EvaluationOptions.

Yaml

To load a yaml formatted specification, I recommend Yaml2JsonNode.

var yaml = new YamlStream();
using var reader = File.OpenText("path/to/openapi-specification.yaml");
yaml.Load(reader);
var document = yaml.ToJsonNode().First();

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 (1)

Showing the top 1 NuGet packages that depend on Evaluation.OpenAPI:

Package Downloads
AspNet.Evaluation.OpenAPI

Integrates OpenAPI Evaluation into ASP.NET

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.2.1 509 11/14/2023
0.2.1-pre-f49ec224 95 11/3/2023
0.2.1-pre-ea6a9e96 92 11/3/2023
0.2.1-pre-a33f16eb 94 11/13/2023
0.2.0 135 10/21/2023
0.2.0-pre-647143b8 100 10/21/2023
0.1.4 182 10/20/2023
0.1.4-pre-ec87d5f0 105 10/20/2023
0.1.3 113 10/20/2023
0.1.3-pre-f4831be4 126 10/18/2023
0.1.3-pre-b1017338 96 9/25/2023
0.1.3-pre-ac8a2be1 92 10/5/2023
0.1.3-pre-aaf91f75 88 10/19/2023
0.1.3-pre-a9418932 97 9/29/2023
0.1.3-pre-8dc1b144 94 10/5/2023
0.1.3-pre-883cad79 108 9/11/2023
0.1.3-pre-7c961d85 100 9/12/2023
0.1.3-pre-5719591c 98 10/7/2023
0.1.3-pre-4e3f9171 96 9/12/2023
0.1.3-pre-44b42e86 89 9/19/2023
0.1.3-pre-384196a7 102 9/12/2023
0.1.3-pre-29a8a676 95 10/6/2023
0.1.3-pre-1a9e6d11 97 9/11/2023
0.1.3-pre-08176b8b 96 9/13/2023
0.1.2 146 9/6/2023

## [v0.2.1](https://github.com/Fresa/OpenAPI.Evaluation/compare/142a115995f18406ce1250cad5496f16bfaf8fe3...845f5dacdf2515dd3e1b2dfcd915b2456fe5b5ba) (2023-11-14)


### Bug Fixes

* **HttpContent:** content needs to be loaded into buffer before getting the stream as the stream gets cached in HttpContent ([ea6a9e9](https://github.com/Fresa/OpenAPI.Evaluation/commit/ea6a9e961f87ed7d88a763445219e8692a473dee))
* **HttpContent:** load content into buffer if content is not seekable ([d5fa43c](https://github.com/Fresa/OpenAPI.Evaluation/commit/d5fa43c9beda57a68693739b4fb0100367d9d4a8))


### Features

* **schema evaluation:** expose the json schema evaluation options to be able to customize how schemas are evaluated ([a33f16e](https://github.com/Fresa/OpenAPI.Evaluation/commit/a33f16eb09b344ebaed043eb625dfa568799b570))