You can open Swaggie.Nswag/Swaggie.Nswag.sln
in Rider or VS to see the sample ASP.NET Core project with NSwag configured. It is working out of the box and it requires dotnet 6.0
. It should be compatible with other dotnet versions as well.
This is how the generated API Client in TypeScript looks like:
/* tslint:disable */
/* eslint-disable */
//----------------------
// <auto-generated>
// Generated using Swaggie (https://github.com/yhnavein/swaggie)
// Please avoid doing any manual changes in this file
// </auto-generated>
//----------------------
// ReSharper disable InconsistentNaming
import Axios, { AxiosPromise, AxiosRequestConfig } from 'axios';
export const axios = Axios.create({
baseURL: '/api',
});
export const userClient = {
/**
* @param user
*/
createUser(user: UserViewModel, $config?: AxiosRequestConfig): AxiosPromise<UserViewModel> {
let url = '/user';
return axios.request<UserViewModel>({
url: url,
method: 'POST',
data: user,
...$config,
});
},
/**
* @param id
*/
deleteUser(id: number, $config?: AxiosRequestConfig): AxiosPromise<any> {
let url = '/user/{id}';
url = url.replace('{id}', encodeURIComponent('' + id));
return axios.request<any>({
url: url,
method: 'DELETE',
...$config,
});
},
/**
*/
getUsers($config?: AxiosRequestConfig): AxiosPromise<UserViewModel[]> {
let url = '/user';
return axios.request<UserViewModel[]>({
url: url,
method: 'GET',
...$config,
});
},
};
function serializeQueryParam(obj: any) {
if (obj === null || obj === undefined) return '';
if (obj instanceof Date) return obj.toJSON();
if (typeof obj !== 'object' || Array.isArray(obj)) return obj;
return Object.keys(obj)
.reduce((a: any, b) => a.push(b + '=' + obj[b]) && a, [])
.join('&');
}
export interface UserViewModel {
id: number;
role: UserRole;
name?: string;
email?: string;
}
export enum UserRole {
Admin = 'Admin',
User = 'User',
Guest = 'Guest',
}