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
.konfigignore
file at the top-level of the generated SDK. The syntax for.konfigignore
is the same as.gitignore
and 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.konfigignore
is how pagination is implemented in SDKs.infoUsing
.konfigignore
covers 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.md
file using thereadmeSnippet
/apiDocumentationAuthenticationPartial
fields 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.md
as some parts of theREADME.md
are auto-generated. -
Konfig supports customizations out of the box such as
topLevelOperations
which places an operation on the top-level client for convenience orclientState
which allows you to add more state to the client to be used in custom files or request lifecycle hooks.