Skip to content

Getting Started

Danmarks Miljøportal edited this page Sep 8, 2020 · 2 revisions

This tutorial demonstrates how to auto-generate a C# client SDK using the OpenAPI v3 specification. Open source and commercial tools for client/server SDK generation are available for the most popular programming languages. A list of recognized tools is available here: https://openapi.tools.

The following example uses NSwag CLI to generate a C# client library and ASP.NET controller stubs.

1. Download and install NPM (Node Package Manager)

Read more https://www.npmjs.com/get-npm

2. Install NSwag CLI (Command Line Interface) from NPM

Open your terminal and enter the following command to install NSwag on your system globally.

npm install nswag -g

3. Generate client code

Open your terminal and enter the following command to generate the client code in the current directory. The command will generate one C# class file with the specified class and filename.

nswag swagger2csclient /input:https://stanlab-api.test.miljoeportal.dk/openapi/v1/swagger.json /classname:StanlabClient /output:StanlabClient.cs
nswag swagger2cscontroller /input:https://stanlab-api.test.miljoeportal.dk/openapi/v1/swagger.json /classname:ControllerBase /output:ControllerBase.cs

For more configuration, see the NSwag command line interface documentation.

https://github.com/RSuter/NSwag/wiki/CommandLine

4. Open and run the project

Open the project in Visual Studio and run the example code.