View Source GitHub.Plugin.TypedDecoder (GitHub REST API Client v0.0.4)

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 JSON decoding responses.

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

Link to this function

decode_response(operation, opts)

View Source
@spec decode_response(
  GitHub.Operation.t(),
  keyword()
) :: {:ok, GitHub.Operation.t()}

Decode a response body based on type information from the operation and schemas

Link to this function

normalize_errors(operation, opts)

View Source
@spec normalize_errors(
  GitHub.Operation.t(),
  keyword()
) :: {:ok, GitHub.Operation.t()} | {:error, GitHub.Error.t()}

Change API error responses into GitHub.Error results