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
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
(* Copyright 2022-2023 Kotoi-Xie Consultancy, Inc. This file is a part of the

==== Bindoj (https://kxc.dev/bindoj) ====

software project that is developed, maintained, and distributed by
Kotoi-Xie Consultancy, Inc. (https://kxc.inc) which is also known as KXC.

Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required
by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License.
                                                                              *)
(* Acknowledgements  --- AnchorZ Inc. ---  The current/initial version or a
significant portion of this file is developed under the funding provided by
AnchorZ Inc. to satisfy its needs in its product development workflow.
                                                                              *)
open Bindoj_openapi_util.V3

module Reference_object = Bindoj_openapi_reference_object.V3
module Example_object = Bindoj_openapi_example_object.V3
module Schema_object = Bindoj_openapi_schema_object.V3
module Style_value = Bindoj_openapi_style_value.V3

module type Common = sig
  type t
  val pp : ppf -> t -> unit
  val yojson_of_t : t -> yojson
end

module Make_encoding_object (Header_object : Common) = struct
  type t = {
    contentType : string option [@yojson.option];
    headers : (Header_object.t, Reference_object.t) either assoc option [@yojson.option];
    style : Style_value.t option [@yojson.option];
    explode : bool option [@yojson.option];
    allowReserved : bool option [@yojson.option];
  } [@@deriving show, yojson_of]

  let mk ?contentType ?headers ?style ?explode ?allowReserved () = {
    contentType = contentType;
    headers = headers;
    style = style;
    explode = explode;
    allowReserved = allowReserved;
  }
end

module Make_media_type_object (Encoding_object : Common) = struct
  type encoding_object = Encoding_object.t

  let pp_encoding_object = Encoding_object.pp
  let yojson_of_encoding_object = Encoding_object.yojson_of_t

  type t = {
    schema : (Schema_object.t, Reference_object.t) either option [@yojson.option];
    example : jv option [@yojson.option];
    examples : (Example_object.t, Reference_object.t) either assoc option [@yojson.option];
    encoding : encoding_object assoc option [@yojson.option];
  } [@@deriving show, yojson_of]

  let mk ?schema ?example ?examples ?encoding () = {
    schema = schema;
    example = example;
    examples = examples;
    encoding = encoding;
  }
end

module rec Header_object : sig
  type t

  type encoding_object

  type media_type_object

  val encoding :
    ?contentType:string ->
    ?headers:(string * (t, Reference_object.t) either) list ->
    ?style:Style_value.t ->
    ?explode:bool ->
    ?allowReserved:bool ->
    unit -> encoding_object

  val media_type :
    ?schema:(Schema_object.t, Reference_object.t) either ->
    ?example:jv ->
    ?examples:(string * (Example_object.t, Reference_object.t) either) list ->
    ?encoding:(string * encoding_object) list ->
    unit -> media_type_object

  val mk :
    ?description:string ->
    ?required:bool ->
    ?deprecated:bool ->
    ?allowEmptyValue:bool ->
    ?style:Style_value.t ->
    ?explode:bool ->
    ?schema:(Schema_object.t, Reference_object.t) either ->
    ?example:jv ->
    ?examples:(string * (Example_object.t, Reference_object.t) either) list ->
    ?content:(string * media_type_object) list ->
    unit -> t

  val pp : ppf -> t -> unit

  val to_json : t -> jv

  val yojson_of_t : t -> yojson

  val pp_encoding_object : ppf -> encoding_object -> unit

  val encoding_object_to_json : encoding_object -> jv

  val yojson_of_encoding_object : encoding_object -> yojson

  val pp_media_type_object : ppf -> media_type_object -> unit

  val media_type_object_to_json : media_type_object -> jv

  val yojson_of_media_type_object : media_type_object -> yojson
end = struct
  module Encoding_object = Make_encoding_object (Header_object)
  module Media_type_object = Make_media_type_object (Encoding_object)

  type encoding_object = Encoding_object.t

  type media_type_object = Media_type_object.t

  let pp_media_type_object = Media_type_object.pp
  let yojson_of_media_type_object = Media_type_object.yojson_of_t

  type t = {
    description : string option [@yojson.option];
    required : bool option [@yojson.option]; (* If the pr_in is Path, this property must be Some true *)
    deprecated : bool option [@yojson.option];
    allowEmptyValue : bool option [@yojson.option];
    style : Style_value.t option [@yojson.option];
    explode : bool option [@yojson.option];
    schema : (Schema_object.t, Reference_object.t) either option [@yojson.option];
    example : jv option;
    examples : (Example_object.t, Reference_object.t) either assoc option [@yojson.option];
    content : media_type_object assoc option [@yojson.option];
  } [@@deriving show, yojson_of]

  let mk ?description ?required ?deprecated ?allowEmptyValue
      ?style ?explode ?schema ?example ?examples
      ?content () = {
    description = description;
    required = required;
    deprecated = deprecated;
    allowEmptyValue = allowEmptyValue;
    style = style;
    explode = explode;
    schema = schema;
    example = example;
    examples = examples;
    content = content;
  }

  let encoding = Encoding_object.mk

  let pp_encoding_object = Encoding_object.pp

  let media_type = Media_type_object.mk

  let pp_media_type_object = Media_type_object.pp

  let to_json : t -> jv = fun t ->
    t |> yojson_of_t |> Json.of_yojson

  let encoding_object_to_json : encoding_object -> jv = fun t ->
    t |> Encoding_object.yojson_of_t |> Json.of_yojson

  let yojson_of_encoding_object = Encoding_object.yojson_of_t

  let media_type_object_to_json : media_type_object -> jv = fun t ->
    t |> Media_type_object.yojson_of_t |> Json.of_yojson

  let yojson_of_media_type_object = Media_type_object.yojson_of_t
end

include Header_object