Hi!
Would you be interested if I opened a PR to relax requireRecordFields = true
?
|
// For now, we hard wire in disabling of non-record bodies as: |
|
// a) it's extra yaks to shave |
|
// b) it's questionable whether allowing one to define event contracts that preclude adding extra fields is a useful idea in the first instance |
|
// See VerbatimUtf8EncoderTests.fs and InteropTests.fs - there are edge cases when `d` fields have null / zero-length / missing values |
|
requireRecordFields = true, |
|
// Round-tripping cases like null and/or empty strings etc involves edge cases that stores, |
|
// FsCodec.NewtonsoftJson.Codec, Interop.fs and InteropTests.fs do not cover, so we disable this |
|
requireRecordFields = true, |
To address your comments:
a) it's extra yaks to shave
I don't disagree :) However, I am willing to shave this yak.
b) it's questionable whether allowing one to define event contracts that preclude adding extra fields is a useful idea in the first instance
Many of my events simply contain a primitive, e.g.
type BranchId = Guid<branchId>
and [<Measure>] branchId
type DefaultBranchUpdated = { BranchId: BranchId }
type Event =
| DefaultBranchUpdated of DefaultBranchUpdated
It would simplify my code (and make it more implementation-agnostic) if I could refactor the above to
type Event =
| DefaultBranchUpdated of BranchId
See VerbatimUtf8EncoderTests.fs and InteropTests.fs - there are edge cases when d
fields have null / zero-length / missing values
I'm not sure what a d
field is. I'm currently only interested in relaxing the rules to include Guid
s, but I could easily see this extending to other primitives.
Round-tripping cases like null and/or empty strings etc involves edge cases that stores, FsCodec.NewtonsoftJson.Codec, Interop.fs and InteropTests.fs do not cover, so we disable this
I'm totally okay with excluding string
.
I got this far with the implementation before realizing "I should probably ask first." >_>
let shape =
match shapeof<'Contract> with
| Shape.FSharpUnion (:? ShapeFSharpUnion<'Contract> as s) -> s
| _ ->
sprintf "Type '%O' is not an F# union" typeof<'Contract>
|> invalidArg "Union"
let isAllowed (scase : ShapeFSharpUnionCase<_>) =
match scase.Fields with
| [| field |] ->
match field.Member with
| Shape.FSharpRecord _
| Shape.Guid _ -> true
| _ -> false
| _ -> false