From 1d2a1a8974d2864a9e9968006950b588e2876828 Mon Sep 17 00:00:00 2001 From: slavkor <30171206+slavkor@users.noreply.github.com> Date: Thu, 4 Jul 2024 12:05:03 +0000 Subject: [PATCH] chore: release data-link SDK --- README.md | 160 ++++++++++++++++++++++++++++++++++++++++++++++++ src/Databox.sln | 10 +-- 2 files changed, 165 insertions(+), 5 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..1259055 --- /dev/null +++ b/README.md @@ -0,0 +1,160 @@ +# Databox - the C# library for the Static OpenAPI document of Push API resource + +Push API resources Open API documentation + +This C# SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project: + +- API version: 1.0 +- SDK version: 0.0.2 +- Generator version: 7.6.0 +- Build package: org.openapitools.codegen.languages.CSharpClientCodegen + + +## Frameworks supported + + +## Dependencies + +- [Json.NET](https://www.nuget.org/packages/Newtonsoft.Json/) - 13.0.2 or later +- [JsonSubTypes](https://www.nuget.org/packages/JsonSubTypes/) - 1.8.0 or later +- [System.ComponentModel.Annotations](https://www.nuget.org/packages/System.ComponentModel.Annotations) - 5.0.0 or later + +The DLLs included in the package may not be the latest version. We recommend using [NuGet](https://docs.nuget.org/consume/installing-nuget) to obtain the latest version of the packages: +``` +Install-Package Newtonsoft.Json +Install-Package JsonSubTypes +Install-Package System.ComponentModel.Annotations +``` + +## Installation +Run the following command to generate the DLL +- [Mac/Linux] `/bin/sh build.sh` +- [Windows] `build.bat` + +Then include the DLL (under the `bin` folder) in the C# project, and use the namespaces: +```csharp +using Databox.Api; +using Databox.Client; +using Databox.Model; +``` + +## Packaging + +A `.nuspec` is included with the project. You can follow the Nuget quickstart to [create](https://docs.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package#create-the-package) and [publish](https://docs.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package#publish-the-package) packages. + +This `.nuspec` uses placeholders from the `.csproj`, so build the `.csproj` directly: + +``` +nuget pack -Build -OutputDirectory out Databox.csproj +``` + +Then, publish to a [local feed](https://docs.microsoft.com/en-us/nuget/hosting-packages/local-feeds) or [other host](https://docs.microsoft.com/en-us/nuget/hosting-packages/overview) and consume the new package via Nuget as usual. + + +## Usage + +To use the API client with a HTTP proxy, setup a `System.Net.WebProxy` +```csharp +Configuration c = new Configuration(); +System.Net.WebProxy webProxy = new System.Net.WebProxy("http://myProxyUrl:80/"); +webProxy.Credentials = System.Net.CredentialCache.DefaultCredentials; +c.Proxy = webProxy; +``` + +### Connections +Each ApiClass (properly the ApiClient inside it) will create an instance of HttpClient. It will use that for the entire lifecycle and dispose it when called the Dispose method. + +To better manager the connections it's a common practice to reuse the HttpClient and HttpClientHandler (see [here](https://docs.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests#issues-with-the-original-httpclient-class-available-in-net) for details). To use your own HttpClient instance just pass it to the ApiClass constructor. + +```csharp +HttpClientHandler yourHandler = new HttpClientHandler(); +HttpClient yourHttpClient = new HttpClient(yourHandler); +var api = new YourApiClass(yourHttpClient, yourHandler); +``` + +If you want to use an HttpClient and don't have access to the handler, for example in a DI context in Asp.net Core when using IHttpClientFactory. + +```csharp +HttpClient yourHttpClient = new HttpClient(); +var api = new YourApiClass(yourHttpClient); +``` +You'll loose some configuration settings, the features affected are: Setting and Retrieving Cookies, Client Certificates, Proxy settings. You need to either manually handle those in your setup of the HttpClient or they won't be available. + +Here an example of DI setup in a sample web project: + +```csharp +services.AddHttpClient(httpClient => + new PetApi(httpClient)); +``` + + + +## Getting Started + +```csharp +using System.Collections.Generic; +using System.Diagnostics; +using System.Net.Http; +using Databox.Api; +using Databox.Client; +using Databox.Model; + +namespace Example +{ + public class Example + { + public static void Main() + { + + Configuration config = new Configuration(); + config.BasePath = "http://localhost:8080/q/openapi"; + // create instances of HttpClient, HttpClientHandler to be reused later with different Api classes + HttpClient httpClient = new HttpClient(); + HttpClientHandler httpClientHandler = new HttpClientHandler(); + var apiInstance = new DefaultApi(httpClient, config, httpClientHandler); + var payloadModel = new PayloadModel?(); // PayloadModel? | (optional) + + try + { + apiInstance.RootPost(payloadModel); + } + catch (ApiException e) + { + Debug.Print("Exception when calling DefaultApi.RootPost: " + e.Message ); + Debug.Print("Status Code: "+ e.ErrorCode); + Debug.Print(e.StackTrace); + } + + } + } +} +``` + + +## Documentation for API Endpoints + +All URIs are relative to *http://localhost:8080/q/openapi* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*DefaultApi* | [**RootPost**](docs/DefaultApi.md#rootpost) | **POST** / | + + + +## Documentation for Models + + - [Model.ApiResponse](docs/ApiResponse.md) + - [Model.PayloadDataModel](docs/PayloadDataModel.md) + - [Model.PayloadModel](docs/PayloadModel.md) + + + +## Documentation for Authorization + + +Authentication schemes defined for the API: + +### basicAuth + +- **Type**: HTTP basic authentication + diff --git a/src/Databox.sln b/src/Databox.sln index 31c6d77..7cd9cc2 100644 --- a/src/Databox.sln +++ b/src/Databox.sln @@ -2,7 +2,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2012 VisualStudioVersion = 12.0.0.0 MinimumVisualStudioVersion = 10.0.0.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Databox", "src\Databox\Databox.csproj", "{C0B0E438-CB79-49E2-86F0-1153235518FE}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Databox", "src\Databox\Databox.csproj", "{0DEDE14F-8852-43F9-AC99-C5304C96F2C5}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Databox.Test", "src\Databox.Test\Databox.Test.csproj", "{19F1DEBC-DE5E-4517-8062-F000CD499087}" EndProject @@ -12,10 +12,10 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {C0B0E438-CB79-49E2-86F0-1153235518FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C0B0E438-CB79-49E2-86F0-1153235518FE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C0B0E438-CB79-49E2-86F0-1153235518FE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C0B0E438-CB79-49E2-86F0-1153235518FE}.Release|Any CPU.Build.0 = Release|Any CPU + {0DEDE14F-8852-43F9-AC99-C5304C96F2C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0DEDE14F-8852-43F9-AC99-C5304C96F2C5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0DEDE14F-8852-43F9-AC99-C5304C96F2C5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0DEDE14F-8852-43F9-AC99-C5304C96F2C5}.Release|Any CPU.Build.0 = Release|Any CPU {19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {19F1DEBC-DE5E-4517-8062-F000CD499087}.Debug|Any CPU.Build.0 = Debug|Any CPU {19F1DEBC-DE5E-4517-8062-F000CD499087}.Release|Any CPU.ActiveCfg = Release|Any CPU