package ocaml_openapi_generator

  1. Overview
  2. Docs
An OpenAPI 3 to OCaml client generator.

Install

Dune Dependency

Authors

Maintainers

Sources

v0.17.0.tar.gz
sha256=a5018999737b39c7d83a597bbf4c3ae0fc6899f3553e809d1abcb96bf2211d6e

doc/src/ocaml_openapi_generator.openapi_runtime/query_parameters.ml.html

Source file query_parameters.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
open! Core

type t = (string * string list) list

let to_list t = t
let concat = List.concat
let singleton f ~key ~value = [ key, [ f value ] ]

let array
  ?(explode = true)
  ?(style = Openapi_spec.Types.Parameter.Query_style.Form)
  f
  ~key
  ~value
  =
  match explode, style with
  | true, (Form | Space_delimited | Pipe_delimited) | (true | false), Deep_object ->
    List.map value ~f:(fun inner -> key, [ f inner ])
  | false, Form -> [ key, List.map value ~f ]
  | false, Space_delimited -> [ key, [ String.concat ~sep:" " (List.map value ~f) ] ]
  | false, Pipe_delimited -> [ key, [ String.concat ~sep:"|" (List.map value ~f) ] ]
;;

let object_
  ?(explode = true)
  ?(style = Openapi_spec.Types.Parameter.Query_style.Form)
  ()
  ~key
  ~value
  =
  match explode, style with
  | true, Form | (true | false), (Space_delimited | Pipe_delimited) ->
    List.map value ~f:(fun (key, json) -> key, [ Jsonaf.to_string json ])
  | false, Form ->
    [ key, List.concat_map value ~f:(fun (key, json) -> [ key; Jsonaf.to_string json ]) ]
  | (true | false), Deep_object ->
    List.map value ~f:(fun (inner_key, json) ->
      [%string {|%{key}[%{inner_key}]|}], [ Jsonaf.to_string json ])
;;
OCaml

Innovation. Community. Security.