···3737- Various improvements to `Atex.Did.Document`
3838 - Add `Atex.DID.Document.Service` and `Atex.DID.Document.VerificationMethod` sub-structs.
3939 - Add `to_json/1` methods and `JSON.Encoder` protocols for easy conversion to camelCase JSON.
4040+- `deflexicon` now emits `content_type/0` functions (on `Input` submodules for typed JSON bodies,
4141+ otherwise on the root module) for procedures.
40424143### Fixed
4244
+36-2
lib/atex/lexicon.ex
···347347348348 input =
349349 if def[:input] && def.input[:schema] do
350350- [schema] = def_to_schema(nsid, "input", def.input.schema)
351351- schema
350350+ encoding = def.input[:encoding]
351351+352352+ [{key, quoted_schema, quoted_type, quoted_struct}] =
353353+ def_to_schema(nsid, "input", def.input.schema)
354354+355355+ quoted_struct =
356356+ quote do
357357+ unquote(quoted_struct)
358358+359359+ @spec content_type() :: String.t()
360360+ def content_type, do: unquote(encoding)
361361+ end
362362+363363+ {key, quoted_schema, quoted_type, quoted_struct}
364364+ end
365365+366366+ # Add `content_type/0` to the root module if the lexicon defines a type without a schema.
367367+ raw_input_encoding =
368368+ if is_nil(input) && def[:input] do
369369+ def.input[:encoding]
352370 end
353371354372 # Root struct containing `input`, `raw_input`, and `params`
···386404 input ->
387405 quote do
388406 defstruct input: nil
407407+ end
408408+409409+ params && raw_input_encoding ->
410410+ quote do
411411+ defstruct raw_input: nil, params: nil
412412+413413+ @spec content_type() :: String.t()
414414+ def content_type, do: unquote(raw_input_encoding)
415415+ end
416416+417417+ raw_input_encoding ->
418418+ quote do
419419+ defstruct raw_input: nil
420420+421421+ @spec content_type() :: String.t()
422422+ def content_type, do: unquote(raw_input_encoding)
389423 end
390424391425 params ->