OpenAPI2JsonSchema 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package OpenAPI2JsonSchema --version 1.1.0
NuGet\Install-Package OpenAPI2JsonSchema -Version 1.1.0
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="OpenAPI2JsonSchema" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OpenAPI2JsonSchema --version 1.1.0
#r "nuget: OpenAPI2JsonSchema, 1.1.0"
#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 OpenAPI2JsonSchema as a Cake Addin
#addin nuget:?package=OpenAPI2JsonSchema&version=1.1.0

// Install OpenAPI2JsonSchema as a Cake Tool
#tool nuget:?package=OpenAPI2JsonSchema&version=1.1.0

OpenApi2JsonSchema

Getting Started

Create OpenAPI-specifiation

First you will need to create an OpenAPI-specification, which you'll be translating to Json-Schema later.

Example

If you use Swashbuckle this might look something like this:

services.AddSwaggerGen(c =>
      {
        c.SwaggerDoc("v1", new OpenApiInfo {Title = "MyApplication", Version = "v1"});
        var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
        var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
        c.IncludeXmlComments(xmlPath);
        c.AddFluentValidationRules();
      });

In this example, an OpenAPI-specification is created. In order to keep Data Annotations out of its model, this examples uses FluentValidationRules, that can be added easily using the last line in the example above.

Installation

Install the library using NuGet-Package Manager:

Install-Package OpenAPI2JsonSchema

Dependency Injection

In order to be able to use the library, simply add the following line to the ConfigureServices()-method in Startup.cs:

services.AddJsonSchemaGenerator();

For this you will need to import the dependency in Startup.cs:

using OpenApi2JsonSchema;

Usage

You can generate a JsonSchema for any type using:

var schema = JsonSchemaGenerator.GetSchemaWithOpenApi<T>("url-to-openapi-file>");

Just replace <url-to-openapi-file> with the URL that points to your OpenAPI-JSON-file.

Create SchemaProvider

Unless you want to specify the OpenAPI-path every time

Configuration

Delete OpenAPI-file on Startup

Since the library downloads the specified OpenAPI-file and caches it for further usage, you can optionally delete the downloaded file on Startup by adding the following lines to the Configure()-method in Startup.cs:

if (File.Exists("swagger.json"))
        File.Delete("swagger.json");

Note that the path to the OpenAPI-file can vary, depending on what download-path you specified.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  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. 
.NET Core netcoreapp3.1 is compatible. 
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
2.0.0 331 2/10/2023
1.1.4 681 6/8/2020
1.1.3 533 6/3/2020
1.1.2 493 5/25/2020
1.1.1 520 3/25/2020
1.1.0 513 3/24/2020
1.0.0 512 3/20/2020