Skip to content

Latest commit

 

History

History
119 lines (98 loc) · 4.31 KB

File metadata and controls

119 lines (98 loc) · 4.31 KB

Created with Openapi Generator

Creating the library

Create a config.yaml file similar to what is below, then run the following powershell command to generate the library java -jar "<path>/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar" generate -c config.yaml

generatorName: csharp
inputSpec: openapi-generator-schema.json
outputDir: out

# https://openapi-generator.tech/docs/generators/csharp
additionalProperties:
  packageGuid: '{530E4D84-E34E-47BB-A9E1-770B33C1B032}'

# https://openapi-generator.tech/docs/integrations/#github-integration
# gitHost:
# gitUserId:
# gitRepoId:

# https://openapi-generator.tech/docs/globals
# globalProperties:

# https://openapi-generator.tech/docs/customization/#inline-schema-naming
# inlineSchemaOptions:

# https://openapi-generator.tech/docs/customization/#name-mapping
# modelNameMappings:
# nameMappings:

# https://openapi-generator.tech/docs/customization/#openapi-normalizer
# openapiNormalizer:

# templateDir: https://openapi-generator.tech/docs/templating/#modifying-templates

# releaseNote:

Using the library in your project

using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using DocSpring.Client.Api;
using DocSpring.Client.Client;
using DocSpring.Client.Model;
using Org.OpenAPITools.Extensions;

namespace YourProject
{
    public class Program
    {
        public static async Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();
            var api = host.Services.GetRequiredService<IClient>();
            IAddFieldsToTemplateApiResponse apiResponse = await api.AddFieldsToTemplateAsync("todo");
            TemplateAddFieldsResponse model = apiResponse.Ok();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args)
          .ConfigureApi((context, services, options) =>
          {
              // The type of token here depends on the api security specifications
              // Available token types are ApiKeyToken, BasicToken, BearerToken, HttpSigningToken, and OAuthToken.
              BearerToken token = new("<your token>");
              options.AddTokens(token);

              // optionally choose the method the tokens will be provided with, default is RateLimitProvider
              options.UseProvider<RateLimitProvider<BearerToken>, BearerToken>();

              options.ConfigureJsonOptions((jsonOptions) =>
              {
                  // your custom converters if any
              });

              options.AddApiHttpClients(client =>
              {
                  // client configuration
              }, builder =>
              {
                  builder
                      .AddRetryPolicy(2)
                      .AddTimeoutPolicy(TimeSpan.FromSeconds(5))
                      .AddCircuitBreakerPolicy(10, TimeSpan.FromSeconds(30));
                      // add whatever middleware you prefer
                  }
              );
          });
    }
}

Questions

  • What about HttpRequest failures and retries? Configure Polly in the IHttpClientBuilder
  • How are tokens used? Tokens are provided by a TokenProvider class. The default is RateLimitProvider which will perform client side rate limiting. Other providers can be used with the UseProvider method.
  • Does an HttpRequest throw an error when the server response is not Ok? It depends how you made the request. If the return type is ApiResponse no error will be thrown, though the Content property will be null. StatusCode and ReasonPhrase will contain information about the error. If the return type is T, then it will throw. If the return type is TOrDefault, it will return null.
  • How do I validate requests and process responses? Use the provided On and After partial methods in the api classes.

Api Information

  • appName: DocSpring API
  • appVersion: v1
  • appDescription: Use DocSpring's API to programmatically fill out PDF forms, convert HTML to PDFs, merge PDFs, or request legally binding e-signatures.

Build

This C# SDK is automatically generated by the OpenAPI Generator project.

  • SDK version: 3.2.0
  • Generator version: 7.16.0-DOCSPRING
  • Build package: org.openapitools.codegen.languages.CSharpClientCodegen