Module Bindoj_gen.Json_codec

This module provides functions to generate OCaml values and functions.

module Json_config = Bindoj_gen_config.Json_config
type builtin_codec = {
  1. encoder : Ppxlib.expression;
  2. decoder : Ppxlib.expression;
}
module Builtin_codecs : sig ... end
val builtin_codecs : (string * builtin_codec) list
val gen_builtin_encoders : ?attrs:Ppxlib.attributes -> Bindoj_typedesc.Type_desc.type_decl -> Ppxlib.value_binding list

Returns builtin encoders of the given type declaration.

val gen_builtin_decoders : ?attrs:Ppxlib.attributes -> Bindoj_typedesc.Type_desc.type_decl -> Ppxlib.value_binding list

Returns builtin decoders of the given type declaration.

type json_shape_explanation_resolution = string -> [ `no_resolution | `default | `open_ of string | `in_module of string ]
val gen_json_encoder : ?self_contained:bool -> ?codec:Bindoj_typedesc.Type_desc.Coretype.codec -> Bindoj_typedesc.Type_desc.type_decl -> Ppxlib.value_binding

Generates a json encoder function of the given type declaration.

  • parameter ?self_contained

    If true, generates builtin encoders.

  • parameter ?codec

    If codec is `default, val <type_name>_to_json is generated. If codec is `in_module _, val to_json is generated.

  • parameter type_decl

    Type declaration to be generated.

  • returns

    value_binding of a encoder function.

val gen_json_decoder_result : ?self_contained:bool -> ?json_shape_explanation_style: [ `inline of json_shape_explanation_resolution option | `reference ] -> ?codec:Bindoj_typedesc.Type_desc.Coretype.codec -> Bindoj_typedesc.Type_desc.type_decl -> Ppxlib.value_binding

Generates a json decoder function of the given type declaration. The generated function has type ?path:jvpath -> jv -> t OfJsonResult.t.

  • parameter ?self_contained

    If true, generates builtin decoders.

  • parameter ?codec

    If codec is `default, val <type_name>_of_json' is generated. If codec is `in_module _, val of_json' is generated.

  • parameter type_decl

    Type declaration to be generated.

  • returns

    value_binding of a decoder function.

val gen_json_decoder_option : ?implementation_style: [ `refer_existing_result_variant_json_decoder | `embed_full_implementation of [ `self_contained | `non_self_contained ] ] -> ?codec:Bindoj_typedesc.Type_desc.Coretype.codec -> Bindoj_typedesc.Type_desc.type_decl -> Ppxlib.value_binding

Generates a json decoder function of the given type declaration. The generated function has type jv -> t option.

  • parameter ?implementation_style

    Specifies how the generated functions are implemented.

  • parameter ?codec

    If codec is `default, val <type_name>_of_json is generated. If codec is `in_module _, val of_json is generated.

  • parameter type_decl

    Type declaration to be generated.

  • returns

    value_binding of a decoder function.

val gen_json_shape_explanation : ?json_shape_explanation_resolution:json_shape_explanation_resolution -> ?codec:Bindoj_typedesc.Type_desc.Coretype.codec -> Bindoj_typedesc.Type_desc.type_decl -> Ppxlib.value_binding

Generates a value_binding of Bindoj_runtime.json_shape_explanation.

  • parameter ?json_shape_explanation_resolution

    How ident is resolved.

  • parameter ?codec

    If codec is `default, val <type_name>_json_shape_explanation is generated. If codec is `in_module _, val json_shape_explanation is generated.

  • parameter type_decl

    Type declaration to be generated.

  • returns

    value_binding of json_shape_explanation.

val gen_discriminator_value_accessor : ?codec:Bindoj_typedesc.Type_desc.Coretype.codec -> Bindoj_typedesc.Type_desc.type_decl -> Ppxlib.value_binding

Generates a function of the given type declaration of Bindoj_typedesc.Type_desc.type_decl_kind.Variant_decl. The generated has type t -> string.

  • parameter ?codec

    If codec is `default, val <type_name>_json_discriminator_value is generated. If codec is `in_module _, val json_discriminator_value is generated.

  • parameter type_decl

    Type declaration to be generated.

  • returns

    value_binding of a discriminator accessor function.

val gen_json_codec : ?self_contained:bool -> ?gen_json_shape_explanation:bool -> ?discriminator_value_accessor:bool -> ?json_shape_explanation_resolution:json_shape_explanation_resolution -> ?codec:Bindoj_typedesc.Type_desc.Coretype.codec -> Bindoj_typedesc.Type_desc.type_decl -> Ppxlib.structure

Generates the whole structure containing the result of gen_json_encoder, gen_json_decoder_result, gen_json_decoder_option, gen_json_shape_explanation and gen_discriminator_value_accessor.

  • parameter ?self_contained

    If true, generates builtin encoders/decoders in encoder/decoder functions.

  • parameter ?gen_json_shape_explanation

    If present, val <type_name>_json_shape_explanation is also generated.

  • parameter ?discriminator_value_accessor

    If true and the given type_decl is Variant_decl, val <type_name>_json_discriminator_value is also generated.

  • parameter ?json_shape_explanation_resolution

    How ident is resolved when generating json_shape_explanation.

  • parameter ?codec

    If codec is `default, type t and val <type_name>_<value_name> are generated. If codec is `in_module _, type <type_name> and val <value_name> are generated.

  • parameter type_decl

    type declaration to be generated.

  • returns

    Ppxlib.structure.

val gen_json_encoder_signature : ?codec:Bindoj_typedesc.Type_desc.Coretype.codec -> Bindoj_typedesc.Type_desc.type_decl -> Ppxlib.value_description
val gen_json_decoder_result_signature : ?codec:Bindoj_typedesc.Type_desc.Coretype.codec -> Bindoj_typedesc.Type_desc.type_decl -> Ppxlib.value_description
val gen_json_decoder_option_signature : ?codec:Bindoj_typedesc.Type_desc.Coretype.codec -> Bindoj_typedesc.Type_desc.type_decl -> Ppxlib.value_description
val gen_json_shape_explanation_signature : ?codec:Bindoj_typedesc.Type_desc.Coretype.codec -> Bindoj_typedesc.Type_desc.type_decl -> Ppxlib.value_description
val gen_discriminator_value_accessor_signature : ?codec:Bindoj_typedesc.Type_desc.Coretype.codec -> Bindoj_typedesc.Type_desc.type_decl -> Ppxlib.value_description
val gen_json_codec_signature : ?gen_json_shape_explanation:bool -> ?discriminator_value_accessor:bool -> ?codec:Bindoj_typedesc.Type_desc.Coretype.codec -> Bindoj_typedesc.Type_desc.type_decl -> Ppxlib.signature

Generates the whole signature containing the result of gen_json_encoder_signature, gen_json_decoder_result_signature, gen_json_decoder_option_signature, gen_json_shape_explanation_signature and gen_discriminator_value_accessor_signature.

  • parameter ?gen_json_shape_explanation

    If present, val <type_name>_json_shape_explanation is also generated.

  • parameter ?discriminator_value_accessor

    If true and the given type_decl is Variant_decl, val <type_name>_json_discriminator_value is also generated.

  • parameter ?codec

    If codec is `default, type t and val <type_name>_<value_name> are generated. If codec is `in_module _, type <type_name> and val <value_name> are generated.

  • parameter type_decl

    type declaration to be generated.

  • returns

    Ppxlib.structure.

exception Incompatible_with_openapi_v3 of string

Generates json schema object.

Generates a json schema object of OpenAPI.