Skip to content

Commit

Permalink
Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ellizio committed Jul 22, 2024
1 parent a85182a commit c0c8953
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 4 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# <p align="center"> Kiota.Autogen </p>

<p align="center"> A set of libraries for auto-generating API clients using Kiota </p>
<p align="center"> A set of libraries for auto-generating API clients using <a href="https://github.com/microsoft/kiota">Kiota</a> </p>

---

## Libraries list

- [![Kiota.Autogen.Swagger](https://buildstats.info/nuget/Kiota.Autogen.Swagger)](https://www.nuget.org/packages/Kiota.Autogen.Swagger/) [Kiota.Autogen.Swagger](src/Kiota.Autogen.Swagger) for generating API client based on `Swashbuckle.AspNetCore`
- [![Kiota.Autogen.Swagger](https://buildstats.info/nuget/Kiota.Autogen.Swagger)](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

Expand Down Expand Up @@ -79,7 +79,7 @@ See [full example](examples/basic_swagger)

## Advanced Usage

You can provide your own implementations of Microsoft.Kiota.Abstractions from the `Class library` project if you need\
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;
Expand Down
8 changes: 7 additions & 1 deletion src/Kiota.Autogen.Swagger/Kiota.Autogen.Swagger.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>

<PackageId>Kiota.Autogen.Swagger</PackageId>
<Title>Kiota.Autogen.Swagger</Title>
<Version>1.15.0</Version>
Expand All @@ -13,8 +13,14 @@
<PackageProjectUrl>https://github.com/ellizio/Kiota.Autogen</PackageProjectUrl>
<RepositoryUrl>https://github.com/ellizio/Kiota.Autogen</RepositoryUrl>
<PackageTags>Kiota;OpenAPI;Client;Swagger;Generation;CodeGen</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>

<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\"/>
</ItemGroup>

<ItemGroup>
<Content Include="build\Kiota.Autogen.Swagger.props" PackagePath="build\" />
<Content Include="build\Kiota.Autogen.Swagger.targets" PackagePath="build\" />
Expand Down
93 changes: 93 additions & 0 deletions src/Kiota.Autogen.Swagger/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
[Kiota.Autogen.Swagger](https://github.com/ellizio/Kiota.Autogen) is a package for auto-generating API clients based on [Swashbuckle.AspNetCore](https://github.com/domaindrivendev/Swashbuckle.AspNetCore) using [Kiota](https://github.com/microsoft/kiota)

---

## Basic Usage

1. Add a `Class Library` project to the solution that contains WebApi project
2. Add WebApi project reference with `ExcludeAssets="All"`
```xml
<ItemGroup>
<ProjectReference Include="..\ExampleService.Api\ExampleService.Api.csproj" ExcludeAssets="All" />
</ItemGroup>
```
3. Install `Kiota.Autogen.Swagger` with `PrivateAssets="All"`
```xml
<ItemGroup>
<PackageReference Include="Kiota.Autogen.Swagger" Version="1.15.0" PrivateAssets="All" />
</ItemGroup>
```
4. Install following `Kiota` packages
```xml
<ItemGroup>
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.9.10" />
<PackageReference Include="Microsoft.Kiota.Http.HttpClientLibrary" Version="1.9.10" />
<PackageReference Include="Microsoft.Kiota.Serialization.Form" Version="1.9.10" />
<PackageReference Include="Microsoft.Kiota.Serialization.Json" Version="1.9.10" />
<PackageReference Include="Microsoft.Kiota.Serialization.Multipart" Version="1.9.10" />
<PackageReference Include="Microsoft.Kiota.Serialization.Text" Version="1.9.10" />
</ItemGroup>
```
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
<PropertyGroup>
... other properties

<IsPackable>true</IsPackable>
<PackageId>ExampleService.Client</PackageId>
</PropertyGroup>
```
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();
```

## 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();
```

## More Examples

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

0 comments on commit c0c8953

Please sign in to comment.