mirror of
https://github.com/tribufu/tribufu-dotnet
synced 2025-06-23 13:14:36 +00:00
Generate client with open-api-generator (#1)
* Generate project with open-api-generator * Add example project * Create wrapper class
This commit is contained in:
.env.example.gitignore.openapi-generator-ignore
.openapi-generator
Directory.Build.propsDirectory.Packages.propsREADME.mdTribufu.Sdk.slnTribufu.slnscripts
src
Tribufu.Example
Tribufu.Generated
Api
Client
ApiClient.csApiException.csApiResponse.csClientUtils.csConfiguration.csExceptionFactory.csGlobalConfiguration.csHttpMethod.csIApiAccessor.csIAsynchronousClient.csIReadableConfiguration.csISynchronousClient.csMultimap.csOpenAPIDateConverter.csRequestOptions.csRetryConfiguration.cs
Model
AbstractOpenAPISchema.csAccount.csApplication.csApplicationType.csAuthorizeRequest.csCodeChallengeMethod.csCryptoViewModel.csGame.csGameServer.csGameServerCluster.csGrantType.csGroup.csGroupGame.csGroupMember.csGroupRank.csHashViewModel.csIntrospectRequest.csIpAddress.csLeaderboardItem.csLeaderboardOrder.csLoginProvider.csLoginRequest.csLoginResponse.csPackage.csProfile.csProfileGame.csProfileGroup.csRefreshRequest.csRegisterRequest.csResponseType.csRevokeRequest.csSearchRequest.csSearchType.csServerMetrics.csServerStatus.csSubscription.csTokenHintType.csTokenRequest.csTokenResponse.csTokenType.csUpdateProfile.csUserInfo.csUserType.cs
README.mdTribufu.Generated.csprojTribufu.Native
Tribufu
vendor/openapi-generator
@ -1,24 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<PackageId>Tribufu</PackageId>
|
||||
<Description>Tribufu .NET SDK</Description>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<TargetFrameworks>netstandard2.0;net45;net5.0</TargetFrameworks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>annotations</Nullable>
|
||||
<OutputType>Library</OutputType>
|
||||
<TargetFrameworks>net6.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Include="README.md" Pack="true" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" />
|
||||
<PackageReference Include="System.ComponentModel.Annotations" />
|
||||
<PackageReference Include="System.Net.Http" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Tribufu.Native\Tribufu.Native.csproj" />
|
||||
<ProjectReference Include="..\Tribufu.Generated\Tribufu.Generated.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
@ -1,14 +1,183 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
using System.Net.Http;
|
||||
using System.Net;
|
||||
using System.Runtime.InteropServices;
|
||||
using Tribufu.Generated.Api;
|
||||
using Tribufu.Generated.Client;
|
||||
|
||||
namespace Tribufu
|
||||
{
|
||||
public class TribufuApi : TribufuApiGenerated
|
||||
/// <summary>
|
||||
/// Tribufu API
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Use this class to interact with the Tribufu API.
|
||||
/// </remarks>
|
||||
public class TribufuApi : TribufuGeneratedApi
|
||||
{
|
||||
public TribufuApi(TribufuApiOptions options) : base(options.BaseUrl, new HttpClient())
|
||||
/// <summary>
|
||||
/// The default base URL for the Tribufu API.
|
||||
/// </summary>
|
||||
public const string DefaultBaseUrl = "https://api.tribufu.com";
|
||||
|
||||
/// <summary>
|
||||
/// Create a <see cref="TribufuApi"/> with the default options.
|
||||
/// </summary>
|
||||
/// <returns><see cref="TribufuApi"/> instance with default configuration</returns>
|
||||
public TribufuApi() : this(string.Empty)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a <see cref="TribufuApi"/> with the given API key.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A API key gives you public read only access to the Tribufu API.
|
||||
/// </remarks>
|
||||
/// <param name="apiKey">The API key for authentication</param>
|
||||
/// <returns><see cref="TribufuApi"/> instance configured with the API key</returns>
|
||||
public TribufuApi(string apiKey) : base(CreateConfiguration(apiKey))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a TribufuApi with the default options.
|
||||
/// </summary>
|
||||
/// <returns>TribufuApi instance with default configuration</returns>
|
||||
public static TribufuApi Default()
|
||||
{
|
||||
return new TribufuApi();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a <see cref="TribufuApi"/> with the given API key.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A API key gives you public read only access to the Tribufu API.
|
||||
/// </remarks>
|
||||
/// <param name="apiKey">The API key for authentication</param>
|
||||
/// <returns><see cref="TribufuApi"/> instance configured with the API key</returns>
|
||||
public static TribufuApi WithApiKey(string apiKey)
|
||||
{
|
||||
return new TribufuApi(apiKey);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Try to create a <see cref="TribufuApi"/> from environment variables.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This will only work if the environment variables are set.
|
||||
/// </remarks>
|
||||
/// <param name="prefix">A prefix for the environment variables. Default is "TRIBUFU".</param>
|
||||
/// <returns><see cref="TribufuApi"/> instance or null if environment variables not set</returns>
|
||||
/// <example>
|
||||
/// // Environment variable TRIBUFU_API_KEY must be set
|
||||
/// var api = TribufuApi.FromEnv();
|
||||
/// </example>
|
||||
public static TribufuApi? FromEnv(string? prefix = null)
|
||||
{
|
||||
prefix ??= "TRIBUFU";
|
||||
|
||||
var apiKey = Environment.GetEnvironmentVariable($"{prefix}_API_KEY");
|
||||
|
||||
if (!string.IsNullOrEmpty(apiKey))
|
||||
{
|
||||
return WithApiKey(apiKey);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a <see cref="TribufuApi"/> from environment variables or the default API.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This will fallback to the default API if the environment variables are not set.
|
||||
/// </remarks>
|
||||
/// <param name="prefix">A prefix for the environment variables. Default is "TRIBUFU".</param>
|
||||
/// <returns><see cref="TribufuApi"/> instance</returns>
|
||||
/// <example>
|
||||
/// // Environment variable TRIBUFU_API_KEY might be unset
|
||||
/// var api = TribufuApi.FromEnvOrDefault();
|
||||
/// </example>
|
||||
public static TribufuApi FromEnvOrDefault(string prefix = "TRIBUFU")
|
||||
{
|
||||
return FromEnv(prefix) ?? Default();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the version of the Tribufu API client.
|
||||
/// </summary>
|
||||
public static string GetVersion()
|
||||
{
|
||||
var version = typeof(TribufuApi).Assembly.GetName().Version;
|
||||
return $"{version?.Major}.{version?.Minor}.{version?.Build}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the user agent string for the Tribufu API client.
|
||||
/// </summary>
|
||||
private static string GetUserAgent()
|
||||
{
|
||||
var version = GetVersion();
|
||||
var frameworkDescription = RuntimeInformation.FrameworkDescription.Trim();
|
||||
var runtimeIdentifier = RuntimeInformation.RuntimeIdentifier.Trim();
|
||||
return $"Tribufu/{version} ({frameworkDescription}; {runtimeIdentifier})";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the base URL for the Tribufu API.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The base URL can be set using the environment variable TRIBUFU_API_URL.
|
||||
/// The custom base URL is only used if debug mode is enabled.
|
||||
/// The default base URL is https://api.tribufu.com.
|
||||
/// </remarks>
|
||||
/// <returns>Base URL string</returns>
|
||||
private static string GetBaseUrl()
|
||||
{
|
||||
var baseUrl = Environment.GetEnvironmentVariable("TRIBUFU_API_URL");
|
||||
|
||||
if (DebugEnabled() && !string.IsNullOrEmpty(baseUrl))
|
||||
{
|
||||
return baseUrl;
|
||||
}
|
||||
|
||||
return DefaultBaseUrl;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if debug mode is enabled.
|
||||
/// </summary>
|
||||
/// <returns>True if debug mode is enabled, otherwise false</returns>
|
||||
private static bool DebugEnabled()
|
||||
{
|
||||
#if DEBUG
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a configuration for the Tribufu API client.
|
||||
/// </summary>
|
||||
private static Configuration CreateConfiguration(string apiKey)
|
||||
{
|
||||
var config = new Configuration
|
||||
{
|
||||
BasePath = GetBaseUrl(),
|
||||
UserAgent = WebUtility.UrlEncode(GetUserAgent()),
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(apiKey))
|
||||
{
|
||||
config.AddApiKeyPrefix("Authorization", "ApiKey");
|
||||
config.AddApiKey("Authorization", apiKey);
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,18 +0,0 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
namespace Tribufu
|
||||
{
|
||||
public class TribufuApiOptions
|
||||
{
|
||||
public string BaseUrl { get; set; }
|
||||
|
||||
public string ApiKey { get; set; }
|
||||
|
||||
public TribufuApiOptions(string baseUrl, string apiKey)
|
||||
{
|
||||
BaseUrl = baseUrl;
|
||||
ApiKey = apiKey;
|
||||
}
|
||||
}
|
||||
}
|
33
src/Tribufu/TribufuApiSingleton.cs
Normal file
33
src/Tribufu/TribufuApiSingleton.cs
Normal file
@ -0,0 +1,33 @@
|
||||
// Copyright (c) Tribufu. All Rights Reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
namespace Tribufu
|
||||
{
|
||||
/// <summary>
|
||||
/// Tribufu API
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Helper class to get a singleton instance of the <see cref="TribufuApi"/>.
|
||||
/// </remarks>
|
||||
public static class TribufuApiSingleton
|
||||
{
|
||||
private static TribufuApi? _instance = null;
|
||||
|
||||
/// <summary>
|
||||
/// Get the singleton instance of <see cref="TribufuApi"/>.
|
||||
/// </summary>
|
||||
public static TribufuApi GetInstance()
|
||||
{
|
||||
_instance ??= TribufuApi.FromEnvOrDefault();
|
||||
return _instance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset the singleton instance of <see cref="TribufuApi"/>.
|
||||
/// </summary>
|
||||
public static void ResetInstance()
|
||||
{
|
||||
_instance = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
{
|
||||
"runtime": "Default",
|
||||
"defaultVariables": null,
|
||||
"documentGenerator": {
|
||||
"fromDocument": {
|
||||
"json": "",
|
||||
"url": "https://api.tribufu.com/v1/openapi.json",
|
||||
"output": null,
|
||||
"newLineBehavior": "Auto"
|
||||
}
|
||||
},
|
||||
"codeGenerators": {
|
||||
"openApiToCSharpClient": {
|
||||
"clientBaseClass": null,
|
||||
"configurationClass": null,
|
||||
"generateClientClasses": true,
|
||||
"suppressClientClassesOutput": false,
|
||||
"generateClientInterfaces": false,
|
||||
"suppressClientInterfacesOutput": false,
|
||||
"clientBaseInterface": null,
|
||||
"injectHttpClient": true,
|
||||
"disposeHttpClient": true,
|
||||
"protectedMethods": [],
|
||||
"generateExceptionClasses": true,
|
||||
"exceptionClass": "TribufuApiException",
|
||||
"wrapDtoExceptions": true,
|
||||
"useHttpClientCreationMethod": false,
|
||||
"httpClientType": "System.Net.Http.HttpClient",
|
||||
"useHttpRequestMessageCreationMethod": false,
|
||||
"useBaseUrl": true,
|
||||
"generateBaseUrlProperty": true,
|
||||
"generateSyncMethods": false,
|
||||
"generatePrepareRequestAndProcessResponseAsAsyncMethods": false,
|
||||
"exposeJsonSerializerSettings": false,
|
||||
"clientClassAccessModifier": "public",
|
||||
"typeAccessModifier": "public",
|
||||
"propertySetterAccessModifier": "",
|
||||
"generateNativeRecords": false,
|
||||
"generateContractsOutput": false,
|
||||
"contractsNamespace": null,
|
||||
"contractsOutputFilePath": null,
|
||||
"parameterDateTimeFormat": "s",
|
||||
"parameterDateFormat": "yyyy-MM-dd",
|
||||
"generateUpdateJsonSerializerSettingsMethod": true,
|
||||
"useRequestAndResponseSerializationSettings": false,
|
||||
"serializeTypeInformation": false,
|
||||
"queryNullValue": "",
|
||||
"className": "TribufuApiGenerated",
|
||||
"operationGenerationMode": "SingleClientFromOperationId",
|
||||
"additionalNamespaceUsages": [],
|
||||
"additionalContractNamespaceUsages": [],
|
||||
"generateOptionalParameters": true,
|
||||
"generateJsonMethods": false,
|
||||
"enforceFlagEnums": false,
|
||||
"parameterArrayType": "System.Collections.Generic.IEnumerable",
|
||||
"parameterDictionaryType": "System.Collections.Generic.IDictionary",
|
||||
"responseArrayType": "System.Collections.Generic.ICollection",
|
||||
"responseDictionaryType": "System.Collections.Generic.IDictionary",
|
||||
"wrapResponses": false,
|
||||
"wrapResponseMethods": [],
|
||||
"generateResponseClasses": true,
|
||||
"responseClass": "SwaggerResponse",
|
||||
"namespace": "Tribufu",
|
||||
"requiredPropertiesMustBeDefined": true,
|
||||
"dateType": "System.DateTimeOffset",
|
||||
"jsonConverters": null,
|
||||
"anyType": "object",
|
||||
"dateTimeType": "System.DateTimeOffset",
|
||||
"timeType": "System.TimeSpan",
|
||||
"timeSpanType": "System.TimeSpan",
|
||||
"arrayType": "System.Collections.Generic.ICollection",
|
||||
"arrayInstanceType": "System.Collections.ObjectModel.Collection",
|
||||
"dictionaryType": "System.Collections.Generic.IDictionary",
|
||||
"dictionaryInstanceType": "System.Collections.Generic.Dictionary",
|
||||
"arrayBaseType": "System.Collections.ObjectModel.Collection",
|
||||
"dictionaryBaseType": "System.Collections.Generic.Dictionary",
|
||||
"classStyle": "Poco",
|
||||
"jsonLibrary": "NewtonsoftJson",
|
||||
"generateDefaultValues": true,
|
||||
"generateDataAnnotations": true,
|
||||
"excludedTypeNames": [],
|
||||
"excludedParameterNames": [],
|
||||
"handleReferences": false,
|
||||
"generateImmutableArrayProperties": false,
|
||||
"generateImmutableDictionaryProperties": false,
|
||||
"jsonSerializerSettingsTransformationMethod": null,
|
||||
"inlineNamedArrays": false,
|
||||
"inlineNamedDictionaries": false,
|
||||
"inlineNamedTuples": true,
|
||||
"inlineNamedAny": false,
|
||||
"generateDtoTypes": true,
|
||||
"generateOptionalPropertiesAsNullable": false,
|
||||
"generateNullableReferenceTypes": false,
|
||||
"templateDirectory": null,
|
||||
"serviceHost": null,
|
||||
"serviceSchemes": null,
|
||||
"output": "TribufuApi.generated.cs",
|
||||
"newLineBehavior": "LF"
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user