An open API service indexing awesome lists of open source software.

https://github.com/ellizio/kiota.autogen

A set of libraries for auto-generating API clients using Kiota
https://github.com/ellizio/kiota.autogen

kiota openapi-client openapi-codegen openapi3 swagger

Last synced: 5 months ago
JSON representation

A set of libraries for auto-generating API clients using Kiota

Awesome Lists containing this project

README

          

#

Kiota.Autogen

A set of libraries for auto-generating API clients using Kiota

---

## Libraries list

- [![](https://img.shields.io/nuget/dt/Kiota.Autogen.Swagger?logo=nuget&color=007edf)](https://www.nuget.org/packages/Kiota.Autogen.Swagger/) [Kiota.Autogen.Swagger](src/Kiota.Autogen.Swagger) for generating API client based on [Swashbuckle.AspNetCore](https://github.com/domaindrivendev/Swashbuckle.AspNetCore)

## Basic Usage

1. Add a `Class Library` project to the solution that contains WebApi project
2. Add WebApi project reference with `ExcludeAssets="All"`
```xml

```
3. Install `Kiota.Autogen.Swagger` with `PrivateAssets="All"`
```xml

```
4. Install following `Kiota` packages
```xml






```
5. Create a `gensettings.json` file with the following structure
```jsonc
[
{
"name": "WeatherClient", // API client name to be generated
"namespace": "Weather.Client", // API client namespace
"version": "v1" // WebApi Swagger document version
},
{
"name": "WeatherClientNew",
"namespace": "Weather.Client.New",
"version": "v2"
}
]
```
6. Set up `Class library` project to build as a nuget package
```xml

... other properties

true
ExampleService.Client

```
7. Pack `Class library` project
8. Enjoy using API client
```csharp
using Microsoft.Kiota.Abstractions.Authentication;
using Microsoft.Kiota.Http.HttpClientLibrary;
using Weather.Client;

using var httpClient = new HttpClient();
httpClient.BaseAddress = new Uri("http://your_service_url");

var provider = new AnonymousAuthenticationProvider();
using var adapter = new HttpClientRequestAdapter(provider, httpClient: httpClient);
var client = new WeatherClient(adapter);

var forecasts = await client.Weatherforecast.GetAsync();
```

See [full example](https://github.com/ellizio/Kiota.Autogen-Examples/tree/master/1.%20Swagger)

## Advanced Usage

You can provide your own implementations of `Microsoft.Kiota.Abstractions` from the `Class library` project if you need\
Usage:
```csharp
using Microsoft.Kiota.Abstractions.Authentication;
using Microsoft.Kiota.Http.HttpClientLibrary;
using Weather.Client;

using var httpClient = new HttpClient();
httpClient.BaseAddress = new Uri("http://your_service_url");

var provider = new AnonymousAuthenticationProvider();
using var adapter = new HttpClientRequestAdapter(provider, new WeatherParseNodeFactory(), new WeatherSerializationWriterFactory(), httpClient: httpClient);
var client = new WeatherClient(adapter);

var forecasts = await client.Weatherforecast.GetAsync();
```

See [full example](https://github.com/ellizio/Kiota.Autogen-Examples/tree/master/2.%20Advanced)

## More Examples

See more examples [here](https://github.com/ellizio/Kiota.Autogen-Examples)

## Additional References

- [Changelog](CHANGELOG.md)
- [Kiota](https://github.com/microsoft/kiota)
- [Swashbuckle.AspNetCore](https://github.com/domaindrivendev/Swashbuckle.AspNetCore)