Customize your SDKs
Why customize your SDK?
Generating your SDK allows you to avoid writing a lot of the tedious boilerplate that a developer would otherwise need to write like configuring authentication, creating HTTP requests, or serializing/deserializing responses. But sometimes its necessary to customize the output of the SDK generation so you can implement custom business logic into your SDKs. Common use-cases are:
- Implementing language-specific paradigms such as JavaScript's async iterators or Python's context manager
- Parameters or Responses that can't be described as part of your OpenAPI Specification such as OS-level primitives like file pointers or custom classes
- Streaming responses
- Request signing
- Custom documentation snippets
- Custom flows (pagination or combining operations)
- Custom functions
How to customize your SDK
Konfig allows you to override or customize any part of a generated SDK by doing any of the following:
-
Create a
.konfigignorefile at the top-level of the generated SDK. The syntax for.konfigignoreis the same as.gitignoreand tells the generator to not override or delete these files when re-generating your SDK. This means you can add new files or modify generated files to fit your exact requirements. Adding particular files to.konfigignoreis how pagination is implemented in SDKs.infoUsing
.konfigignorecovers all customization use-cases as it allows you to modify anything about the generated SDK. -
Implement request lifecycle hooks. For example here is a Python SDK with a custom lifecycle hook for request signing: https://github.com/passiv/snaptrade-sdks/blob/master/sdks/python/snaptrade_client/request_after_hook.py). This is helpful when you need to modify the contents of every request without customizing core files in the generated SDK.
-
Every generator config allows you to override documentation snippets. For example here is a Python SDK that contains a custom "getting started" snippet in the top-level
README.mdfile using thereadmeSnippet/apiDocumentationAuthenticationPartialfields https://github.com/passiv/snaptrade-sdks/tree/master/sdks/python. This is helpful when you have a default workflow that all your API users need to follow and don't want to override the entireREADME.mdas some parts of theREADME.mdare auto-generated. -
Konfig supports customizations out of the box such as
topLevelOperationswhich places an operation on the top-level client for convenience orclientStatewhich allows you to add more state to the client to be used in custom files or request lifecycle hooks.