Giter Site home page Giter Site logo

slamj1 / nswag Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ricosuter/nswag

0.0 3.0 0.0 29.63 MB

The Swagger (Open API) toolchain for .NET, Web API and TypeScript.

Home Page: http://NSwag.org

License: MIT License

Batchfile 0.05% C# 73.29% ASP 0.01% HTML 4.23% JavaScript 0.36% TypeScript 21.97% CSS 0.08% PowerShell 0.01%

nswag's Introduction

NSwag: The Swagger (Open API) toolchain for .NET, Web API and TypeScript

NuGet Version npm Build status Build status MyGet CI Gitter StackOverflow

NSwag is a Swagger 2.0 API (OpenAPI) toolchain for .NET, Web API, ASP.NET Core, TypeScript (jQuery, AngularJS, Angular 2+, Aurelia, KnockoutJS, and more) and other platforms, written in C#. The Swagger specification uses JSON and JSON Schema to describe a RESTful web API. The NSwag project provides tools to generate Swagger specifications from existing ASP.NET Web API controllers and client code from these Swagger specifications.

The project combines the functionality of Swashbuckle (Swagger generation) and AutoRest (client generation) in one toolchain. This way a lot of incompatibilites can be avoided and features which are not well described by the Swagger specification or JSON Schema are better supported (e.g. inheritance, enum and reference handling). The NSwag project heavily uses NJsonSchema for .NET for JSON Schema handling and C#/TypeScript class/interface generation.

ToolchainDiagram

The project is developed and maintained by Rico Suter and other contributors.

Ways to use the toolchain:

Tutorials

Swagger Generators:

Code Generators:

  • TypeScript Client
    • SwaggerToTypeScriptClientGenerator
      • Generates TypeScript clients from a Swagger specification
      • Available templates/supported libraries:
        • JQuery with Callbacks, JQueryCallbacks
        • JQuery with promises JQueryPromises
        • AngularJS using $http, AngularJS
        • Angular (v2+) using the http service, Angular
        • window.fetch API and ES6 promises, Fetch (use this template in your React/Redux app)
        • Aurelia using the HttpClient from aurelia-fetch-client, Aurelia (based on the Fetch template)
  • CSharp Client
  • CSharp WebAPI Controllers (contract first/schema first development)

Downloads

NPM Packages

  • NSwag: Command line tools (.NET and .NET Core) distributed as NPM package

NuGet Packages

  • NSwag.Core (PCL 259 / .NETStandard 1.0):
    • The Swagger reader and writer classes
  • NSwag.Annotations (PCL 259 / .NETStandard 1.0):
    • Attributes to decorate Web API controllers to control the Swagger generation
  • NSwag.SwaggerGeneration (PCL 259 / .NETStandard 1.0):
    • Classes to generate Swagger specifications
  • NSwag.SwaggerGeneration.WebApi (PCL 259 / .NETStandard 1.0):
    • Classes to generate Swagger specifications from Web API controllers
  • NSwag.CodeGeneration (PCL 259 / .NETStandard 1.0):
    • Base classes to generate clients from Swagger specifications
  • NSwag.CodeGeneration.CSharp (PCL 259 / .NETStandard 1.0):
    • Classes to generate C# clients from Swagger specifications
  • NSwag.CodeGeneration.TypeScript (PCL 259 / .NETStandard 1.0):
    • Classes to generate TypeScript clients from Swagger specifications
  • NSwag.AssemblyLoader (.NET 4.5+):
    • Classes to load assemblies in an isolated AppDomain and generate Swagger specs from Web API controllers
  • NSwag.AssemblyLoaderCore (.NET Core, .NETStandard 1.6):
    • Classes to load assemblies in an AssemblyLoaderContext and generate Swagger specs from Web API controllers
  • NSwag.MSBuild (MSBuild .targets):
    • Adds a .targets file to your Visual Studio project, so that you can run the NSwag command line tool in an MSBuild target
  • NSwag.AspNetCore (.NETStandard 1.6 and .NET 4.5.1+):
  • NSwag.AspNet.Owin (.NET 4.5+):
    • ASP.NET Core/OWIN middlewares for serving Swagger specifications and Swagger UI
  • NSwag.AspNet.WebApi (.NET 4.5+):
  • NSwagStudio (Chocolatey, Windows):
    • Package to install the NSwagStudio and command line tools via Chocolatey
  • NSwag.Commands (PCL 259 / .NETStandard 1.0):
    • Commands for the command line tool implementations and UI
  • NSwag.ConsoleCore (PCL 259 / .NETStandard 1.0):
    • Command line tool for .NET Core (dotnet nswag)

CI NuGet Feed: https://www.myget.org/gallery/nswag-ci

The NuGet packages may require the Microsoft.NETCore.Portable.Compatibility package on .NET Core/UWP targets (if mscorlib is missing).

LayerDiagram

Usage in C#

The following code shows how to read a Swagger specification and generate C# client classes to call the described web services:

var swaggerSettings = new WebApiToSwaggerGeneratorSettings();
var swaggerGenerator = new WebApiToSwaggerGenerator(swaggerSettings);

var document = await swaggerGenerator.GenerateForControllerAsync<PersonsController>();

var clientSettings = new SwaggerToCSharpClientGeneratorSettings 
{
    ClassName = "MyClass",
    Namespace = "MyNamespace"
};
var clientGenerator = new SwaggerToCSharpClientGenerator(document, clientSettings);

var code = clientGenerator.GenerateFile();

Check out the project Wiki for more information.

NSwagStudio

The generators can be used in a comfortable and simple Windows GUI called NSwagStudio:

nswag's People

Contributors

aelbatal avatar alpercelik avatar alphaleonis avatar ashleygrant avatar bitdeli-chef avatar cpx86 avatar dgioulakis avatar duartepatriani avatar egorikas avatar eihag avatar filipw avatar grovesnl avatar hmflash avatar jameschch avatar jkonecki avatar krisztiankocsis avatar loicnz avatar lordjz avatar michaelaird avatar mvandevy avatar omkarmore83 avatar paulomorgado avatar peterhenell avatar rado0x54 avatar ricosuter avatar sandord avatar shakann avatar sharmavishalvk avatar thumnet avatar weitzhandler avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.