Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@

* [x] AwsJson1.0
* [x] AwsJson1.1
* [x] AwsQuery (core: serialise/deserialise/typed errors, unions; passes smithy conformance suite. Pending: idempotency-token auto-fill, request compression)
* [ ] Wire [UInt64] (or [Int64]) into codegen for `smithy.api#Long` - currently maps to OCaml [int], overflowing for values > 2^62-1
* [ ] Represent `smithy.api#BigInteger` / `smithy.api#BigDecimal` beyond [int]/[float] - [UInt64] only covers 0..2^64-1; BigInteger is unbounded and BigDecimal needs >15 sig digits. Likely needs a string passthrough or a bignum dependency (ask before adding deps)
* [x] AwsQuery (core: serialise/deserialise/typed errors, unions; passes smithy conformance suite. Pending: request compression)
* [x] ResponseMetadata handling in awsQuery responses with no result wrapper
* [x] Wire [Int64] into codegen for `smithy.api#Long` - no longer maps to OCaml [int]
* [x] Represent `smithy.api#BigInteger` / `smithy.api#BigDecimal` beyond [int]/[float] using zarith-backed [CoreTypes.BigInt] / [CoreTypes.BigDecimal]
* [x] awsQuery union serialisation/deserialisation
* [ ] `@idempotencyToken` auto-fill (`QueryProtocolIdempotencyTokenAutoFill` is banned)
* [x] `@idempotencyToken` auto-fill using uuidm
* [ ] `@requestCompression` gzip (`SDKAppliedContentEncoding_awsQuery` / `SDKAppendsGzipAndIgnoresHttpProvidedEncoding_awsQuery` are banned)
* [ ] awsJson error-response test generation (`make_error_response_test_str` is awsQuery-only; awsJson error fixtures need a JSON error reader)
* [x] awsJson error-response test generation (`make_error_response_test_str` now works for awsJson too, with header/body error-type extraction)
* [ ] REST
* [ ] S3
26 changes: 23 additions & 3 deletions codegen/AwsProtocolJson.ml
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,32 @@ module Serialiser = struct
(Location.mknoloc
(func_name ~member_traits:mem.traits ~namespace_resolver mem.target))
in
let is_idempotency_token = Trait.hasTrait mem.traits Trait.isIdempotencyTokenTrait in
let value =
match is_required with
| true ->
match (is_required, is_idempotency_token) with
| true, _ ->
B.pexp_construct (lident_noloc "Some")
(Some (B.pexp_apply basic_value_exp [ (Nolabel, field_lookup) ]))
| false ->
| false, true ->
(* Auto-fill idempotency tokens when the caller does not supply one. *)
let filled =
B.pexp_apply
(B.pexp_ident (Location.mknoloc (make_lident ~names:[ "Option"; "value" ])))
[
(Nolabel, field_lookup);
( Labelled "default",
B.pexp_apply
(B.pexp_ident
(Location.mknoloc
(make_lident ~names:[ "Smaws_Lib"; "Uuid"; "generate" ])))
[
(Nolabel, B.pexp_construct (Location.mknoloc Ppxlib.(Lident "()")) None);
] );
]
in
B.pexp_construct (lident_noloc "Some")
(Some (B.pexp_apply basic_value_exp [ (Nolabel, filled) ]))
| false, false ->
B.pexp_apply
(B.pexp_ident (lident_noloc "option_to_yojson"))
[ (Nolabel, basic_value_exp); (Nolabel, field_lookup) ]
Expand Down
55 changes: 45 additions & 10 deletions codegen/AwsProtocolQuery.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ module Serialiser = struct
?(shape_traits : Trait.t list option = None) target_name =
match target_name with
| "smithy.api#String" | "smithy.api#Unit" -> Some "string_field"
| "smithy.api#Integer" | "smithy.api#Byte" | "smithy.api#Short" | "smithy.api#Long"
| "smithy.api#BigInteger" ->
Some "int_field"
| "smithy.api#Integer" | "smithy.api#Byte" | "smithy.api#Short" -> Some "int_field"
| "smithy.api#Long" -> Some "long_field"
| "smithy.api#BigInteger" -> Some "big_int_field"
| "smithy.api#BigDecimal" -> Some "big_decimal_field"
| "smithy.api#Boolean" -> Some "bool_field"
| "smithy.api#Float" | "smithy.api#Double" | "smithy.api#BigDecimal" -> Some "float_field"
| "smithy.api#Float" | "smithy.api#Double" -> Some "float_field"
| "smithy.api#Blob" -> Some "blob_field"
| "smithy.api#Timestamp" ->
let fmt = resolve_timestamp_format ~member_traits ~shape_traits () in
Expand Down Expand Up @@ -158,6 +159,7 @@ module Serialiser = struct
let generate_member_expr ~namespace_resolver ~shape_resolver (mem : Shape.member) =
let open Trait in
let is_required = hasTrait mem.traits isRequiredTrait in
let is_idempotency_token = hasTrait mem.traits isIdempotencyTokenTrait in
let xml_key = xml_name mem.traits mem.name in
let path_expr = path_append path_ident xml_key in
let field_access =
Expand All @@ -173,9 +175,18 @@ module Serialiser = struct
member_value_expr ~namespace_resolver ~shape_resolver ~member_traits ~shape_traits
~path_expr v_expr mem.target
in
let none_rhs =
if is_idempotency_token then
inner_expr
(B.pexp_apply
(B.pexp_ident
(Location.mknoloc (make_lident ~names:[ "Smaws_Lib"; "Uuid"; "generate" ])))
[ (Nolabel, unit_expr) ])
else B.elist []
in
B.pexp_match field_access
[
B.case ~lhs:(B.ppat_construct (lident_noloc "None") None) ~guard:None ~rhs:(B.elist []);
B.case ~lhs:(B.ppat_construct (lident_noloc "None") None) ~guard:None ~rhs:none_rhs;
B.case
~lhs:(B.ppat_construct (lident_noloc "Some") (Some (B.ppat_var (Location.mknoloc "v"))))
~guard:None
Expand Down Expand Up @@ -347,8 +358,10 @@ module Serialiser = struct
(exp_fun_untyped "v"
(serialize_call helper [ (Nolabel, exp_ident "path"); (Nolabel, exp_ident "v") ]))))
else Some (primitive_field_lambda "string_field")
| IntegerShape _ | LongShape _ | ShortShape _ | ByteShape _ ->
Some (primitive_field_lambda "int_field")
| IntegerShape _ | ShortShape _ | ByteShape _ -> Some (primitive_field_lambda "int_field")
| LongShape _ -> Some (primitive_field_lambda "long_field")
| BigIntegerShape _ -> Some (primitive_field_lambda "big_int_field")
| BigDecimalShape _ -> Some (primitive_field_lambda "big_decimal_field")
| BooleanShape _ -> Some (primitive_field_lambda "bool_field")
| FloatShape _ | DoubleShape _ -> Some (primitive_field_lambda "float_field")
| BlobShape _ -> Some (primitive_field_lambda "blob_field")
Expand Down Expand Up @@ -465,12 +478,32 @@ module Deserialiser = struct
let parse_primitive_from_string target_name str_expr =
match target_name with
| "smithy.api#String" -> Some str_expr
| "smithy.api#Integer" | "smithy.api#Byte" | "smithy.api#Short" | "smithy.api#Long"
| "smithy.api#BigInteger" ->
| "smithy.api#Integer" | "smithy.api#Byte" | "smithy.api#Short" ->
Some (B.pexp_apply (exp_ident "int_of_string") [ (Nolabel, str_expr) ])
| "smithy.api#Long" ->
Some
(B.pexp_apply
(B.pexp_ident
(Location.mknoloc
(make_lident ~names:[ "Smaws_Lib"; "CoreTypes"; "Int64"; "of_string" ])))
[ (Nolabel, str_expr) ])
| "smithy.api#BigInteger" ->
Some
(B.pexp_apply
(B.pexp_ident
(Location.mknoloc
(make_lident ~names:[ "Smaws_Lib"; "CoreTypes"; "BigInt"; "of_string" ])))
[ (Nolabel, str_expr) ])
| "smithy.api#BigDecimal" ->
Some
(B.pexp_apply
(B.pexp_ident
(Location.mknoloc
(make_lident ~names:[ "Smaws_Lib"; "CoreTypes"; "BigDecimal"; "of_string" ])))
[ (Nolabel, str_expr) ])
| "smithy.api#Boolean" ->
Some (B.pexp_apply (exp_ident "bool_of_string") [ (Nolabel, str_expr) ])
| "smithy.api#Float" | "smithy.api#Double" | "smithy.api#BigDecimal" ->
| "smithy.api#Float" | "smithy.api#Double" ->
Some (B.pexp_apply (exp_ident "float_of_string") [ (Nolabel, str_expr) ])
| "smithy.api#Blob" ->
Some
Expand Down Expand Up @@ -843,6 +876,8 @@ module Deserialiser = struct
else Some (read_data_lambda ())
| IntegerShape _ | LongShape _ | ShortShape _ | ByteShape _ ->
Some (primitive_of_xml_lambda "int_of_string")
| BigIntegerShape _ -> Some (primitive_of_xml_lambda "big_int_of_string")
| BigDecimalShape _ -> Some (primitive_of_xml_lambda "big_decimal_of_string")
| BooleanShape _ -> Some (primitive_of_xml_lambda "bool_of_string")
| FloatShape _ | DoubleShape _ -> Some (primitive_of_xml_lambda "float_of_string")
| BlobShape _ -> Some (primitive_of_xml_lambda "blob_of_string")
Expand Down
7 changes: 4 additions & 3 deletions codegen/Types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,16 @@ let make_basic_type_manifest ctx descriptor
~(namespace_resolver : Namespace_resolver.Namespace_resolver.t) () =
let open Ast.Shape in
match descriptor with
| BigDecimalShape { traits; _ } -> [%type: Bigdecimal.t]
| BigIntegerShape { traits; _ } -> [%type: Big_int.big_int]
| BigDecimalShape { traits; _ } -> [%type: Smaws_Lib.CoreTypes.BigDecimal.t]
| BigIntegerShape { traits; _ } -> [%type: Smaws_Lib.CoreTypes.BigInt.t]
| ByteShape { traits; _ } -> [%type: int]
| ShortShape { traits; _ } -> [%type: int]
| BlobShape { traits; _ } -> [%type: bytes]
| BooleanShape { traits; _ } -> [%type: bool]
| DocumentShape -> Builtin_types.document
| FloatShape { traits; _ } | DoubleShape { traits; _ } -> [%type: float]
| LongShape { traits; _ } | IntegerShape { traits; _ } -> [%type: int]
| LongShape { traits; _ } -> [%type: Smaws_Lib.CoreTypes.Int64.t]
| IntegerShape { traits; _ } -> [%type: int]
| StringShape { traits; _ } -> [%type: string]
| SetShape { target; traits } | ListShape { target; traits; _ } ->
(* List types are considered "dense" by default, which means they do not contain null values. However,
Expand Down
2 changes: 2 additions & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
(>= "3.4.0"))
(digestif
(>= "1.1.4"))
zarith
uuidm
(eio-ssl
(>= "0.3.0"))
(uri
Expand Down
Loading
Loading