View Source GitHub.Plugin.TypedDecoder (GitHub REST API Client v0.0.11)
Transform map responses into well-typed structs
In a normal client stack, the HTTP request is followed by a JSON decoder such as
GitHub.Plugin.JasonSerializer
. If the JSON library/plugin does not support decoding typed
structs, then a separate step is necessary to transform the map responses into structs like
GitHub.Repository
.
This module provides a two plugins: decode_response/2
and normalize_errors/2
, that accept no
configuration. decode_response/2
uses the type information available in the operation and each
module's __fields__/1
functions to decode the data. normalize_errors/2
changes API error
responses into standard GitHub.Error
results. It is recommended to run these plugins towards
the end of the stack, after decoding JSON responses.
The normalized errors will be GitHub.Error
structs with relevant reason fields where possible.
special-cases
Special Cases
There are a few special cases where the decoder must make an inference about which type to use. If you find that you are unable to decode something, please open an issue with information about the operation and types involved.
Union types often require this kind of inference. This module handles them on a case-by-case basis using required keys to determine the correct type. Some of these are done on a "best guess" basis due to a lack of official documentation.
Link to this section Summary
Functions
Decode a response body based on type information from the operation and schemas
Change API error responses into GitHub.Error
results
Link to this section Functions
@spec decode_response( GitHub.Operation.t(), keyword() ) :: {:ok, GitHub.Operation.t()}
Decode a response body based on type information from the operation and schemas
@spec normalize_errors( GitHub.Operation.t(), keyword() ) :: {:ok, GitHub.Operation.t()} | {:error, GitHub.Error.t()}
Change API error responses into GitHub.Error
results