Test case
1 generated file · +7 −1test/inputs/graphql/github6.graphql
Mgraphql-elixirdefault / QuickType.ex+7 −1
| @@ -20,10 +20,16 @@ defmodule UniformResourceLocatable do | ||
| 20 | 20 | def encode_url(value) when is_binary(value), do: value |
| 21 | 21 | def encode_url(_), do: {:error, "Unexpected type when encoding UniformResourceLocatable.url"} |
| 22 | 22 | |
| 23 | + def decode_login(value) when is_binary(value), do: value | |
| 24 | + def decode_login(_), do: {:error, "Unexpected type when decoding UniformResourceLocatable.login"} | |
| 25 | + | |
| 26 | + def encode_login(value) when is_binary(value), do: value | |
| 27 | + def encode_login(_), do: {:error, "Unexpected type when encoding UniformResourceLocatable.login"} | |
| 28 | + | |
| 23 | 29 | def from_map(m) do |
| 24 | 30 | %UniformResourceLocatable{ |
| 25 | 31 | url: decode_url(m["url"]), |
| 26 | - login: m["login"], | |
| 32 | + login: m["login"] && decode_login(m["login"]), | |
| 27 | 33 | } |
| 28 | 34 | end |
Test case
1 generated file · +7 −1test/inputs/graphql/github8.graphql
Mgraphql-elixirdefault / QuickType.ex+7 −1
| @@ -60,9 +60,15 @@ defmodule IssueOrPullRequest do | ||
| 60 | 60 | merged: boolean() | nil |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | + def decode_title(value) when is_binary(value), do: value | |
| 64 | + def decode_title(_), do: {:error, "Unexpected type when decoding IssueOrPullRequest.title"} | |
| 65 | + | |
| 66 | + def encode_title(value) when is_binary(value), do: value | |
| 67 | + def encode_title(_), do: {:error, "Unexpected type when encoding IssueOrPullRequest.title"} | |
| 68 | + | |
| 63 | 69 | def from_map(m) do |
| 64 | 70 | %IssueOrPullRequest{ |
| 65 | - title: m["title"], | |
| 71 | + title: m["title"] && decode_title(m["title"]), | |
| 66 | 72 | state: m["state"] && IssueState.decode(m["state"]), |
| 67 | 73 | merged: m["merged"], |
| 68 | 74 | } |
Test case
1 generated file · +56 −8test/inputs/json/misc/0a91a.json
Melixirdefault / QuickType.ex+56 −8
| @@ -24,6 +24,12 @@ defmodule Actor do | ||
| 24 | 24 | def encode_avatar_url(value) when is_binary(value), do: value |
| 25 | 25 | def encode_avatar_url(_), do: {:error, "Unexpected type when encoding Actor.avatar_url"} |
| 26 | 26 | |
| 27 | + def decode_display_login(value) when is_binary(value), do: value | |
| 28 | + def decode_display_login(_), do: {:error, "Unexpected type when decoding Actor.display_login"} | |
| 29 | + | |
| 30 | + def encode_display_login(value) when is_binary(value), do: value | |
| 31 | + def encode_display_login(_), do: {:error, "Unexpected type when encoding Actor.display_login"} | |
| 32 | + | |
| 27 | 33 | def decode_gravatar_id(value) when is_binary(value), do: value |
| 28 | 34 | def decode_gravatar_id(_), do: {:error, "Unexpected type when decoding Actor.gravatar_id"} |
| 29 | 35 | |
| @@ -51,7 +57,7 @@ defmodule Actor do | ||
| 51 | 57 | def from_map(m) do |
| 52 | 58 | %Actor{ |
| 53 | 59 | avatar_url: decode_avatar_url(m["avatar_url"]), |
| 54 | - display_login: m["display_login"], | |
| 60 | + display_login: m["display_login"] && decode_display_login(m["display_login"]), | |
| 55 | 61 | gravatar_id: decode_gravatar_id(m["gravatar_id"]), |
| 56 | 62 | id: decode_id(m["id"]), |
| 57 | 63 | login: decode_login(m["login"]), |
| @@ -1573,21 +1579,63 @@ defmodule Payload do | ||
| 1573 | 1579 | size: integer() | nil |
| 1574 | 1580 | } |
| 1575 | 1581 | |
| 1582 | + def decode_action(value) when is_binary(value), do: value | |
| 1583 | + def decode_action(_), do: {:error, "Unexpected type when decoding Payload.action"} | |
| 1584 | + | |
| 1585 | + def encode_action(value) when is_binary(value), do: value | |
| 1586 | + def encode_action(_), do: {:error, "Unexpected type when encoding Payload.action"} | |
| 1587 | + | |
| 1588 | + def decode_before(value) when is_binary(value), do: value | |
| 1589 | + def decode_before(_), do: {:error, "Unexpected type when decoding Payload.before"} | |
| 1590 | + | |
| 1591 | + def encode_before(value) when is_binary(value), do: value | |
| 1592 | + def encode_before(_), do: {:error, "Unexpected type when encoding Payload.before"} | |
| 1593 | + | |
| 1594 | + def decode_head(value) when is_binary(value), do: value | |
| 1595 | + def decode_head(_), do: {:error, "Unexpected type when decoding Payload.head"} | |
| 1596 | + | |
| 1597 | + def encode_head(value) when is_binary(value), do: value | |
| 1598 | + def encode_head(_), do: {:error, "Unexpected type when encoding Payload.head"} | |
| 1599 | + | |
| 1600 | + def decode_master_branch(value) when is_binary(value), do: value | |
| 1601 | + def decode_master_branch(_), do: {:error, "Unexpected type when decoding Payload.master_branch"} | |
| 1602 | + | |
| 1603 | + def encode_master_branch(value) when is_binary(value), do: value | |
| 1604 | + def encode_master_branch(_), do: {:error, "Unexpected type when encoding Payload.master_branch"} | |
| 1605 | + | |
| 1606 | + def decode_pusher_type(value) when is_binary(value), do: value | |
| 1607 | + def decode_pusher_type(_), do: {:error, "Unexpected type when decoding Payload.pusher_type"} | |
| 1608 | + | |
| 1609 | + def encode_pusher_type(value) when is_binary(value), do: value | |
| 1610 | + def encode_pusher_type(_), do: {:error, "Unexpected type when encoding Payload.pusher_type"} | |
| 1611 | + | |
| 1612 | + def decode_ref(value) when is_binary(value), do: value | |
| 1613 | + def decode_ref(_), do: {:error, "Unexpected type when decoding Payload.ref"} | |
| 1614 | + | |
| 1615 | + def encode_ref(value) when is_binary(value), do: value | |
| 1616 | + def encode_ref(_), do: {:error, "Unexpected type when encoding Payload.ref"} | |
| 1617 | + | |
| 1618 | + def decode_ref_type(value) when is_binary(value), do: value | |
| 1619 | + def decode_ref_type(_), do: {:error, "Unexpected type when decoding Payload.ref_type"} | |
| 1620 | + | |
| 1621 | + def encode_ref_type(value) when is_binary(value), do: value | |
| 1622 | + def encode_ref_type(_), do: {:error, "Unexpected type when encoding Payload.ref_type"} | |
| 1623 | + | |
| 1576 | 1624 | def from_map(m) do |
| 1577 | 1625 | %Payload{ |
| 1578 | - action: m["action"], | |
| 1579 | - before: m["before"], | |
| 1626 | + action: m["action"] && decode_action(m["action"]), | |
| 1627 | + before: m["before"] && decode_before(m["before"]), | |
| 1580 | 1628 | commits: m["commits"] && Enum.map(m["commits"], &Commit.from_map/1), |
| 1581 | 1629 | description: m["description"], |
| 1582 | 1630 | distinct_size: m["distinct_size"], |
| 1583 | - head: m["head"], | |
| 1584 | - master_branch: m["master_branch"], | |
| 1631 | + head: m["head"] && decode_head(m["head"]), | |
| 1632 | + master_branch: m["master_branch"] && decode_master_branch(m["master_branch"]), | |
| 1585 | 1633 | number: m["number"], |
| 1586 | 1634 | pull_request: m["pull_request"] && PullRequest.from_map(m["pull_request"]), |
| 1587 | 1635 | push_id: m["push_id"], |
| 1588 | - pusher_type: m["pusher_type"], | |
| 1589 | - ref: m["ref"], | |
| 1590 | - ref_type: m["ref_type"], | |
| 1636 | + pusher_type: m["pusher_type"] && decode_pusher_type(m["pusher_type"]), | |
| 1637 | + ref: m["ref"] && decode_ref(m["ref"]), | |
| 1638 | + ref_type: m["ref_type"] && decode_ref_type(m["ref_type"]), | |
| 1591 | 1639 | size: m["size"], |
| 1592 | 1640 | } |
| 1593 | 1641 | end |
Test case
1 generated file · +35 −5test/inputs/json/misc/0cffa.json
Melixirdefault / QuickType.ex+35 −5
| @@ -22,6 +22,12 @@ defmodule The480_WStill do | ||
| 22 | 22 | def encode_height(value) when is_binary(value), do: value |
| 23 | 23 | def encode_height(_), do: {:error, "Unexpected type when encoding The480_WStill.height"} |
| 24 | 24 | |
| 25 | + def decode_size(value) when is_binary(value), do: value | |
| 26 | + def decode_size(_), do: {:error, "Unexpected type when decoding The480_WStill.size"} | |
| 27 | + | |
| 28 | + def encode_size(value) when is_binary(value), do: value | |
| 29 | + def encode_size(_), do: {:error, "Unexpected type when encoding The480_WStill.size"} | |
| 30 | + | |
| 25 | 31 | def decode_url(value) when is_binary(value), do: value |
| 26 | 32 | def decode_url(_), do: {:error, "Unexpected type when decoding The480_WStill.url"} |
| 27 | 33 | |
| @@ -37,7 +43,7 @@ defmodule The480_WStill do | ||
| 37 | 43 | def from_map(m) do |
| 38 | 44 | %The480_WStill{ |
| 39 | 45 | height: decode_height(m["height"]), |
| 40 | - size: m["size"], | |
| 46 | + size: m["size"] && decode_size(m["size"]), | |
| 41 | 47 | url: decode_url(m["url"]), |
| 42 | 48 | width: decode_width(m["width"]), |
| 43 | 49 | } |
| @@ -148,12 +154,36 @@ defmodule FixedHeight do | ||
| 148 | 154 | width: String.t() |
| 149 | 155 | } |
| 150 | 156 | |
| 157 | + def decode_frames(value) when is_binary(value), do: value | |
| 158 | + def decode_frames(_), do: {:error, "Unexpected type when decoding FixedHeight.frames"} | |
| 159 | + | |
| 160 | + def encode_frames(value) when is_binary(value), do: value | |
| 161 | + def encode_frames(_), do: {:error, "Unexpected type when encoding FixedHeight.frames"} | |
| 162 | + | |
| 163 | + def decode_hash(value) when is_binary(value), do: value | |
| 164 | + def decode_hash(_), do: {:error, "Unexpected type when decoding FixedHeight.hash"} | |
| 165 | + | |
| 166 | + def encode_hash(value) when is_binary(value), do: value | |
| 167 | + def encode_hash(_), do: {:error, "Unexpected type when encoding FixedHeight.hash"} | |
| 168 | + | |
| 151 | 169 | def decode_height(value) when is_binary(value), do: value |
| 152 | 170 | def decode_height(_), do: {:error, "Unexpected type when decoding FixedHeight.height"} |
| 153 | 171 | |
| 154 | 172 | def encode_height(value) when is_binary(value), do: value |
| 155 | 173 | def encode_height(_), do: {:error, "Unexpected type when encoding FixedHeight.height"} |
| 156 | 174 | |
| 175 | + def decode_mp4(value) when is_binary(value), do: value | |
| 176 | + def decode_mp4(_), do: {:error, "Unexpected type when decoding FixedHeight.mp4"} | |
| 177 | + | |
| 178 | + def encode_mp4(value) when is_binary(value), do: value | |
| 179 | + def encode_mp4(_), do: {:error, "Unexpected type when encoding FixedHeight.mp4"} | |
| 180 | + | |
| 181 | + def decode_mp4_size(value) when is_binary(value), do: value | |
| 182 | + def decode_mp4_size(_), do: {:error, "Unexpected type when decoding FixedHeight.mp4_size"} | |
| 183 | + | |
| 184 | + def encode_mp4_size(value) when is_binary(value), do: value | |
| 185 | + def encode_mp4_size(_), do: {:error, "Unexpected type when encoding FixedHeight.mp4_size"} | |
| 186 | + | |
| 157 | 187 | def decode_size(value) when is_binary(value), do: value |
| 158 | 188 | def decode_size(_), do: {:error, "Unexpected type when decoding FixedHeight.size"} |
| 159 | 189 | |
| @@ -186,11 +216,11 @@ defmodule FixedHeight do | ||
| 186 | 216 | |
| 187 | 217 | def from_map(m) do |
| 188 | 218 | %FixedHeight{ |
| 189 | - frames: m["frames"], | |
| 190 | - hash: m["hash"], | |
| 219 | + frames: m["frames"] && decode_frames(m["frames"]), | |
| 220 | + hash: m["hash"] && decode_hash(m["hash"]), | |
| 191 | 221 | height: decode_height(m["height"]), |
| 192 | - mp4: m["mp4"], | |
| 193 | - mp4_size: m["mp4_size"], | |
| 222 | + mp4: m["mp4"] && decode_mp4(m["mp4"]), | |
| 223 | + mp4_size: m["mp4_size"] && decode_mp4_size(m["mp4_size"]), | |
| 194 | 224 | size: decode_size(m["size"]), |
| 195 | 225 | url: decode_url(m["url"]), |
| 196 | 226 | webp: decode_webp(m["webp"]), |
Test case
1 generated file · +42 −6test/inputs/json/misc/127a1.json
Melixirdefault / QuickType.ex+42 −6
| @@ -22,6 +22,12 @@ defmodule The480_WStill do | ||
| 22 | 22 | def encode_height(value) when is_binary(value), do: value |
| 23 | 23 | def encode_height(_), do: {:error, "Unexpected type when encoding The480_WStill.height"} |
| 24 | 24 | |
| 25 | + def decode_size(value) when is_binary(value), do: value | |
| 26 | + def decode_size(_), do: {:error, "Unexpected type when decoding The480_WStill.size"} | |
| 27 | + | |
| 28 | + def encode_size(value) when is_binary(value), do: value | |
| 29 | + def encode_size(_), do: {:error, "Unexpected type when encoding The480_WStill.size"} | |
| 30 | + | |
| 25 | 31 | def decode_url(value) when is_binary(value), do: value |
| 26 | 32 | def decode_url(_), do: {:error, "Unexpected type when decoding The480_WStill.url"} |
| 27 | 33 | |
| @@ -37,7 +43,7 @@ defmodule The480_WStill do | ||
| 37 | 43 | def from_map(m) do |
| 38 | 44 | %The480_WStill{ |
| 39 | 45 | height: decode_height(m["height"]), |
| 40 | - size: m["size"], | |
| 46 | + size: m["size"] && decode_size(m["size"]), | |
| 41 | 47 | url: decode_url(m["url"]), |
| 42 | 48 | width: decode_width(m["width"]), |
| 43 | 49 | } |
| @@ -148,12 +154,36 @@ defmodule FixedHeight do | ||
| 148 | 154 | width: String.t() |
| 149 | 155 | } |
| 150 | 156 | |
| 157 | + def decode_frames(value) when is_binary(value), do: value | |
| 158 | + def decode_frames(_), do: {:error, "Unexpected type when decoding FixedHeight.frames"} | |
| 159 | + | |
| 160 | + def encode_frames(value) when is_binary(value), do: value | |
| 161 | + def encode_frames(_), do: {:error, "Unexpected type when encoding FixedHeight.frames"} | |
| 162 | + | |
| 163 | + def decode_hash(value) when is_binary(value), do: value | |
| 164 | + def decode_hash(_), do: {:error, "Unexpected type when decoding FixedHeight.hash"} | |
| 165 | + | |
| 166 | + def encode_hash(value) when is_binary(value), do: value | |
| 167 | + def encode_hash(_), do: {:error, "Unexpected type when encoding FixedHeight.hash"} | |
| 168 | + | |
| 151 | 169 | def decode_height(value) when is_binary(value), do: value |
| 152 | 170 | def decode_height(_), do: {:error, "Unexpected type when decoding FixedHeight.height"} |
| 153 | 171 | |
| 154 | 172 | def encode_height(value) when is_binary(value), do: value |
| 155 | 173 | def encode_height(_), do: {:error, "Unexpected type when encoding FixedHeight.height"} |
| 156 | 174 | |
| 175 | + def decode_mp4(value) when is_binary(value), do: value | |
| 176 | + def decode_mp4(_), do: {:error, "Unexpected type when decoding FixedHeight.mp4"} | |
| 177 | + | |
| 178 | + def encode_mp4(value) when is_binary(value), do: value | |
| 179 | + def encode_mp4(_), do: {:error, "Unexpected type when encoding FixedHeight.mp4"} | |
| 180 | + | |
| 181 | + def decode_mp4_size(value) when is_binary(value), do: value | |
| 182 | + def decode_mp4_size(_), do: {:error, "Unexpected type when decoding FixedHeight.mp4_size"} | |
| 183 | + | |
| 184 | + def encode_mp4_size(value) when is_binary(value), do: value | |
| 185 | + def encode_mp4_size(_), do: {:error, "Unexpected type when encoding FixedHeight.mp4_size"} | |
| 186 | + | |
| 157 | 187 | def decode_size(value) when is_binary(value), do: value |
| 158 | 188 | def decode_size(_), do: {:error, "Unexpected type when decoding FixedHeight.size"} |
| 159 | 189 | |
| @@ -186,11 +216,11 @@ defmodule FixedHeight do | ||
| 186 | 216 | |
| 187 | 217 | def from_map(m) do |
| 188 | 218 | %FixedHeight{ |
| 189 | - frames: m["frames"], | |
| 190 | - hash: m["hash"], | |
| 219 | + frames: m["frames"] && decode_frames(m["frames"]), | |
| 220 | + hash: m["hash"] && decode_hash(m["hash"]), | |
| 191 | 221 | height: decode_height(m["height"]), |
| 192 | - mp4: m["mp4"], | |
| 193 | - mp4_size: m["mp4_size"], | |
| 222 | + mp4: m["mp4"] && decode_mp4(m["mp4"]), | |
| 223 | + mp4_size: m["mp4_size"] && decode_mp4_size(m["mp4_size"]), | |
| 194 | 224 | size: decode_size(m["size"]), |
| 195 | 225 | url: decode_url(m["url"]), |
| 196 | 226 | webp: decode_webp(m["webp"]), |
| @@ -549,13 +579,19 @@ defmodule User do | ||
| 549 | 579 | def encode_profile_url(value) when is_binary(value), do: value |
| 550 | 580 | def encode_profile_url(_), do: {:error, "Unexpected type when encoding User.profile_url"} |
| 551 | 581 | |
| 582 | + def decode_twitter(value) when is_binary(value), do: value | |
| 583 | + def decode_twitter(_), do: {:error, "Unexpected type when decoding User.twitter"} | |
| 584 | + | |
| 585 | + def encode_twitter(value) when is_binary(value), do: value | |
| 586 | + def encode_twitter(_), do: {:error, "Unexpected type when encoding User.twitter"} | |
| 587 | + | |
| 552 | 588 | def from_map(m) do |
| 553 | 589 | %User{ |
| 554 | 590 | avatar_url: decode_avatar_url(m["avatar_url"]), |
| 555 | 591 | banner_url: decode_banner_url(m["banner_url"]), |
| 556 | 592 | display_name: decode_display_name(m["display_name"]), |
| 557 | 593 | profile_url: decode_profile_url(m["profile_url"]), |
| 558 | - twitter: m["twitter"], | |
| 594 | + twitter: m["twitter"] && decode_twitter(m["twitter"]), | |
| 559 | 595 | username: Username.decode(m["username"]), |
| 560 | 596 | } |
| 561 | 597 | end |
Test case
1 generated file · +14 −2test/inputs/json/misc/176f1.json
Melixirdefault / QuickType.ex+14 −2
| @@ -13,10 +13,22 @@ defmodule Footnote do | ||
| 13 | 13 | text: String.t() | nil |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | + def decode_code(value) when is_binary(value), do: value | |
| 17 | + def decode_code(_), do: {:error, "Unexpected type when decoding Footnote.code"} | |
| 18 | + | |
| 19 | + def encode_code(value) when is_binary(value), do: value | |
| 20 | + def encode_code(_), do: {:error, "Unexpected type when encoding Footnote.code"} | |
| 21 | + | |
| 22 | + def decode_text(value) when is_binary(value), do: value | |
| 23 | + def decode_text(_), do: {:error, "Unexpected type when decoding Footnote.text"} | |
| 24 | + | |
| 25 | + def encode_text(value) when is_binary(value), do: value | |
| 26 | + def encode_text(_), do: {:error, "Unexpected type when encoding Footnote.text"} | |
| 27 | + | |
| 16 | 28 | def from_map(m) do |
| 17 | 29 | %Footnote{ |
| 18 | - code: m["code"], | |
| 19 | - text: m["text"], | |
| 30 | + code: m["code"] && decode_code(m["code"]), | |
| 31 | + text: m["text"] && decode_text(m["text"]), | |
| 20 | 32 | } |
| 21 | 33 | end |
Test case
1 generated file · +14 −2test/inputs/json/misc/1b409.json
Melixirdefault / QuickType.ex+14 −2
| @@ -80,19 +80,31 @@ defmodule Extra do | ||
| 80 | 80 | def encode_address(value) when is_binary(value), do: value |
| 81 | 81 | def encode_address(_), do: {:error, "Unexpected type when encoding Extra.address"} |
| 82 | 82 | |
| 83 | + def decode_contact_form(value) when is_binary(value), do: value | |
| 84 | + def decode_contact_form(_), do: {:error, "Unexpected type when decoding Extra.contact_form"} | |
| 85 | + | |
| 86 | + def encode_contact_form(value) when is_binary(value), do: value | |
| 87 | + def encode_contact_form(_), do: {:error, "Unexpected type when encoding Extra.contact_form"} | |
| 88 | + | |
| 83 | 89 | def decode_office(value) when is_binary(value), do: value |
| 84 | 90 | def decode_office(_), do: {:error, "Unexpected type when decoding Extra.office"} |
| 85 | 91 | |
| 86 | 92 | def encode_office(value) when is_binary(value), do: value |
| 87 | 93 | def encode_office(_), do: {:error, "Unexpected type when encoding Extra.office"} |
| 88 | 94 | |
| 95 | + def decode_rss_url(value) when is_binary(value), do: value | |
| 96 | + def decode_rss_url(_), do: {:error, "Unexpected type when decoding Extra.rss_url"} | |
| 97 | + | |
| 98 | + def encode_rss_url(value) when is_binary(value), do: value | |
| 99 | + def encode_rss_url(_), do: {:error, "Unexpected type when encoding Extra.rss_url"} | |
| 100 | + | |
| 89 | 101 | def from_map(m) do |
| 90 | 102 | %Extra{ |
| 91 | 103 | address: decode_address(m["address"]), |
| 92 | - contact_form: m["contact_form"], | |
| 104 | + contact_form: m["contact_form"] && decode_contact_form(m["contact_form"]), | |
| 93 | 105 | fax: m["fax"], |
| 94 | 106 | office: decode_office(m["office"]), |
| 95 | - rss_url: m["rss_url"], | |
| 107 | + rss_url: m["rss_url"] && decode_rss_url(m["rss_url"]), | |
| 96 | 108 | } |
| 97 | 109 | end |
Test case
1 generated file · +42 −6test/inputs/json/misc/26b49.json
Melixirdefault / QuickType.ex+42 −6
| @@ -22,6 +22,12 @@ defmodule The480_WStill do | ||
| 22 | 22 | def encode_height(value) when is_binary(value), do: value |
| 23 | 23 | def encode_height(_), do: {:error, "Unexpected type when encoding The480_WStill.height"} |
| 24 | 24 | |
| 25 | + def decode_size(value) when is_binary(value), do: value | |
| 26 | + def decode_size(_), do: {:error, "Unexpected type when decoding The480_WStill.size"} | |
| 27 | + | |
| 28 | + def encode_size(value) when is_binary(value), do: value | |
| 29 | + def encode_size(_), do: {:error, "Unexpected type when encoding The480_WStill.size"} | |
| 30 | + | |
| 25 | 31 | def decode_url(value) when is_binary(value), do: value |
| 26 | 32 | def decode_url(_), do: {:error, "Unexpected type when decoding The480_WStill.url"} |
| 27 | 33 | |
| @@ -37,7 +43,7 @@ defmodule The480_WStill do | ||
| 37 | 43 | def from_map(m) do |
| 38 | 44 | %The480_WStill{ |
| 39 | 45 | height: decode_height(m["height"]), |
| 40 | - size: m["size"], | |
| 46 | + size: m["size"] && decode_size(m["size"]), | |
| 41 | 47 | url: decode_url(m["url"]), |
| 42 | 48 | width: decode_width(m["width"]), |
| 43 | 49 | } |
| @@ -148,12 +154,36 @@ defmodule FixedHeight do | ||
| 148 | 154 | width: String.t() |
| 149 | 155 | } |
| 150 | 156 | |
| 157 | + def decode_frames(value) when is_binary(value), do: value | |
| 158 | + def decode_frames(_), do: {:error, "Unexpected type when decoding FixedHeight.frames"} | |
| 159 | + | |
| 160 | + def encode_frames(value) when is_binary(value), do: value | |
| 161 | + def encode_frames(_), do: {:error, "Unexpected type when encoding FixedHeight.frames"} | |
| 162 | + | |
| 163 | + def decode_hash(value) when is_binary(value), do: value | |
| 164 | + def decode_hash(_), do: {:error, "Unexpected type when decoding FixedHeight.hash"} | |
| 165 | + | |
| 166 | + def encode_hash(value) when is_binary(value), do: value | |
| 167 | + def encode_hash(_), do: {:error, "Unexpected type when encoding FixedHeight.hash"} | |
| 168 | + | |
| 151 | 169 | def decode_height(value) when is_binary(value), do: value |
| 152 | 170 | def decode_height(_), do: {:error, "Unexpected type when decoding FixedHeight.height"} |
| 153 | 171 | |
| 154 | 172 | def encode_height(value) when is_binary(value), do: value |
| 155 | 173 | def encode_height(_), do: {:error, "Unexpected type when encoding FixedHeight.height"} |
| 156 | 174 | |
| 175 | + def decode_mp4(value) when is_binary(value), do: value | |
| 176 | + def decode_mp4(_), do: {:error, "Unexpected type when decoding FixedHeight.mp4"} | |
| 177 | + | |
| 178 | + def encode_mp4(value) when is_binary(value), do: value | |
| 179 | + def encode_mp4(_), do: {:error, "Unexpected type when encoding FixedHeight.mp4"} | |
| 180 | + | |
| 181 | + def decode_mp4_size(value) when is_binary(value), do: value | |
| 182 | + def decode_mp4_size(_), do: {:error, "Unexpected type when decoding FixedHeight.mp4_size"} | |
| 183 | + | |
| 184 | + def encode_mp4_size(value) when is_binary(value), do: value | |
| 185 | + def encode_mp4_size(_), do: {:error, "Unexpected type when encoding FixedHeight.mp4_size"} | |
| 186 | + | |
| 157 | 187 | def decode_size(value) when is_binary(value), do: value |
| 158 | 188 | def decode_size(_), do: {:error, "Unexpected type when decoding FixedHeight.size"} |
| 159 | 189 | |
| @@ -186,11 +216,11 @@ defmodule FixedHeight do | ||
| 186 | 216 | |
| 187 | 217 | def from_map(m) do |
| 188 | 218 | %FixedHeight{ |
| 189 | - frames: m["frames"], | |
| 190 | - hash: m["hash"], | |
| 219 | + frames: m["frames"] && decode_frames(m["frames"]), | |
| 220 | + hash: m["hash"] && decode_hash(m["hash"]), | |
| 191 | 221 | height: decode_height(m["height"]), |
| 192 | - mp4: m["mp4"], | |
| 193 | - mp4_size: m["mp4_size"], | |
| 222 | + mp4: m["mp4"] && decode_mp4(m["mp4"]), | |
| 223 | + mp4_size: m["mp4_size"] && decode_mp4_size(m["mp4_size"]), | |
| 194 | 224 | size: decode_size(m["size"]), |
| 195 | 225 | url: decode_url(m["url"]), |
| 196 | 226 | webp: decode_webp(m["webp"]), |
| @@ -507,6 +537,12 @@ defmodule User do | ||
| 507 | 537 | def encode_profile_url(value) when is_binary(value), do: value |
| 508 | 538 | def encode_profile_url(_), do: {:error, "Unexpected type when encoding User.profile_url"} |
| 509 | 539 | |
| 540 | + def decode_twitter(value) when is_binary(value), do: value | |
| 541 | + def decode_twitter(_), do: {:error, "Unexpected type when decoding User.twitter"} | |
| 542 | + | |
| 543 | + def encode_twitter(value) when is_binary(value), do: value | |
| 544 | + def encode_twitter(_), do: {:error, "Unexpected type when encoding User.twitter"} | |
| 545 | + | |
| 510 | 546 | def decode_username(value) when is_binary(value), do: value |
| 511 | 547 | def decode_username(_), do: {:error, "Unexpected type when decoding User.username"} |
| 512 | 548 | |
| @@ -519,7 +555,7 @@ defmodule User do | ||
| 519 | 555 | banner_url: decode_banner_url(m["banner_url"]), |
| 520 | 556 | display_name: decode_display_name(m["display_name"]), |
| 521 | 557 | profile_url: decode_profile_url(m["profile_url"]), |
| 522 | - twitter: m["twitter"], | |
| 558 | + twitter: m["twitter"] && decode_twitter(m["twitter"]), | |
| 523 | 559 | username: decode_username(m["username"]), |
| 524 | 560 | } |
| 525 | 561 | end |
Test case
1 generated file · +42 −6test/inputs/json/misc/26c9c.json
Melixirdefault / QuickType.ex+42 −6
| @@ -67,6 +67,12 @@ defmodule CachedContents do | ||
| 67 | 67 | top: [Top.t()] |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | + def decode_average(value) when is_binary(value), do: value | |
| 71 | + def decode_average(_), do: {:error, "Unexpected type when decoding CachedContents.average"} | |
| 72 | + | |
| 73 | + def encode_average(value) when is_binary(value), do: value | |
| 74 | + def encode_average(_), do: {:error, "Unexpected type when encoding CachedContents.average"} | |
| 75 | + | |
| 70 | 76 | def decode_largest(value) when is_binary(value), do: value |
| 71 | 77 | def decode_largest(_), do: {:error, "Unexpected type when decoding CachedContents.largest"} |
| 72 | 78 | |
| @@ -91,6 +97,12 @@ defmodule CachedContents do | ||
| 91 | 97 | def encode_smallest(value) when is_binary(value), do: value |
| 92 | 98 | def encode_smallest(_), do: {:error, "Unexpected type when encoding CachedContents.smallest"} |
| 93 | 99 | |
| 100 | + def decode_sum(value) when is_binary(value), do: value | |
| 101 | + def decode_sum(_), do: {:error, "Unexpected type when decoding CachedContents.sum"} | |
| 102 | + | |
| 103 | + def encode_sum(value) when is_binary(value), do: value | |
| 104 | + def encode_sum(_), do: {:error, "Unexpected type when encoding CachedContents.sum"} | |
| 105 | + | |
| 94 | 106 | def decode_top(value) when is_list(value), do: value |
| 95 | 107 | def decode_top(_), do: {:error, "Unexpected type when decoding CachedContents.top"} |
| 96 | 108 | |
| @@ -99,12 +111,12 @@ defmodule CachedContents do | ||
| 99 | 111 | |
| 100 | 112 | def from_map(m) do |
| 101 | 113 | %CachedContents{ |
| 102 | - average: m["average"], | |
| 114 | + average: m["average"] && decode_average(m["average"]), | |
| 103 | 115 | largest: decode_largest(m["largest"]), |
| 104 | 116 | non_null: decode_non_null(m["non_null"]), |
| 105 | 117 | null: decode_null(m["null"]), |
| 106 | 118 | smallest: decode_smallest(m["smallest"]), |
| 107 | - sum: m["sum"], | |
| 119 | + sum: m["sum"] && decode_sum(m["sum"]), | |
| 108 | 120 | top: Enum.map(m["top"], &Top.from_map/1), |
| 109 | 121 | } |
| 110 | 122 | end |
| @@ -144,12 +156,36 @@ defmodule Format do | ||
| 144 | 156 | view: String.t() | nil |
| 145 | 157 | } |
| 146 | 158 | |
| 159 | + def decode_align(value) when is_binary(value), do: value | |
| 160 | + def decode_align(_), do: {:error, "Unexpected type when decoding Format.align"} | |
| 161 | + | |
| 162 | + def encode_align(value) when is_binary(value), do: value | |
| 163 | + def encode_align(_), do: {:error, "Unexpected type when encoding Format.align"} | |
| 164 | + | |
| 165 | + def decode_no_commas(value) when is_binary(value), do: value | |
| 166 | + def decode_no_commas(_), do: {:error, "Unexpected type when decoding Format.no_commas"} | |
| 167 | + | |
| 168 | + def encode_no_commas(value) when is_binary(value), do: value | |
| 169 | + def encode_no_commas(_), do: {:error, "Unexpected type when encoding Format.no_commas"} | |
| 170 | + | |
| 171 | + def decode_precision_style(value) when is_binary(value), do: value | |
| 172 | + def decode_precision_style(_), do: {:error, "Unexpected type when decoding Format.precision_style"} | |
| 173 | + | |
| 174 | + def encode_precision_style(value) when is_binary(value), do: value | |
| 175 | + def encode_precision_style(_), do: {:error, "Unexpected type when encoding Format.precision_style"} | |
| 176 | + | |
| 177 | + def decode_view(value) when is_binary(value), do: value | |
| 178 | + def decode_view(_), do: {:error, "Unexpected type when decoding Format.view"} | |
| 179 | + | |
| 180 | + def encode_view(value) when is_binary(value), do: value | |
| 181 | + def encode_view(_), do: {:error, "Unexpected type when encoding Format.view"} | |
| 182 | + | |
| 147 | 183 | def from_map(m) do |
| 148 | 184 | %Format{ |
| 149 | - align: m["align"], | |
| 150 | - no_commas: m["noCommas"], | |
| 151 | - precision_style: m["precisionStyle"], | |
| 152 | - view: m["view"], | |
| 185 | + align: m["align"] && decode_align(m["align"]), | |
| 186 | + no_commas: m["noCommas"] && decode_no_commas(m["noCommas"]), | |
| 187 | + precision_style: m["precisionStyle"] && decode_precision_style(m["precisionStyle"]), | |
| 188 | + view: m["view"] && decode_view(m["view"]), | |
| 153 | 189 | } |
| 154 | 190 | end |
Test case
1 generated file · +7 −1test/inputs/json/misc/27332.json
Melixirdefault / QuickType.ex+7 −1
| @@ -237,9 +237,15 @@ defmodule MediaEmbed do | ||
| 237 | 237 | width: integer() | nil |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | + def decode_content(value) when is_binary(value), do: value | |
| 241 | + def decode_content(_), do: {:error, "Unexpected type when decoding MediaEmbed.content"} | |
| 242 | + | |
| 243 | + def encode_content(value) when is_binary(value), do: value | |
| 244 | + def encode_content(_), do: {:error, "Unexpected type when encoding MediaEmbed.content"} | |
| 245 | + | |
| 240 | 246 | def from_map(m) do |
| 241 | 247 | %MediaEmbed{ |
| 242 | - content: m["content"], | |
| 248 | + content: m["content"] && decode_content(m["content"]), | |
| 243 | 249 | height: m["height"], |
| 244 | 250 | scrolling: m["scrolling"], |
| 245 | 251 | width: m["width"], |
Test case
1 generated file · +14 −2test/inputs/json/misc/2d4e2.json
Melixirdefault / QuickType.ex+14 −2
| @@ -133,19 +133,31 @@ defmodule Extra do | ||
| 133 | 133 | def encode_contact_form(value) when is_binary(value), do: value |
| 134 | 134 | def encode_contact_form(_), do: {:error, "Unexpected type when encoding Extra.contact_form"} |
| 135 | 135 | |
| 136 | + def decode_fax(value) when is_binary(value), do: value | |
| 137 | + def decode_fax(_), do: {:error, "Unexpected type when decoding Extra.fax"} | |
| 138 | + | |
| 139 | + def encode_fax(value) when is_binary(value), do: value | |
| 140 | + def encode_fax(_), do: {:error, "Unexpected type when encoding Extra.fax"} | |
| 141 | + | |
| 136 | 142 | def decode_office(value) when is_binary(value), do: value |
| 137 | 143 | def decode_office(_), do: {:error, "Unexpected type when decoding Extra.office"} |
| 138 | 144 | |
| 139 | 145 | def encode_office(value) when is_binary(value), do: value |
| 140 | 146 | def encode_office(_), do: {:error, "Unexpected type when encoding Extra.office"} |
| 141 | 147 | |
| 148 | + def decode_rss_url(value) when is_binary(value), do: value | |
| 149 | + def decode_rss_url(_), do: {:error, "Unexpected type when decoding Extra.rss_url"} | |
| 150 | + | |
| 151 | + def encode_rss_url(value) when is_binary(value), do: value | |
| 152 | + def encode_rss_url(_), do: {:error, "Unexpected type when encoding Extra.rss_url"} | |
| 153 | + | |
| 142 | 154 | def from_map(m) do |
| 143 | 155 | %Extra{ |
| 144 | 156 | address: decode_address(m["address"]), |
| 145 | 157 | contact_form: decode_contact_form(m["contact_form"]), |
| 146 | - fax: m["fax"], | |
| 158 | + fax: m["fax"] && decode_fax(m["fax"]), | |
| 147 | 159 | office: decode_office(m["office"]), |
| 148 | - rss_url: m["rss_url"], | |
| 160 | + rss_url: m["rss_url"] && decode_rss_url(m["rss_url"]), | |
| 149 | 161 | } |
| 150 | 162 | end |
Test case
1 generated file · +105 −15test/inputs/json/misc/33d2e.json
Melixirdefault / QuickType.ex+105 −15
| @@ -61,11 +61,29 @@ defmodule AffiliationClass do | ||
| 61 | 61 | name: String.t() | nil |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | + def decode_city(value) when is_binary(value), do: value | |
| 65 | + def decode_city(_), do: {:error, "Unexpected type when decoding AffiliationClass.city"} | |
| 66 | + | |
| 67 | + def encode_city(value) when is_binary(value), do: value | |
| 68 | + def encode_city(_), do: {:error, "Unexpected type when encoding AffiliationClass.city"} | |
| 69 | + | |
| 70 | + def decode_country(value) when is_binary(value), do: value | |
| 71 | + def decode_country(_), do: {:error, "Unexpected type when decoding AffiliationClass.country"} | |
| 72 | + | |
| 73 | + def encode_country(value) when is_binary(value), do: value | |
| 74 | + def encode_country(_), do: {:error, "Unexpected type when encoding AffiliationClass.country"} | |
| 75 | + | |
| 76 | + def decode_name(value) when is_binary(value), do: value | |
| 77 | + def decode_name(_), do: {:error, "Unexpected type when decoding AffiliationClass.name"} | |
| 78 | + | |
| 79 | + def encode_name(value) when is_binary(value), do: value | |
| 80 | + def encode_name(_), do: {:error, "Unexpected type when encoding AffiliationClass.name"} | |
| 81 | + | |
| 64 | 82 | def from_map(m) do |
| 65 | 83 | %AffiliationClass{ |
| 66 | - city: m["city"], | |
| 67 | - country: m["country"], | |
| 68 | - name: m["name"], | |
| 84 | + city: m["city"] && decode_city(m["city"]), | |
| 85 | + country: m["country"] && decode_country(m["country"]), | |
| 86 | + name: m["name"] && decode_name(m["name"]), | |
| 69 | 87 | } |
| 70 | 88 | end |
| 71 | 89 | |
| @@ -167,14 +185,38 @@ defmodule Prize do | ||
| 167 | 185 | def encode_affiliations_element(value) when is_list(value), do: value |
| 168 | 186 | def encode_affiliations_element(_), do: {:error, "Unexpected type when encoding Prize.affiliations"} |
| 169 | 187 | |
| 188 | + def decode_motivation(value) when is_binary(value), do: value | |
| 189 | + def decode_motivation(_), do: {:error, "Unexpected type when decoding Prize.motivation"} | |
| 190 | + | |
| 191 | + def encode_motivation(value) when is_binary(value), do: value | |
| 192 | + def encode_motivation(_), do: {:error, "Unexpected type when encoding Prize.motivation"} | |
| 193 | + | |
| 194 | + def decode_overall_motivation(value) when is_binary(value), do: value | |
| 195 | + def decode_overall_motivation(_), do: {:error, "Unexpected type when decoding Prize.overall_motivation"} | |
| 196 | + | |
| 197 | + def encode_overall_motivation(value) when is_binary(value), do: value | |
| 198 | + def encode_overall_motivation(_), do: {:error, "Unexpected type when encoding Prize.overall_motivation"} | |
| 199 | + | |
| 200 | + def decode_share(value) when is_binary(value), do: value | |
| 201 | + def decode_share(_), do: {:error, "Unexpected type when decoding Prize.share"} | |
| 202 | + | |
| 203 | + def encode_share(value) when is_binary(value), do: value | |
| 204 | + def encode_share(_), do: {:error, "Unexpected type when encoding Prize.share"} | |
| 205 | + | |
| 206 | + def decode_year(value) when is_binary(value), do: value | |
| 207 | + def decode_year(_), do: {:error, "Unexpected type when decoding Prize.year"} | |
| 208 | + | |
| 209 | + def encode_year(value) when is_binary(value), do: value | |
| 210 | + def encode_year(_), do: {:error, "Unexpected type when encoding Prize.year"} | |
| 211 | + | |
| 170 | 212 | def from_map(m) do |
| 171 | 213 | %Prize{ |
| 172 | 214 | affiliations: Enum.map(m["affiliations"], &decode_affiliations_element/1), |
| 173 | 215 | category: m["category"] && Category.decode(m["category"]), |
| 174 | - motivation: m["motivation"], | |
| 175 | - overall_motivation: m["overallMotivation"], | |
| 176 | - share: m["share"], | |
| 177 | - year: m["year"], | |
| 216 | + motivation: m["motivation"] && decode_motivation(m["motivation"]), | |
| 217 | + overall_motivation: m["overallMotivation"] && decode_overall_motivation(m["overallMotivation"]), | |
| 218 | + share: m["share"] && decode_share(m["share"]), | |
| 219 | + year: m["year"] && decode_year(m["year"]), | |
| 178 | 220 | } |
| 179 | 221 | end |
| 180 | 222 | |
| @@ -228,12 +270,54 @@ defmodule Laureate do | ||
| 228 | 270 | def encode_born(value) when is_binary(value), do: value |
| 229 | 271 | def encode_born(_), do: {:error, "Unexpected type when encoding Laureate.born"} |
| 230 | 272 | |
| 273 | + def decode_born_city(value) when is_binary(value), do: value | |
| 274 | + def decode_born_city(_), do: {:error, "Unexpected type when decoding Laureate.born_city"} | |
| 275 | + | |
| 276 | + def encode_born_city(value) when is_binary(value), do: value | |
| 277 | + def encode_born_city(_), do: {:error, "Unexpected type when encoding Laureate.born_city"} | |
| 278 | + | |
| 279 | + def decode_born_country(value) when is_binary(value), do: value | |
| 280 | + def decode_born_country(_), do: {:error, "Unexpected type when decoding Laureate.born_country"} | |
| 281 | + | |
| 282 | + def encode_born_country(value) when is_binary(value), do: value | |
| 283 | + def encode_born_country(_), do: {:error, "Unexpected type when encoding Laureate.born_country"} | |
| 284 | + | |
| 285 | + def decode_born_country_code(value) when is_binary(value), do: value | |
| 286 | + def decode_born_country_code(_), do: {:error, "Unexpected type when decoding Laureate.born_country_code"} | |
| 287 | + | |
| 288 | + def encode_born_country_code(value) when is_binary(value), do: value | |
| 289 | + def encode_born_country_code(_), do: {:error, "Unexpected type when encoding Laureate.born_country_code"} | |
| 290 | + | |
| 231 | 291 | def decode_died(value) when is_binary(value), do: value |
| 232 | 292 | def decode_died(_), do: {:error, "Unexpected type when decoding Laureate.died"} |
| 233 | 293 | |
| 234 | 294 | def encode_died(value) when is_binary(value), do: value |
| 235 | 295 | def encode_died(_), do: {:error, "Unexpected type when encoding Laureate.died"} |
| 236 | 296 | |
| 297 | + def decode_died_city(value) when is_binary(value), do: value | |
| 298 | + def decode_died_city(_), do: {:error, "Unexpected type when decoding Laureate.died_city"} | |
| 299 | + | |
| 300 | + def encode_died_city(value) when is_binary(value), do: value | |
| 301 | + def encode_died_city(_), do: {:error, "Unexpected type when encoding Laureate.died_city"} | |
| 302 | + | |
| 303 | + def decode_died_country(value) when is_binary(value), do: value | |
| 304 | + def decode_died_country(_), do: {:error, "Unexpected type when decoding Laureate.died_country"} | |
| 305 | + | |
| 306 | + def encode_died_country(value) when is_binary(value), do: value | |
| 307 | + def encode_died_country(_), do: {:error, "Unexpected type when encoding Laureate.died_country"} | |
| 308 | + | |
| 309 | + def decode_died_country_code(value) when is_binary(value), do: value | |
| 310 | + def decode_died_country_code(_), do: {:error, "Unexpected type when decoding Laureate.died_country_code"} | |
| 311 | + | |
| 312 | + def encode_died_country_code(value) when is_binary(value), do: value | |
| 313 | + def encode_died_country_code(_), do: {:error, "Unexpected type when encoding Laureate.died_country_code"} | |
| 314 | + | |
| 315 | + def decode_firstname(value) when is_binary(value), do: value | |
| 316 | + def decode_firstname(_), do: {:error, "Unexpected type when decoding Laureate.firstname"} | |
| 317 | + | |
| 318 | + def encode_firstname(value) when is_binary(value), do: value | |
| 319 | + def encode_firstname(_), do: {:error, "Unexpected type when encoding Laureate.firstname"} | |
| 320 | + | |
| 237 | 321 | def decode_id(value) when is_binary(value), do: value |
| 238 | 322 | def decode_id(_), do: {:error, "Unexpected type when decoding Laureate.id"} |
| 239 | 323 | |
| @@ -246,21 +330,27 @@ defmodule Laureate do | ||
| 246 | 330 | def encode_prizes(value) when is_list(value), do: value |
| 247 | 331 | def encode_prizes(_), do: {:error, "Unexpected type when encoding Laureate.prizes"} |
| 248 | 332 | |
| 333 | + def decode_surname(value) when is_binary(value), do: value | |
| 334 | + def decode_surname(_), do: {:error, "Unexpected type when decoding Laureate.surname"} | |
| 335 | + | |
| 336 | + def encode_surname(value) when is_binary(value), do: value | |
| 337 | + def encode_surname(_), do: {:error, "Unexpected type when encoding Laureate.surname"} | |
| 338 | + | |
| 249 | 339 | def from_map(m) do |
| 250 | 340 | %Laureate{ |
| 251 | 341 | born: decode_born(m["born"]), |
| 252 | - born_city: m["bornCity"], | |
| 253 | - born_country: m["bornCountry"], | |
| 254 | - born_country_code: m["bornCountryCode"], | |
| 342 | + born_city: m["bornCity"] && decode_born_city(m["bornCity"]), | |
| 343 | + born_country: m["bornCountry"] && decode_born_country(m["bornCountry"]), | |
| 344 | + born_country_code: m["bornCountryCode"] && decode_born_country_code(m["bornCountryCode"]), | |
| 255 | 345 | died: decode_died(m["died"]), |
| 256 | - died_city: m["diedCity"], | |
| 257 | - died_country: m["diedCountry"], | |
| 258 | - died_country_code: m["diedCountryCode"], | |
| 259 | - firstname: m["firstname"], | |
| 346 | + died_city: m["diedCity"] && decode_died_city(m["diedCity"]), | |
| 347 | + died_country: m["diedCountry"] && decode_died_country(m["diedCountry"]), | |
| 348 | + died_country_code: m["diedCountryCode"] && decode_died_country_code(m["diedCountryCode"]), | |
| 349 | + firstname: m["firstname"] && decode_firstname(m["firstname"]), | |
| 260 | 350 | gender: Gender.decode(m["gender"]), |
| 261 | 351 | id: decode_id(m["id"]), |
| 262 | 352 | prizes: Enum.map(m["prizes"], &Prize.from_map/1), |
| 263 | - surname: m["surname"], | |
| 353 | + surname: m["surname"] && decode_surname(m["surname"]), | |
| 264 | 354 | } |
| 265 | 355 | end |
Test case
1 generated file · +14 −2test/inputs/json/misc/3e9a3.json
Melixirdefault / QuickType.ex+14 −2
| @@ -13,10 +13,22 @@ defmodule Footnote do | ||
| 13 | 13 | text: String.t() | nil |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | + def decode_code(value) when is_binary(value), do: value | |
| 17 | + def decode_code(_), do: {:error, "Unexpected type when decoding Footnote.code"} | |
| 18 | + | |
| 19 | + def encode_code(value) when is_binary(value), do: value | |
| 20 | + def encode_code(_), do: {:error, "Unexpected type when encoding Footnote.code"} | |
| 21 | + | |
| 22 | + def decode_text(value) when is_binary(value), do: value | |
| 23 | + def decode_text(_), do: {:error, "Unexpected type when decoding Footnote.text"} | |
| 24 | + | |
| 25 | + def encode_text(value) when is_binary(value), do: value | |
| 26 | + def encode_text(_), do: {:error, "Unexpected type when encoding Footnote.text"} | |
| 27 | + | |
| 16 | 28 | def from_map(m) do |
| 17 | 29 | %Footnote{ |
| 18 | - code: m["code"], | |
| 19 | - text: m["text"], | |
| 30 | + code: m["code"] && decode_code(m["code"]), | |
| 31 | + text: m["text"] && decode_text(m["text"]), | |
| 20 | 32 | } |
| 21 | 33 | end |
Test case
1 generated file · +28 −4test/inputs/json/misc/421d4.json
Melixirdefault / QuickType.ex+28 −4
| @@ -67,6 +67,18 @@ defmodule CachedContents do | ||
| 67 | 67 | top: [Top.t()] | nil |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | + def decode_average(value) when is_binary(value), do: value | |
| 71 | + def decode_average(_), do: {:error, "Unexpected type when decoding CachedContents.average"} | |
| 72 | + | |
| 73 | + def encode_average(value) when is_binary(value), do: value | |
| 74 | + def encode_average(_), do: {:error, "Unexpected type when encoding CachedContents.average"} | |
| 75 | + | |
| 76 | + def decode_largest(value) when is_binary(value), do: value | |
| 77 | + def decode_largest(_), do: {:error, "Unexpected type when decoding CachedContents.largest"} | |
| 78 | + | |
| 79 | + def encode_largest(value) when is_binary(value), do: value | |
| 80 | + def encode_largest(_), do: {:error, "Unexpected type when encoding CachedContents.largest"} | |
| 81 | + | |
| 70 | 82 | def decode_non_null(value) when is_integer(value), do: value |
| 71 | 83 | def decode_non_null(_), do: {:error, "Unexpected type when decoding CachedContents.non_null"} |
| 72 | 84 | |
| @@ -79,14 +91,26 @@ defmodule CachedContents do | ||
| 79 | 91 | def encode_null(value) when is_integer(value), do: value |
| 80 | 92 | def encode_null(_), do: {:error, "Unexpected type when encoding CachedContents.null"} |
| 81 | 93 | |
| 94 | + def decode_smallest(value) when is_binary(value), do: value | |
| 95 | + def decode_smallest(_), do: {:error, "Unexpected type when decoding CachedContents.smallest"} | |
| 96 | + | |
| 97 | + def encode_smallest(value) when is_binary(value), do: value | |
| 98 | + def encode_smallest(_), do: {:error, "Unexpected type when encoding CachedContents.smallest"} | |
| 99 | + | |
| 100 | + def decode_sum(value) when is_binary(value), do: value | |
| 101 | + def decode_sum(_), do: {:error, "Unexpected type when decoding CachedContents.sum"} | |
| 102 | + | |
| 103 | + def encode_sum(value) when is_binary(value), do: value | |
| 104 | + def encode_sum(_), do: {:error, "Unexpected type when encoding CachedContents.sum"} | |
| 105 | + | |
| 82 | 106 | def from_map(m) do |
| 83 | 107 | %CachedContents{ |
| 84 | - average: m["average"], | |
| 85 | - largest: m["largest"], | |
| 108 | + average: m["average"] && decode_average(m["average"]), | |
| 109 | + largest: m["largest"] && decode_largest(m["largest"]), | |
| 86 | 110 | non_null: decode_non_null(m["non_null"]), |
| 87 | 111 | null: decode_null(m["null"]), |
| 88 | - smallest: m["smallest"], | |
| 89 | - sum: m["sum"], | |
| 112 | + smallest: m["smallest"] && decode_smallest(m["smallest"]), | |
| 113 | + sum: m["sum"] && decode_sum(m["sum"]), | |
| 90 | 114 | top: m["top"] && Enum.map(m["top"], &Top.from_map/1), |
| 91 | 115 | } |
| 92 | 116 | end |
Test case
1 generated file · +28 −4test/inputs/json/misc/437e7.json
Melixirdefault / QuickType.ex+28 −4
| @@ -22,6 +22,12 @@ defmodule Downsized do | ||
| 22 | 22 | def encode_height(value) when is_binary(value), do: value |
| 23 | 23 | def encode_height(_), do: {:error, "Unexpected type when encoding Downsized.height"} |
| 24 | 24 | |
| 25 | + def decode_size(value) when is_binary(value), do: value | |
| 26 | + def decode_size(_), do: {:error, "Unexpected type when decoding Downsized.size"} | |
| 27 | + | |
| 28 | + def encode_size(value) when is_binary(value), do: value | |
| 29 | + def encode_size(_), do: {:error, "Unexpected type when encoding Downsized.size"} | |
| 30 | + | |
| 25 | 31 | def decode_url(value) when is_binary(value), do: value |
| 26 | 32 | def decode_url(_), do: {:error, "Unexpected type when decoding Downsized.url"} |
| 27 | 33 | |
| @@ -37,7 +43,7 @@ defmodule Downsized do | ||
| 37 | 43 | def from_map(m) do |
| 38 | 44 | %Downsized{ |
| 39 | 45 | height: decode_height(m["height"]), |
| 40 | - size: m["size"], | |
| 46 | + size: m["size"] && decode_size(m["size"]), | |
| 41 | 47 | url: decode_url(m["url"]), |
| 42 | 48 | width: decode_width(m["width"]), |
| 43 | 49 | } |
| @@ -147,12 +153,30 @@ defmodule FixedHeight do | ||
| 147 | 153 | width: String.t() |
| 148 | 154 | } |
| 149 | 155 | |
| 156 | + def decode_frames(value) when is_binary(value), do: value | |
| 157 | + def decode_frames(_), do: {:error, "Unexpected type when decoding FixedHeight.frames"} | |
| 158 | + | |
| 159 | + def encode_frames(value) when is_binary(value), do: value | |
| 160 | + def encode_frames(_), do: {:error, "Unexpected type when encoding FixedHeight.frames"} | |
| 161 | + | |
| 150 | 162 | def decode_height(value) when is_binary(value), do: value |
| 151 | 163 | def decode_height(_), do: {:error, "Unexpected type when decoding FixedHeight.height"} |
| 152 | 164 | |
| 153 | 165 | def encode_height(value) when is_binary(value), do: value |
| 154 | 166 | def encode_height(_), do: {:error, "Unexpected type when encoding FixedHeight.height"} |
| 155 | 167 | |
| 168 | + def decode_mp4(value) when is_binary(value), do: value | |
| 169 | + def decode_mp4(_), do: {:error, "Unexpected type when decoding FixedHeight.mp4"} | |
| 170 | + | |
| 171 | + def encode_mp4(value) when is_binary(value), do: value | |
| 172 | + def encode_mp4(_), do: {:error, "Unexpected type when encoding FixedHeight.mp4"} | |
| 173 | + | |
| 174 | + def decode_mp4_size(value) when is_binary(value), do: value | |
| 175 | + def decode_mp4_size(_), do: {:error, "Unexpected type when decoding FixedHeight.mp4_size"} | |
| 176 | + | |
| 177 | + def encode_mp4_size(value) when is_binary(value), do: value | |
| 178 | + def encode_mp4_size(_), do: {:error, "Unexpected type when encoding FixedHeight.mp4_size"} | |
| 179 | + | |
| 156 | 180 | def decode_size(value) when is_binary(value), do: value |
| 157 | 181 | def decode_size(_), do: {:error, "Unexpected type when decoding FixedHeight.size"} |
| 158 | 182 | |
| @@ -185,10 +209,10 @@ defmodule FixedHeight do | ||
| 185 | 209 | |
| 186 | 210 | def from_map(m) do |
| 187 | 211 | %FixedHeight{ |
| 188 | - frames: m["frames"], | |
| 212 | + frames: m["frames"] && decode_frames(m["frames"]), | |
| 189 | 213 | height: decode_height(m["height"]), |
| 190 | - mp4: m["mp4"], | |
| 191 | - mp4_size: m["mp4_size"], | |
| 214 | + mp4: m["mp4"] && decode_mp4(m["mp4"]), | |
| 215 | + mp4_size: m["mp4_size"] && decode_mp4_size(m["mp4_size"]), | |
| 192 | 216 | size: decode_size(m["size"]), |
| 193 | 217 | url: decode_url(m["url"]), |
| 194 | 218 | webp: decode_webp(m["webp"]), |
Test case
1 generated file · +7 −1test/inputs/json/misc/4d6fb.json
Melixirdefault / QuickType.ex+7 −1
| @@ -204,9 +204,15 @@ defmodule MediaEmbed do | ||
| 204 | 204 | width: integer() | nil |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | + def decode_content(value) when is_binary(value), do: value | |
| 208 | + def decode_content(_), do: {:error, "Unexpected type when decoding MediaEmbed.content"} | |
| 209 | + | |
| 210 | + def encode_content(value) when is_binary(value), do: value | |
| 211 | + def encode_content(_), do: {:error, "Unexpected type when encoding MediaEmbed.content"} | |
| 212 | + | |
| 207 | 213 | def from_map(m) do |
| 208 | 214 | %MediaEmbed{ |
| 209 | - content: m["content"], | |
| 215 | + content: m["content"] && decode_content(m["content"]), | |
| 210 | 216 | height: m["height"], |
| 211 | 217 | scrolling: m["scrolling"], |
| 212 | 218 | width: m["width"], |
Test case
1 generated file · +14 −2test/inputs/json/misc/5f7fe.json
Melixirdefault / QuickType.ex+14 −2
| @@ -183,10 +183,22 @@ defmodule Format do | ||
| 183 | 183 | view: String.t() | nil |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | + def decode_align(value) when is_binary(value), do: value | |
| 187 | + def decode_align(_), do: {:error, "Unexpected type when decoding Format.align"} | |
| 188 | + | |
| 189 | + def encode_align(value) when is_binary(value), do: value | |
| 190 | + def encode_align(_), do: {:error, "Unexpected type when encoding Format.align"} | |
| 191 | + | |
| 192 | + def decode_view(value) when is_binary(value), do: value | |
| 193 | + def decode_view(_), do: {:error, "Unexpected type when decoding Format.view"} | |
| 194 | + | |
| 195 | + def encode_view(value) when is_binary(value), do: value | |
| 196 | + def encode_view(_), do: {:error, "Unexpected type when encoding Format.view"} | |
| 197 | + | |
| 186 | 198 | def from_map(m) do |
| 187 | 199 | %Format{ |
| 188 | - align: m["align"], | |
| 189 | - view: m["view"], | |
| 200 | + align: m["align"] && decode_align(m["align"]), | |
| 201 | + view: m["view"] && decode_view(m["view"]), | |
| 190 | 202 | } |
| 191 | 203 | end |
Test case
1 generated file · +21 −3test/inputs/json/misc/617e8.json
Melixirdefault / QuickType.ex+21 −3
| @@ -183,10 +183,22 @@ defmodule Format do | ||
| 183 | 183 | view: String.t() | nil |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | + def decode_align(value) when is_binary(value), do: value | |
| 187 | + def decode_align(_), do: {:error, "Unexpected type when decoding Format.align"} | |
| 188 | + | |
| 189 | + def encode_align(value) when is_binary(value), do: value | |
| 190 | + def encode_align(_), do: {:error, "Unexpected type when encoding Format.align"} | |
| 191 | + | |
| 192 | + def decode_view(value) when is_binary(value), do: value | |
| 193 | + def decode_view(_), do: {:error, "Unexpected type when decoding Format.view"} | |
| 194 | + | |
| 195 | + def encode_view(value) when is_binary(value), do: value | |
| 196 | + def encode_view(_), do: {:error, "Unexpected type when encoding Format.view"} | |
| 197 | + | |
| 186 | 198 | def from_map(m) do |
| 187 | 199 | %Format{ |
| 188 | - align: m["align"], | |
| 189 | - view: m["view"], | |
| 200 | + align: m["align"] && decode_align(m["align"]), | |
| 201 | + view: m["view"] && decode_view(m["view"]), | |
| 190 | 202 | } |
| 191 | 203 | end |
| 192 | 204 | |
| @@ -229,6 +241,12 @@ defmodule Column do | ||
| 229 | 241 | width: integer() | nil |
| 230 | 242 | } |
| 231 | 243 | |
| 244 | + def decode_description(value) when is_binary(value), do: value | |
| 245 | + def decode_description(_), do: {:error, "Unexpected type when decoding Column.description"} | |
| 246 | + | |
| 247 | + def encode_description(value) when is_binary(value), do: value | |
| 248 | + def encode_description(_), do: {:error, "Unexpected type when encoding Column.description"} | |
| 249 | + | |
| 232 | 250 | def decode_field_name(value) when is_binary(value), do: value |
| 233 | 251 | def decode_field_name(_), do: {:error, "Unexpected type when decoding Column.field_name"} |
| 234 | 252 | |
| @@ -257,7 +275,7 @@ defmodule Column do | ||
| 257 | 275 | %Column{ |
| 258 | 276 | cached_contents: m["cachedContents"] && CachedContents.from_map(m["cachedContents"]), |
| 259 | 277 | data_type_name: TypeName.decode(m["dataTypeName"]), |
| 260 | - description: m["description"], | |
| 278 | + description: m["description"] && decode_description(m["description"]), | |
| 261 | 279 | field_name: decode_field_name(m["fieldName"]), |
| 262 | 280 | flags: m["flags"], |
| 263 | 281 | format: Format.from_map(m["format"]), |
Test case
1 generated file · +42 −6test/inputs/json/misc/65dec.json
Melixirdefault / QuickType.ex+42 −6
| @@ -430,6 +430,12 @@ defmodule Card do | ||
| 430 | 430 | def encode_cmc(value) when is_integer(value), do: value |
| 431 | 431 | def encode_cmc(_), do: {:error, "Unexpected type when encoding Card.cmc"} |
| 432 | 432 | |
| 433 | + def decode_flavor(value) when is_binary(value), do: value | |
| 434 | + def decode_flavor(_), do: {:error, "Unexpected type when decoding Card.flavor"} | |
| 435 | + | |
| 436 | + def encode_flavor(value) when is_binary(value), do: value | |
| 437 | + def encode_flavor(_), do: {:error, "Unexpected type when encoding Card.flavor"} | |
| 438 | + | |
| 433 | 439 | def decode_id(value) when is_binary(value), do: value |
| 434 | 440 | def decode_id(_), do: {:error, "Unexpected type when decoding Card.id"} |
| 435 | 441 | |
| @@ -448,6 +454,18 @@ defmodule Card do | ||
| 448 | 454 | def encode_legalities(value) when is_list(value), do: value |
| 449 | 455 | def encode_legalities(_), do: {:error, "Unexpected type when encoding Card.legalities"} |
| 450 | 456 | |
| 457 | + def decode_mana_cost(value) when is_binary(value), do: value | |
| 458 | + def decode_mana_cost(_), do: {:error, "Unexpected type when decoding Card.mana_cost"} | |
| 459 | + | |
| 460 | + def encode_mana_cost(value) when is_binary(value), do: value | |
| 461 | + def encode_mana_cost(_), do: {:error, "Unexpected type when encoding Card.mana_cost"} | |
| 462 | + | |
| 463 | + def decode_mci_number(value) when is_binary(value), do: value | |
| 464 | + def decode_mci_number(_), do: {:error, "Unexpected type when decoding Card.mci_number"} | |
| 465 | + | |
| 466 | + def encode_mci_number(value) when is_binary(value), do: value | |
| 467 | + def encode_mci_number(_), do: {:error, "Unexpected type when encoding Card.mci_number"} | |
| 468 | + | |
| 451 | 469 | def decode_multiverseid(value) when is_integer(value), do: value |
| 452 | 470 | def decode_multiverseid(_), do: {:error, "Unexpected type when decoding Card.multiverseid"} |
| 453 | 471 | |
| @@ -472,12 +490,30 @@ defmodule Card do | ||
| 472 | 490 | def encode_original_type(value) when is_binary(value), do: value |
| 473 | 491 | def encode_original_type(_), do: {:error, "Unexpected type when encoding Card.original_type"} |
| 474 | 492 | |
| 493 | + def decode_power(value) when is_binary(value), do: value | |
| 494 | + def decode_power(_), do: {:error, "Unexpected type when decoding Card.power"} | |
| 495 | + | |
| 496 | + def encode_power(value) when is_binary(value), do: value | |
| 497 | + def encode_power(_), do: {:error, "Unexpected type when encoding Card.power"} | |
| 498 | + | |
| 475 | 499 | def decode_printings(value) when is_list(value), do: value |
| 476 | 500 | def decode_printings(_), do: {:error, "Unexpected type when decoding Card.printings"} |
| 477 | 501 | |
| 478 | 502 | def encode_printings(value) when is_list(value), do: value |
| 479 | 503 | def encode_printings(_), do: {:error, "Unexpected type when encoding Card.printings"} |
| 480 | 504 | |
| 505 | + def decode_text(value) when is_binary(value), do: value | |
| 506 | + def decode_text(_), do: {:error, "Unexpected type when decoding Card.text"} | |
| 507 | + | |
| 508 | + def encode_text(value) when is_binary(value), do: value | |
| 509 | + def encode_text(_), do: {:error, "Unexpected type when encoding Card.text"} | |
| 510 | + | |
| 511 | + def decode_toughness(value) when is_binary(value), do: value | |
| 512 | + def decode_toughness(_), do: {:error, "Unexpected type when decoding Card.toughness"} | |
| 513 | + | |
| 514 | + def encode_toughness(value) when is_binary(value), do: value | |
| 515 | + def encode_toughness(_), do: {:error, "Unexpected type when encoding Card.toughness"} | |
| 516 | + | |
| 481 | 517 | def decode_type(value) when is_binary(value), do: value |
| 482 | 518 | def decode_type(_), do: {:error, "Unexpected type when decoding Card.type"} |
| 483 | 519 | |
| @@ -496,26 +532,26 @@ defmodule Card do | ||
| 496 | 532 | cmc: decode_cmc(m["cmc"]), |
| 497 | 533 | color_identity: m["colorIdentity"] && Enum.map(m["colorIdentity"], &ColorIdentity.decode/1), |
| 498 | 534 | colors: m["colors"] && Enum.map(m["colors"], &Watermark.decode/1), |
| 499 | - flavor: m["flavor"], | |
| 535 | + flavor: m["flavor"] && decode_flavor(m["flavor"]), | |
| 500 | 536 | id: decode_id(m["id"]), |
| 501 | 537 | image_name: decode_image_name(m["imageName"]), |
| 502 | 538 | layout: Layout.decode(m["layout"]), |
| 503 | 539 | legalities: Enum.map(m["legalities"], &LegalityElement.from_map/1), |
| 504 | - mana_cost: m["manaCost"], | |
| 505 | - mci_number: m["mciNumber"], | |
| 540 | + mana_cost: m["manaCost"] && decode_mana_cost(m["manaCost"]), | |
| 541 | + mci_number: m["mciNumber"] && decode_mci_number(m["mciNumber"]), | |
| 506 | 542 | multiverseid: decode_multiverseid(m["multiverseid"]), |
| 507 | 543 | name: decode_name(m["name"]), |
| 508 | 544 | original_text: decode_original_text(m["originalText"]), |
| 509 | 545 | original_type: decode_original_type(m["originalType"]), |
| 510 | - power: m["power"], | |
| 546 | + power: m["power"] && decode_power(m["power"]), | |
| 511 | 547 | printings: decode_printings(m["printings"]), |
| 512 | 548 | rarity: Rarity.decode(m["rarity"]), |
| 513 | 549 | reserved: m["reserved"], |
| 514 | 550 | rulings: m["rulings"] && Enum.map(m["rulings"], &Ruling.from_map/1), |
| 515 | 551 | subtypes: m["subtypes"], |
| 516 | 552 | supertypes: m["supertypes"], |
| 517 | - text: m["text"], | |
| 518 | - toughness: m["toughness"], | |
| 553 | + text: m["text"] && decode_text(m["text"]), | |
| 554 | + toughness: m["toughness"] && decode_toughness(m["toughness"]), | |
| 519 | 555 | type: decode_type(m["type"]), |
| 520 | 556 | types: Enum.map(m["types"], &Type.decode/1), |
| 521 | 557 | variations: m["variations"], |
Test case
1 generated file · +7 −1test/inputs/json/misc/6de06.json
Melixirdefault / QuickType.ex+7 −1
| @@ -195,9 +195,15 @@ defmodule MediaEmbed do | ||
| 195 | 195 | width: integer() | nil |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | + def decode_content(value) when is_binary(value), do: value | |
| 199 | + def decode_content(_), do: {:error, "Unexpected type when decoding MediaEmbed.content"} | |
| 200 | + | |
| 201 | + def encode_content(value) when is_binary(value), do: value | |
| 202 | + def encode_content(_), do: {:error, "Unexpected type when encoding MediaEmbed.content"} | |
| 203 | + | |
| 198 | 204 | def from_map(m) do |
| 199 | 205 | %MediaEmbed{ |
| 200 | - content: m["content"], | |
| 206 | + content: m["content"] && decode_content(m["content"]), | |
| 201 | 207 | height: m["height"], |
| 202 | 208 | scrolling: m["scrolling"], |
| 203 | 209 | width: m["width"], |
Test case
1 generated file · +28 −4test/inputs/json/misc/734ad.json
Melixirdefault / QuickType.ex+28 −4
| @@ -187,6 +187,30 @@ defmodule Result do | ||
| 187 | 187 | def encode_activity_relevant_comm(value) when is_binary(value), do: value |
| 188 | 188 | def encode_activity_relevant_comm(_), do: {:error, "Unexpected type when encoding Result.activity_relevant_comm"} |
| 189 | 189 | |
| 190 | + def decode_be_office_country(value) when is_binary(value), do: value | |
| 191 | + def decode_be_office_country(_), do: {:error, "Unexpected type when decoding Result.be_office_country"} | |
| 192 | + | |
| 193 | + def encode_be_office_country(value) when is_binary(value), do: value | |
| 194 | + def encode_be_office_country(_), do: {:error, "Unexpected type when encoding Result.be_office_country"} | |
| 195 | + | |
| 196 | + def decode_be_office_phone(value) when is_binary(value), do: value | |
| 197 | + def decode_be_office_phone(_), do: {:error, "Unexpected type when decoding Result.be_office_phone"} | |
| 198 | + | |
| 199 | + def encode_be_office_phone(value) when is_binary(value), do: value | |
| 200 | + def encode_be_office_phone(_), do: {:error, "Unexpected type when encoding Result.be_office_phone"} | |
| 201 | + | |
| 202 | + def decode_be_office_street(value) when is_binary(value), do: value | |
| 203 | + def decode_be_office_street(_), do: {:error, "Unexpected type when decoding Result.be_office_street"} | |
| 204 | + | |
| 205 | + def encode_be_office_street(value) when is_binary(value), do: value | |
| 206 | + def encode_be_office_street(_), do: {:error, "Unexpected type when encoding Result.be_office_street"} | |
| 207 | + | |
| 208 | + def decode_be_office_town(value) when is_binary(value), do: value | |
| 209 | + def decode_be_office_town(_), do: {:error, "Unexpected type when decoding Result.be_office_town"} | |
| 210 | + | |
| 211 | + def encode_be_office_town(value) when is_binary(value), do: value | |
| 212 | + def encode_be_office_town(_), do: {:error, "Unexpected type when encoding Result.be_office_town"} | |
| 213 | + | |
| 190 | 214 | def decode_code_of_conduct(value) when is_binary(value), do: value |
| 191 | 215 | def decode_code_of_conduct(_), do: {:error, "Unexpected type when decoding Result.code_of_conduct"} |
| 192 | 216 | |
| @@ -368,14 +392,14 @@ defmodule Result do | ||
| 368 | 392 | activity_inter_groups: decode_activity_inter_groups(m["activity_inter_groups"]), |
| 369 | 393 | activity_other: Map.fetch!(m, "activity_other"), |
| 370 | 394 | activity_relevant_comm: decode_activity_relevant_comm(m["activity_relevant_comm"]), |
| 371 | - be_office_country: m["be_office_country"], | |
| 395 | + be_office_country: m["be_office_country"] && decode_be_office_country(m["be_office_country"]), | |
| 372 | 396 | be_office_lat: m["be_office_lat"], |
| 373 | 397 | be_office_lon: m["be_office_lon"], |
| 374 | - be_office_phone: m["be_office_phone"], | |
| 398 | + be_office_phone: m["be_office_phone"] && decode_be_office_phone(m["be_office_phone"]), | |
| 375 | 399 | be_office_post_code: m["be_office_post_code"], |
| 376 | 400 | be_office_postbox: m["be_office_postbox"], |
| 377 | - be_office_street: m["be_office_street"], | |
| 378 | - be_office_town: m["be_office_town"], | |
| 401 | + be_office_street: m["be_office_street"] && decode_be_office_street(m["be_office_street"]), | |
| 402 | + be_office_town: m["be_office_town"] && decode_be_office_town(m["be_office_town"]), | |
| 379 | 403 | code_of_conduct: decode_code_of_conduct(m["code_of_conduct"]), |
| 380 | 404 | contact_country: decode_contact_country(m["contact_country"]), |
| 381 | 405 | created_at: decode_created_at(m["created_at"]), |
Test case
1 generated file · +42 −6test/inputs/json/misc/7681c.json
Melixirdefault / QuickType.ex+42 −6
| @@ -22,6 +22,12 @@ defmodule The480_WStill do | ||
| 22 | 22 | def encode_height(value) when is_binary(value), do: value |
| 23 | 23 | def encode_height(_), do: {:error, "Unexpected type when encoding The480_WStill.height"} |
| 24 | 24 | |
| 25 | + def decode_size(value) when is_binary(value), do: value | |
| 26 | + def decode_size(_), do: {:error, "Unexpected type when decoding The480_WStill.size"} | |
| 27 | + | |
| 28 | + def encode_size(value) when is_binary(value), do: value | |
| 29 | + def encode_size(_), do: {:error, "Unexpected type when encoding The480_WStill.size"} | |
| 30 | + | |
| 25 | 31 | def decode_url(value) when is_binary(value), do: value |
| 26 | 32 | def decode_url(_), do: {:error, "Unexpected type when decoding The480_WStill.url"} |
| 27 | 33 | |
| @@ -37,7 +43,7 @@ defmodule The480_WStill do | ||
| 37 | 43 | def from_map(m) do |
| 38 | 44 | %The480_WStill{ |
| 39 | 45 | height: decode_height(m["height"]), |
| 40 | - size: m["size"], | |
| 46 | + size: m["size"] && decode_size(m["size"]), | |
| 41 | 47 | url: decode_url(m["url"]), |
| 42 | 48 | width: decode_width(m["width"]), |
| 43 | 49 | } |
| @@ -148,12 +154,36 @@ defmodule FixedHeight do | ||
| 148 | 154 | width: String.t() |
| 149 | 155 | } |
| 150 | 156 | |
| 157 | + def decode_frames(value) when is_binary(value), do: value | |
| 158 | + def decode_frames(_), do: {:error, "Unexpected type when decoding FixedHeight.frames"} | |
| 159 | + | |
| 160 | + def encode_frames(value) when is_binary(value), do: value | |
| 161 | + def encode_frames(_), do: {:error, "Unexpected type when encoding FixedHeight.frames"} | |
| 162 | + | |
| 163 | + def decode_hash(value) when is_binary(value), do: value | |
| 164 | + def decode_hash(_), do: {:error, "Unexpected type when decoding FixedHeight.hash"} | |
| 165 | + | |
| 166 | + def encode_hash(value) when is_binary(value), do: value | |
| 167 | + def encode_hash(_), do: {:error, "Unexpected type when encoding FixedHeight.hash"} | |
| 168 | + | |
| 151 | 169 | def decode_height(value) when is_binary(value), do: value |
| 152 | 170 | def decode_height(_), do: {:error, "Unexpected type when decoding FixedHeight.height"} |
| 153 | 171 | |
| 154 | 172 | def encode_height(value) when is_binary(value), do: value |
| 155 | 173 | def encode_height(_), do: {:error, "Unexpected type when encoding FixedHeight.height"} |
| 156 | 174 | |
| 175 | + def decode_mp4(value) when is_binary(value), do: value | |
| 176 | + def decode_mp4(_), do: {:error, "Unexpected type when decoding FixedHeight.mp4"} | |
| 177 | + | |
| 178 | + def encode_mp4(value) when is_binary(value), do: value | |
| 179 | + def encode_mp4(_), do: {:error, "Unexpected type when encoding FixedHeight.mp4"} | |
| 180 | + | |
| 181 | + def decode_mp4_size(value) when is_binary(value), do: value | |
| 182 | + def decode_mp4_size(_), do: {:error, "Unexpected type when decoding FixedHeight.mp4_size"} | |
| 183 | + | |
| 184 | + def encode_mp4_size(value) when is_binary(value), do: value | |
| 185 | + def encode_mp4_size(_), do: {:error, "Unexpected type when encoding FixedHeight.mp4_size"} | |
| 186 | + | |
| 157 | 187 | def decode_size(value) when is_binary(value), do: value |
| 158 | 188 | def decode_size(_), do: {:error, "Unexpected type when decoding FixedHeight.size"} |
| 159 | 189 | |
| @@ -186,11 +216,11 @@ defmodule FixedHeight do | ||
| 186 | 216 | |
| 187 | 217 | def from_map(m) do |
| 188 | 218 | %FixedHeight{ |
| 189 | - frames: m["frames"], | |
| 190 | - hash: m["hash"], | |
| 219 | + frames: m["frames"] && decode_frames(m["frames"]), | |
| 220 | + hash: m["hash"] && decode_hash(m["hash"]), | |
| 191 | 221 | height: decode_height(m["height"]), |
| 192 | - mp4: m["mp4"], | |
| 193 | - mp4_size: m["mp4_size"], | |
| 222 | + mp4: m["mp4"] && decode_mp4(m["mp4"]), | |
| 223 | + mp4_size: m["mp4_size"] && decode_mp4_size(m["mp4_size"]), | |
| 194 | 224 | size: decode_size(m["size"]), |
| 195 | 225 | url: decode_url(m["url"]), |
| 196 | 226 | webp: decode_webp(m["webp"]), |
| @@ -503,6 +533,12 @@ defmodule User do | ||
| 503 | 533 | def encode_profile_url(value) when is_binary(value), do: value |
| 504 | 534 | def encode_profile_url(_), do: {:error, "Unexpected type when encoding User.profile_url"} |
| 505 | 535 | |
| 536 | + def decode_twitter(value) when is_binary(value), do: value | |
| 537 | + def decode_twitter(_), do: {:error, "Unexpected type when decoding User.twitter"} | |
| 538 | + | |
| 539 | + def encode_twitter(value) when is_binary(value), do: value | |
| 540 | + def encode_twitter(_), do: {:error, "Unexpected type when encoding User.twitter"} | |
| 541 | + | |
| 506 | 542 | def decode_username(value) when is_binary(value), do: value |
| 507 | 543 | def decode_username(_), do: {:error, "Unexpected type when decoding User.username"} |
| 508 | 544 | |
| @@ -515,7 +551,7 @@ defmodule User do | ||
| 515 | 551 | banner_url: decode_banner_url(m["banner_url"]), |
| 516 | 552 | display_name: decode_display_name(m["display_name"]), |
| 517 | 553 | profile_url: decode_profile_url(m["profile_url"]), |
| 518 | - twitter: m["twitter"], | |
| 554 | + twitter: m["twitter"] && decode_twitter(m["twitter"]), | |
| 519 | 555 | username: decode_username(m["username"]), |
| 520 | 556 | } |
| 521 | 557 | end |
Test case
1 generated file · +21 −3test/inputs/json/misc/77392.json
Melixirdefault / QuickType.ex+21 −3
| @@ -134,6 +134,12 @@ defmodule TopLevelElement do | ||
| 134 | 134 | def encode_discovery_date(value) when is_binary(value), do: value |
| 135 | 135 | def encode_discovery_date(_), do: {:error, "Unexpected type when encoding TopLevelElement.discovery_date"} |
| 136 | 136 | |
| 137 | + def decode_h_mag(value) when is_binary(value), do: value | |
| 138 | + def decode_h_mag(_), do: {:error, "Unexpected type when decoding TopLevelElement.h_mag"} | |
| 139 | + | |
| 140 | + def encode_h_mag(value) when is_binary(value), do: value | |
| 141 | + def encode_h_mag(_), do: {:error, "Unexpected type when encoding TopLevelElement.h_mag"} | |
| 142 | + | |
| 137 | 143 | def decode_i_deg(value) when is_binary(value), do: value |
| 138 | 144 | def decode_i_deg(_), do: {:error, "Unexpected type when decoding TopLevelElement.i_deg"} |
| 139 | 145 | |
| @@ -146,24 +152,36 @@ defmodule TopLevelElement do | ||
| 146 | 152 | def encode_moid_au(value) when is_binary(value), do: value |
| 147 | 153 | def encode_moid_au(_), do: {:error, "Unexpected type when encoding TopLevelElement.moid_au"} |
| 148 | 154 | |
| 155 | + def decode_period_yr(value) when is_binary(value), do: value | |
| 156 | + def decode_period_yr(_), do: {:error, "Unexpected type when decoding TopLevelElement.period_yr"} | |
| 157 | + | |
| 158 | + def encode_period_yr(value) when is_binary(value), do: value | |
| 159 | + def encode_period_yr(_), do: {:error, "Unexpected type when encoding TopLevelElement.period_yr"} | |
| 160 | + | |
| 149 | 161 | def decode_q_au_1(value) when is_binary(value), do: value |
| 150 | 162 | def decode_q_au_1(_), do: {:error, "Unexpected type when decoding TopLevelElement.q_au_1"} |
| 151 | 163 | |
| 152 | 164 | def encode_q_au_1(value) when is_binary(value), do: value |
| 153 | 165 | def encode_q_au_1(_), do: {:error, "Unexpected type when encoding TopLevelElement.q_au_1"} |
| 154 | 166 | |
| 167 | + def decode_q_au_2(value) when is_binary(value), do: value | |
| 168 | + def decode_q_au_2(_), do: {:error, "Unexpected type when decoding TopLevelElement.q_au_2"} | |
| 169 | + | |
| 170 | + def encode_q_au_2(value) when is_binary(value), do: value | |
| 171 | + def encode_q_au_2(_), do: {:error, "Unexpected type when encoding TopLevelElement.q_au_2"} | |
| 172 | + | |
| 155 | 173 | def from_map(m) do |
| 156 | 174 | %TopLevelElement{ |
| 157 | 175 | designation: decode_designation(m["designation"]), |
| 158 | 176 | discovery_date: decode_discovery_date(m["discovery_date"]), |
| 159 | - h_mag: m["h_mag"], | |
| 177 | + h_mag: m["h_mag"] && decode_h_mag(m["h_mag"]), | |
| 160 | 178 | i_deg: decode_i_deg(m["i_deg"]), |
| 161 | 179 | moid_au: decode_moid_au(m["moid_au"]), |
| 162 | 180 | orbit_class: OrbitClass.decode(m["orbit_class"]), |
| 163 | - period_yr: m["period_yr"], | |
| 181 | + period_yr: m["period_yr"] && decode_period_yr(m["period_yr"]), | |
| 164 | 182 | pha: Pha.decode(m["pha"]), |
| 165 | 183 | q_au_1: decode_q_au_1(m["q_au_1"]), |
| 166 | - q_au_2: m["q_au_2"], | |
| 184 | + q_au_2: m["q_au_2"] && decode_q_au_2(m["q_au_2"]), | |
| 167 | 185 | } |
| 168 | 186 | end |
Test case
1 generated file · +14 −2test/inputs/json/misc/a3d8c.json
Melixirdefault / QuickType.ex+14 −2
| @@ -67,6 +67,12 @@ defmodule CachedContents do | ||
| 67 | 67 | top: [Top.t()] |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | + def decode_average(value) when is_binary(value), do: value | |
| 71 | + def decode_average(_), do: {:error, "Unexpected type when decoding CachedContents.average"} | |
| 72 | + | |
| 73 | + def encode_average(value) when is_binary(value), do: value | |
| 74 | + def encode_average(_), do: {:error, "Unexpected type when encoding CachedContents.average"} | |
| 75 | + | |
| 70 | 76 | def decode_largest(value) when is_binary(value), do: value |
| 71 | 77 | def decode_largest(_), do: {:error, "Unexpected type when decoding CachedContents.largest"} |
| 72 | 78 | |
| @@ -91,6 +97,12 @@ defmodule CachedContents do | ||
| 91 | 97 | def encode_smallest(value) when is_binary(value), do: value |
| 92 | 98 | def encode_smallest(_), do: {:error, "Unexpected type when encoding CachedContents.smallest"} |
| 93 | 99 | |
| 100 | + def decode_sum(value) when is_binary(value), do: value | |
| 101 | + def decode_sum(_), do: {:error, "Unexpected type when decoding CachedContents.sum"} | |
| 102 | + | |
| 103 | + def encode_sum(value) when is_binary(value), do: value | |
| 104 | + def encode_sum(_), do: {:error, "Unexpected type when encoding CachedContents.sum"} | |
| 105 | + | |
| 94 | 106 | def decode_top(value) when is_list(value), do: value |
| 95 | 107 | def decode_top(_), do: {:error, "Unexpected type when decoding CachedContents.top"} |
| 96 | 108 | |
| @@ -99,12 +111,12 @@ defmodule CachedContents do | ||
| 99 | 111 | |
| 100 | 112 | def from_map(m) do |
| 101 | 113 | %CachedContents{ |
| 102 | - average: m["average"], | |
| 114 | + average: m["average"] && decode_average(m["average"]), | |
| 103 | 115 | largest: decode_largest(m["largest"]), |
| 104 | 116 | non_null: decode_non_null(m["non_null"]), |
| 105 | 117 | null: decode_null(m["null"]), |
| 106 | 118 | smallest: decode_smallest(m["smallest"]), |
| 107 | - sum: m["sum"], | |
| 119 | + sum: m["sum"] && decode_sum(m["sum"]), | |
| 108 | 120 | top: Enum.map(m["top"], &Top.from_map/1), |
| 109 | 121 | } |
| 110 | 122 | end |
Test case
1 generated file · +42 −6test/inputs/json/misc/b4865.json
Melixirdefault / QuickType.ex+42 −6
| @@ -202,12 +202,30 @@ defmodule TopLevelElement do | ||
| 202 | 202 | year: String.t() | nil |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | + def decode_computed_region_cbhk_fwbd(value) when is_binary(value), do: value | |
| 206 | + def decode_computed_region_cbhk_fwbd(_), do: {:error, "Unexpected type when decoding TopLevelElement.computed_region_cbhk_fwbd"} | |
| 207 | + | |
| 208 | + def encode_computed_region_cbhk_fwbd(value) when is_binary(value), do: value | |
| 209 | + def encode_computed_region_cbhk_fwbd(_), do: {:error, "Unexpected type when encoding TopLevelElement.computed_region_cbhk_fwbd"} | |
| 210 | + | |
| 211 | + def decode_computed_region_nnqa_25_f4(value) when is_binary(value), do: value | |
| 212 | + def decode_computed_region_nnqa_25_f4(_), do: {:error, "Unexpected type when decoding TopLevelElement.computed_region_nnqa_25_f4"} | |
| 213 | + | |
| 214 | + def encode_computed_region_nnqa_25_f4(value) when is_binary(value), do: value | |
| 215 | + def encode_computed_region_nnqa_25_f4(_), do: {:error, "Unexpected type when encoding TopLevelElement.computed_region_nnqa_25_f4"} | |
| 216 | + | |
| 205 | 217 | def decode_id(value) when is_binary(value), do: value |
| 206 | 218 | def decode_id(_), do: {:error, "Unexpected type when decoding TopLevelElement.id"} |
| 207 | 219 | |
| 208 | 220 | def encode_id(value) when is_binary(value), do: value |
| 209 | 221 | def encode_id(_), do: {:error, "Unexpected type when encoding TopLevelElement.id"} |
| 210 | 222 | |
| 223 | + def decode_mass(value) when is_binary(value), do: value | |
| 224 | + def decode_mass(_), do: {:error, "Unexpected type when decoding TopLevelElement.mass"} | |
| 225 | + | |
| 226 | + def encode_mass(value) when is_binary(value), do: value | |
| 227 | + def encode_mass(_), do: {:error, "Unexpected type when encoding TopLevelElement.mass"} | |
| 228 | + | |
| 211 | 229 | def decode_name(value) when is_binary(value), do: value |
| 212 | 230 | def decode_name(_), do: {:error, "Unexpected type when decoding TopLevelElement.name"} |
| 213 | 231 | |
| @@ -220,20 +238,38 @@ defmodule TopLevelElement do | ||
| 220 | 238 | def encode_recclass(value) when is_binary(value), do: value |
| 221 | 239 | def encode_recclass(_), do: {:error, "Unexpected type when encoding TopLevelElement.recclass"} |
| 222 | 240 | |
| 241 | + def decode_reclat(value) when is_binary(value), do: value | |
| 242 | + def decode_reclat(_), do: {:error, "Unexpected type when decoding TopLevelElement.reclat"} | |
| 243 | + | |
| 244 | + def encode_reclat(value) when is_binary(value), do: value | |
| 245 | + def encode_reclat(_), do: {:error, "Unexpected type when encoding TopLevelElement.reclat"} | |
| 246 | + | |
| 247 | + def decode_reclong(value) when is_binary(value), do: value | |
| 248 | + def decode_reclong(_), do: {:error, "Unexpected type when decoding TopLevelElement.reclong"} | |
| 249 | + | |
| 250 | + def encode_reclong(value) when is_binary(value), do: value | |
| 251 | + def encode_reclong(_), do: {:error, "Unexpected type when encoding TopLevelElement.reclong"} | |
| 252 | + | |
| 253 | + def decode_year(value) when is_binary(value), do: value | |
| 254 | + def decode_year(_), do: {:error, "Unexpected type when decoding TopLevelElement.year"} | |
| 255 | + | |
| 256 | + def encode_year(value) when is_binary(value), do: value | |
| 257 | + def encode_year(_), do: {:error, "Unexpected type when encoding TopLevelElement.year"} | |
| 258 | + | |
| 223 | 259 | def from_map(m) do |
| 224 | 260 | %TopLevelElement{ |
| 225 | - computed_region_cbhk_fwbd: m[":@computed_region_cbhk_fwbd"], | |
| 226 | - computed_region_nnqa_25_f4: m[":@computed_region_nnqa_25f4"], | |
| 261 | + computed_region_cbhk_fwbd: m[":@computed_region_cbhk_fwbd"] && decode_computed_region_cbhk_fwbd(m[":@computed_region_cbhk_fwbd"]), | |
| 262 | + computed_region_nnqa_25_f4: m[":@computed_region_nnqa_25f4"] && decode_computed_region_nnqa_25_f4(m[":@computed_region_nnqa_25f4"]), | |
| 227 | 263 | fall: Fall.decode(m["fall"]), |
| 228 | 264 | geolocation: m["geolocation"] && Geolocation.from_map(m["geolocation"]), |
| 229 | 265 | id: decode_id(m["id"]), |
| 230 | - mass: m["mass"], | |
| 266 | + mass: m["mass"] && decode_mass(m["mass"]), | |
| 231 | 267 | name: decode_name(m["name"]), |
| 232 | 268 | nametype: Nametype.decode(m["nametype"]), |
| 233 | 269 | recclass: decode_recclass(m["recclass"]), |
| 234 | - reclat: m["reclat"], | |
| 235 | - reclong: m["reclong"], | |
| 236 | - year: m["year"], | |
| 270 | + reclat: m["reclat"] && decode_reclat(m["reclat"]), | |
| 271 | + reclong: m["reclong"] && decode_reclong(m["reclong"]), | |
| 272 | + year: m["year"] && decode_year(m["year"]), | |
| 237 | 273 | } |
| 238 | 274 | end |
Test case
1 generated file · +7 −1test/inputs/json/misc/be234.json
Melixirdefault / QuickType.ex+7 −1
| @@ -238,9 +238,15 @@ defmodule MediaEmbed do | ||
| 238 | 238 | width: integer() | nil |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | + def decode_content(value) when is_binary(value), do: value | |
| 242 | + def decode_content(_), do: {:error, "Unexpected type when decoding MediaEmbed.content"} | |
| 243 | + | |
| 244 | + def encode_content(value) when is_binary(value), do: value | |
| 245 | + def encode_content(_), do: {:error, "Unexpected type when encoding MediaEmbed.content"} | |
| 246 | + | |
| 241 | 247 | def from_map(m) do |
| 242 | 248 | %MediaEmbed{ |
| 243 | - content: m["content"], | |
| 249 | + content: m["content"] && decode_content(m["content"]), | |
| 244 | 250 | height: m["height"], |
| 245 | 251 | scrolling: m["scrolling"], |
| 246 | 252 | width: m["width"], |
Test case
1 generated file · +35 −5test/inputs/json/misc/c3303.json
Melixirdefault / QuickType.ex+35 −5
| @@ -22,6 +22,12 @@ defmodule The480_WStill do | ||
| 22 | 22 | def encode_height(value) when is_binary(value), do: value |
| 23 | 23 | def encode_height(_), do: {:error, "Unexpected type when encoding The480_WStill.height"} |
| 24 | 24 | |
| 25 | + def decode_size(value) when is_binary(value), do: value | |
| 26 | + def decode_size(_), do: {:error, "Unexpected type when decoding The480_WStill.size"} | |
| 27 | + | |
| 28 | + def encode_size(value) when is_binary(value), do: value | |
| 29 | + def encode_size(_), do: {:error, "Unexpected type when encoding The480_WStill.size"} | |
| 30 | + | |
| 25 | 31 | def decode_url(value) when is_binary(value), do: value |
| 26 | 32 | def decode_url(_), do: {:error, "Unexpected type when decoding The480_WStill.url"} |
| 27 | 33 | |
| @@ -37,7 +43,7 @@ defmodule The480_WStill do | ||
| 37 | 43 | def from_map(m) do |
| 38 | 44 | %The480_WStill{ |
| 39 | 45 | height: decode_height(m["height"]), |
| 40 | - size: m["size"], | |
| 46 | + size: m["size"] && decode_size(m["size"]), | |
| 41 | 47 | url: decode_url(m["url"]), |
| 42 | 48 | width: decode_width(m["width"]), |
| 43 | 49 | } |
| @@ -148,12 +154,36 @@ defmodule FixedHeight do | ||
| 148 | 154 | width: String.t() |
| 149 | 155 | } |
| 150 | 156 | |
| 157 | + def decode_frames(value) when is_binary(value), do: value | |
| 158 | + def decode_frames(_), do: {:error, "Unexpected type when decoding FixedHeight.frames"} | |
| 159 | + | |
| 160 | + def encode_frames(value) when is_binary(value), do: value | |
| 161 | + def encode_frames(_), do: {:error, "Unexpected type when encoding FixedHeight.frames"} | |
| 162 | + | |
| 163 | + def decode_hash(value) when is_binary(value), do: value | |
| 164 | + def decode_hash(_), do: {:error, "Unexpected type when decoding FixedHeight.hash"} | |
| 165 | + | |
| 166 | + def encode_hash(value) when is_binary(value), do: value | |
| 167 | + def encode_hash(_), do: {:error, "Unexpected type when encoding FixedHeight.hash"} | |
| 168 | + | |
| 151 | 169 | def decode_height(value) when is_binary(value), do: value |
| 152 | 170 | def decode_height(_), do: {:error, "Unexpected type when decoding FixedHeight.height"} |
| 153 | 171 | |
| 154 | 172 | def encode_height(value) when is_binary(value), do: value |
| 155 | 173 | def encode_height(_), do: {:error, "Unexpected type when encoding FixedHeight.height"} |
| 156 | 174 | |
| 175 | + def decode_mp4(value) when is_binary(value), do: value | |
| 176 | + def decode_mp4(_), do: {:error, "Unexpected type when decoding FixedHeight.mp4"} | |
| 177 | + | |
| 178 | + def encode_mp4(value) when is_binary(value), do: value | |
| 179 | + def encode_mp4(_), do: {:error, "Unexpected type when encoding FixedHeight.mp4"} | |
| 180 | + | |
| 181 | + def decode_mp4_size(value) when is_binary(value), do: value | |
| 182 | + def decode_mp4_size(_), do: {:error, "Unexpected type when decoding FixedHeight.mp4_size"} | |
| 183 | + | |
| 184 | + def encode_mp4_size(value) when is_binary(value), do: value | |
| 185 | + def encode_mp4_size(_), do: {:error, "Unexpected type when encoding FixedHeight.mp4_size"} | |
| 186 | + | |
| 157 | 187 | def decode_size(value) when is_binary(value), do: value |
| 158 | 188 | def decode_size(_), do: {:error, "Unexpected type when decoding FixedHeight.size"} |
| 159 | 189 | |
| @@ -186,11 +216,11 @@ defmodule FixedHeight do | ||
| 186 | 216 | |
| 187 | 217 | def from_map(m) do |
| 188 | 218 | %FixedHeight{ |
| 189 | - frames: m["frames"], | |
| 190 | - hash: m["hash"], | |
| 219 | + frames: m["frames"] && decode_frames(m["frames"]), | |
| 220 | + hash: m["hash"] && decode_hash(m["hash"]), | |
| 191 | 221 | height: decode_height(m["height"]), |
| 192 | - mp4: m["mp4"], | |
| 193 | - mp4_size: m["mp4_size"], | |
| 222 | + mp4: m["mp4"] && decode_mp4(m["mp4"]), | |
| 223 | + mp4_size: m["mp4_size"] && decode_mp4_size(m["mp4_size"]), | |
| 194 | 224 | size: decode_size(m["size"]), |
| 195 | 225 | url: decode_url(m["url"]), |
| 196 | 226 | webp: decode_webp(m["webp"]), |
Test case
1 generated file · +14 −2test/inputs/json/misc/cb0cc.json
Melixirdefault / QuickType.ex+14 −2
| @@ -79,6 +79,12 @@ defmodule Laureate do | ||
| 79 | 79 | def encode_id(value) when is_binary(value), do: value |
| 80 | 80 | def encode_id(_), do: {:error, "Unexpected type when encoding Laureate.id"} |
| 81 | 81 | |
| 82 | + def decode_motivation(value) when is_binary(value), do: value | |
| 83 | + def decode_motivation(_), do: {:error, "Unexpected type when decoding Laureate.motivation"} | |
| 84 | + | |
| 85 | + def encode_motivation(value) when is_binary(value), do: value | |
| 86 | + def encode_motivation(_), do: {:error, "Unexpected type when encoding Laureate.motivation"} | |
| 87 | + | |
| 82 | 88 | def decode_share(value) when is_binary(value), do: value |
| 83 | 89 | def decode_share(_), do: {:error, "Unexpected type when decoding Laureate.share"} |
| 84 | 90 | |
| @@ -95,7 +101,7 @@ defmodule Laureate do | ||
| 95 | 101 | %Laureate{ |
| 96 | 102 | firstname: decode_firstname(m["firstname"]), |
| 97 | 103 | id: decode_id(m["id"]), |
| 98 | - motivation: m["motivation"], | |
| 104 | + motivation: m["motivation"] && decode_motivation(m["motivation"]), | |
| 99 | 105 | share: decode_share(m["share"]), |
| 100 | 106 | surname: decode_surname(m["surname"]), |
| 101 | 107 | } |
| @@ -141,6 +147,12 @@ defmodule Prize do | ||
| 141 | 147 | def encode_laureates(value) when is_list(value), do: value |
| 142 | 148 | def encode_laureates(_), do: {:error, "Unexpected type when encoding Prize.laureates"} |
| 143 | 149 | |
| 150 | + def decode_overall_motivation(value) when is_binary(value), do: value | |
| 151 | + def decode_overall_motivation(_), do: {:error, "Unexpected type when decoding Prize.overall_motivation"} | |
| 152 | + | |
| 153 | + def encode_overall_motivation(value) when is_binary(value), do: value | |
| 154 | + def encode_overall_motivation(_), do: {:error, "Unexpected type when encoding Prize.overall_motivation"} | |
| 155 | + | |
| 144 | 156 | def decode_year(value) when is_binary(value), do: value |
| 145 | 157 | def decode_year(_), do: {:error, "Unexpected type when decoding Prize.year"} |
| 146 | 158 | |
| @@ -151,7 +163,7 @@ defmodule Prize do | ||
| 151 | 163 | %Prize{ |
| 152 | 164 | category: Category.decode(m["category"]), |
| 153 | 165 | laureates: Enum.map(m["laureates"], &Laureate.from_map/1), |
| 154 | - overall_motivation: m["overallMotivation"], | |
| 166 | + overall_motivation: m["overallMotivation"] && decode_overall_motivation(m["overallMotivation"]), | |
| 155 | 167 | year: decode_year(m["year"]), |
| 156 | 168 | } |
| 157 | 169 | end |
Test case
1 generated file · +49 −7test/inputs/json/misc/dc44f.json
Melixirdefault / QuickType.ex+49 −7
| @@ -589,6 +589,12 @@ defmodule Card do | ||
| 589 | 589 | def encode_cmc(value) when is_integer(value), do: value |
| 590 | 590 | def encode_cmc(_), do: {:error, "Unexpected type when encoding Card.cmc"} |
| 591 | 591 | |
| 592 | + def decode_flavor(value) when is_binary(value), do: value | |
| 593 | + def decode_flavor(_), do: {:error, "Unexpected type when decoding Card.flavor"} | |
| 594 | + | |
| 595 | + def encode_flavor(value) when is_binary(value), do: value | |
| 596 | + def encode_flavor(_), do: {:error, "Unexpected type when encoding Card.flavor"} | |
| 597 | + | |
| 592 | 598 | def decode_id(value) when is_binary(value), do: value |
| 593 | 599 | def decode_id(_), do: {:error, "Unexpected type when decoding Card.id"} |
| 594 | 600 | |
| @@ -607,6 +613,18 @@ defmodule Card do | ||
| 607 | 613 | def encode_legalities(value) when is_list(value), do: value |
| 608 | 614 | def encode_legalities(_), do: {:error, "Unexpected type when encoding Card.legalities"} |
| 609 | 615 | |
| 616 | + def decode_mana_cost(value) when is_binary(value), do: value | |
| 617 | + def decode_mana_cost(_), do: {:error, "Unexpected type when decoding Card.mana_cost"} | |
| 618 | + | |
| 619 | + def encode_mana_cost(value) when is_binary(value), do: value | |
| 620 | + def encode_mana_cost(_), do: {:error, "Unexpected type when encoding Card.mana_cost"} | |
| 621 | + | |
| 622 | + def decode_mci_number(value) when is_binary(value), do: value | |
| 623 | + def decode_mci_number(_), do: {:error, "Unexpected type when decoding Card.mci_number"} | |
| 624 | + | |
| 625 | + def encode_mci_number(value) when is_binary(value), do: value | |
| 626 | + def encode_mci_number(_), do: {:error, "Unexpected type when encoding Card.mci_number"} | |
| 627 | + | |
| 610 | 628 | def decode_multiverseid(value) when is_integer(value), do: value |
| 611 | 629 | def decode_multiverseid(_), do: {:error, "Unexpected type when decoding Card.multiverseid"} |
| 612 | 630 | |
| @@ -619,18 +637,42 @@ defmodule Card do | ||
| 619 | 637 | def encode_name(value) when is_binary(value), do: value |
| 620 | 638 | def encode_name(_), do: {:error, "Unexpected type when encoding Card.name"} |
| 621 | 639 | |
| 640 | + def decode_original_text(value) when is_binary(value), do: value | |
| 641 | + def decode_original_text(_), do: {:error, "Unexpected type when decoding Card.original_text"} | |
| 642 | + | |
| 643 | + def encode_original_text(value) when is_binary(value), do: value | |
| 644 | + def encode_original_text(_), do: {:error, "Unexpected type when encoding Card.original_text"} | |
| 645 | + | |
| 622 | 646 | def decode_original_type(value) when is_binary(value), do: value |
| 623 | 647 | def decode_original_type(_), do: {:error, "Unexpected type when decoding Card.original_type"} |
| 624 | 648 | |
| 625 | 649 | def encode_original_type(value) when is_binary(value), do: value |
| 626 | 650 | def encode_original_type(_), do: {:error, "Unexpected type when encoding Card.original_type"} |
| 627 | 651 | |
| 652 | + def decode_power(value) when is_binary(value), do: value | |
| 653 | + def decode_power(_), do: {:error, "Unexpected type when decoding Card.power"} | |
| 654 | + | |
| 655 | + def encode_power(value) when is_binary(value), do: value | |
| 656 | + def encode_power(_), do: {:error, "Unexpected type when encoding Card.power"} | |
| 657 | + | |
| 628 | 658 | def decode_printings(value) when is_list(value), do: value |
| 629 | 659 | def decode_printings(_), do: {:error, "Unexpected type when decoding Card.printings"} |
| 630 | 660 | |
| 631 | 661 | def encode_printings(value) when is_list(value), do: value |
| 632 | 662 | def encode_printings(_), do: {:error, "Unexpected type when encoding Card.printings"} |
| 633 | 663 | |
| 664 | + def decode_text(value) when is_binary(value), do: value | |
| 665 | + def decode_text(_), do: {:error, "Unexpected type when decoding Card.text"} | |
| 666 | + | |
| 667 | + def encode_text(value) when is_binary(value), do: value | |
| 668 | + def encode_text(_), do: {:error, "Unexpected type when encoding Card.text"} | |
| 669 | + | |
| 670 | + def decode_toughness(value) when is_binary(value), do: value | |
| 671 | + def decode_toughness(_), do: {:error, "Unexpected type when decoding Card.toughness"} | |
| 672 | + | |
| 673 | + def encode_toughness(value) when is_binary(value), do: value | |
| 674 | + def encode_toughness(_), do: {:error, "Unexpected type when encoding Card.toughness"} | |
| 675 | + | |
| 634 | 676 | def decode_type(value) when is_binary(value), do: value |
| 635 | 677 | def decode_type(_), do: {:error, "Unexpected type when decoding Card.type"} |
| 636 | 678 | |
| @@ -649,26 +691,26 @@ defmodule Card do | ||
| 649 | 691 | cmc: decode_cmc(m["cmc"]), |
| 650 | 692 | color_identity: m["colorIdentity"] && Enum.map(m["colorIdentity"], &ColorIdentity.decode/1), |
| 651 | 693 | colors: m["colors"] && Enum.map(m["colors"], &Color.decode/1), |
| 652 | - flavor: m["flavor"], | |
| 694 | + flavor: m["flavor"] && decode_flavor(m["flavor"]), | |
| 653 | 695 | id: decode_id(m["id"]), |
| 654 | 696 | image_name: decode_image_name(m["imageName"]), |
| 655 | 697 | layout: Layout.decode(m["layout"]), |
| 656 | 698 | legalities: Enum.map(m["legalities"], &LegalityElement.from_map/1), |
| 657 | - mana_cost: m["manaCost"], | |
| 658 | - mci_number: m["mciNumber"], | |
| 699 | + mana_cost: m["manaCost"] && decode_mana_cost(m["manaCost"]), | |
| 700 | + mci_number: m["mciNumber"] && decode_mci_number(m["mciNumber"]), | |
| 659 | 701 | multiverseid: decode_multiverseid(m["multiverseid"]), |
| 660 | 702 | name: decode_name(m["name"]), |
| 661 | - original_text: m["originalText"], | |
| 703 | + original_text: m["originalText"] && decode_original_text(m["originalText"]), | |
| 662 | 704 | original_type: decode_original_type(m["originalType"]), |
| 663 | - power: m["power"], | |
| 705 | + power: m["power"] && decode_power(m["power"]), | |
| 664 | 706 | printings: decode_printings(m["printings"]), |
| 665 | 707 | rarity: Rarity.decode(m["rarity"]), |
| 666 | 708 | reserved: m["reserved"], |
| 667 | 709 | rulings: m["rulings"] && Enum.map(m["rulings"], &Ruling.from_map/1), |
| 668 | 710 | subtypes: m["subtypes"], |
| 669 | 711 | supertypes: m["supertypes"] && Enum.map(m["supertypes"], &Supertype.decode/1), |
| 670 | - text: m["text"], | |
| 671 | - toughness: m["toughness"], | |
| 712 | + text: m["text"] && decode_text(m["text"]), | |
| 713 | + toughness: m["toughness"] && decode_toughness(m["toughness"]), | |
| 672 | 714 | type: decode_type(m["type"]), |
| 673 | 715 | types: Enum.map(m["types"], &Type.decode/1), |
| 674 | 716 | variations: m["variations"], |
Test case
1 generated file · +49 −7test/inputs/json/misc/dd1ce.json
Melixirdefault / QuickType.ex+49 −7
| @@ -589,6 +589,12 @@ defmodule Card do | ||
| 589 | 589 | def encode_cmc(value) when is_integer(value), do: value |
| 590 | 590 | def encode_cmc(_), do: {:error, "Unexpected type when encoding Card.cmc"} |
| 591 | 591 | |
| 592 | + def decode_flavor(value) when is_binary(value), do: value | |
| 593 | + def decode_flavor(_), do: {:error, "Unexpected type when decoding Card.flavor"} | |
| 594 | + | |
| 595 | + def encode_flavor(value) when is_binary(value), do: value | |
| 596 | + def encode_flavor(_), do: {:error, "Unexpected type when encoding Card.flavor"} | |
| 597 | + | |
| 592 | 598 | def decode_id(value) when is_binary(value), do: value |
| 593 | 599 | def decode_id(_), do: {:error, "Unexpected type when decoding Card.id"} |
| 594 | 600 | |
| @@ -607,6 +613,18 @@ defmodule Card do | ||
| 607 | 613 | def encode_legalities(value) when is_list(value), do: value |
| 608 | 614 | def encode_legalities(_), do: {:error, "Unexpected type when encoding Card.legalities"} |
| 609 | 615 | |
| 616 | + def decode_mana_cost(value) when is_binary(value), do: value | |
| 617 | + def decode_mana_cost(_), do: {:error, "Unexpected type when decoding Card.mana_cost"} | |
| 618 | + | |
| 619 | + def encode_mana_cost(value) when is_binary(value), do: value | |
| 620 | + def encode_mana_cost(_), do: {:error, "Unexpected type when encoding Card.mana_cost"} | |
| 621 | + | |
| 622 | + def decode_mci_number(value) when is_binary(value), do: value | |
| 623 | + def decode_mci_number(_), do: {:error, "Unexpected type when decoding Card.mci_number"} | |
| 624 | + | |
| 625 | + def encode_mci_number(value) when is_binary(value), do: value | |
| 626 | + def encode_mci_number(_), do: {:error, "Unexpected type when encoding Card.mci_number"} | |
| 627 | + | |
| 610 | 628 | def decode_multiverseid(value) when is_integer(value), do: value |
| 611 | 629 | def decode_multiverseid(_), do: {:error, "Unexpected type when decoding Card.multiverseid"} |
| 612 | 630 | |
| @@ -619,18 +637,42 @@ defmodule Card do | ||
| 619 | 637 | def encode_name(value) when is_binary(value), do: value |
| 620 | 638 | def encode_name(_), do: {:error, "Unexpected type when encoding Card.name"} |
| 621 | 639 | |
| 640 | + def decode_original_text(value) when is_binary(value), do: value | |
| 641 | + def decode_original_text(_), do: {:error, "Unexpected type when decoding Card.original_text"} | |
| 642 | + | |
| 643 | + def encode_original_text(value) when is_binary(value), do: value | |
| 644 | + def encode_original_text(_), do: {:error, "Unexpected type when encoding Card.original_text"} | |
| 645 | + | |
| 622 | 646 | def decode_original_type(value) when is_binary(value), do: value |
| 623 | 647 | def decode_original_type(_), do: {:error, "Unexpected type when decoding Card.original_type"} |
| 624 | 648 | |
| 625 | 649 | def encode_original_type(value) when is_binary(value), do: value |
| 626 | 650 | def encode_original_type(_), do: {:error, "Unexpected type when encoding Card.original_type"} |
| 627 | 651 | |
| 652 | + def decode_power(value) when is_binary(value), do: value | |
| 653 | + def decode_power(_), do: {:error, "Unexpected type when decoding Card.power"} | |
| 654 | + | |
| 655 | + def encode_power(value) when is_binary(value), do: value | |
| 656 | + def encode_power(_), do: {:error, "Unexpected type when encoding Card.power"} | |
| 657 | + | |
| 628 | 658 | def decode_printings(value) when is_list(value), do: value |
| 629 | 659 | def decode_printings(_), do: {:error, "Unexpected type when decoding Card.printings"} |
| 630 | 660 | |
| 631 | 661 | def encode_printings(value) when is_list(value), do: value |
| 632 | 662 | def encode_printings(_), do: {:error, "Unexpected type when encoding Card.printings"} |
| 633 | 663 | |
| 664 | + def decode_text(value) when is_binary(value), do: value | |
| 665 | + def decode_text(_), do: {:error, "Unexpected type when decoding Card.text"} | |
| 666 | + | |
| 667 | + def encode_text(value) when is_binary(value), do: value | |
| 668 | + def encode_text(_), do: {:error, "Unexpected type when encoding Card.text"} | |
| 669 | + | |
| 670 | + def decode_toughness(value) when is_binary(value), do: value | |
| 671 | + def decode_toughness(_), do: {:error, "Unexpected type when decoding Card.toughness"} | |
| 672 | + | |
| 673 | + def encode_toughness(value) when is_binary(value), do: value | |
| 674 | + def encode_toughness(_), do: {:error, "Unexpected type when encoding Card.toughness"} | |
| 675 | + | |
| 634 | 676 | def decode_type(value) when is_binary(value), do: value |
| 635 | 677 | def decode_type(_), do: {:error, "Unexpected type when decoding Card.type"} |
| 636 | 678 | |
| @@ -649,26 +691,26 @@ defmodule Card do | ||
| 649 | 691 | cmc: decode_cmc(m["cmc"]), |
| 650 | 692 | color_identity: m["colorIdentity"] && Enum.map(m["colorIdentity"], &ColorIdentity.decode/1), |
| 651 | 693 | colors: m["colors"] && Enum.map(m["colors"], &Color.decode/1), |
| 652 | - flavor: m["flavor"], | |
| 694 | + flavor: m["flavor"] && decode_flavor(m["flavor"]), | |
| 653 | 695 | id: decode_id(m["id"]), |
| 654 | 696 | image_name: decode_image_name(m["imageName"]), |
| 655 | 697 | layout: Layout.decode(m["layout"]), |
| 656 | 698 | legalities: Enum.map(m["legalities"], &LegalityElement.from_map/1), |
| 657 | - mana_cost: m["manaCost"], | |
| 658 | - mci_number: m["mciNumber"], | |
| 699 | + mana_cost: m["manaCost"] && decode_mana_cost(m["manaCost"]), | |
| 700 | + mci_number: m["mciNumber"] && decode_mci_number(m["mciNumber"]), | |
| 659 | 701 | multiverseid: decode_multiverseid(m["multiverseid"]), |
| 660 | 702 | name: decode_name(m["name"]), |
| 661 | - original_text: m["originalText"], | |
| 703 | + original_text: m["originalText"] && decode_original_text(m["originalText"]), | |
| 662 | 704 | original_type: decode_original_type(m["originalType"]), |
| 663 | - power: m["power"], | |
| 705 | + power: m["power"] && decode_power(m["power"]), | |
| 664 | 706 | printings: decode_printings(m["printings"]), |
| 665 | 707 | rarity: Rarity.decode(m["rarity"]), |
| 666 | 708 | reserved: m["reserved"], |
| 667 | 709 | rulings: m["rulings"] && Enum.map(m["rulings"], &Ruling.from_map/1), |
| 668 | 710 | subtypes: m["subtypes"], |
| 669 | 711 | supertypes: m["supertypes"] && Enum.map(m["supertypes"], &Supertype.decode/1), |
| 670 | - text: m["text"], | |
| 671 | - toughness: m["toughness"], | |
| 712 | + text: m["text"] && decode_text(m["text"]), | |
| 713 | + toughness: m["toughness"] && decode_toughness(m["toughness"]), | |
| 672 | 714 | type: decode_type(m["type"]), |
| 673 | 715 | types: Enum.map(m["types"], &Type.decode/1), |
| 674 | 716 | variations: m["variations"], |
Test case
1 generated file · +35 −5test/inputs/json/misc/e0ac7.json
Melixirdefault / QuickType.ex+35 −5
| @@ -22,6 +22,12 @@ defmodule Downsized do | ||
| 22 | 22 | def encode_height(value) when is_binary(value), do: value |
| 23 | 23 | def encode_height(_), do: {:error, "Unexpected type when encoding Downsized.height"} |
| 24 | 24 | |
| 25 | + def decode_size(value) when is_binary(value), do: value | |
| 26 | + def decode_size(_), do: {:error, "Unexpected type when decoding Downsized.size"} | |
| 27 | + | |
| 28 | + def encode_size(value) when is_binary(value), do: value | |
| 29 | + def encode_size(_), do: {:error, "Unexpected type when encoding Downsized.size"} | |
| 30 | + | |
| 25 | 31 | def decode_url(value) when is_binary(value), do: value |
| 26 | 32 | def decode_url(_), do: {:error, "Unexpected type when decoding Downsized.url"} |
| 27 | 33 | |
| @@ -37,7 +43,7 @@ defmodule Downsized do | ||
| 37 | 43 | def from_map(m) do |
| 38 | 44 | %Downsized{ |
| 39 | 45 | height: decode_height(m["height"]), |
| 40 | - size: m["size"], | |
| 46 | + size: m["size"] && decode_size(m["size"]), | |
| 41 | 47 | url: decode_url(m["url"]), |
| 42 | 48 | width: decode_width(m["width"]), |
| 43 | 49 | } |
| @@ -148,12 +154,36 @@ defmodule FixedHeight do | ||
| 148 | 154 | width: String.t() |
| 149 | 155 | } |
| 150 | 156 | |
| 157 | + def decode_frames(value) when is_binary(value), do: value | |
| 158 | + def decode_frames(_), do: {:error, "Unexpected type when decoding FixedHeight.frames"} | |
| 159 | + | |
| 160 | + def encode_frames(value) when is_binary(value), do: value | |
| 161 | + def encode_frames(_), do: {:error, "Unexpected type when encoding FixedHeight.frames"} | |
| 162 | + | |
| 163 | + def decode_hash(value) when is_binary(value), do: value | |
| 164 | + def decode_hash(_), do: {:error, "Unexpected type when decoding FixedHeight.hash"} | |
| 165 | + | |
| 166 | + def encode_hash(value) when is_binary(value), do: value | |
| 167 | + def encode_hash(_), do: {:error, "Unexpected type when encoding FixedHeight.hash"} | |
| 168 | + | |
| 151 | 169 | def decode_height(value) when is_binary(value), do: value |
| 152 | 170 | def decode_height(_), do: {:error, "Unexpected type when decoding FixedHeight.height"} |
| 153 | 171 | |
| 154 | 172 | def encode_height(value) when is_binary(value), do: value |
| 155 | 173 | def encode_height(_), do: {:error, "Unexpected type when encoding FixedHeight.height"} |
| 156 | 174 | |
| 175 | + def decode_mp4(value) when is_binary(value), do: value | |
| 176 | + def decode_mp4(_), do: {:error, "Unexpected type when decoding FixedHeight.mp4"} | |
| 177 | + | |
| 178 | + def encode_mp4(value) when is_binary(value), do: value | |
| 179 | + def encode_mp4(_), do: {:error, "Unexpected type when encoding FixedHeight.mp4"} | |
| 180 | + | |
| 181 | + def decode_mp4_size(value) when is_binary(value), do: value | |
| 182 | + def decode_mp4_size(_), do: {:error, "Unexpected type when decoding FixedHeight.mp4_size"} | |
| 183 | + | |
| 184 | + def encode_mp4_size(value) when is_binary(value), do: value | |
| 185 | + def encode_mp4_size(_), do: {:error, "Unexpected type when encoding FixedHeight.mp4_size"} | |
| 186 | + | |
| 157 | 187 | def decode_size(value) when is_binary(value), do: value |
| 158 | 188 | def decode_size(_), do: {:error, "Unexpected type when decoding FixedHeight.size"} |
| 159 | 189 | |
| @@ -186,11 +216,11 @@ defmodule FixedHeight do | ||
| 186 | 216 | |
| 187 | 217 | def from_map(m) do |
| 188 | 218 | %FixedHeight{ |
| 189 | - frames: m["frames"], | |
| 190 | - hash: m["hash"], | |
| 219 | + frames: m["frames"] && decode_frames(m["frames"]), | |
| 220 | + hash: m["hash"] && decode_hash(m["hash"]), | |
| 191 | 221 | height: decode_height(m["height"]), |
| 192 | - mp4: m["mp4"], | |
| 193 | - mp4_size: m["mp4_size"], | |
| 222 | + mp4: m["mp4"] && decode_mp4(m["mp4"]), | |
| 223 | + mp4_size: m["mp4_size"] && decode_mp4_size(m["mp4_size"]), | |
| 194 | 224 | size: decode_size(m["size"]), |
| 195 | 225 | url: decode_url(m["url"]), |
| 196 | 226 | webp: decode_webp(m["webp"]), |
Test case
1 generated file · +98 −14test/inputs/json/misc/e8b04.json
Melixirdefault / QuickType.ex+98 −14
| @@ -450,6 +450,12 @@ defmodule Select do | ||
| 450 | 450 | column_field_name: String.t() |
| 451 | 451 | } |
| 452 | 452 | |
| 453 | + def decode_aggregate(value) when is_binary(value), do: value | |
| 454 | + def decode_aggregate(_), do: {:error, "Unexpected type when decoding Select.aggregate"} | |
| 455 | + | |
| 456 | + def encode_aggregate(value) when is_binary(value), do: value | |
| 457 | + def encode_aggregate(_), do: {:error, "Unexpected type when encoding Select.aggregate"} | |
| 458 | + | |
| 453 | 459 | def decode_column_field_name(value) when is_binary(value), do: value |
| 454 | 460 | def decode_column_field_name(_), do: {:error, "Unexpected type when decoding Select.column_field_name"} |
| 455 | 461 | |
| @@ -458,7 +464,7 @@ defmodule Select do | ||
| 458 | 464 | |
| 459 | 465 | def from_map(m) do |
| 460 | 466 | %Select{ |
| 461 | - aggregate: m["aggregate"], | |
| 467 | + aggregate: m["aggregate"] && decode_aggregate(m["aggregate"]), | |
| 462 | 468 | column_field_name: decode_column_field_name(m["columnFieldName"]), |
| 463 | 469 | } |
| 464 | 470 | end |
| @@ -720,12 +726,18 @@ defmodule Child do | ||
| 720 | 726 | value: String.t() | nil |
| 721 | 727 | } |
| 722 | 728 | |
| 729 | + def decode_value(value) when is_binary(value), do: value | |
| 730 | + def decode_value(_), do: {:error, "Unexpected type when decoding Child.value"} | |
| 731 | + | |
| 732 | + def encode_value(value) when is_binary(value), do: value | |
| 733 | + def encode_value(_), do: {:error, "Unexpected type when encoding Child.value"} | |
| 734 | + | |
| 723 | 735 | def from_map(m) do |
| 724 | 736 | %Child{ |
| 725 | 737 | column_field_name: ChildColumnFieldName.decode(m["columnFieldName"]), |
| 726 | 738 | metadata: m["metadata"] && ChildMetadata.from_map(m["metadata"]), |
| 727 | 739 | operator: ChildOperator.decode(m["operator"]), |
| 728 | - value: m["value"], | |
| 740 | + value: m["value"] && decode_value(m["value"]), | |
| 729 | 741 | } |
| 730 | 742 | end |
| 731 | 743 | |
| @@ -809,13 +821,19 @@ defmodule Where do | ||
| 809 | 821 | value: String.t() | nil |
| 810 | 822 | } |
| 811 | 823 | |
| 824 | + def decode_value(value) when is_binary(value), do: value | |
| 825 | + def decode_value(_), do: {:error, "Unexpected type when decoding Where.value"} | |
| 826 | + | |
| 827 | + def encode_value(value) when is_binary(value), do: value | |
| 828 | + def encode_value(_), do: {:error, "Unexpected type when encoding Where.value"} | |
| 829 | + | |
| 812 | 830 | def from_map(m) do |
| 813 | 831 | %Where{ |
| 814 | 832 | children: m["children"] && Enum.map(m["children"], &Child.from_map/1), |
| 815 | 833 | column_field_name: m["columnFieldName"] && ChildColumnFieldName.decode(m["columnFieldName"]), |
| 816 | 834 | metadata: m["metadata"] && ChildMetadata.from_map(m["metadata"]), |
| 817 | 835 | operator: WhereOperator.decode(m["operator"]), |
| 818 | - value: m["value"], | |
| 836 | + value: m["value"] && decode_value(m["value"]), | |
| 819 | 837 | } |
| 820 | 838 | end |
| 821 | 839 | |
| @@ -1445,17 +1463,41 @@ defmodule TopLevelMetadata do | ||
| 1445 | 1463 | v1_archived_properties: V1ArchivedProperties.t() | nil |
| 1446 | 1464 | } |
| 1447 | 1465 | |
| 1466 | + def decode_rdf_class(value) when is_binary(value), do: value | |
| 1467 | + def decode_rdf_class(_), do: {:error, "Unexpected type when decoding TopLevelMetadata.rdf_class"} | |
| 1468 | + | |
| 1469 | + def encode_rdf_class(value) when is_binary(value), do: value | |
| 1470 | + def encode_rdf_class(_), do: {:error, "Unexpected type when encoding TopLevelMetadata.rdf_class"} | |
| 1471 | + | |
| 1472 | + def decode_rdf_subject(value) when is_binary(value), do: value | |
| 1473 | + def decode_rdf_subject(_), do: {:error, "Unexpected type when decoding TopLevelMetadata.rdf_subject"} | |
| 1474 | + | |
| 1475 | + def encode_rdf_subject(value) when is_binary(value), do: value | |
| 1476 | + def encode_rdf_subject(_), do: {:error, "Unexpected type when encoding TopLevelMetadata.rdf_subject"} | |
| 1477 | + | |
| 1478 | + def decode_row_identifier(value) when is_binary(value), do: value | |
| 1479 | + def decode_row_identifier(_), do: {:error, "Unexpected type when decoding TopLevelMetadata.row_identifier"} | |
| 1480 | + | |
| 1481 | + def encode_row_identifier(value) when is_binary(value), do: value | |
| 1482 | + def encode_row_identifier(_), do: {:error, "Unexpected type when encoding TopLevelMetadata.row_identifier"} | |
| 1483 | + | |
| 1484 | + def decode_row_label(value) when is_binary(value), do: value | |
| 1485 | + def decode_row_label(_), do: {:error, "Unexpected type when decoding TopLevelMetadata.row_label"} | |
| 1486 | + | |
| 1487 | + def encode_row_label(value) when is_binary(value), do: value | |
| 1488 | + def encode_row_label(_), do: {:error, "Unexpected type when encoding TopLevelMetadata.row_label"} | |
| 1489 | + | |
| 1448 | 1490 | def from_map(m) do |
| 1449 | 1491 | %TopLevelMetadata{ |
| 1450 | 1492 | available_display_types: m["availableDisplayTypes"] && Enum.map(m["availableDisplayTypes"], &DisplayType.decode/1), |
| 1451 | 1493 | custom_fields: m["custom_fields"] && CustomFields.from_map(m["custom_fields"]), |
| 1452 | 1494 | json_query: m["jsonQuery"] && JSONQuery.from_map(m["jsonQuery"]), |
| 1453 | - rdf_class: m["rdfClass"], | |
| 1454 | - rdf_subject: m["rdfSubject"], | |
| 1495 | + rdf_class: m["rdfClass"] && decode_rdf_class(m["rdfClass"]), | |
| 1496 | + rdf_subject: m["rdfSubject"] && decode_rdf_subject(m["rdfSubject"]), | |
| 1455 | 1497 | render_type_config: m["renderTypeConfig"] && MetadataRenderTypeConfig.from_map(m["renderTypeConfig"]), |
| 1456 | 1498 | rich_renderer_configs: m["richRendererConfigs"] && RichRendererConfigs.from_map(m["richRendererConfigs"]), |
| 1457 | - row_identifier: m["rowIdentifier"], | |
| 1458 | - row_label: m["rowLabel"], | |
| 1499 | + row_identifier: m["rowIdentifier"] && decode_row_identifier(m["rowIdentifier"]), | |
| 1500 | + row_label: m["rowLabel"] && decode_row_label(m["rowLabel"]), | |
| 1459 | 1501 | v1_archived_properties: m["v1_archived_properties"] && V1ArchivedProperties.from_map(m["v1_archived_properties"]), |
| 1460 | 1502 | } |
| 1461 | 1503 | end |
| @@ -1608,6 +1650,24 @@ defmodule Owner do | ||
| 1608 | 1650 | def encode_id(value) when is_binary(value), do: value |
| 1609 | 1651 | def encode_id(_), do: {:error, "Unexpected type when encoding Owner.id"} |
| 1610 | 1652 | |
| 1653 | + def decode_profile_image_url_large(value) when is_binary(value), do: value | |
| 1654 | + def decode_profile_image_url_large(_), do: {:error, "Unexpected type when decoding Owner.profile_image_url_large"} | |
| 1655 | + | |
| 1656 | + def encode_profile_image_url_large(value) when is_binary(value), do: value | |
| 1657 | + def encode_profile_image_url_large(_), do: {:error, "Unexpected type when encoding Owner.profile_image_url_large"} | |
| 1658 | + | |
| 1659 | + def decode_profile_image_url_medium(value) when is_binary(value), do: value | |
| 1660 | + def decode_profile_image_url_medium(_), do: {:error, "Unexpected type when decoding Owner.profile_image_url_medium"} | |
| 1661 | + | |
| 1662 | + def encode_profile_image_url_medium(value) when is_binary(value), do: value | |
| 1663 | + def encode_profile_image_url_medium(_), do: {:error, "Unexpected type when encoding Owner.profile_image_url_medium"} | |
| 1664 | + | |
| 1665 | + def decode_profile_image_url_small(value) when is_binary(value), do: value | |
| 1666 | + def decode_profile_image_url_small(_), do: {:error, "Unexpected type when decoding Owner.profile_image_url_small"} | |
| 1667 | + | |
| 1668 | + def encode_profile_image_url_small(value) when is_binary(value), do: value | |
| 1669 | + def encode_profile_image_url_small(_), do: {:error, "Unexpected type when encoding Owner.profile_image_url_small"} | |
| 1670 | + | |
| 1611 | 1671 | def decode_screen_name(value) when is_binary(value), do: value |
| 1612 | 1672 | def decode_screen_name(_), do: {:error, "Unexpected type when decoding Owner.screen_name"} |
| 1613 | 1673 | |
| @@ -1620,9 +1680,9 @@ defmodule Owner do | ||
| 1620 | 1680 | flags: m["flags"], |
| 1621 | 1681 | id: decode_id(m["id"]), |
| 1622 | 1682 | last_notification_seen_at: m["lastNotificationSeenAt"], |
| 1623 | - profile_image_url_large: m["profileImageUrlLarge"], | |
| 1624 | - profile_image_url_medium: m["profileImageUrlMedium"], | |
| 1625 | - profile_image_url_small: m["profileImageUrlSmall"], | |
| 1683 | + profile_image_url_large: m["profileImageUrlLarge"] && decode_profile_image_url_large(m["profileImageUrlLarge"]), | |
| 1684 | + profile_image_url_medium: m["profileImageUrlMedium"] && decode_profile_image_url_medium(m["profileImageUrlMedium"]), | |
| 1685 | + profile_image_url_small: m["profileImageUrlSmall"] && decode_profile_image_url_small(m["profileImageUrlSmall"]), | |
| 1626 | 1686 | rights: m["rights"], |
| 1627 | 1687 | role_name: m["roleName"] && RoleName.decode(m["roleName"]), |
| 1628 | 1688 | screen_name: decode_screen_name(m["screenName"]), |
| @@ -2040,12 +2100,24 @@ defmodule TopLevelElement do | ||
| 2040 | 2100 | def encode_average_rating(value) when is_integer(value), do: value |
| 2041 | 2101 | def encode_average_rating(_), do: {:error, "Unexpected type when encoding TopLevelElement.average_rating"} |
| 2042 | 2102 | |
| 2103 | + def decode_category(value) when is_binary(value), do: value | |
| 2104 | + def decode_category(_), do: {:error, "Unexpected type when decoding TopLevelElement.category"} | |
| 2105 | + | |
| 2106 | + def encode_category(value) when is_binary(value), do: value | |
| 2107 | + def encode_category(_), do: {:error, "Unexpected type when encoding TopLevelElement.category"} | |
| 2108 | + | |
| 2043 | 2109 | def decode_created_at(value) when is_integer(value), do: value |
| 2044 | 2110 | def decode_created_at(_), do: {:error, "Unexpected type when decoding TopLevelElement.created_at"} |
| 2045 | 2111 | |
| 2046 | 2112 | def encode_created_at(value) when is_integer(value), do: value |
| 2047 | 2113 | def encode_created_at(_), do: {:error, "Unexpected type when encoding TopLevelElement.created_at"} |
| 2048 | 2114 | |
| 2115 | + def decode_description(value) when is_binary(value), do: value | |
| 2116 | + def decode_description(_), do: {:error, "Unexpected type when decoding TopLevelElement.description"} | |
| 2117 | + | |
| 2118 | + def encode_description(value) when is_binary(value), do: value | |
| 2119 | + def encode_description(_), do: {:error, "Unexpected type when encoding TopLevelElement.description"} | |
| 2120 | + | |
| 2049 | 2121 | def decode_download_count(value) when is_integer(value), do: value |
| 2050 | 2122 | def decode_download_count(_), do: {:error, "Unexpected type when decoding TopLevelElement.download_count"} |
| 2051 | 2123 | |
| @@ -2118,12 +2190,24 @@ defmodule TopLevelElement do | ||
| 2118 | 2190 | def encode_publication_group(value) when is_integer(value), do: value |
| 2119 | 2191 | def encode_publication_group(_), do: {:error, "Unexpected type when encoding TopLevelElement.publication_group"} |
| 2120 | 2192 | |
| 2193 | + def decode_resource_name(value) when is_binary(value), do: value | |
| 2194 | + def decode_resource_name(_), do: {:error, "Unexpected type when decoding TopLevelElement.resource_name"} | |
| 2195 | + | |
| 2196 | + def encode_resource_name(value) when is_binary(value), do: value | |
| 2197 | + def encode_resource_name(_), do: {:error, "Unexpected type when encoding TopLevelElement.resource_name"} | |
| 2198 | + | |
| 2121 | 2199 | def decode_rights(value) when is_list(value), do: value |
| 2122 | 2200 | def decode_rights(_), do: {:error, "Unexpected type when decoding TopLevelElement.rights"} |
| 2123 | 2201 | |
| 2124 | 2202 | def encode_rights(value) when is_list(value), do: value |
| 2125 | 2203 | def encode_rights(_), do: {:error, "Unexpected type when encoding TopLevelElement.rights"} |
| 2126 | 2204 | |
| 2205 | + def decode_row_class(value) when is_binary(value), do: value | |
| 2206 | + def decode_row_class(_), do: {:error, "Unexpected type when decoding TopLevelElement.row_class"} | |
| 2207 | + | |
| 2208 | + def encode_row_class(value) when is_binary(value), do: value | |
| 2209 | + def encode_row_class(_), do: {:error, "Unexpected type when encoding TopLevelElement.row_class"} | |
| 2210 | + | |
| 2127 | 2211 | def decode_table_id(value) when is_integer(value), do: value |
| 2128 | 2212 | def decode_table_id(_), do: {:error, "Unexpected type when decoding TopLevelElement.table_id"} |
| 2129 | 2213 | |
| @@ -2151,9 +2235,9 @@ defmodule TopLevelElement do | ||
| 2151 | 2235 | def from_map(m) do |
| 2152 | 2236 | %TopLevelElement{ |
| 2153 | 2237 | average_rating: decode_average_rating(m["averageRating"]), |
| 2154 | - category: m["category"], | |
| 2238 | + category: m["category"] && decode_category(m["category"]), | |
| 2155 | 2239 | created_at: decode_created_at(m["createdAt"]), |
| 2156 | - description: m["description"], | |
| 2240 | + description: m["description"] && decode_description(m["description"]), | |
| 2157 | 2241 | display_type: m["displayType"] && DisplayType.decode(m["displayType"]), |
| 2158 | 2242 | download_count: decode_download_count(m["downloadCount"]), |
| 2159 | 2243 | flags: m["flags"] && Enum.map(m["flags"], &TopLevelFlag.decode/1), |
| @@ -2177,9 +2261,9 @@ defmodule TopLevelElement do | ||
| 2177 | 2261 | publication_group: decode_publication_group(m["publicationGroup"]), |
| 2178 | 2262 | publication_stage: PublicationStage.decode(m["publicationStage"]), |
| 2179 | 2263 | ratings: m["ratings"] && Ratings.from_map(m["ratings"]), |
| 2180 | - resource_name: m["resourceName"], | |
| 2264 | + resource_name: m["resourceName"] && decode_resource_name(m["resourceName"]), | |
| 2181 | 2265 | rights: Enum.map(m["rights"], &Right.decode/1), |
| 2182 | - row_class: m["rowClass"], | |
| 2266 | + row_class: m["rowClass"] && decode_row_class(m["rowClass"]), | |
| 2183 | 2267 | row_identifier_column_id: m["rowIdentifierColumnId"], |
| 2184 | 2268 | rows_updated_at: m["rowsUpdatedAt"], |
| 2185 | 2269 | rows_updated_by: m["rowsUpdatedBy"] && RowsUpdatedBy.decode(m["rowsUpdatedBy"]), |
Test case
1 generated file · +35 −5test/inputs/json/misc/f6a65.json
Melixirdefault / QuickType.ex+35 −5
| @@ -22,6 +22,12 @@ defmodule The480_WStill do | ||
| 22 | 22 | def encode_height(value) when is_binary(value), do: value |
| 23 | 23 | def encode_height(_), do: {:error, "Unexpected type when encoding The480_WStill.height"} |
| 24 | 24 | |
| 25 | + def decode_size(value) when is_binary(value), do: value | |
| 26 | + def decode_size(_), do: {:error, "Unexpected type when decoding The480_WStill.size"} | |
| 27 | + | |
| 28 | + def encode_size(value) when is_binary(value), do: value | |
| 29 | + def encode_size(_), do: {:error, "Unexpected type when encoding The480_WStill.size"} | |
| 30 | + | |
| 25 | 31 | def decode_url(value) when is_binary(value), do: value |
| 26 | 32 | def decode_url(_), do: {:error, "Unexpected type when decoding The480_WStill.url"} |
| 27 | 33 | |
| @@ -37,7 +43,7 @@ defmodule The480_WStill do | ||
| 37 | 43 | def from_map(m) do |
| 38 | 44 | %The480_WStill{ |
| 39 | 45 | height: decode_height(m["height"]), |
| 40 | - size: m["size"], | |
| 46 | + size: m["size"] && decode_size(m["size"]), | |
| 41 | 47 | url: decode_url(m["url"]), |
| 42 | 48 | width: decode_width(m["width"]), |
| 43 | 49 | } |
| @@ -148,12 +154,36 @@ defmodule FixedHeight do | ||
| 148 | 154 | width: String.t() |
| 149 | 155 | } |
| 150 | 156 | |
| 157 | + def decode_frames(value) when is_binary(value), do: value | |
| 158 | + def decode_frames(_), do: {:error, "Unexpected type when decoding FixedHeight.frames"} | |
| 159 | + | |
| 160 | + def encode_frames(value) when is_binary(value), do: value | |
| 161 | + def encode_frames(_), do: {:error, "Unexpected type when encoding FixedHeight.frames"} | |
| 162 | + | |
| 163 | + def decode_hash(value) when is_binary(value), do: value | |
| 164 | + def decode_hash(_), do: {:error, "Unexpected type when decoding FixedHeight.hash"} | |
| 165 | + | |
| 166 | + def encode_hash(value) when is_binary(value), do: value | |
| 167 | + def encode_hash(_), do: {:error, "Unexpected type when encoding FixedHeight.hash"} | |
| 168 | + | |
| 151 | 169 | def decode_height(value) when is_binary(value), do: value |
| 152 | 170 | def decode_height(_), do: {:error, "Unexpected type when decoding FixedHeight.height"} |
| 153 | 171 | |
| 154 | 172 | def encode_height(value) when is_binary(value), do: value |
| 155 | 173 | def encode_height(_), do: {:error, "Unexpected type when encoding FixedHeight.height"} |
| 156 | 174 | |
| 175 | + def decode_mp4(value) when is_binary(value), do: value | |
| 176 | + def decode_mp4(_), do: {:error, "Unexpected type when decoding FixedHeight.mp4"} | |
| 177 | + | |
| 178 | + def encode_mp4(value) when is_binary(value), do: value | |
| 179 | + def encode_mp4(_), do: {:error, "Unexpected type when encoding FixedHeight.mp4"} | |
| 180 | + | |
| 181 | + def decode_mp4_size(value) when is_binary(value), do: value | |
| 182 | + def decode_mp4_size(_), do: {:error, "Unexpected type when decoding FixedHeight.mp4_size"} | |
| 183 | + | |
| 184 | + def encode_mp4_size(value) when is_binary(value), do: value | |
| 185 | + def encode_mp4_size(_), do: {:error, "Unexpected type when encoding FixedHeight.mp4_size"} | |
| 186 | + | |
| 157 | 187 | def decode_size(value) when is_binary(value), do: value |
| 158 | 188 | def decode_size(_), do: {:error, "Unexpected type when decoding FixedHeight.size"} |
| 159 | 189 | |
| @@ -186,11 +216,11 @@ defmodule FixedHeight do | ||
| 186 | 216 | |
| 187 | 217 | def from_map(m) do |
| 188 | 218 | %FixedHeight{ |
| 189 | - frames: m["frames"], | |
| 190 | - hash: m["hash"], | |
| 219 | + frames: m["frames"] && decode_frames(m["frames"]), | |
| 220 | + hash: m["hash"] && decode_hash(m["hash"]), | |
| 191 | 221 | height: decode_height(m["height"]), |
| 192 | - mp4: m["mp4"], | |
| 193 | - mp4_size: m["mp4_size"], | |
| 222 | + mp4: m["mp4"] && decode_mp4(m["mp4"]), | |
| 223 | + mp4_size: m["mp4_size"] && decode_mp4_size(m["mp4_size"]), | |
| 194 | 224 | size: decode_size(m["size"]), |
| 195 | 225 | url: decode_url(m["url"]), |
| 196 | 226 | webp: decode_webp(m["webp"]), |
Test case
1 generated file · +14 −2test/inputs/json/misc/f74d5.json
Melixirdefault / QuickType.ex+14 −2
| @@ -67,6 +67,12 @@ defmodule CachedContents do | ||
| 67 | 67 | top: [Top.t()] |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | + def decode_average(value) when is_binary(value), do: value | |
| 71 | + def decode_average(_), do: {:error, "Unexpected type when decoding CachedContents.average"} | |
| 72 | + | |
| 73 | + def encode_average(value) when is_binary(value), do: value | |
| 74 | + def encode_average(_), do: {:error, "Unexpected type when encoding CachedContents.average"} | |
| 75 | + | |
| 70 | 76 | def decode_largest(value) when is_binary(value), do: value |
| 71 | 77 | def decode_largest(_), do: {:error, "Unexpected type when decoding CachedContents.largest"} |
| 72 | 78 | |
| @@ -91,6 +97,12 @@ defmodule CachedContents do | ||
| 91 | 97 | def encode_smallest(value) when is_binary(value), do: value |
| 92 | 98 | def encode_smallest(_), do: {:error, "Unexpected type when encoding CachedContents.smallest"} |
| 93 | 99 | |
| 100 | + def decode_sum(value) when is_binary(value), do: value | |
| 101 | + def decode_sum(_), do: {:error, "Unexpected type when decoding CachedContents.sum"} | |
| 102 | + | |
| 103 | + def encode_sum(value) when is_binary(value), do: value | |
| 104 | + def encode_sum(_), do: {:error, "Unexpected type when encoding CachedContents.sum"} | |
| 105 | + | |
| 94 | 106 | def decode_top(value) when is_list(value), do: value |
| 95 | 107 | def decode_top(_), do: {:error, "Unexpected type when decoding CachedContents.top"} |
| 96 | 108 | |
| @@ -99,12 +111,12 @@ defmodule CachedContents do | ||
| 99 | 111 | |
| 100 | 112 | def from_map(m) do |
| 101 | 113 | %CachedContents{ |
| 102 | - average: m["average"], | |
| 114 | + average: m["average"] && decode_average(m["average"]), | |
| 103 | 115 | largest: decode_largest(m["largest"]), |
| 104 | 116 | non_null: decode_non_null(m["non_null"]), |
| 105 | 117 | null: decode_null(m["null"]), |
| 106 | 118 | smallest: decode_smallest(m["smallest"]), |
| 107 | - sum: m["sum"], | |
| 119 | + sum: m["sum"] && decode_sum(m["sum"]), | |
| 108 | 120 | top: Enum.map(m["top"], &Top.from_map/1), |
| 109 | 121 | } |
| 110 | 122 | end |
Test case
1 generated file · +42 −6test/inputs/json/misc/fcca3.json
Melixirdefault / QuickType.ex+42 −6
| @@ -67,6 +67,12 @@ defmodule CachedContents do | ||
| 67 | 67 | top: [Top.t()] |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | + def decode_average(value) when is_binary(value), do: value | |
| 71 | + def decode_average(_), do: {:error, "Unexpected type when decoding CachedContents.average"} | |
| 72 | + | |
| 73 | + def encode_average(value) when is_binary(value), do: value | |
| 74 | + def encode_average(_), do: {:error, "Unexpected type when encoding CachedContents.average"} | |
| 75 | + | |
| 70 | 76 | def decode_largest(value) when is_binary(value), do: value |
| 71 | 77 | def decode_largest(_), do: {:error, "Unexpected type when decoding CachedContents.largest"} |
| 72 | 78 | |
| @@ -91,6 +97,12 @@ defmodule CachedContents do | ||
| 91 | 97 | def encode_smallest(value) when is_binary(value), do: value |
| 92 | 98 | def encode_smallest(_), do: {:error, "Unexpected type when encoding CachedContents.smallest"} |
| 93 | 99 | |
| 100 | + def decode_sum(value) when is_binary(value), do: value | |
| 101 | + def decode_sum(_), do: {:error, "Unexpected type when decoding CachedContents.sum"} | |
| 102 | + | |
| 103 | + def encode_sum(value) when is_binary(value), do: value | |
| 104 | + def encode_sum(_), do: {:error, "Unexpected type when encoding CachedContents.sum"} | |
| 105 | + | |
| 94 | 106 | def decode_top(value) when is_list(value), do: value |
| 95 | 107 | def decode_top(_), do: {:error, "Unexpected type when decoding CachedContents.top"} |
| 96 | 108 | |
| @@ -99,12 +111,12 @@ defmodule CachedContents do | ||
| 99 | 111 | |
| 100 | 112 | def from_map(m) do |
| 101 | 113 | %CachedContents{ |
| 102 | - average: m["average"], | |
| 114 | + average: m["average"] && decode_average(m["average"]), | |
| 103 | 115 | largest: decode_largest(m["largest"]), |
| 104 | 116 | non_null: decode_non_null(m["non_null"]), |
| 105 | 117 | null: decode_null(m["null"]), |
| 106 | 118 | smallest: decode_smallest(m["smallest"]), |
| 107 | - sum: m["sum"], | |
| 119 | + sum: m["sum"] && decode_sum(m["sum"]), | |
| 108 | 120 | top: Enum.map(m["top"], &Top.from_map/1), |
| 109 | 121 | } |
| 110 | 122 | end |
| @@ -190,11 +202,29 @@ defmodule Format do | ||
| 190 | 202 | precision_style: String.t() | nil |
| 191 | 203 | } |
| 192 | 204 | |
| 205 | + def decode_align(value) when is_binary(value), do: value | |
| 206 | + def decode_align(_), do: {:error, "Unexpected type when decoding Format.align"} | |
| 207 | + | |
| 208 | + def encode_align(value) when is_binary(value), do: value | |
| 209 | + def encode_align(_), do: {:error, "Unexpected type when encoding Format.align"} | |
| 210 | + | |
| 211 | + def decode_no_commas(value) when is_binary(value), do: value | |
| 212 | + def decode_no_commas(_), do: {:error, "Unexpected type when decoding Format.no_commas"} | |
| 213 | + | |
| 214 | + def encode_no_commas(value) when is_binary(value), do: value | |
| 215 | + def encode_no_commas(_), do: {:error, "Unexpected type when encoding Format.no_commas"} | |
| 216 | + | |
| 217 | + def decode_precision_style(value) when is_binary(value), do: value | |
| 218 | + def decode_precision_style(_), do: {:error, "Unexpected type when decoding Format.precision_style"} | |
| 219 | + | |
| 220 | + def encode_precision_style(value) when is_binary(value), do: value | |
| 221 | + def encode_precision_style(_), do: {:error, "Unexpected type when encoding Format.precision_style"} | |
| 222 | + | |
| 193 | 223 | def from_map(m) do |
| 194 | 224 | %Format{ |
| 195 | - align: m["align"], | |
| 196 | - no_commas: m["noCommas"], | |
| 197 | - precision_style: m["precisionStyle"], | |
| 225 | + align: m["align"] && decode_align(m["align"]), | |
| 226 | + no_commas: m["noCommas"] && decode_no_commas(m["noCommas"]), | |
| 227 | + precision_style: m["precisionStyle"] && decode_precision_style(m["precisionStyle"]), | |
| 198 | 228 | } |
| 199 | 229 | end |
| 200 | 230 | |
| @@ -238,6 +268,12 @@ defmodule Column do | ||
| 238 | 268 | width: integer() | nil |
| 239 | 269 | } |
| 240 | 270 | |
| 271 | + def decode_description(value) when is_binary(value), do: value | |
| 272 | + def decode_description(_), do: {:error, "Unexpected type when decoding Column.description"} | |
| 273 | + | |
| 274 | + def encode_description(value) when is_binary(value), do: value | |
| 275 | + def encode_description(_), do: {:error, "Unexpected type when encoding Column.description"} | |
| 276 | + | |
| 241 | 277 | def decode_field_name(value) when is_binary(value), do: value |
| 242 | 278 | def decode_field_name(_), do: {:error, "Unexpected type when decoding Column.field_name"} |
| 243 | 279 | |
| @@ -266,7 +302,7 @@ defmodule Column do | ||
| 266 | 302 | %Column{ |
| 267 | 303 | cached_contents: m["cachedContents"] && CachedContents.from_map(m["cachedContents"]), |
| 268 | 304 | data_type_name: TypeName.decode(m["dataTypeName"]), |
| 269 | - description: m["description"], | |
| 305 | + description: m["description"] && decode_description(m["description"]), | |
| 270 | 306 | field_name: decode_field_name(m["fieldName"]), |
| 271 | 307 | flags: m["flags"], |
| 272 | 308 | format: Format.from_map(m["format"]), |
Test case
1 generated file · +7 −1test/inputs/json/priority/bug2521.json
Melixirdefault / QuickType.ex+7 −1
| @@ -14,6 +14,12 @@ defmodule Option do | ||
| 14 | 14 | name: String.t() |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | + def decode_foo(value) when is_binary(value), do: value | |
| 18 | + def decode_foo(_), do: {:error, "Unexpected type when decoding Option.foo"} | |
| 19 | + | |
| 20 | + def encode_foo(value) when is_binary(value), do: value | |
| 21 | + def encode_foo(_), do: {:error, "Unexpected type when encoding Option.foo"} | |
| 22 | + | |
| 17 | 23 | def decode_name(value) when is_binary(value), do: value |
| 18 | 24 | def decode_name(_), do: {:error, "Unexpected type when decoding Option.name"} |
| 19 | 25 | |
| @@ -22,7 +28,7 @@ defmodule Option do | ||
| 22 | 28 | |
| 23 | 29 | def from_map(m) do |
| 24 | 30 | %Option{ |
| 25 | - foo: m["foo"], | |
| 31 | + foo: m["foo"] && decode_foo(m["foo"]), | |
| 26 | 32 | name: decode_name(m["name"]), |
| 27 | 33 | } |
| 28 | 34 | end |
Test case
1 generated file · +147 −21test/inputs/json/priority/bug427.json
Melixirdefault / QuickType.ex+147 −21
| @@ -533,11 +533,29 @@ defmodule GetSignatureComment do | ||
| 533 | 533 | text: String.t() | nil |
| 534 | 534 | } |
| 535 | 535 | |
| 536 | + def decode_returns(value) when is_binary(value), do: value | |
| 537 | + def decode_returns(_), do: {:error, "Unexpected type when decoding GetSignatureComment.returns"} | |
| 538 | + | |
| 539 | + def encode_returns(value) when is_binary(value), do: value | |
| 540 | + def encode_returns(_), do: {:error, "Unexpected type when encoding GetSignatureComment.returns"} | |
| 541 | + | |
| 542 | + def decode_short_text(value) when is_binary(value), do: value | |
| 543 | + def decode_short_text(_), do: {:error, "Unexpected type when decoding GetSignatureComment.short_text"} | |
| 544 | + | |
| 545 | + def encode_short_text(value) when is_binary(value), do: value | |
| 546 | + def encode_short_text(_), do: {:error, "Unexpected type when encoding GetSignatureComment.short_text"} | |
| 547 | + | |
| 548 | + def decode_text(value) when is_binary(value), do: value | |
| 549 | + def decode_text(_), do: {:error, "Unexpected type when decoding GetSignatureComment.text"} | |
| 550 | + | |
| 551 | + def encode_text(value) when is_binary(value), do: value | |
| 552 | + def encode_text(_), do: {:error, "Unexpected type when encoding GetSignatureComment.text"} | |
| 553 | + | |
| 536 | 554 | def from_map(m) do |
| 537 | 555 | %GetSignatureComment{ |
| 538 | - returns: m["returns"], | |
| 539 | - short_text: m["shortText"], | |
| 540 | - text: m["text"], | |
| 556 | + returns: m["returns"] && decode_returns(m["returns"]), | |
| 557 | + short_text: m["shortText"] && decode_short_text(m["shortText"]), | |
| 558 | + text: m["text"] && decode_text(m["text"]), | |
| 541 | 559 | } |
| 542 | 560 | end |
| 543 | 561 | |
| @@ -627,10 +645,22 @@ defmodule Comment3 do | ||
| 627 | 645 | text: String.t() | nil |
| 628 | 646 | } |
| 629 | 647 | |
| 648 | + def decode_short_text(value) when is_binary(value), do: value | |
| 649 | + def decode_short_text(_), do: {:error, "Unexpected type when decoding Comment3.short_text"} | |
| 650 | + | |
| 651 | + def encode_short_text(value) when is_binary(value), do: value | |
| 652 | + def encode_short_text(_), do: {:error, "Unexpected type when encoding Comment3.short_text"} | |
| 653 | + | |
| 654 | + def decode_text(value) when is_binary(value), do: value | |
| 655 | + def decode_text(_), do: {:error, "Unexpected type when decoding Comment3.text"} | |
| 656 | + | |
| 657 | + def encode_text(value) when is_binary(value), do: value | |
| 658 | + def encode_text(_), do: {:error, "Unexpected type when encoding Comment3.text"} | |
| 659 | + | |
| 630 | 660 | def from_map(m) do |
| 631 | 661 | %Comment3{ |
| 632 | - short_text: m["shortText"], | |
| 633 | - text: m["text"], | |
| 662 | + short_text: m["shortText"] && decode_short_text(m["shortText"]), | |
| 663 | + text: m["text"] && decode_text(m["text"]), | |
| 634 | 664 | } |
| 635 | 665 | end |
| 636 | 666 | |
| @@ -1100,6 +1130,12 @@ defmodule GetSignature do | ||
| 1100 | 1130 | type_parameter: [GetSignature.t()] | nil |
| 1101 | 1131 | } |
| 1102 | 1132 | |
| 1133 | + def decode_default_value(value) when is_binary(value), do: value | |
| 1134 | + def decode_default_value(_), do: {:error, "Unexpected type when decoding GetSignature.default_value"} | |
| 1135 | + | |
| 1136 | + def encode_default_value(value) when is_binary(value), do: value | |
| 1137 | + def encode_default_value(_), do: {:error, "Unexpected type when encoding GetSignature.default_value"} | |
| 1138 | + | |
| 1103 | 1139 | def decode_id(value) when is_integer(value), do: value |
| 1104 | 1140 | def decode_id(_), do: {:error, "Unexpected type when decoding GetSignature.id"} |
| 1105 | 1141 | |
| @@ -1128,7 +1164,7 @@ defmodule GetSignature do | ||
| 1128 | 1164 | %GetSignature{ |
| 1129 | 1165 | children: m["children"] && Enum.map(m["children"], &GetSignatureChild.from_map/1), |
| 1130 | 1166 | comment: m["comment"] && GetSignatureComment.from_map(m["comment"]), |
| 1131 | - default_value: m["defaultValue"], | |
| 1167 | + default_value: m["defaultValue"] && decode_default_value(m["defaultValue"]), | |
| 1132 | 1168 | flags: GetSignatureFlags.from_map(m["flags"]), |
| 1133 | 1169 | groups: m["groups"] && Enum.map(m["groups"], &Group.from_map/1), |
| 1134 | 1170 | id: decode_id(m["id"]), |
| @@ -1441,6 +1477,12 @@ defmodule Child3 do | ||
| 1441 | 1477 | type: TypeElement.t() | nil |
| 1442 | 1478 | } |
| 1443 | 1479 | |
| 1480 | + def decode_default_value(value) when is_binary(value), do: value | |
| 1481 | + def decode_default_value(_), do: {:error, "Unexpected type when decoding Child3.default_value"} | |
| 1482 | + | |
| 1483 | + def encode_default_value(value) when is_binary(value), do: value | |
| 1484 | + def encode_default_value(_), do: {:error, "Unexpected type when encoding Child3.default_value"} | |
| 1485 | + | |
| 1444 | 1486 | def decode_id(value) when is_integer(value), do: value |
| 1445 | 1487 | def decode_id(_), do: {:error, "Unexpected type when decoding Child3.id"} |
| 1446 | 1488 | |
| @@ -1468,7 +1510,7 @@ defmodule Child3 do | ||
| 1468 | 1510 | def from_map(m) do |
| 1469 | 1511 | %Child3{ |
| 1470 | 1512 | comment: m["comment"] && Comment1.from_map(m["comment"]), |
| 1471 | - default_value: m["defaultValue"], | |
| 1513 | + default_value: m["defaultValue"] && decode_default_value(m["defaultValue"]), | |
| 1472 | 1514 | flags: Flags1.from_map(m["flags"]), |
| 1473 | 1515 | id: decode_id(m["id"]), |
| 1474 | 1516 | kind: decode_kind(m["kind"]), |
| @@ -1566,12 +1608,30 @@ defmodule Comment4 do | ||
| 1566 | 1608 | text: String.t() | nil |
| 1567 | 1609 | } |
| 1568 | 1610 | |
| 1611 | + def decode_returns(value) when is_binary(value), do: value | |
| 1612 | + def decode_returns(_), do: {:error, "Unexpected type when decoding Comment4.returns"} | |
| 1613 | + | |
| 1614 | + def encode_returns(value) when is_binary(value), do: value | |
| 1615 | + def encode_returns(_), do: {:error, "Unexpected type when encoding Comment4.returns"} | |
| 1616 | + | |
| 1617 | + def decode_short_text(value) when is_binary(value), do: value | |
| 1618 | + def decode_short_text(_), do: {:error, "Unexpected type when decoding Comment4.short_text"} | |
| 1619 | + | |
| 1620 | + def encode_short_text(value) when is_binary(value), do: value | |
| 1621 | + def encode_short_text(_), do: {:error, "Unexpected type when encoding Comment4.short_text"} | |
| 1622 | + | |
| 1623 | + def decode_text(value) when is_binary(value), do: value | |
| 1624 | + def decode_text(_), do: {:error, "Unexpected type when decoding Comment4.text"} | |
| 1625 | + | |
| 1626 | + def encode_text(value) when is_binary(value), do: value | |
| 1627 | + def encode_text(_), do: {:error, "Unexpected type when encoding Comment4.text"} | |
| 1628 | + | |
| 1569 | 1629 | def from_map(m) do |
| 1570 | 1630 | %Comment4{ |
| 1571 | - returns: m["returns"], | |
| 1572 | - short_text: m["shortText"], | |
| 1631 | + returns: m["returns"] && decode_returns(m["returns"]), | |
| 1632 | + short_text: m["shortText"] && decode_short_text(m["shortText"]), | |
| 1573 | 1633 | tags: m["tags"] && Enum.map(m["tags"], &Tag.from_map/1), |
| 1574 | - text: m["text"], | |
| 1634 | + text: m["text"] && decode_text(m["text"]), | |
| 1575 | 1635 | } |
| 1576 | 1636 | end |
| 1577 | 1637 | |
| @@ -1748,6 +1808,12 @@ defmodule Type4 do | ||
| 1748 | 1808 | type_arguments: [ElementType.t()] | nil |
| 1749 | 1809 | } |
| 1750 | 1810 | |
| 1811 | + def decode_name(value) when is_binary(value), do: value | |
| 1812 | + def decode_name(_), do: {:error, "Unexpected type when decoding Type4.name"} | |
| 1813 | + | |
| 1814 | + def encode_name(value) when is_binary(value), do: value | |
| 1815 | + def encode_name(_), do: {:error, "Unexpected type when encoding Type4.name"} | |
| 1816 | + | |
| 1751 | 1817 | def from_map(m) do |
| 1752 | 1818 | %Type4{ |
| 1753 | 1819 | constraint: m["constraint"] && ExtendedBy.from_map(m["constraint"]), |
| @@ -1755,7 +1821,7 @@ defmodule Type4 do | ||
| 1755 | 1821 | element_type: m["elementType"] && ElementType.from_map(m["elementType"]), |
| 1756 | 1822 | elements: m["elements"] && Enum.map(m["elements"], &ExtendedBy.from_map/1), |
| 1757 | 1823 | id: m["id"], |
| 1758 | - name: m["name"], | |
| 1824 | + name: m["name"] && decode_name(m["name"]), | |
| 1759 | 1825 | type: TypeEnum.decode(m["type"]), |
| 1760 | 1826 | type_arguments: m["typeArguments"] && Enum.map(m["typeArguments"], &ElementType.from_map/1), |
| 1761 | 1827 | } |
| @@ -2532,6 +2598,12 @@ defmodule Type5 do | ||
| 2532 | 2598 | types: [TypeElement.t()] | nil |
| 2533 | 2599 | } |
| 2534 | 2600 | |
| 2601 | + def decode_name(value) when is_binary(value), do: value | |
| 2602 | + def decode_name(_), do: {:error, "Unexpected type when decoding Type5.name"} | |
| 2603 | + | |
| 2604 | + def encode_name(value) when is_binary(value), do: value | |
| 2605 | + def encode_name(_), do: {:error, "Unexpected type when encoding Type5.name"} | |
| 2606 | + | |
| 2535 | 2607 | def from_map(m) do |
| 2536 | 2608 | %Type5{ |
| 2537 | 2609 | constraint: m["constraint"] && ExtendedBy.from_map(m["constraint"]), |
| @@ -2539,7 +2611,7 @@ defmodule Type5 do | ||
| 2539 | 2611 | element_type: m["elementType"] && ExtendedBy.from_map(m["elementType"]), |
| 2540 | 2612 | elements: m["elements"] && Enum.map(m["elements"], &ElementType.from_map/1), |
| 2541 | 2613 | id: m["id"], |
| 2542 | - name: m["name"], | |
| 2614 | + name: m["name"] && decode_name(m["name"]), | |
| 2543 | 2615 | type: TypeEnum.decode(m["type"]), |
| 2544 | 2616 | type_arguments: m["typeArguments"] && Enum.map(m["typeArguments"], &TypeArgument1.from_map/1), |
| 2545 | 2617 | types: m["types"] && Enum.map(m["types"], &TypeElement.from_map/1), |
| @@ -2597,6 +2669,12 @@ defmodule Child2 do | ||
| 2597 | 2669 | type: Type5.t() | nil |
| 2598 | 2670 | } |
| 2599 | 2671 | |
| 2672 | + def decode_default_value(value) when is_binary(value), do: value | |
| 2673 | + def decode_default_value(_), do: {:error, "Unexpected type when decoding Child2.default_value"} | |
| 2674 | + | |
| 2675 | + def encode_default_value(value) when is_binary(value), do: value | |
| 2676 | + def encode_default_value(_), do: {:error, "Unexpected type when encoding Child2.default_value"} | |
| 2677 | + | |
| 2600 | 2678 | def decode_id(value) when is_integer(value), do: value |
| 2601 | 2679 | def decode_id(_), do: {:error, "Unexpected type when decoding Child2.id"} |
| 2602 | 2680 | |
| @@ -2625,7 +2703,7 @@ defmodule Child2 do | ||
| 2625 | 2703 | %Child2{ |
| 2626 | 2704 | children: m["children"] && Enum.map(m["children"], &Child3.from_map/1), |
| 2627 | 2705 | comment: m["comment"] && Comment4.from_map(m["comment"]), |
| 2628 | - default_value: m["defaultValue"], | |
| 2706 | + default_value: m["defaultValue"] && decode_default_value(m["defaultValue"]), | |
| 2629 | 2707 | flags: Flags4.from_map(m["flags"]), |
| 2630 | 2708 | get_signature: m["getSignature"] && GetSignature.from_map(m["getSignature"]), |
| 2631 | 2709 | groups: m["groups"] && Enum.map(m["groups"], &Group.from_map/1), |
| @@ -2796,6 +2874,12 @@ defmodule Child5 do | ||
| 2796 | 2874 | type: Type6.t() |
| 2797 | 2875 | } |
| 2798 | 2876 | |
| 2877 | + def decode_default_value(value) when is_binary(value), do: value | |
| 2878 | + def decode_default_value(_), do: {:error, "Unexpected type when decoding Child5.default_value"} | |
| 2879 | + | |
| 2880 | + def encode_default_value(value) when is_binary(value), do: value | |
| 2881 | + def encode_default_value(_), do: {:error, "Unexpected type when encoding Child5.default_value"} | |
| 2882 | + | |
| 2799 | 2883 | def decode_id(value) when is_integer(value), do: value |
| 2800 | 2884 | def decode_id(_), do: {:error, "Unexpected type when decoding Child5.id"} |
| 2801 | 2885 | |
| @@ -2823,7 +2907,7 @@ defmodule Child5 do | ||
| 2823 | 2907 | def from_map(m) do |
| 2824 | 2908 | %Child5{ |
| 2825 | 2909 | comment: Comment2.from_map(m["comment"]), |
| 2826 | - default_value: m["defaultValue"], | |
| 2910 | + default_value: m["defaultValue"] && decode_default_value(m["defaultValue"]), | |
| 2827 | 2911 | flags: Flags2.from_map(m["flags"]), |
| 2828 | 2912 | id: decode_id(m["id"]), |
| 2829 | 2913 | kind: decode_kind(m["kind"]), |
| @@ -2964,12 +3048,18 @@ defmodule Type8 do | ||
| 2964 | 3048 | type_arguments: [ElementType.t()] | nil |
| 2965 | 3049 | } |
| 2966 | 3050 | |
| 3051 | + def decode_name(value) when is_binary(value), do: value | |
| 3052 | + def decode_name(_), do: {:error, "Unexpected type when decoding Type8.name"} | |
| 3053 | + | |
| 3054 | + def encode_name(value) when is_binary(value), do: value | |
| 3055 | + def encode_name(_), do: {:error, "Unexpected type when encoding Type8.name"} | |
| 3056 | + | |
| 2967 | 3057 | def from_map(m) do |
| 2968 | 3058 | %Type8{ |
| 2969 | 3059 | declaration: m["declaration"] && Declaration3.from_map(m["declaration"]), |
| 2970 | 3060 | element_type: m["elementType"] && ElementType.from_map(m["elementType"]), |
| 2971 | 3061 | id: m["id"], |
| 2972 | - name: m["name"], | |
| 3062 | + name: m["name"] && decode_name(m["name"]), | |
| 2973 | 3063 | type: TypeEnum.decode(m["type"]), |
| 2974 | 3064 | type_arguments: m["typeArguments"] && Enum.map(m["typeArguments"], &ElementType.from_map/1), |
| 2975 | 3065 | } |
| @@ -3015,6 +3105,12 @@ defmodule Parameter3 do | ||
| 3015 | 3105 | type: Type8.t() |
| 3016 | 3106 | } |
| 3017 | 3107 | |
| 3108 | + def decode_default_value(value) when is_binary(value), do: value | |
| 3109 | + def decode_default_value(_), do: {:error, "Unexpected type when decoding Parameter3.default_value"} | |
| 3110 | + | |
| 3111 | + def encode_default_value(value) when is_binary(value), do: value | |
| 3112 | + def encode_default_value(_), do: {:error, "Unexpected type when encoding Parameter3.default_value"} | |
| 3113 | + | |
| 3018 | 3114 | def decode_id(value) when is_integer(value), do: value |
| 3019 | 3115 | def decode_id(_), do: {:error, "Unexpected type when decoding Parameter3.id"} |
| 3020 | 3116 | |
| @@ -3033,16 +3129,22 @@ defmodule Parameter3 do | ||
| 3033 | 3129 | def encode_name(value) when is_binary(value), do: value |
| 3034 | 3130 | def encode_name(_), do: {:error, "Unexpected type when encoding Parameter3.name"} |
| 3035 | 3131 | |
| 3132 | + def decode_original_name(value) when is_binary(value), do: value | |
| 3133 | + def decode_original_name(_), do: {:error, "Unexpected type when decoding Parameter3.original_name"} | |
| 3134 | + | |
| 3135 | + def encode_original_name(value) when is_binary(value), do: value | |
| 3136 | + def encode_original_name(_), do: {:error, "Unexpected type when encoding Parameter3.original_name"} | |
| 3137 | + | |
| 3036 | 3138 | def from_map(m) do |
| 3037 | 3139 | %Parameter3{ |
| 3038 | 3140 | comment: m["comment"] && Comment3.from_map(m["comment"]), |
| 3039 | - default_value: m["defaultValue"], | |
| 3141 | + default_value: m["defaultValue"] && decode_default_value(m["defaultValue"]), | |
| 3040 | 3142 | flags: Flags3.from_map(m["flags"]), |
| 3041 | 3143 | id: decode_id(m["id"]), |
| 3042 | 3144 | kind: decode_kind(m["kind"]), |
| 3043 | 3145 | kind_string: ParameterKindString.decode(m["kindString"]), |
| 3044 | 3146 | name: decode_name(m["name"]), |
| 3045 | - original_name: m["originalName"], | |
| 3147 | + original_name: m["originalName"] && decode_original_name(m["originalName"]), | |
| 3046 | 3148 | type: Type8.from_map(m["type"]), |
| 3047 | 3149 | } |
| 3048 | 3150 | end |
| @@ -3546,17 +3648,29 @@ defmodule Type10 do | ||
| 3546 | 3648 | value: String.t() | nil |
| 3547 | 3649 | } |
| 3548 | 3650 | |
| 3651 | + def decode_name(value) when is_binary(value), do: value | |
| 3652 | + def decode_name(_), do: {:error, "Unexpected type when decoding Type10.name"} | |
| 3653 | + | |
| 3654 | + def encode_name(value) when is_binary(value), do: value | |
| 3655 | + def encode_name(_), do: {:error, "Unexpected type when encoding Type10.name"} | |
| 3656 | + | |
| 3657 | + def decode_value(value) when is_binary(value), do: value | |
| 3658 | + def decode_value(_), do: {:error, "Unexpected type when decoding Type10.value"} | |
| 3659 | + | |
| 3660 | + def encode_value(value) when is_binary(value), do: value | |
| 3661 | + def encode_value(_), do: {:error, "Unexpected type when encoding Type10.value"} | |
| 3662 | + | |
| 3549 | 3663 | def from_map(m) do |
| 3550 | 3664 | %Type10{ |
| 3551 | 3665 | declaration: m["declaration"] && Declaration4.from_map(m["declaration"]), |
| 3552 | 3666 | element_type: m["elementType"] && ElementType.from_map(m["elementType"]), |
| 3553 | 3667 | elements: m["elements"] && Enum.map(m["elements"], &ExtendedBy.from_map/1), |
| 3554 | 3668 | id: m["id"], |
| 3555 | - name: m["name"], | |
| 3669 | + name: m["name"] && decode_name(m["name"]), | |
| 3556 | 3670 | type: TypeEnum.decode(m["type"]), |
| 3557 | 3671 | type_arguments: m["typeArguments"] && Enum.map(m["typeArguments"], &TypeArgument2.from_map/1), |
| 3558 | 3672 | types: m["types"] && Enum.map(m["types"], &ExtendedBy.from_map/1), |
| 3559 | - value: m["value"], | |
| 3673 | + value: m["value"] && decode_value(m["value"]), | |
| 3560 | 3674 | } |
| 3561 | 3675 | end |
| 3562 | 3676 | |
| @@ -3599,6 +3713,12 @@ defmodule Type12 do | ||
| 3599 | 3713 | type: String.t() |
| 3600 | 3714 | } |
| 3601 | 3715 | |
| 3716 | + def decode_operator(value) when is_binary(value), do: value | |
| 3717 | + def decode_operator(_), do: {:error, "Unexpected type when decoding Type12.operator"} | |
| 3718 | + | |
| 3719 | + def encode_operator(value) when is_binary(value), do: value | |
| 3720 | + def encode_operator(_), do: {:error, "Unexpected type when encoding Type12.operator"} | |
| 3721 | + | |
| 3602 | 3722 | def decode_type(value) when is_binary(value), do: value |
| 3603 | 3723 | def decode_type(_), do: {:error, "Unexpected type when decoding Type12.type"} |
| 3604 | 3724 | |
| @@ -3609,7 +3729,7 @@ defmodule Type12 do | ||
| 3609 | 3729 | %Type12{ |
| 3610 | 3730 | id: m["id"], |
| 3611 | 3731 | name: m["name"] && Name.decode(m["name"]), |
| 3612 | - operator: m["operator"], | |
| 3732 | + operator: m["operator"] && decode_operator(m["operator"]), | |
| 3613 | 3733 | target: m["target"] && ElementType.from_map(m["target"]), |
| 3614 | 3734 | type: decode_type(m["type"]), |
| 3615 | 3735 | } |
| @@ -3737,6 +3857,12 @@ defmodule Child1 do | ||
| 3737 | 3857 | type_parameter: [TypeParameter.t()] | nil |
| 3738 | 3858 | } |
| 3739 | 3859 | |
| 3860 | + def decode_default_value(value) when is_binary(value), do: value | |
| 3861 | + def decode_default_value(_), do: {:error, "Unexpected type when decoding Child1.default_value"} | |
| 3862 | + | |
| 3863 | + def encode_default_value(value) when is_binary(value), do: value | |
| 3864 | + def encode_default_value(_), do: {:error, "Unexpected type when encoding Child1.default_value"} | |
| 3865 | + | |
| 3740 | 3866 | def decode_id(value) when is_integer(value), do: value |
| 3741 | 3867 | def decode_id(_), do: {:error, "Unexpected type when decoding Child1.id"} |
| 3742 | 3868 | |
| @@ -3765,7 +3891,7 @@ defmodule Child1 do | ||
| 3765 | 3891 | %Child1{ |
| 3766 | 3892 | children: m["children"] && Enum.map(m["children"], &Child2.from_map/1), |
| 3767 | 3893 | comment: m["comment"] && Comment4.from_map(m["comment"]), |
| 3768 | - default_value: m["defaultValue"], | |
| 3894 | + default_value: m["defaultValue"] && decode_default_value(m["defaultValue"]), | |
| 3769 | 3895 | extended_by: m["extendedBy"] && Enum.map(m["extendedBy"], &ExtendedBy.from_map/1), |
| 3770 | 3896 | extended_types: m["extendedTypes"] && Enum.map(m["extendedTypes"], &ExtendedBy.from_map/1), |
| 3771 | 3897 | flags: Flags6.from_map(m["flags"]), |
Test case
1 generated file · +21 −3test/inputs/json/priority/combinations1.json
Melixirdefault / QuickType.ex+21 −3
| @@ -246,6 +246,12 @@ defmodule ChemotherapeuticClass do | ||
| 246 | 246 | unshy: nil | nil |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | + def decode_disdiapason(value) when is_binary(value), do: value | |
| 250 | + def decode_disdiapason(_), do: {:error, "Unexpected type when decoding ChemotherapeuticClass.disdiapason"} | |
| 251 | + | |
| 252 | + def encode_disdiapason(value) when is_binary(value), do: value | |
| 253 | + def encode_disdiapason(_), do: {:error, "Unexpected type when encoding ChemotherapeuticClass.disdiapason"} | |
| 254 | + | |
| 249 | 255 | def from_map(m) do |
| 250 | 256 | %ChemotherapeuticClass{ |
| 251 | 257 | angioneurotic: m["angioneurotic"], |
| @@ -255,7 +261,7 @@ defmodule ChemotherapeuticClass do | ||
| 255 | 261 | caulis: m["caulis"], |
| 256 | 262 | chalcus: m["chalcus"], |
| 257 | 263 | chirotherium: m["Chirotherium"], |
| 258 | - disdiapason: m["disdiapason"], | |
| 264 | + disdiapason: m["disdiapason"] && decode_disdiapason(m["disdiapason"]), | |
| 259 | 265 | enteradenological: m["enteradenological"], |
| 260 | 266 | homocerc: m["homocerc"], |
| 261 | 267 | imporosity: m["imporosity"], |
| @@ -427,13 +433,19 @@ defmodule CoadjustClass do | ||
| 427 | 433 | unchargeable: nil | nil |
| 428 | 434 | } |
| 429 | 435 | |
| 436 | + def decode_disdiapason(value) when is_binary(value), do: value | |
| 437 | + def decode_disdiapason(_), do: {:error, "Unexpected type when decoding CoadjustClass.disdiapason"} | |
| 438 | + | |
| 439 | + def encode_disdiapason(value) when is_binary(value), do: value | |
| 440 | + def encode_disdiapason(_), do: {:error, "Unexpected type when encoding CoadjustClass.disdiapason"} | |
| 441 | + | |
| 430 | 442 | def from_map(m) do |
| 431 | 443 | %CoadjustClass{ |
| 432 | 444 | amidosulphonal: m["amidosulphonal"], |
| 433 | 445 | benny: m["Benny"], |
| 434 | 446 | catharticalness: m["catharticalness"], |
| 435 | 447 | chirotherium: m["Chirotherium"], |
| 436 | - disdiapason: m["disdiapason"], | |
| 448 | + disdiapason: m["disdiapason"] && decode_disdiapason(m["disdiapason"]), | |
| 437 | 449 | ensnare: m["ensnare"], |
| 438 | 450 | homocerc: m["homocerc"], |
| 439 | 451 | hybridizer: m["hybridizer"], |
| @@ -2001,6 +2013,12 @@ defmodule HemocoeleClass do | ||
| 2001 | 2013 | walt: nil | nil |
| 2002 | 2014 | } |
| 2003 | 2015 | |
| 2016 | + def decode_disdiapason(value) when is_binary(value), do: value | |
| 2017 | + def decode_disdiapason(_), do: {:error, "Unexpected type when decoding HemocoeleClass.disdiapason"} | |
| 2018 | + | |
| 2019 | + def encode_disdiapason(value) when is_binary(value), do: value | |
| 2020 | + def encode_disdiapason(_), do: {:error, "Unexpected type when encoding HemocoeleClass.disdiapason"} | |
| 2021 | + | |
| 2004 | 2022 | def from_map(m) do |
| 2005 | 2023 | %HemocoeleClass{ |
| 2006 | 2024 | acrogamy: m["acrogamy"], |
| @@ -2009,7 +2027,7 @@ defmodule HemocoeleClass do | ||
| 2009 | 2027 | berat: m["berat"], |
| 2010 | 2028 | catharticalness: m["catharticalness"], |
| 2011 | 2029 | chirotherium: m["Chirotherium"], |
| 2012 | - disdiapason: m["disdiapason"], | |
| 2030 | + disdiapason: m["disdiapason"] && decode_disdiapason(m["disdiapason"]), | |
| 2013 | 2031 | disproportionably: m["disproportionably"], |
| 2014 | 2032 | erythrite: m["erythrite"], |
| 2015 | 2033 | graphic: m["graphic"], |
Test case
1 generated file · +21 −3test/inputs/json/priority/combinations2.json
Melixirdefault / QuickType.ex+21 −3
| @@ -323,6 +323,12 @@ defmodule Amphithyron do | ||
| 323 | 323 | undecimal: integer() | nil |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | + def decode_disdiapason(value) when is_binary(value), do: value | |
| 327 | + def decode_disdiapason(_), do: {:error, "Unexpected type when decoding Amphithyron.disdiapason"} | |
| 328 | + | |
| 329 | + def encode_disdiapason(value) when is_binary(value), do: value | |
| 330 | + def encode_disdiapason(_), do: {:error, "Unexpected type when encoding Amphithyron.disdiapason"} | |
| 331 | + | |
| 326 | 332 | def from_map(m) do |
| 327 | 333 | %Amphithyron{ |
| 328 | 334 | akroasis: m["akroasis"], |
| @@ -331,7 +337,7 @@ defmodule Amphithyron do | ||
| 331 | 337 | catharticalness: m["catharticalness"], |
| 332 | 338 | chirotherium: m["Chirotherium"], |
| 333 | 339 | conductometric: m["conductometric"], |
| 334 | - disdiapason: m["disdiapason"], | |
| 340 | + disdiapason: m["disdiapason"] && decode_disdiapason(m["disdiapason"]), | |
| 335 | 341 | ensilation: m["ensilation"], |
| 336 | 342 | eyebolt: m["eyebolt"], |
| 337 | 343 | fistulated: m["fistulated"], |
| @@ -1057,6 +1063,12 @@ defmodule DiscordiaClass do | ||
| 1057 | 1063 | wingle: integer() | nil |
| 1058 | 1064 | } |
| 1059 | 1065 | |
| 1066 | + def decode_disdiapason(value) when is_binary(value), do: value | |
| 1067 | + def decode_disdiapason(_), do: {:error, "Unexpected type when decoding DiscordiaClass.disdiapason"} | |
| 1068 | + | |
| 1069 | + def encode_disdiapason(value) when is_binary(value), do: value | |
| 1070 | + def encode_disdiapason(_), do: {:error, "Unexpected type when encoding DiscordiaClass.disdiapason"} | |
| 1071 | + | |
| 1060 | 1072 | def from_map(m) do |
| 1061 | 1073 | %DiscordiaClass{ |
| 1062 | 1074 | altaic: m["Altaic"], |
| @@ -1065,7 +1077,7 @@ defmodule DiscordiaClass do | ||
| 1065 | 1077 | catharticalness: m["catharticalness"], |
| 1066 | 1078 | chirotherium: m["Chirotherium"], |
| 1067 | 1079 | disciplinability: m["disciplinability"], |
| 1068 | - disdiapason: m["disdiapason"], | |
| 1080 | + disdiapason: m["disdiapason"] && decode_disdiapason(m["disdiapason"]), | |
| 1069 | 1081 | goofer: m["goofer"], |
| 1070 | 1082 | homocerc: m["homocerc"], |
| 1071 | 1083 | laryngograph: m["laryngograph"], |
| @@ -1371,6 +1383,12 @@ defmodule LaviniaClass do | ||
| 1371 | 1383 | uproute: integer() | nil |
| 1372 | 1384 | } |
| 1373 | 1385 | |
| 1386 | + def decode_disdiapason(value) when is_binary(value), do: value | |
| 1387 | + def decode_disdiapason(_), do: {:error, "Unexpected type when decoding LaviniaClass.disdiapason"} | |
| 1388 | + | |
| 1389 | + def encode_disdiapason(value) when is_binary(value), do: value | |
| 1390 | + def encode_disdiapason(_), do: {:error, "Unexpected type when encoding LaviniaClass.disdiapason"} | |
| 1391 | + | |
| 1374 | 1392 | def from_map(m) do |
| 1375 | 1393 | %LaviniaClass{ |
| 1376 | 1394 | agitable: m["agitable"], |
| @@ -1381,7 +1399,7 @@ defmodule LaviniaClass do | ||
| 1381 | 1399 | chirotherium: m["Chirotherium"], |
| 1382 | 1400 | cholesteatomatous: m["cholesteatomatous"], |
| 1383 | 1401 | deprivement: m["deprivement"], |
| 1384 | - disdiapason: m["disdiapason"], | |
| 1402 | + disdiapason: m["disdiapason"] && decode_disdiapason(m["disdiapason"]), | |
| 1385 | 1403 | flippantness: m["flippantness"], |
| 1386 | 1404 | fogproof: m["fogproof"], |
| 1387 | 1405 | homocerc: m["homocerc"], |
Test case
1 generated file · +35 −5test/inputs/json/priority/combinations3.json
Melixirdefault / QuickType.ex+35 −5
| @@ -666,6 +666,12 @@ defmodule LupusClass do | ||
| 666 | 666 | vendible: integer() | nil |
| 667 | 667 | } |
| 668 | 668 | |
| 669 | + def decode_disdiapason(value) when is_binary(value), do: value | |
| 670 | + def decode_disdiapason(_), do: {:error, "Unexpected type when decoding LupusClass.disdiapason"} | |
| 671 | + | |
| 672 | + def encode_disdiapason(value) when is_binary(value), do: value | |
| 673 | + def encode_disdiapason(_), do: {:error, "Unexpected type when encoding LupusClass.disdiapason"} | |
| 674 | + | |
| 669 | 675 | def from_map(m) do |
| 670 | 676 | %LupusClass{ |
| 671 | 677 | catharticalness: m["catharticalness"], |
| @@ -673,7 +679,7 @@ defmodule LupusClass do | ||
| 673 | 679 | chlorioninae: m["Chlorioninae"], |
| 674 | 680 | corvinae: m["Corvinae"], |
| 675 | 681 | crassina: m["Crassina"], |
| 676 | - disdiapason: m["disdiapason"], | |
| 682 | + disdiapason: m["disdiapason"] && decode_disdiapason(m["disdiapason"]), | |
| 677 | 683 | exiguity: m["exiguity"], |
| 678 | 684 | farcist: m["farcist"], |
| 679 | 685 | holographical: m["holographical"], |
| @@ -790,6 +796,12 @@ defmodule Maslin do | ||
| 790 | 796 | unjudiciously: nil | nil |
| 791 | 797 | } |
| 792 | 798 | |
| 799 | + def decode_disdiapason(value) when is_binary(value), do: value | |
| 800 | + def decode_disdiapason(_), do: {:error, "Unexpected type when decoding Maslin.disdiapason"} | |
| 801 | + | |
| 802 | + def encode_disdiapason(value) when is_binary(value), do: value | |
| 803 | + def encode_disdiapason(_), do: {:error, "Unexpected type when encoding Maslin.disdiapason"} | |
| 804 | + | |
| 793 | 805 | def from_map(m) do |
| 794 | 806 | %Maslin{ |
| 795 | 807 | alicant: m["Alicant"], |
| @@ -805,7 +817,7 @@ defmodule Maslin do | ||
| 805 | 817 | curtailedly: m["curtailedly"], |
| 806 | 818 | dellenite: m["dellenite"], |
| 807 | 819 | dimitry: m["Dimitry"], |
| 808 | - disdiapason: m["disdiapason"], | |
| 820 | + disdiapason: m["disdiapason"] && decode_disdiapason(m["disdiapason"]), | |
| 809 | 821 | edifying: m["edifying"], |
| 810 | 822 | ethmoiditis: m["ethmoiditis"], |
| 811 | 823 | gastralgy: m["gastralgy"], |
| @@ -1011,6 +1023,12 @@ defmodule MonotheisticallyClass do | ||
| 1011 | 1023 | whitestone: nil | nil |
| 1012 | 1024 | } |
| 1013 | 1025 | |
| 1026 | + def decode_disdiapason(value) when is_binary(value), do: value | |
| 1027 | + def decode_disdiapason(_), do: {:error, "Unexpected type when decoding MonotheisticallyClass.disdiapason"} | |
| 1028 | + | |
| 1029 | + def encode_disdiapason(value) when is_binary(value), do: value | |
| 1030 | + def encode_disdiapason(_), do: {:error, "Unexpected type when encoding MonotheisticallyClass.disdiapason"} | |
| 1031 | + | |
| 1014 | 1032 | def from_map(m) do |
| 1015 | 1033 | %MonotheisticallyClass{ |
| 1016 | 1034 | blaspheme: m["blaspheme"], |
| @@ -1018,7 +1036,7 @@ defmodule MonotheisticallyClass do | ||
| 1018 | 1036 | celiosalpingectomy: m["celiosalpingectomy"], |
| 1019 | 1037 | chirotherium: m["Chirotherium"], |
| 1020 | 1038 | consummativeness: m["consummativeness"], |
| 1021 | - disdiapason: m["disdiapason"], | |
| 1039 | + disdiapason: m["disdiapason"] && decode_disdiapason(m["disdiapason"]), | |
| 1022 | 1040 | egestive: m["egestive"], |
| 1023 | 1041 | enchylema: m["enchylema"], |
| 1024 | 1042 | gasconade: m["gasconade"], |
| @@ -1612,6 +1630,12 @@ defmodule PiaculumClass do | ||
| 1612 | 1630 | zipper: integer() | nil |
| 1613 | 1631 | } |
| 1614 | 1632 | |
| 1633 | + def decode_disdiapason(value) when is_binary(value), do: value | |
| 1634 | + def decode_disdiapason(_), do: {:error, "Unexpected type when decoding PiaculumClass.disdiapason"} | |
| 1635 | + | |
| 1636 | + def encode_disdiapason(value) when is_binary(value), do: value | |
| 1637 | + def encode_disdiapason(_), do: {:error, "Unexpected type when encoding PiaculumClass.disdiapason"} | |
| 1638 | + | |
| 1615 | 1639 | def from_map(m) do |
| 1616 | 1640 | %PiaculumClass{ |
| 1617 | 1641 | alada: m["alada"], |
| @@ -1621,7 +1645,7 @@ defmodule PiaculumClass do | ||
| 1621 | 1645 | chirotherium: m["Chirotherium"], |
| 1622 | 1646 | decardinalize: m["decardinalize"], |
| 1623 | 1647 | discouragement: m["discouragement"], |
| 1624 | - disdiapason: m["disdiapason"], | |
| 1648 | + disdiapason: m["disdiapason"] && decode_disdiapason(m["disdiapason"]), | |
| 1625 | 1649 | doitrified: m["doitrified"], |
| 1626 | 1650 | hexaspermous: m["hexaspermous"], |
| 1627 | 1651 | homocerc: m["homocerc"], |
| @@ -1716,6 +1740,12 @@ defmodule Pneumocele do | ||
| 1716 | 1740 | visitorial: nil | nil |
| 1717 | 1741 | } |
| 1718 | 1742 | |
| 1743 | + def decode_disdiapason(value) when is_binary(value), do: value | |
| 1744 | + def decode_disdiapason(_), do: {:error, "Unexpected type when decoding Pneumocele.disdiapason"} | |
| 1745 | + | |
| 1746 | + def encode_disdiapason(value) when is_binary(value), do: value | |
| 1747 | + def encode_disdiapason(_), do: {:error, "Unexpected type when encoding Pneumocele.disdiapason"} | |
| 1748 | + | |
| 1719 | 1749 | def from_map(m) do |
| 1720 | 1750 | %Pneumocele{ |
| 1721 | 1751 | carbonarism: m["Carbonarism"], |
| @@ -1725,7 +1755,7 @@ defmodule Pneumocele do | ||
| 1725 | 1755 | cobbly: m["cobbly"], |
| 1726 | 1756 | conchyliferous: m["conchyliferous"], |
| 1727 | 1757 | congregation: m["congregation"], |
| 1728 | - disdiapason: m["disdiapason"], | |
| 1758 | + disdiapason: m["disdiapason"] && decode_disdiapason(m["disdiapason"]), | |
| 1729 | 1759 | enterotomy: m["enterotomy"], |
| 1730 | 1760 | entophytal: m["entophytal"], |
| 1731 | 1761 | fewtrils: m["fewtrils"], |
Test case
1 generated file · +42 −6test/inputs/json/priority/combinations4.json
Melixirdefault / QuickType.ex+42 −6
| @@ -533,6 +533,12 @@ defmodule Reimagine do | ||
| 533 | 533 | waltzlike: nil | nil |
| 534 | 534 | } |
| 535 | 535 | |
| 536 | + def decode_disdiapason(value) when is_binary(value), do: value | |
| 537 | + def decode_disdiapason(_), do: {:error, "Unexpected type when decoding Reimagine.disdiapason"} | |
| 538 | + | |
| 539 | + def encode_disdiapason(value) when is_binary(value), do: value | |
| 540 | + def encode_disdiapason(_), do: {:error, "Unexpected type when encoding Reimagine.disdiapason"} | |
| 541 | + | |
| 536 | 542 | def from_map(m) do |
| 537 | 543 | %Reimagine{ |
| 538 | 544 | adducible: m["adducible"], |
| @@ -541,7 +547,7 @@ defmodule Reimagine do | ||
| 541 | 547 | catharticalness: m["catharticalness"], |
| 542 | 548 | chirotherium: m["Chirotherium"], |
| 543 | 549 | chrysamine: m["chrysamine"], |
| 544 | - disdiapason: m["disdiapason"], | |
| 550 | + disdiapason: m["disdiapason"] && decode_disdiapason(m["disdiapason"]), | |
| 545 | 551 | fluxweed: m["fluxweed"], |
| 546 | 552 | glaucine: m["glaucine"], |
| 547 | 553 | grobianism: m["grobianism"], |
| @@ -1267,6 +1273,12 @@ defmodule SaxtenClass do | ||
| 1267 | 1273 | withdrawnness: nil | nil |
| 1268 | 1274 | } |
| 1269 | 1275 | |
| 1276 | + def decode_disdiapason(value) when is_binary(value), do: value | |
| 1277 | + def decode_disdiapason(_), do: {:error, "Unexpected type when decoding SaxtenClass.disdiapason"} | |
| 1278 | + | |
| 1279 | + def encode_disdiapason(value) when is_binary(value), do: value | |
| 1280 | + def encode_disdiapason(_), do: {:error, "Unexpected type when encoding SaxtenClass.disdiapason"} | |
| 1281 | + | |
| 1270 | 1282 | def from_map(m) do |
| 1271 | 1283 | %SaxtenClass{ |
| 1272 | 1284 | algarrobilla: m["algarrobilla"], |
| @@ -1274,7 +1286,7 @@ defmodule SaxtenClass do | ||
| 1274 | 1286 | catharticalness: m["catharticalness"], |
| 1275 | 1287 | centaurid: m["Centaurid"], |
| 1276 | 1288 | chirotherium: m["Chirotherium"], |
| 1277 | - disdiapason: m["disdiapason"], | |
| 1289 | + disdiapason: m["disdiapason"] && decode_disdiapason(m["disdiapason"]), | |
| 1278 | 1290 | flix: m["flix"], |
| 1279 | 1291 | germanely: m["germanely"], |
| 1280 | 1292 | homocerc: m["homocerc"], |
| @@ -1791,13 +1803,19 @@ defmodule Staghunting do | ||
| 1791 | 1803 | ungirlish: integer() | nil |
| 1792 | 1804 | } |
| 1793 | 1805 | |
| 1806 | + def decode_disdiapason(value) when is_binary(value), do: value | |
| 1807 | + def decode_disdiapason(_), do: {:error, "Unexpected type when decoding Staghunting.disdiapason"} | |
| 1808 | + | |
| 1809 | + def encode_disdiapason(value) when is_binary(value), do: value | |
| 1810 | + def encode_disdiapason(_), do: {:error, "Unexpected type when encoding Staghunting.disdiapason"} | |
| 1811 | + | |
| 1794 | 1812 | def from_map(m) do |
| 1795 | 1813 | %Staghunting{ |
| 1796 | 1814 | calorimetric: m["calorimetric"], |
| 1797 | 1815 | canid: m["canid"], |
| 1798 | 1816 | catharticalness: m["catharticalness"], |
| 1799 | 1817 | chirotherium: m["Chirotherium"], |
| 1800 | - disdiapason: m["disdiapason"], | |
| 1818 | + disdiapason: m["disdiapason"] && decode_disdiapason(m["disdiapason"]), | |
| 1801 | 1819 | ditriglyphic: m["ditriglyphic"], |
| 1802 | 1820 | floriferousness: m["floriferousness"], |
| 1803 | 1821 | gamelike: m["gamelike"], |
| @@ -1895,6 +1913,12 @@ defmodule StrenuosityClass do | ||
| 1895 | 1913 | yankeeist: integer() | nil |
| 1896 | 1914 | } |
| 1897 | 1915 | |
| 1916 | + def decode_disdiapason(value) when is_binary(value), do: value | |
| 1917 | + def decode_disdiapason(_), do: {:error, "Unexpected type when decoding StrenuosityClass.disdiapason"} | |
| 1918 | + | |
| 1919 | + def encode_disdiapason(value) when is_binary(value), do: value | |
| 1920 | + def encode_disdiapason(_), do: {:error, "Unexpected type when encoding StrenuosityClass.disdiapason"} | |
| 1921 | + | |
| 1898 | 1922 | def from_map(m) do |
| 1899 | 1923 | %StrenuosityClass{ |
| 1900 | 1924 | bliss: m["bliss"], |
| @@ -1903,7 +1927,7 @@ defmodule StrenuosityClass do | ||
| 1903 | 1927 | catharticalness: m["catharticalness"], |
| 1904 | 1928 | chirotherium: m["Chirotherium"], |
| 1905 | 1929 | crumblingness: m["crumblingness"], |
| 1906 | - disdiapason: m["disdiapason"], | |
| 1930 | + disdiapason: m["disdiapason"] && decode_disdiapason(m["disdiapason"]), | |
| 1907 | 1931 | engagedly: m["engagedly"], |
| 1908 | 1932 | fightable: m["fightable"], |
| 1909 | 1933 | hoariness: m["hoariness"], |
| @@ -1999,6 +2023,12 @@ defmodule TruantcyClass do | ||
| 1999 | 2023 | yuman: nil | nil |
| 2000 | 2024 | } |
| 2001 | 2025 | |
| 2026 | + def decode_disdiapason(value) when is_binary(value), do: value | |
| 2027 | + def decode_disdiapason(_), do: {:error, "Unexpected type when decoding TruantcyClass.disdiapason"} | |
| 2028 | + | |
| 2029 | + def encode_disdiapason(value) when is_binary(value), do: value | |
| 2030 | + def encode_disdiapason(_), do: {:error, "Unexpected type when encoding TruantcyClass.disdiapason"} | |
| 2031 | + | |
| 2002 | 2032 | def from_map(m) do |
| 2003 | 2033 | %TruantcyClass{ |
| 2004 | 2034 | alfiona: m["alfiona"], |
| @@ -2008,7 +2038,7 @@ defmodule TruantcyClass do | ||
| 2008 | 2038 | ceroxyle: m["ceroxyle"], |
| 2009 | 2039 | chirotherium: m["Chirotherium"], |
| 2010 | 2040 | chorology: m["chorology"], |
| 2011 | - disdiapason: m["disdiapason"], | |
| 2041 | + disdiapason: m["disdiapason"] && decode_disdiapason(m["disdiapason"]), | |
| 2012 | 2042 | enmarble: m["enmarble"], |
| 2013 | 2043 | epeira: m["Epeira"], |
| 2014 | 2044 | eurylaimi: m["Eurylaimi"], |
| @@ -2103,6 +2133,12 @@ defmodule UnimpeachablyClass do | ||
| 2103 | 2133 | unsuggestedness: integer() | nil |
| 2104 | 2134 | } |
| 2105 | 2135 | |
| 2136 | + def decode_disdiapason(value) when is_binary(value), do: value | |
| 2137 | + def decode_disdiapason(_), do: {:error, "Unexpected type when decoding UnimpeachablyClass.disdiapason"} | |
| 2138 | + | |
| 2139 | + def encode_disdiapason(value) when is_binary(value), do: value | |
| 2140 | + def encode_disdiapason(_), do: {:error, "Unexpected type when encoding UnimpeachablyClass.disdiapason"} | |
| 2141 | + | |
| 2106 | 2142 | def from_map(m) do |
| 2107 | 2143 | %UnimpeachablyClass{ |
| 2108 | 2144 | acerin: m["acerin"], |
| @@ -2112,7 +2148,7 @@ defmodule UnimpeachablyClass do | ||
| 2112 | 2148 | chlorophylligenous: m["chlorophylligenous"], |
| 2113 | 2149 | conversational: m["conversational"], |
| 2114 | 2150 | demiowl: m["demiowl"], |
| 2115 | - disdiapason: m["disdiapason"], | |
| 2151 | + disdiapason: m["disdiapason"] && decode_disdiapason(m["disdiapason"]), | |
| 2116 | 2152 | ectorhinal: m["ectorhinal"], |
| 2117 | 2153 | gamblesomeness: m["gamblesomeness"], |
| 2118 | 2154 | homocerc: m["homocerc"], |
Test case
1 generated file · +7 −1test/inputs/json/priority/empty-enum.json
Melixirdefault / QuickType.ex+7 −1
| @@ -12,9 +12,15 @@ defmodule Foo do | ||
| 12 | 12 | bar: String.t() | nil |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | + def decode_bar(value) when is_binary(value), do: value | |
| 16 | + def decode_bar(_), do: {:error, "Unexpected type when decoding Foo.bar"} | |
| 17 | + | |
| 18 | + def encode_bar(value) when is_binary(value), do: value | |
| 19 | + def encode_bar(_), do: {:error, "Unexpected type when encoding Foo.bar"} | |
| 20 | + | |
| 15 | 21 | def from_map(m) do |
| 16 | 22 | %Foo{ |
| 17 | - bar: m["bar"], | |
| 23 | + bar: m["bar"] && decode_bar(m["bar"]), | |
| 18 | 24 | } |
| 19 | 25 | end |
Test case
1 generated file · +84 −12test/inputs/json/priority/nbl-stats.json
Melixirdefault / QuickType.ex+84 −12
| @@ -529,12 +529,36 @@ defmodule Pbp do | ||
| 529 | 529 | tno: integer() |
| 530 | 530 | } |
| 531 | 531 | |
| 532 | + def decode_family_name(value) when is_binary(value), do: value | |
| 533 | + def decode_family_name(_), do: {:error, "Unexpected type when decoding Pbp.family_name"} | |
| 534 | + | |
| 535 | + def encode_family_name(value) when is_binary(value), do: value | |
| 536 | + def encode_family_name(_), do: {:error, "Unexpected type when encoding Pbp.family_name"} | |
| 537 | + | |
| 538 | + def decode_first_name(value) when is_binary(value), do: value | |
| 539 | + def decode_first_name(_), do: {:error, "Unexpected type when decoding Pbp.first_name"} | |
| 540 | + | |
| 541 | + def encode_first_name(value) when is_binary(value), do: value | |
| 542 | + def encode_first_name(_), do: {:error, "Unexpected type when encoding Pbp.first_name"} | |
| 543 | + | |
| 532 | 544 | def decode_gt(value) when is_binary(value), do: value |
| 533 | 545 | def decode_gt(_), do: {:error, "Unexpected type when decoding Pbp.gt"} |
| 534 | 546 | |
| 535 | 547 | def encode_gt(value) when is_binary(value), do: value |
| 536 | 548 | def encode_gt(_), do: {:error, "Unexpected type when encoding Pbp.gt"} |
| 537 | 549 | |
| 550 | + def decode_international_family_name(value) when is_binary(value), do: value | |
| 551 | + def decode_international_family_name(_), do: {:error, "Unexpected type when decoding Pbp.international_family_name"} | |
| 552 | + | |
| 553 | + def encode_international_family_name(value) when is_binary(value), do: value | |
| 554 | + def encode_international_family_name(_), do: {:error, "Unexpected type when encoding Pbp.international_family_name"} | |
| 555 | + | |
| 556 | + def decode_international_first_name(value) when is_binary(value), do: value | |
| 557 | + def decode_international_first_name(_), do: {:error, "Unexpected type when decoding Pbp.international_first_name"} | |
| 558 | + | |
| 559 | + def encode_international_first_name(value) when is_binary(value), do: value | |
| 560 | + def encode_international_first_name(_), do: {:error, "Unexpected type when encoding Pbp.international_first_name"} | |
| 561 | + | |
| 538 | 562 | def decode_lead(value) when is_integer(value), do: value |
| 539 | 563 | def decode_lead(_), do: {:error, "Unexpected type when decoding Pbp.lead"} |
| 540 | 564 | |
| @@ -610,14 +634,14 @@ defmodule Pbp do | ||
| 610 | 634 | def from_map(m) do |
| 611 | 635 | %Pbp{ |
| 612 | 636 | action_type: ActionType.decode(m["actionType"]), |
| 613 | - family_name: m["familyName"], | |
| 637 | + family_name: m["familyName"] && decode_family_name(m["familyName"]), | |
| 614 | 638 | family_name_initial: m["familyNameInitial"] && FamilyNameInitial.decode(m["familyNameInitial"]), |
| 615 | - first_name: m["firstName"], | |
| 639 | + first_name: m["firstName"] && decode_first_name(m["firstName"]), | |
| 616 | 640 | first_name_initial: m["firstNameInitial"] && FirstNameInitial.decode(m["firstNameInitial"]), |
| 617 | 641 | gt: decode_gt(m["gt"]), |
| 618 | - international_family_name: m["internationalFamilyName"], | |
| 642 | + international_family_name: m["internationalFamilyName"] && decode_international_family_name(m["internationalFamilyName"]), | |
| 619 | 643 | international_family_name_initial: m["internationalFamilyNameInitial"] && FamilyNameInitial.decode(m["internationalFamilyNameInitial"]), |
| 620 | - international_first_name: m["internationalFirstName"], | |
| 644 | + international_first_name: m["internationalFirstName"] && decode_international_first_name(m["internationalFirstName"]), | |
| 621 | 645 | international_first_name_initial: m["internationalFirstNameInitial"] && FirstNameInitial.decode(m["internationalFirstNameInitial"]), |
| 622 | 646 | lead: decode_lead(m["lead"]), |
| 623 | 647 | period: decode_period(m["period"]), |
| @@ -756,6 +780,48 @@ defmodule Scorer do | ||
| 756 | 780 | tot: integer() | nil |
| 757 | 781 | } |
| 758 | 782 | |
| 783 | + def decode_family_name(value) when is_binary(value), do: value | |
| 784 | + def decode_family_name(_), do: {:error, "Unexpected type when decoding Scorer.family_name"} | |
| 785 | + | |
| 786 | + def encode_family_name(value) when is_binary(value), do: value | |
| 787 | + def encode_family_name(_), do: {:error, "Unexpected type when encoding Scorer.family_name"} | |
| 788 | + | |
| 789 | + def decode_first_name(value) when is_binary(value), do: value | |
| 790 | + def decode_first_name(_), do: {:error, "Unexpected type when decoding Scorer.first_name"} | |
| 791 | + | |
| 792 | + def encode_first_name(value) when is_binary(value), do: value | |
| 793 | + def encode_first_name(_), do: {:error, "Unexpected type when encoding Scorer.first_name"} | |
| 794 | + | |
| 795 | + def decode_gt(value) when is_binary(value), do: value | |
| 796 | + def decode_gt(_), do: {:error, "Unexpected type when decoding Scorer.gt"} | |
| 797 | + | |
| 798 | + def encode_gt(value) when is_binary(value), do: value | |
| 799 | + def encode_gt(_), do: {:error, "Unexpected type when encoding Scorer.gt"} | |
| 800 | + | |
| 801 | + def decode_international_family_name(value) when is_binary(value), do: value | |
| 802 | + def decode_international_family_name(_), do: {:error, "Unexpected type when decoding Scorer.international_family_name"} | |
| 803 | + | |
| 804 | + def encode_international_family_name(value) when is_binary(value), do: value | |
| 805 | + def encode_international_family_name(_), do: {:error, "Unexpected type when encoding Scorer.international_family_name"} | |
| 806 | + | |
| 807 | + def decode_international_first_name(value) when is_binary(value), do: value | |
| 808 | + def decode_international_first_name(_), do: {:error, "Unexpected type when decoding Scorer.international_first_name"} | |
| 809 | + | |
| 810 | + def encode_international_first_name(value) when is_binary(value), do: value | |
| 811 | + def encode_international_first_name(_), do: {:error, "Unexpected type when encoding Scorer.international_first_name"} | |
| 812 | + | |
| 813 | + def decode_name(value) when is_binary(value), do: value | |
| 814 | + def decode_name(_), do: {:error, "Unexpected type when decoding Scorer.name"} | |
| 815 | + | |
| 816 | + def encode_name(value) when is_binary(value), do: value | |
| 817 | + def encode_name(_), do: {:error, "Unexpected type when encoding Scorer.name"} | |
| 818 | + | |
| 819 | + def decode_player(value) when is_binary(value), do: value | |
| 820 | + def decode_player(_), do: {:error, "Unexpected type when decoding Scorer.player"} | |
| 821 | + | |
| 822 | + def encode_player(value) when is_binary(value), do: value | |
| 823 | + def encode_player(_), do: {:error, "Unexpected type when encoding Scorer.player"} | |
| 824 | + | |
| 759 | 825 | def decode_pno(value) when is_integer(value), do: value |
| 760 | 826 | def decode_pno(_), do: {:error, "Unexpected type when decoding Scorer.pno"} |
| 761 | 827 | |
| @@ -768,6 +834,12 @@ defmodule Scorer do | ||
| 768 | 834 | def encode_shirt_number(value) when is_binary(value), do: value |
| 769 | 835 | def encode_shirt_number(_), do: {:error, "Unexpected type when encoding Scorer.shirt_number"} |
| 770 | 836 | |
| 837 | + def decode_summary(value) when is_binary(value), do: value | |
| 838 | + def decode_summary(_), do: {:error, "Unexpected type when decoding Scorer.summary"} | |
| 839 | + | |
| 840 | + def encode_summary(value) when is_binary(value), do: value | |
| 841 | + def encode_summary(_), do: {:error, "Unexpected type when encoding Scorer.summary"} | |
| 842 | + | |
| 771 | 843 | def decode_tno(value) when is_integer(value), do: value |
| 772 | 844 | def decode_tno(_), do: {:error, "Unexpected type when decoding Scorer.tno"} |
| 773 | 845 | |
| @@ -776,23 +848,23 @@ defmodule Scorer do | ||
| 776 | 848 | |
| 777 | 849 | def from_map(m) do |
| 778 | 850 | %Scorer{ |
| 779 | - family_name: m["familyName"], | |
| 851 | + family_name: m["familyName"] && decode_family_name(m["familyName"]), | |
| 780 | 852 | family_name_initial: m["familyNameInitial"] && FamilyNameInitial.decode(m["familyNameInitial"]), |
| 781 | - first_name: m["firstName"], | |
| 853 | + first_name: m["firstName"] && decode_first_name(m["firstName"]), | |
| 782 | 854 | first_name_initial: m["firstNameInitial"] && FirstNameInitial.decode(m["firstNameInitial"]), |
| 783 | - gt: m["gt"], | |
| 784 | - international_family_name: m["internationalFamilyName"], | |
| 855 | + gt: m["gt"] && decode_gt(m["gt"]), | |
| 856 | + international_family_name: m["internationalFamilyName"] && decode_international_family_name(m["internationalFamilyName"]), | |
| 785 | 857 | international_family_name_initial: m["internationalFamilyNameInitial"] && FamilyNameInitial.decode(m["internationalFamilyNameInitial"]), |
| 786 | - international_first_name: m["internationalFirstName"], | |
| 858 | + international_first_name: m["internationalFirstName"] && decode_international_first_name(m["internationalFirstName"]), | |
| 787 | 859 | international_first_name_initial: m["internationalFirstNameInitial"] && FirstNameInitial.decode(m["internationalFirstNameInitial"]), |
| 788 | - name: m["name"], | |
| 860 | + name: m["name"] && decode_name(m["name"]), | |
| 789 | 861 | per: m["per"], |
| 790 | 862 | per_type: m["perType"] && PerType.decode(m["perType"]), |
| 791 | - player: m["player"], | |
| 863 | + player: m["player"] && decode_player(m["player"]), | |
| 792 | 864 | pno: decode_pno(m["pno"]), |
| 793 | 865 | scoreboard_name: m["scoreboardName"] && ScoreboardName.decode(m["scoreboardName"]), |
| 794 | 866 | shirt_number: decode_shirt_number(m["shirtNumber"]), |
| 795 | - summary: m["summary"], | |
| 867 | + summary: m["summary"] && decode_summary(m["summary"]), | |
| 796 | 868 | times: m["times"] && Enum.map(m["times"], &TimeElement.from_map/1), |
| 797 | 869 | tno: decode_tno(m["tno"]), |
| 798 | 870 | tot: m["tot"], |
Test case
1 generated file · +63 −9test/inputs/json/samples/github-events.json
Melixirdefault / QuickType.ex+63 −9
| @@ -24,6 +24,12 @@ defmodule Actor do | ||
| 24 | 24 | def encode_avatar_url(value) when is_binary(value), do: value |
| 25 | 25 | def encode_avatar_url(_), do: {:error, "Unexpected type when encoding Actor.avatar_url"} |
| 26 | 26 | |
| 27 | + def decode_display_login(value) when is_binary(value), do: value | |
| 28 | + def decode_display_login(_), do: {:error, "Unexpected type when decoding Actor.display_login"} | |
| 29 | + | |
| 30 | + def encode_display_login(value) when is_binary(value), do: value | |
| 31 | + def encode_display_login(_), do: {:error, "Unexpected type when encoding Actor.display_login"} | |
| 32 | + | |
| 27 | 33 | def decode_gravatar_id(value) when is_binary(value), do: value |
| 28 | 34 | def decode_gravatar_id(_), do: {:error, "Unexpected type when decoding Actor.gravatar_id"} |
| 29 | 35 | |
| @@ -51,7 +57,7 @@ defmodule Actor do | ||
| 51 | 57 | def from_map(m) do |
| 52 | 58 | %Actor{ |
| 53 | 59 | avatar_url: decode_avatar_url(m["avatar_url"]), |
| 54 | - display_login: m["display_login"], | |
| 60 | + display_login: m["display_login"] && decode_display_login(m["display_login"]), | |
| 55 | 61 | gravatar_id: decode_gravatar_id(m["gravatar_id"]), |
| 56 | 62 | id: decode_id(m["id"]), |
| 57 | 63 | login: decode_login(m["login"]), |
| @@ -2209,23 +2215,71 @@ defmodule Payload do | ||
| 2209 | 2215 | size: integer() | nil |
| 2210 | 2216 | } |
| 2211 | 2217 | |
| 2218 | + def decode_action(value) when is_binary(value), do: value | |
| 2219 | + def decode_action(_), do: {:error, "Unexpected type when decoding Payload.action"} | |
| 2220 | + | |
| 2221 | + def encode_action(value) when is_binary(value), do: value | |
| 2222 | + def encode_action(_), do: {:error, "Unexpected type when encoding Payload.action"} | |
| 2223 | + | |
| 2224 | + def decode_before(value) when is_binary(value), do: value | |
| 2225 | + def decode_before(_), do: {:error, "Unexpected type when decoding Payload.before"} | |
| 2226 | + | |
| 2227 | + def encode_before(value) when is_binary(value), do: value | |
| 2228 | + def encode_before(_), do: {:error, "Unexpected type when encoding Payload.before"} | |
| 2229 | + | |
| 2230 | + def decode_description(value) when is_binary(value), do: value | |
| 2231 | + def decode_description(_), do: {:error, "Unexpected type when decoding Payload.description"} | |
| 2232 | + | |
| 2233 | + def encode_description(value) when is_binary(value), do: value | |
| 2234 | + def encode_description(_), do: {:error, "Unexpected type when encoding Payload.description"} | |
| 2235 | + | |
| 2236 | + def decode_head(value) when is_binary(value), do: value | |
| 2237 | + def decode_head(_), do: {:error, "Unexpected type when decoding Payload.head"} | |
| 2238 | + | |
| 2239 | + def encode_head(value) when is_binary(value), do: value | |
| 2240 | + def encode_head(_), do: {:error, "Unexpected type when encoding Payload.head"} | |
| 2241 | + | |
| 2242 | + def decode_master_branch(value) when is_binary(value), do: value | |
| 2243 | + def decode_master_branch(_), do: {:error, "Unexpected type when decoding Payload.master_branch"} | |
| 2244 | + | |
| 2245 | + def encode_master_branch(value) when is_binary(value), do: value | |
| 2246 | + def encode_master_branch(_), do: {:error, "Unexpected type when encoding Payload.master_branch"} | |
| 2247 | + | |
| 2248 | + def decode_pusher_type(value) when is_binary(value), do: value | |
| 2249 | + def decode_pusher_type(_), do: {:error, "Unexpected type when decoding Payload.pusher_type"} | |
| 2250 | + | |
| 2251 | + def encode_pusher_type(value) when is_binary(value), do: value | |
| 2252 | + def encode_pusher_type(_), do: {:error, "Unexpected type when encoding Payload.pusher_type"} | |
| 2253 | + | |
| 2254 | + def decode_ref(value) when is_binary(value), do: value | |
| 2255 | + def decode_ref(_), do: {:error, "Unexpected type when decoding Payload.ref"} | |
| 2256 | + | |
| 2257 | + def encode_ref(value) when is_binary(value), do: value | |
| 2258 | + def encode_ref(_), do: {:error, "Unexpected type when encoding Payload.ref"} | |
| 2259 | + | |
| 2260 | + def decode_ref_type(value) when is_binary(value), do: value | |
| 2261 | + def decode_ref_type(_), do: {:error, "Unexpected type when decoding Payload.ref_type"} | |
| 2262 | + | |
| 2263 | + def encode_ref_type(value) when is_binary(value), do: value | |
| 2264 | + def encode_ref_type(_), do: {:error, "Unexpected type when encoding Payload.ref_type"} | |
| 2265 | + | |
| 2212 | 2266 | def from_map(m) do |
| 2213 | 2267 | %Payload{ |
| 2214 | - action: m["action"], | |
| 2215 | - before: m["before"], | |
| 2268 | + action: m["action"] && decode_action(m["action"]), | |
| 2269 | + before: m["before"] && decode_before(m["before"]), | |
| 2216 | 2270 | comment: m["comment"] && Comment.from_map(m["comment"]), |
| 2217 | 2271 | commits: m["commits"] && Enum.map(m["commits"], &Commit.from_map/1), |
| 2218 | - description: m["description"], | |
| 2272 | + description: m["description"] && decode_description(m["description"]), | |
| 2219 | 2273 | distinct_size: m["distinct_size"], |
| 2220 | - head: m["head"], | |
| 2274 | + head: m["head"] && decode_head(m["head"]), | |
| 2221 | 2275 | issue: m["issue"] && Issue.from_map(m["issue"]), |
| 2222 | - master_branch: m["master_branch"], | |
| 2276 | + master_branch: m["master_branch"] && decode_master_branch(m["master_branch"]), | |
| 2223 | 2277 | number: m["number"], |
| 2224 | 2278 | pull_request: m["pull_request"] && PayloadPullRequest.from_map(m["pull_request"]), |
| 2225 | 2279 | push_id: m["push_id"], |
| 2226 | - pusher_type: m["pusher_type"], | |
| 2227 | - ref: m["ref"], | |
| 2228 | - ref_type: m["ref_type"], | |
| 2280 | + pusher_type: m["pusher_type"] && decode_pusher_type(m["pusher_type"]), | |
| 2281 | + ref: m["ref"] && decode_ref(m["ref"]), | |
| 2282 | + ref_type: m["ref_type"] && decode_ref_type(m["ref_type"]), | |
| 2229 | 2283 | size: m["size"], |
| 2230 | 2284 | } |
| 2231 | 2285 | end |
Test case
1 generated file · +7 −1test/inputs/json/samples/null-safe.json
Melixirdefault / QuickType.ex+7 −1
| @@ -73,6 +73,12 @@ defmodule Item do | ||
| 73 | 73 | sex: integer() | nil |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | + def decode_created_at(value) when is_binary(value), do: value | |
| 77 | + def decode_created_at(_), do: {:error, "Unexpected type when decoding Item.created_at"} | |
| 78 | + | |
| 79 | + def encode_created_at(value) when is_binary(value), do: value | |
| 80 | + def encode_created_at(_), do: {:error, "Unexpected type when encoding Item.created_at"} | |
| 81 | + | |
| 76 | 82 | def decode_name(value) when is_binary(value), do: value |
| 77 | 83 | def decode_name(_), do: {:error, "Unexpected type when decoding Item.name"} |
| 78 | 84 | |
| @@ -82,7 +88,7 @@ defmodule Item do | ||
| 82 | 88 | def from_map(m) do |
| 83 | 89 | %Item{ |
| 84 | 90 | address: m["address"] && Address.from_map(m["address"]), |
| 85 | - created_at: m["created_at"], | |
| 91 | + created_at: m["created_at"] && decode_created_at(m["created_at"]), | |
| 86 | 92 | name: decode_name(m["name"]), |
| 87 | 93 | sex: Map.fetch!(m, "sex"), |
| 88 | 94 | } |
Test case
1 generated file · +14 −2test/inputs/json/samples/us-senators.json
Melixirdefault / QuickType.ex+14 −2
| @@ -133,19 +133,31 @@ defmodule Extra do | ||
| 133 | 133 | def encode_contact_form(value) when is_binary(value), do: value |
| 134 | 134 | def encode_contact_form(_), do: {:error, "Unexpected type when encoding Extra.contact_form"} |
| 135 | 135 | |
| 136 | + def decode_fax(value) when is_binary(value), do: value | |
| 137 | + def decode_fax(_), do: {:error, "Unexpected type when decoding Extra.fax"} | |
| 138 | + | |
| 139 | + def encode_fax(value) when is_binary(value), do: value | |
| 140 | + def encode_fax(_), do: {:error, "Unexpected type when encoding Extra.fax"} | |
| 141 | + | |
| 136 | 142 | def decode_office(value) when is_binary(value), do: value |
| 137 | 143 | def decode_office(_), do: {:error, "Unexpected type when decoding Extra.office"} |
| 138 | 144 | |
| 139 | 145 | def encode_office(value) when is_binary(value), do: value |
| 140 | 146 | def encode_office(_), do: {:error, "Unexpected type when encoding Extra.office"} |
| 141 | 147 | |
| 148 | + def decode_rss_url(value) when is_binary(value), do: value | |
| 149 | + def decode_rss_url(_), do: {:error, "Unexpected type when decoding Extra.rss_url"} | |
| 150 | + | |
| 151 | + def encode_rss_url(value) when is_binary(value), do: value | |
| 152 | + def encode_rss_url(_), do: {:error, "Unexpected type when encoding Extra.rss_url"} | |
| 153 | + | |
| 142 | 154 | def from_map(m) do |
| 143 | 155 | %Extra{ |
| 144 | 156 | address: decode_address(m["address"]), |
| 145 | 157 | contact_form: decode_contact_form(m["contact_form"]), |
| 146 | - fax: m["fax"], | |
| 158 | + fax: m["fax"] && decode_fax(m["fax"]), | |
| 147 | 159 | office: decode_office(m["office"]), |
| 148 | - rss_url: m["rss_url"], | |
| 160 | + rss_url: m["rss_url"] && decode_rss_url(m["rss_url"]), | |
| 149 | 161 | } |
| 150 | 162 | end |
Test case
1 generated file · +7 −1test/inputs/schema/all-of-additional-properties-false.schema
Mschema-elixirdefault / QuickType.ex+7 −1
| @@ -117,11 +117,17 @@ defmodule TopLevel do | ||
| 117 | 117 | def encode_amount(value) when is_integer(value), do: value |
| 118 | 118 | def encode_amount(_), do: {:error, "Unexpected type when encoding TopLevel.amount"} |
| 119 | 119 | |
| 120 | + def decode_description(value) when is_binary(value), do: value | |
| 121 | + def decode_description(_), do: {:error, "Unexpected type when decoding TopLevel.description"} | |
| 122 | + | |
| 123 | + def encode_description(value) when is_binary(value), do: value | |
| 124 | + def encode_description(_), do: {:error, "Unexpected type when encoding TopLevel.description"} | |
| 125 | + | |
| 120 | 126 | def from_map(m) do |
| 121 | 127 | %TopLevel{ |
| 122 | 128 | amount: decode_amount(m["amount"]), |
| 123 | 129 | frequency: Frequency.decode(m["frequency"]), |
| 124 | - description: m["description"], | |
| 130 | + description: m["description"] && decode_description(m["description"]), | |
| 125 | 131 | type: Type.decode(m["type"]), |
| 126 | 132 | } |
| 127 | 133 | end |
Test case
1 generated file · +7 −1test/inputs/schema/bool-string.schema
Mschema-elixirdefault / QuickType.ex+7 −1
| @@ -33,13 +33,19 @@ defmodule TopLevel do | ||
| 33 | 33 | def encode_one(value) when is_binary(value), do: value |
| 34 | 34 | def encode_one(_), do: {:error, "Unexpected type when encoding TopLevel.one"} |
| 35 | 35 | |
| 36 | + def decode_optional(value) when is_binary(value), do: value | |
| 37 | + def decode_optional(_), do: {:error, "Unexpected type when decoding TopLevel.optional"} | |
| 38 | + | |
| 39 | + def encode_optional(value) when is_binary(value), do: value | |
| 40 | + def encode_optional(_), do: {:error, "Unexpected type when encoding TopLevel.optional"} | |
| 41 | + | |
| 36 | 42 | def from_map(m) do |
| 37 | 43 | %TopLevel{ |
| 38 | 44 | arr_nullable: m["arrNullable"] && Enum.map(m["arrNullable"], &decode_arr_nullable_element/1), |
| 39 | 45 | arr_one: m["arrOne"], |
| 40 | 46 | nullable: Map.fetch!(m, "nullable"), |
| 41 | 47 | one: decode_one(m["one"]), |
| 42 | - optional: m["optional"], | |
| 48 | + optional: m["optional"] && decode_optional(m["optional"]), | |
| 43 | 49 | union_with_bool: Map.fetch!(m, "unionWithBool"), |
| 44 | 50 | union_with_bool_and_enum: Map.fetch!(m, "unionWithBoolAndEnum"), |
| 45 | 51 | } |
Test case
1 generated file · +14 −2test/inputs/schema/camelCase.schema
Mschema-elixirdefault / QuickType.ex+14 −2
| @@ -13,10 +13,22 @@ defmodule TopLevel do | ||
| 13 | 13 | second_property: String.t() | nil |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | + def decode_my_property(value) when is_binary(value), do: value | |
| 17 | + def decode_my_property(_), do: {:error, "Unexpected type when decoding TopLevel.my_property"} | |
| 18 | + | |
| 19 | + def encode_my_property(value) when is_binary(value), do: value | |
| 20 | + def encode_my_property(_), do: {:error, "Unexpected type when encoding TopLevel.my_property"} | |
| 21 | + | |
| 22 | + def decode_second_property(value) when is_binary(value), do: value | |
| 23 | + def decode_second_property(_), do: {:error, "Unexpected type when decoding TopLevel.second_property"} | |
| 24 | + | |
| 25 | + def encode_second_property(value) when is_binary(value), do: value | |
| 26 | + def encode_second_property(_), do: {:error, "Unexpected type when encoding TopLevel.second_property"} | |
| 27 | + | |
| 16 | 28 | def from_map(m) do |
| 17 | 29 | %TopLevel{ |
| 18 | - my_property: m["myProperty"], | |
| 19 | - second_property: m["secondProperty"], | |
| 30 | + my_property: m["myProperty"] && decode_my_property(m["myProperty"]), | |
| 31 | + second_property: m["secondProperty"] && decode_second_property(m["secondProperty"]), | |
| 20 | 32 | } |
| 21 | 33 | end |
Test case
1 generated file · +21 −3test/inputs/schema/comment-injection.schema
Mschema-elixirdefault / QuickType.ex+21 −3
| @@ -35,6 +35,24 @@ defmodule TopLevel do | ||
| 35 | 35 | value: String.t() |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | + def decode_trailing_backslash(value) when is_binary(value), do: value | |
| 39 | + def decode_trailing_backslash(_), do: {:error, "Unexpected type when decoding TopLevel.trailing_backslash"} | |
| 40 | + | |
| 41 | + def encode_trailing_backslash(value) when is_binary(value), do: value | |
| 42 | + def encode_trailing_backslash(_), do: {:error, "Unexpected type when encoding TopLevel.trailing_backslash"} | |
| 43 | + | |
| 44 | + def decode_trailing_quote(value) when is_binary(value), do: value | |
| 45 | + def decode_trailing_quote(_), do: {:error, "Unexpected type when decoding TopLevel.trailing_quote"} | |
| 46 | + | |
| 47 | + def encode_trailing_quote(value) when is_binary(value), do: value | |
| 48 | + def encode_trailing_quote(_), do: {:error, "Unexpected type when encoding TopLevel.trailing_quote"} | |
| 49 | + | |
| 50 | + def decode_trailing_triple_quote(value) when is_binary(value), do: value | |
| 51 | + def decode_trailing_triple_quote(_), do: {:error, "Unexpected type when decoding TopLevel.trailing_triple_quote"} | |
| 52 | + | |
| 53 | + def encode_trailing_triple_quote(value) when is_binary(value), do: value | |
| 54 | + def encode_trailing_triple_quote(_), do: {:error, "Unexpected type when encoding TopLevel.trailing_triple_quote"} | |
| 55 | + | |
| 38 | 56 | def decode_value(value) when is_binary(value), do: value |
| 39 | 57 | def decode_value(_), do: {:error, "Unexpected type when decoding TopLevel.value"} |
| 40 | 58 | |
| @@ -43,9 +61,9 @@ defmodule TopLevel do | ||
| 43 | 61 | |
| 44 | 62 | def from_map(m) do |
| 45 | 63 | %TopLevel{ |
| 46 | - trailing_backslash: m["trailingBackslash"], | |
| 47 | - trailing_quote: m["trailingQuote"], | |
| 48 | - trailing_triple_quote: m["trailingTripleQuote"], | |
| 64 | + trailing_backslash: m["trailingBackslash"] && decode_trailing_backslash(m["trailingBackslash"]), | |
| 65 | + trailing_quote: m["trailingQuote"] && decode_trailing_quote(m["trailingQuote"]), | |
| 66 | + trailing_triple_quote: m["trailingTripleQuote"] && decode_trailing_triple_quote(m["trailingTripleQuote"]), | |
| 49 | 67 | value: decode_value(m["value"]), |
| 50 | 68 | } |
| 51 | 69 | end |
Test case
1 generated file · +7 −1test/inputs/schema/enum.schema
Mschema-elixirdefault / QuickType.ex+7 −1
| @@ -166,10 +166,16 @@ defmodule TopLevel do | ||
| 166 | 166 | def encode_arr_element(value) when is_integer(value), do: value |
| 167 | 167 | def encode_arr_element(_), do: {:error, "Unexpected type when encoding TopLevel.arr"} |
| 168 | 168 | |
| 169 | + def decode_for(value) when is_binary(value), do: value | |
| 170 | + def decode_for(_), do: {:error, "Unexpected type when decoding TopLevel.for"} | |
| 171 | + | |
| 172 | + def encode_for(value) when is_binary(value), do: value | |
| 173 | + def encode_for(_), do: {:error, "Unexpected type when encoding TopLevel.for"} | |
| 174 | + | |
| 169 | 175 | def from_map(m) do |
| 170 | 176 | %TopLevel{ |
| 171 | 177 | arr: m["arr"] && Enum.map(m["arr"], &decode_arr_element/1), |
| 172 | - for: m["for"], | |
| 178 | + for: m["for"] && decode_for(m["for"]), | |
| 173 | 179 | gve: Gve.decode(m["gve"]), |
| 174 | 180 | lvc: m["lvc"] && Lvc.decode(m["lvc"]), |
| 175 | 181 | other_arr: m["otherArr"] && Enum.map(m["otherArr"], &OtherArr.decode/1), |
Test case
1 generated file · +7 −1test/inputs/schema/implicit-one-of.schema
Mschema-elixirdefault / QuickType.ex+7 −1
| @@ -21,11 +21,17 @@ defmodule TopLevel do | ||
| 21 | 21 | def encode_foo(value) when is_integer(value), do: value |
| 22 | 22 | def encode_foo(_), do: {:error, "Unexpected type when encoding TopLevel.foo"} |
| 23 | 23 | |
| 24 | + def decode_quux(value) when is_binary(value), do: value | |
| 25 | + def decode_quux(_), do: {:error, "Unexpected type when decoding TopLevel.quux"} | |
| 26 | + | |
| 27 | + def encode_quux(value) when is_binary(value), do: value | |
| 28 | + def encode_quux(_), do: {:error, "Unexpected type when encoding TopLevel.quux"} | |
| 29 | + | |
| 24 | 30 | def from_map(m) do |
| 25 | 31 | %TopLevel{ |
| 26 | 32 | foo: decode_foo(m["foo"]), |
| 27 | 33 | bar: m["bar"], |
| 28 | - quux: m["quux"], | |
| 34 | + quux: m["quux"] && decode_quux(m["quux"]), | |
| 29 | 35 | } |
| 30 | 36 | end |
Test case
1 generated file · +7 −1test/inputs/schema/integer-string.schema
Mschema-elixirdefault / QuickType.ex+7 −1
| @@ -33,13 +33,19 @@ defmodule TopLevel do | ||
| 33 | 33 | def encode_one(value) when is_binary(value), do: value |
| 34 | 34 | def encode_one(_), do: {:error, "Unexpected type when encoding TopLevel.one"} |
| 35 | 35 | |
| 36 | + def decode_optional(value) when is_binary(value), do: value | |
| 37 | + def decode_optional(_), do: {:error, "Unexpected type when decoding TopLevel.optional"} | |
| 38 | + | |
| 39 | + def encode_optional(value) when is_binary(value), do: value | |
| 40 | + def encode_optional(_), do: {:error, "Unexpected type when encoding TopLevel.optional"} | |
| 41 | + | |
| 36 | 42 | def from_map(m) do |
| 37 | 43 | %TopLevel{ |
| 38 | 44 | arr_nullable: m["arrNullable"] && Enum.map(m["arrNullable"], &decode_arr_nullable_element/1), |
| 39 | 45 | arr_one: m["arrOne"], |
| 40 | 46 | nullable: Map.fetch!(m, "nullable"), |
| 41 | 47 | one: decode_one(m["one"]), |
| 42 | - optional: m["optional"], | |
| 48 | + optional: m["optional"] && decode_optional(m["optional"]), | |
| 43 | 49 | union_with_int: Map.fetch!(m, "unionWithInt"), |
| 44 | 50 | union_with_int_and_enum: Map.fetch!(m, "unionWithIntAndEnum"), |
| 45 | 51 | } |
Test case
1 generated file · +7 −1test/inputs/schema/intersection.schema
Mschema-elixirdefault / QuickType.ex+7 −1
| @@ -22,10 +22,16 @@ defmodule Intersection do | ||
| 22 | 22 | def encode_foo(value) when is_integer(value), do: value |
| 23 | 23 | def encode_foo(_), do: {:error, "Unexpected type when encoding Intersection.foo"} |
| 24 | 24 | |
| 25 | + def decode_bar(value) when is_binary(value), do: value | |
| 26 | + def decode_bar(_), do: {:error, "Unexpected type when decoding Intersection.bar"} | |
| 27 | + | |
| 28 | + def encode_bar(value) when is_binary(value), do: value | |
| 29 | + def encode_bar(_), do: {:error, "Unexpected type when encoding Intersection.bar"} | |
| 30 | + | |
| 25 | 31 | def from_map(m) do |
| 26 | 32 | %Intersection{ |
| 27 | 33 | foo: decode_foo(m["foo"]), |
| 28 | - bar: m["bar"], | |
| 34 | + bar: m["bar"] && decode_bar(m["bar"]), | |
| 29 | 35 | } |
| 30 | 36 | end |
Test case
1 generated file · +18 −6test/inputs/schema/minmaxlength.schema
Mschema-elixirdefault / QuickType.ex+18 −6
| @@ -20,31 +20,41 @@ defmodule TopLevel do | ||
| 20 | 20 | union: String.t() |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - def decode_intersection(value) when is_binary(value), do: value | |
| 23 | + def decode_intersection(value) when is_binary(value) do | |
| 24 | + if String.length(value) >= 4 and String.length(value) <= 5, do: value, else: raise(ArgumentError) | |
| 25 | + end | |
| 24 | 26 | def decode_intersection(_), do: {:error, "Unexpected type when decoding TopLevel.intersection"} |
| 25 | 27 | |
| 26 | 28 | def encode_intersection(value) when is_binary(value), do: value |
| 27 | 29 | def encode_intersection(_), do: {:error, "Unexpected type when encoding TopLevel.intersection"} |
| 28 | 30 | |
| 29 | - def decode_maxlength(value) when is_binary(value), do: value | |
| 31 | + def decode_maxlength(value) when is_binary(value) do | |
| 32 | + if String.length(value) <= 5, do: value, else: raise(ArgumentError) | |
| 33 | + end | |
| 30 | 34 | def decode_maxlength(_), do: {:error, "Unexpected type when decoding TopLevel.maxlength"} |
| 31 | 35 | |
| 32 | 36 | def encode_maxlength(value) when is_binary(value), do: value |
| 33 | 37 | def encode_maxlength(_), do: {:error, "Unexpected type when encoding TopLevel.maxlength"} |
| 34 | 38 | |
| 35 | - def decode_minlength(value) when is_binary(value), do: value | |
| 39 | + def decode_minlength(value) when is_binary(value) do | |
| 40 | + if String.length(value) >= 3, do: value, else: raise(ArgumentError) | |
| 41 | + end | |
| 36 | 42 | def decode_minlength(_), do: {:error, "Unexpected type when decoding TopLevel.minlength"} |
| 37 | 43 | |
| 38 | 44 | def encode_minlength(value) when is_binary(value), do: value |
| 39 | 45 | def encode_minlength(_), do: {:error, "Unexpected type when encoding TopLevel.minlength"} |
| 40 | 46 | |
| 41 | - def decode_min_max_intersection(value) when is_binary(value), do: value | |
| 47 | + def decode_min_max_intersection(value) when is_binary(value) do | |
| 48 | + if String.length(value) >= 3 and String.length(value) <= 5, do: value, else: raise(ArgumentError) | |
| 49 | + end | |
| 42 | 50 | def decode_min_max_intersection(_), do: {:error, "Unexpected type when decoding TopLevel.min_max_intersection"} |
| 43 | 51 | |
| 44 | 52 | def encode_min_max_intersection(value) when is_binary(value), do: value |
| 45 | 53 | def encode_min_max_intersection(_), do: {:error, "Unexpected type when encoding TopLevel.min_max_intersection"} |
| 46 | 54 | |
| 47 | - def decode_minmaxlength(value) when is_binary(value), do: value | |
| 55 | + def decode_minmaxlength(value) when is_binary(value) do | |
| 56 | + if String.length(value) >= 3 and String.length(value) <= 5, do: value, else: raise(ArgumentError) | |
| 57 | + end | |
| 48 | 58 | def decode_minmaxlength(_), do: {:error, "Unexpected type when decoding TopLevel.minmaxlength"} |
| 49 | 59 | |
| 50 | 60 | def encode_minmaxlength(value) when is_binary(value), do: value |
| @@ -56,7 +66,9 @@ defmodule TopLevel do | ||
| 56 | 66 | def encode_min_max_union(value) when is_binary(value), do: value |
| 57 | 67 | def encode_min_max_union(_), do: {:error, "Unexpected type when encoding TopLevel.min_max_union"} |
| 58 | 68 | |
| 59 | - def decode_union(value) when is_binary(value), do: value | |
| 69 | + def decode_union(value) when is_binary(value) do | |
| 70 | + if String.length(value) >= 3 and String.length(value) <= 6, do: value, else: raise(ArgumentError) | |
| 71 | + end | |
| 60 | 72 | def decode_union(_), do: {:error, "Unexpected type when decoding TopLevel.union"} |
| 61 | 73 | |
| 62 | 74 | def encode_union(value) when is_binary(value), do: value |
Test case
1 generated file · +28 −4test/inputs/schema/nested-intersection-union.schema
Mschema-elixirdefault / QuickType.ex+28 −4
| @@ -15,12 +15,36 @@ defmodule Item do | ||
| 15 | 15 | summary: String.t() | nil |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | + def decode_content(value) when is_binary(value), do: value | |
| 19 | + def decode_content(_), do: {:error, "Unexpected type when decoding Item.content"} | |
| 20 | + | |
| 21 | + def encode_content(value) when is_binary(value), do: value | |
| 22 | + def encode_content(_), do: {:error, "Unexpected type when encoding Item.content"} | |
| 23 | + | |
| 24 | + def decode_id(value) when is_binary(value), do: value | |
| 25 | + def decode_id(_), do: {:error, "Unexpected type when decoding Item.id"} | |
| 26 | + | |
| 27 | + def encode_id(value) when is_binary(value), do: value | |
| 28 | + def encode_id(_), do: {:error, "Unexpected type when encoding Item.id"} | |
| 29 | + | |
| 30 | + def decode_output(value) when is_binary(value), do: value | |
| 31 | + def decode_output(_), do: {:error, "Unexpected type when decoding Item.output"} | |
| 32 | + | |
| 33 | + def encode_output(value) when is_binary(value), do: value | |
| 34 | + def encode_output(_), do: {:error, "Unexpected type when encoding Item.output"} | |
| 35 | + | |
| 36 | + def decode_summary(value) when is_binary(value), do: value | |
| 37 | + def decode_summary(_), do: {:error, "Unexpected type when decoding Item.summary"} | |
| 38 | + | |
| 39 | + def encode_summary(value) when is_binary(value), do: value | |
| 40 | + def encode_summary(_), do: {:error, "Unexpected type when encoding Item.summary"} | |
| 41 | + | |
| 18 | 42 | def from_map(m) do |
| 19 | 43 | %Item{ |
| 20 | - content: m["content"], | |
| 21 | - id: m["id"], | |
| 22 | - output: m["output"], | |
| 23 | - summary: m["summary"], | |
| 44 | + content: m["content"] && decode_content(m["content"]), | |
| 45 | + id: m["id"] && decode_id(m["id"]), | |
| 46 | + output: m["output"] && decode_output(m["output"]), | |
| 47 | + summary: m["summary"] && decode_summary(m["summary"]), | |
| 24 | 48 | } |
| 25 | 49 | end |
Test case
1 generated file · +7 −1test/inputs/schema/object-type-required.schema
Mschema-elixirdefault / QuickType.ex+7 −1
| @@ -20,10 +20,16 @@ defmodule TopLevel do | ||
| 20 | 20 | def encode_foo(value) when is_binary(value), do: value |
| 21 | 21 | def encode_foo(_), do: {:error, "Unexpected type when encoding TopLevel.foo"} |
| 22 | 22 | |
| 23 | + def decode_bar(value) when is_binary(value), do: value | |
| 24 | + def decode_bar(_), do: {:error, "Unexpected type when decoding TopLevel.bar"} | |
| 25 | + | |
| 26 | + def encode_bar(value) when is_binary(value), do: value | |
| 27 | + def encode_bar(_), do: {:error, "Unexpected type when encoding TopLevel.bar"} | |
| 28 | + | |
| 23 | 29 | def from_map(m) do |
| 24 | 30 | %TopLevel{ |
| 25 | 31 | foo: decode_foo(m["foo"]), |
| 26 | - bar: m["bar"], | |
| 32 | + bar: m["bar"] && decode_bar(m["bar"]), | |
| 27 | 33 | } |
| 28 | 34 | end |
Test case
1 generated file · +12 −2test/inputs/schema/optional-const-ref.schema
Mschema-elixirdefault / QuickType.ex+12 −2
| @@ -71,6 +71,14 @@ defmodule TopLevel do | ||
| 71 | 71 | weight: float() | nil |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | + def decode_label(value) when is_binary(value) do | |
| 75 | + if String.length(value) >= 2 and String.length(value) <= 16, do: value, else: raise(ArgumentError) | |
| 76 | + end | |
| 77 | + def decode_label(_), do: {:error, "Unexpected type when decoding TopLevel.label"} | |
| 78 | + | |
| 79 | + def encode_label(value) when is_binary(value), do: value | |
| 80 | + def encode_label(_), do: {:error, "Unexpected type when encoding TopLevel.label"} | |
| 81 | + | |
| 74 | 82 | def decode_required_coordinates(value) when is_list(value), do: value |
| 75 | 83 | def decode_required_coordinates(_), do: {:error, "Unexpected type when decoding TopLevel.required_coordinates"} |
| 76 | 84 | |
| @@ -83,7 +91,9 @@ defmodule TopLevel do | ||
| 83 | 91 | def encode_required_count(value) when is_integer(value), do: value |
| 84 | 92 | def encode_required_count(_), do: {:error, "Unexpected type when encoding TopLevel.required_count"} |
| 85 | 93 | |
| 86 | - def decode_required_label(value) when is_binary(value), do: value | |
| 94 | + def decode_required_label(value) when is_binary(value) do | |
| 95 | + if String.length(value) >= 2 and String.length(value) <= 16, do: value, else: raise(ArgumentError) | |
| 96 | + end | |
| 87 | 97 | def decode_required_label(_), do: {:error, "Unexpected type when decoding TopLevel.required_label"} |
| 88 | 98 | |
| 89 | 99 | def encode_required_label(value) when is_binary(value), do: value |
| @@ -93,7 +103,7 @@ defmodule TopLevel do | ||
| 93 | 103 | %TopLevel{ |
| 94 | 104 | coordinates: m["coordinates"] && Enum.map(m["coordinates"], &Coordinate.from_map/1), |
| 95 | 105 | count: m["count"], |
| 96 | - label: m["label"], | |
| 106 | + label: m["label"] && decode_label(m["label"]), | |
| 97 | 107 | required_coordinates: Enum.map(m["requiredCoordinates"], &Coordinate.from_map/1), |
| 98 | 108 | required_count: decode_required_count(m["requiredCount"]), |
| 99 | 109 | required_label: decode_required_label(m["requiredLabel"]), |
Test case
1 generated file · +16 −2test/inputs/schema/optional-constraints.schema
Mschema-elixirdefault / QuickType.ex+16 −2
| @@ -17,6 +17,20 @@ defmodule TopLevel do | ||
| 17 | 17 | req_zero_min: integer() |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | + def decode_opt_pattern(value) when is_binary(value), do: value | |
| 21 | + def decode_opt_pattern(_), do: {:error, "Unexpected type when decoding TopLevel.opt_pattern"} | |
| 22 | + | |
| 23 | + def encode_opt_pattern(value) when is_binary(value), do: value | |
| 24 | + def encode_opt_pattern(_), do: {:error, "Unexpected type when encoding TopLevel.opt_pattern"} | |
| 25 | + | |
| 26 | + def decode_opt_string(value) when is_binary(value) do | |
| 27 | + if String.length(value) >= 3 and String.length(value) <= 10, do: value, else: raise(ArgumentError) | |
| 28 | + end | |
| 29 | + def decode_opt_string(_), do: {:error, "Unexpected type when decoding TopLevel.opt_string"} | |
| 30 | + | |
| 31 | + def encode_opt_string(value) when is_binary(value), do: value | |
| 32 | + def encode_opt_string(_), do: {:error, "Unexpected type when encoding TopLevel.opt_string"} | |
| 33 | + | |
| 20 | 34 | def decode_req_zero_min(value) when is_integer(value), do: value |
| 21 | 35 | def decode_req_zero_min(_), do: {:error, "Unexpected type when decoding TopLevel.req_zero_min"} |
| 22 | 36 | |
| @@ -27,8 +41,8 @@ defmodule TopLevel do | ||
| 27 | 41 | %TopLevel{ |
| 28 | 42 | opt_double: m["optDouble"], |
| 29 | 43 | opt_int: m["optInt"], |
| 30 | - opt_pattern: m["optPattern"], | |
| 31 | - opt_string: m["optString"], | |
| 44 | + opt_pattern: m["optPattern"] && decode_opt_pattern(m["optPattern"]), | |
| 45 | + opt_string: m["optString"] && decode_opt_string(m["optString"]), | |
| 32 | 46 | req_zero_min: decode_req_zero_min(m["reqZeroMin"]), |
| 33 | 47 | } |
| 34 | 48 | end |
Test case
1 generated file · +21 −3test/inputs/schema/optional-date-time.schema
Mschema-elixirdefault / QuickType.ex+21 −3
| @@ -18,6 +18,24 @@ defmodule TopLevel do | ||
| 18 | 18 | required_time: String.t() |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | + def decode_optional_date(value) when is_binary(value), do: value | |
| 22 | + def decode_optional_date(_), do: {:error, "Unexpected type when decoding TopLevel.optional_date"} | |
| 23 | + | |
| 24 | + def encode_optional_date(value) when is_binary(value), do: value | |
| 25 | + def encode_optional_date(_), do: {:error, "Unexpected type when encoding TopLevel.optional_date"} | |
| 26 | + | |
| 27 | + def decode_optional_date_time(value) when is_binary(value), do: value | |
| 28 | + def decode_optional_date_time(_), do: {:error, "Unexpected type when decoding TopLevel.optional_date_time"} | |
| 29 | + | |
| 30 | + def encode_optional_date_time(value) when is_binary(value), do: value | |
| 31 | + def encode_optional_date_time(_), do: {:error, "Unexpected type when encoding TopLevel.optional_date_time"} | |
| 32 | + | |
| 33 | + def decode_optional_time(value) when is_binary(value), do: value | |
| 34 | + def decode_optional_time(_), do: {:error, "Unexpected type when decoding TopLevel.optional_time"} | |
| 35 | + | |
| 36 | + def encode_optional_time(value) when is_binary(value), do: value | |
| 37 | + def encode_optional_time(_), do: {:error, "Unexpected type when encoding TopLevel.optional_time"} | |
| 38 | + | |
| 21 | 39 | def decode_required_date(value) when is_binary(value), do: value |
| 22 | 40 | def decode_required_date(_), do: {:error, "Unexpected type when decoding TopLevel.required_date"} |
| 23 | 41 | |
| @@ -38,9 +56,9 @@ defmodule TopLevel do | ||
| 38 | 56 | |
| 39 | 57 | def from_map(m) do |
| 40 | 58 | %TopLevel{ |
| 41 | - optional_date: m["optional-date"], | |
| 42 | - optional_date_time: m["optional-date-time"], | |
| 43 | - optional_time: m["optional-time"], | |
| 59 | + optional_date: m["optional-date"] && decode_optional_date(m["optional-date"]), | |
| 60 | + optional_date_time: m["optional-date-time"] && decode_optional_date_time(m["optional-date-time"]), | |
| 61 | + optional_time: m["optional-time"] && decode_optional_time(m["optional-time"]), | |
| 44 | 62 | required_date: decode_required_date(m["required-date"]), |
| 45 | 63 | required_date_time: decode_required_date_time(m["required-date-time"]), |
| 46 | 64 | required_time: decode_required_time(m["required-time"]), |
Test case
1 generated file · +14 −2test/inputs/schema/postman-collection.schema
Mschema-elixirdefault / QuickType.ex+14 −2
| @@ -12,9 +12,15 @@ defmodule Response do | ||
| 12 | 12 | body: String.t() | nil |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | + def decode_body(value) when is_binary(value), do: value | |
| 16 | + def decode_body(_), do: {:error, "Unexpected type when decoding Response.body"} | |
| 17 | + | |
| 18 | + def encode_body(value) when is_binary(value), do: value | |
| 19 | + def encode_body(_), do: {:error, "Unexpected type when encoding Response.body"} | |
| 20 | + | |
| 15 | 21 | def from_map(m) do |
| 16 | 22 | %Response{ |
| 17 | - body: m["body"], | |
| 23 | + body: m["body"] && decode_body(m["body"]), | |
| 18 | 24 | } |
| 19 | 25 | end |
| 20 | 26 | |
| @@ -50,10 +56,16 @@ defmodule TopLevel do | ||
| 50 | 56 | response: [Response.t()] | nil |
| 51 | 57 | } |
| 52 | 58 | |
| 59 | + def decode_name(value) when is_binary(value), do: value | |
| 60 | + def decode_name(_), do: {:error, "Unexpected type when decoding TopLevel.name"} | |
| 61 | + | |
| 62 | + def encode_name(value) when is_binary(value), do: value | |
| 63 | + def encode_name(_), do: {:error, "Unexpected type when encoding TopLevel.name"} | |
| 64 | + | |
| 53 | 65 | def from_map(m) do |
| 54 | 66 | %TopLevel{ |
| 55 | 67 | item: m["item"] && Enum.map(m["item"], &TopLevel.from_map/1), |
| 56 | - name: m["name"], | |
| 68 | + name: m["name"] && decode_name(m["name"]), | |
| 57 | 69 | response: m["response"] && Enum.map(m["response"], &Response.from_map/1), |
| 58 | 70 | } |
| 59 | 71 | end |
Test case
1 generated file · +74 −10test/inputs/schema/renaming-bug.schema
Mschema-elixirdefault / QuickType.ex+74 −10
| @@ -44,9 +44,15 @@ defmodule CircularShape do | ||
| 44 | 44 | shape_name: String.t() | nil |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | + def decode_shape_name(value) when is_binary(value), do: value | |
| 48 | + def decode_shape_name(_), do: {:error, "Unexpected type when decoding CircularShape.shape_name"} | |
| 49 | + | |
| 50 | + def encode_shape_name(value) when is_binary(value), do: value | |
| 51 | + def encode_shape_name(_), do: {:error, "Unexpected type when encoding CircularShape.shape_name"} | |
| 52 | + | |
| 47 | 53 | def from_map(m) do |
| 48 | 54 | %CircularShape{ |
| 49 | - shape_name: m["shapeName"], | |
| 55 | + shape_name: m["shapeName"] && decode_shape_name(m["shapeName"]), | |
| 50 | 56 | } |
| 51 | 57 | end |
| 52 | 58 | |
| @@ -78,11 +84,29 @@ defmodule Part do | ||
| 78 | 84 | width: String.t() | nil |
| 79 | 85 | } |
| 80 | 86 | |
| 87 | + def decode_depth(value) when is_binary(value), do: value | |
| 88 | + def decode_depth(_), do: {:error, "Unexpected type when decoding Part.depth"} | |
| 89 | + | |
| 90 | + def encode_depth(value) when is_binary(value), do: value | |
| 91 | + def encode_depth(_), do: {:error, "Unexpected type when encoding Part.depth"} | |
| 92 | + | |
| 93 | + def decode_length(value) when is_binary(value), do: value | |
| 94 | + def decode_length(_), do: {:error, "Unexpected type when decoding Part.length"} | |
| 95 | + | |
| 96 | + def encode_length(value) when is_binary(value), do: value | |
| 97 | + def encode_length(_), do: {:error, "Unexpected type when encoding Part.length"} | |
| 98 | + | |
| 99 | + def decode_width(value) when is_binary(value), do: value | |
| 100 | + def decode_width(_), do: {:error, "Unexpected type when decoding Part.width"} | |
| 101 | + | |
| 102 | + def encode_width(value) when is_binary(value), do: value | |
| 103 | + def encode_width(_), do: {:error, "Unexpected type when encoding Part.width"} | |
| 104 | + | |
| 81 | 105 | def from_map(m) do |
| 82 | 106 | %Part{ |
| 83 | - depth: m["depth"], | |
| 84 | - length: m["length"], | |
| 85 | - width: m["width"], | |
| 107 | + depth: m["depth"] && decode_depth(m["depth"]), | |
| 108 | + length: m["length"] && decode_length(m["length"]), | |
| 109 | + width: m["width"] && decode_width(m["width"]), | |
| 86 | 110 | } |
| 87 | 111 | end |
| 88 | 112 | |
| @@ -181,9 +205,15 @@ defmodule History do | ||
| 181 | 205 | class: String.t() | nil |
| 182 | 206 | } |
| 183 | 207 | |
| 208 | + def decode_class(value) when is_binary(value), do: value | |
| 209 | + def decode_class(_), do: {:error, "Unexpected type when decoding History.class"} | |
| 210 | + | |
| 211 | + def encode_class(value) when is_binary(value), do: value | |
| 212 | + def encode_class(_), do: {:error, "Unexpected type when encoding History.class"} | |
| 213 | + | |
| 184 | 214 | def from_map(m) do |
| 185 | 215 | %History{ |
| 186 | - class: m["class"], | |
| 216 | + class: m["class"] && decode_class(m["class"]), | |
| 187 | 217 | } |
| 188 | 218 | end |
| 189 | 219 | |
| @@ -250,10 +280,18 @@ defmodule Berry do | ||
| 250 | 280 | shapes: [Shape.t()] | nil |
| 251 | 281 | } |
| 252 | 282 | |
| 283 | + def decode_name(value) when is_binary(value) do | |
| 284 | + if String.length(value) >= 1, do: value, else: raise(ArgumentError) | |
| 285 | + end | |
| 286 | + def decode_name(_), do: {:error, "Unexpected type when decoding Berry.name"} | |
| 287 | + | |
| 288 | + def encode_name(value) when is_binary(value), do: value | |
| 289 | + def encode_name(_), do: {:error, "Unexpected type when encoding Berry.name"} | |
| 290 | + | |
| 253 | 291 | def from_map(m) do |
| 254 | 292 | %Berry{ |
| 255 | 293 | color: m["color"] && Color.from_map(m["color"]), |
| 256 | - name: m["name"], | |
| 294 | + name: m["name"] && decode_name(m["name"]), | |
| 257 | 295 | shapes: m["shapes"] && Enum.map(m["shapes"], &Shape.from_map/1), |
| 258 | 296 | } |
| 259 | 297 | end |
| @@ -537,14 +575,34 @@ defmodule Vehicle do | ||
| 537 | 575 | year: String.t() | nil |
| 538 | 576 | } |
| 539 | 577 | |
| 578 | + def decode_brand(value) when is_binary(value), do: value | |
| 579 | + def decode_brand(_), do: {:error, "Unexpected type when decoding Vehicle.brand"} | |
| 580 | + | |
| 581 | + def encode_brand(value) when is_binary(value), do: value | |
| 582 | + def encode_brand(_), do: {:error, "Unexpected type when encoding Vehicle.brand"} | |
| 583 | + | |
| 584 | + def decode_id(value) when is_binary(value) do | |
| 585 | + if String.length(value) >= 1, do: value, else: raise(ArgumentError) | |
| 586 | + end | |
| 587 | + def decode_id(_), do: {:error, "Unexpected type when decoding Vehicle.id"} | |
| 588 | + | |
| 589 | + def encode_id(value) when is_binary(value), do: value | |
| 590 | + def encode_id(_), do: {:error, "Unexpected type when encoding Vehicle.id"} | |
| 591 | + | |
| 592 | + def decode_year(value) when is_binary(value), do: value | |
| 593 | + def decode_year(_), do: {:error, "Unexpected type when decoding Vehicle.year"} | |
| 594 | + | |
| 595 | + def encode_year(value) when is_binary(value), do: value | |
| 596 | + def encode_year(_), do: {:error, "Unexpected type when encoding Vehicle.year"} | |
| 597 | + | |
| 540 | 598 | def from_map(m) do |
| 541 | 599 | %Vehicle{ |
| 542 | - brand: m["brand"], | |
| 543 | - id: m["id"], | |
| 600 | + brand: m["brand"] && decode_brand(m["brand"]), | |
| 601 | + id: m["id"] && decode_id(m["id"]), | |
| 544 | 602 | speed: m["speed"] && Speed.from_map(m["speed"]), |
| 545 | 603 | sub_module: m["subModule"], |
| 546 | 604 | type: m["type"] && VehicleType.from_map(m["type"]), |
| 547 | - year: m["year"], | |
| 605 | + year: m["year"] && decode_year(m["year"]), | |
| 548 | 606 | } |
| 549 | 607 | end |
| 550 | 608 | |
| @@ -581,9 +639,15 @@ defmodule TopLevel do | ||
| 581 | 639 | vehicles: [Vehicle.t()] | nil |
| 582 | 640 | } |
| 583 | 641 | |
| 642 | + def decode_version(value) when is_binary(value), do: value | |
| 643 | + def decode_version(_), do: {:error, "Unexpected type when decoding TopLevel.version"} | |
| 644 | + | |
| 645 | + def encode_version(value) when is_binary(value), do: value | |
| 646 | + def encode_version(_), do: {:error, "Unexpected type when encoding TopLevel.version"} | |
| 647 | + | |
| 584 | 648 | def from_map(m) do |
| 585 | 649 | %TopLevel{ |
| 586 | - version: m["version"], | |
| 650 | + version: m["version"] && decode_version(m["version"]), | |
| 587 | 651 | fruits: m["fruits"] && Enum.map(m["fruits"], &Fruit.from_map/1), |
| 588 | 652 | vehicles: m["vehicles"] && Enum.map(m["vehicles"], &Vehicle.from_map/1), |
| 589 | 653 | } |
Test case
1 generated file · +3 −1test/inputs/schema/schema-constraints.schema
Mschema-elixirdefault / QuickType.ex+3 −1
| @@ -14,7 +14,9 @@ defmodule TopLevel do | ||
| 14 | 14 | percent: float() |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | - def decode_min_max_length(value) when is_binary(value), do: value | |
| 17 | + def decode_min_max_length(value) when is_binary(value) do | |
| 18 | + if String.length(value) >= 5 and String.length(value) <= 5, do: value, else: raise(ArgumentError) | |
| 19 | + end | |
| 18 | 20 | def decode_min_max_length(_), do: {:error, "Unexpected type when decoding TopLevel.min_max_length"} |
| 19 | 21 | |
| 20 | 22 | def encode_min_max_length(value) when is_binary(value), do: value |
Test case
1 generated file · +7 −1test/inputs/schema/unevaluated-properties.schema
Mschema-elixirdefault / QuickType.ex+7 −1
| @@ -109,10 +109,16 @@ defmodule ConfigClass do | ||
| 109 | 109 | def encode_closed(value) when is_list(value), do: value |
| 110 | 110 | def encode_closed(_), do: {:error, "Unexpected type when encoding ConfigClass.closed"} |
| 111 | 111 | |
| 112 | + def decode_name(value) when is_binary(value), do: value | |
| 113 | + def decode_name(_), do: {:error, "Unexpected type when decoding ConfigClass.name"} | |
| 114 | + | |
| 115 | + def encode_name(value) when is_binary(value), do: value | |
| 116 | + def encode_name(_), do: {:error, "Unexpected type when encoding ConfigClass.name"} | |
| 117 | + | |
| 112 | 118 | def from_map(m) do |
| 113 | 119 | %ConfigClass{ |
| 114 | 120 | closed: decode_closed(m["closed"]), |
| 115 | - name: m["name"], | |
| 121 | + name: m["name"] && decode_name(m["name"]), | |
| 116 | 122 | settings: m["settings"] |
| 117 | 123 | |> Map.new(fn {key, value} -> {key, (fn value -> Enum.map(value, &Item.from_map/1) end).(value)} end), |
| 118 | 124 | } |
Test case
1 generated file · +7 −1test/inputs/schema/uuid.schema
Mschema-elixirdefault / QuickType.ex+7 −1
| @@ -32,6 +32,12 @@ defmodule TopLevel do | ||
| 32 | 32 | def encode_one(value) when is_binary(value), do: value |
| 33 | 33 | def encode_one(_), do: {:error, "Unexpected type when encoding TopLevel.one"} |
| 34 | 34 | |
| 35 | + def decode_optional(value) when is_binary(value), do: value | |
| 36 | + def decode_optional(_), do: {:error, "Unexpected type when decoding TopLevel.optional"} | |
| 37 | + | |
| 38 | + def encode_optional(value) when is_binary(value), do: value | |
| 39 | + def encode_optional(_), do: {:error, "Unexpected type when encoding TopLevel.optional"} | |
| 40 | + | |
| 35 | 41 | def decode_union_with_enum(value) when is_binary(value), do: value |
| 36 | 42 | def decode_union_with_enum(_), do: {:error, "Unexpected type when decoding TopLevel.union_with_enum"} |
| 37 | 43 | |
| @@ -44,7 +50,7 @@ defmodule TopLevel do | ||
| 44 | 50 | arr_one: m["arrOne"], |
| 45 | 51 | nullable: Map.fetch!(m, "nullable"), |
| 46 | 52 | one: decode_one(m["one"]), |
| 47 | - optional: m["optional"], | |
| 53 | + optional: m["optional"] && decode_optional(m["optional"]), | |
| 48 | 54 | union_with_enum: decode_union_with_enum(m["unionWithEnum"]), |
| 49 | 55 | } |
| 50 | 56 | end |
Test case
1 generated file · +770 −110test/inputs/schema/vega-lite.schema
Mschema-elixirdefault / QuickType.ex+770 −110
| @@ -661,6 +661,24 @@ defmodule MarkConfig do | ||
| 661 | 661 | theta: float() | nil |
| 662 | 662 | } |
| 663 | 663 | |
| 664 | + def decode_color(value) when is_binary(value), do: value | |
| 665 | + def decode_color(_), do: {:error, "Unexpected type when decoding MarkConfig.color"} | |
| 666 | + | |
| 667 | + def encode_color(value) when is_binary(value), do: value | |
| 668 | + def encode_color(_), do: {:error, "Unexpected type when encoding MarkConfig.color"} | |
| 669 | + | |
| 670 | + def decode_fill(value) when is_binary(value), do: value | |
| 671 | + def decode_fill(_), do: {:error, "Unexpected type when decoding MarkConfig.fill"} | |
| 672 | + | |
| 673 | + def encode_fill(value) when is_binary(value), do: value | |
| 674 | + def encode_fill(_), do: {:error, "Unexpected type when encoding MarkConfig.fill"} | |
| 675 | + | |
| 676 | + def decode_font(value) when is_binary(value), do: value | |
| 677 | + def decode_font(_), do: {:error, "Unexpected type when decoding MarkConfig.font"} | |
| 678 | + | |
| 679 | + def encode_font(value) when is_binary(value), do: value | |
| 680 | + def encode_font(_), do: {:error, "Unexpected type when encoding MarkConfig.font"} | |
| 681 | + | |
| 664 | 682 | def decode_font_weight(value) when is_binary(value), do: FontWeight.decode(value) |
| 665 | 683 | def decode_font_weight(value) when is_float(value), do: value |
| 666 | 684 | def decode_font_weight(value) when is_integer(value), do: value |
| @@ -673,37 +691,61 @@ defmodule MarkConfig do | ||
| 673 | 691 | def encode_font_weight(value) when is_nil(value), do: value |
| 674 | 692 | def encode_font_weight(_), do: {:error, "Unexpected type when encoding MarkConfig.font_weight"} |
| 675 | 693 | |
| 694 | + def decode_href(value) when is_binary(value), do: value | |
| 695 | + def decode_href(_), do: {:error, "Unexpected type when decoding MarkConfig.href"} | |
| 696 | + | |
| 697 | + def encode_href(value) when is_binary(value), do: value | |
| 698 | + def encode_href(_), do: {:error, "Unexpected type when encoding MarkConfig.href"} | |
| 699 | + | |
| 700 | + def decode_shape(value) when is_binary(value), do: value | |
| 701 | + def decode_shape(_), do: {:error, "Unexpected type when decoding MarkConfig.shape"} | |
| 702 | + | |
| 703 | + def encode_shape(value) when is_binary(value), do: value | |
| 704 | + def encode_shape(_), do: {:error, "Unexpected type when encoding MarkConfig.shape"} | |
| 705 | + | |
| 706 | + def decode_stroke(value) when is_binary(value), do: value | |
| 707 | + def decode_stroke(_), do: {:error, "Unexpected type when decoding MarkConfig.stroke"} | |
| 708 | + | |
| 709 | + def encode_stroke(value) when is_binary(value), do: value | |
| 710 | + def encode_stroke(_), do: {:error, "Unexpected type when encoding MarkConfig.stroke"} | |
| 711 | + | |
| 712 | + def decode_text(value) when is_binary(value), do: value | |
| 713 | + def decode_text(_), do: {:error, "Unexpected type when decoding MarkConfig.text"} | |
| 714 | + | |
| 715 | + def encode_text(value) when is_binary(value), do: value | |
| 716 | + def encode_text(_), do: {:error, "Unexpected type when encoding MarkConfig.text"} | |
| 717 | + | |
| 676 | 718 | def from_map(m) do |
| 677 | 719 | %MarkConfig{ |
| 678 | 720 | align: m["align"] && HorizontalAlign.decode(m["align"]), |
| 679 | 721 | angle: m["angle"], |
| 680 | 722 | baseline: m["baseline"] && VerticalAlign.decode(m["baseline"]), |
| 681 | - color: m["color"], | |
| 723 | + color: m["color"] && decode_color(m["color"]), | |
| 682 | 724 | cursor: m["cursor"] && Cursor.decode(m["cursor"]), |
| 683 | 725 | dx: m["dx"], |
| 684 | 726 | dy: m["dy"], |
| 685 | - fill: m["fill"], | |
| 727 | + fill: m["fill"] && decode_fill(m["fill"]), | |
| 686 | 728 | filled: m["filled"], |
| 687 | 729 | fill_opacity: m["fillOpacity"], |
| 688 | - font: m["font"], | |
| 730 | + font: m["font"] && decode_font(m["font"]), | |
| 689 | 731 | font_size: m["fontSize"], |
| 690 | 732 | font_style: m["fontStyle"] && FontStyle.decode(m["fontStyle"]), |
| 691 | 733 | font_weight: decode_font_weight(m["fontWeight"]), |
| 692 | - href: m["href"], | |
| 734 | + href: m["href"] && decode_href(m["href"]), | |
| 693 | 735 | interpolate: m["interpolate"] && Interpolate.decode(m["interpolate"]), |
| 694 | 736 | limit: m["limit"], |
| 695 | 737 | opacity: m["opacity"], |
| 696 | 738 | orient: m["orient"] && Orient.decode(m["orient"]), |
| 697 | 739 | radius: m["radius"], |
| 698 | - shape: m["shape"], | |
| 740 | + shape: m["shape"] && decode_shape(m["shape"]), | |
| 699 | 741 | size: m["size"], |
| 700 | - stroke: m["stroke"], | |
| 742 | + stroke: m["stroke"] && decode_stroke(m["stroke"]), | |
| 701 | 743 | stroke_dash: m["strokeDash"], |
| 702 | 744 | stroke_dash_offset: m["strokeDashOffset"], |
| 703 | 745 | stroke_opacity: m["strokeOpacity"], |
| 704 | 746 | stroke_width: m["strokeWidth"], |
| 705 | 747 | tension: m["tension"], |
| 706 | - text: m["text"], | |
| 748 | + text: m["text"] && decode_text(m["text"]), | |
| 707 | 749 | theta: m["theta"], |
| 708 | 750 | } |
| 709 | 751 | end |
| @@ -892,6 +934,30 @@ defmodule AxisConfig do | ||
| 892 | 934 | title_y: float() | nil |
| 893 | 935 | } |
| 894 | 936 | |
| 937 | + def decode_domain_color(value) when is_binary(value), do: value | |
| 938 | + def decode_domain_color(_), do: {:error, "Unexpected type when decoding AxisConfig.domain_color"} | |
| 939 | + | |
| 940 | + def encode_domain_color(value) when is_binary(value), do: value | |
| 941 | + def encode_domain_color(_), do: {:error, "Unexpected type when encoding AxisConfig.domain_color"} | |
| 942 | + | |
| 943 | + def decode_grid_color(value) when is_binary(value), do: value | |
| 944 | + def decode_grid_color(_), do: {:error, "Unexpected type when decoding AxisConfig.grid_color"} | |
| 945 | + | |
| 946 | + def encode_grid_color(value) when is_binary(value), do: value | |
| 947 | + def encode_grid_color(_), do: {:error, "Unexpected type when encoding AxisConfig.grid_color"} | |
| 948 | + | |
| 949 | + def decode_label_color(value) when is_binary(value), do: value | |
| 950 | + def decode_label_color(_), do: {:error, "Unexpected type when decoding AxisConfig.label_color"} | |
| 951 | + | |
| 952 | + def encode_label_color(value) when is_binary(value), do: value | |
| 953 | + def encode_label_color(_), do: {:error, "Unexpected type when encoding AxisConfig.label_color"} | |
| 954 | + | |
| 955 | + def decode_label_font(value) when is_binary(value), do: value | |
| 956 | + def decode_label_font(_), do: {:error, "Unexpected type when decoding AxisConfig.label_font"} | |
| 957 | + | |
| 958 | + def encode_label_font(value) when is_binary(value), do: value | |
| 959 | + def encode_label_font(_), do: {:error, "Unexpected type when encoding AxisConfig.label_font"} | |
| 960 | + | |
| 895 | 961 | def decode_label_overlap(value) when is_boolean(value), do: value |
| 896 | 962 | def decode_label_overlap(value) when is_binary(value), do: LabelOverlapEnum.decode(value) |
| 897 | 963 | def decode_label_overlap(value) when is_nil(value), do: value |
| @@ -902,22 +968,52 @@ defmodule AxisConfig do | ||
| 902 | 968 | def encode_label_overlap(value) when is_nil(value), do: value |
| 903 | 969 | def encode_label_overlap(_), do: {:error, "Unexpected type when encoding AxisConfig.label_overlap"} |
| 904 | 970 | |
| 971 | + def decode_tick_color(value) when is_binary(value), do: value | |
| 972 | + def decode_tick_color(_), do: {:error, "Unexpected type when decoding AxisConfig.tick_color"} | |
| 973 | + | |
| 974 | + def encode_tick_color(value) when is_binary(value), do: value | |
| 975 | + def encode_tick_color(_), do: {:error, "Unexpected type when encoding AxisConfig.tick_color"} | |
| 976 | + | |
| 977 | + def decode_title_align(value) when is_binary(value), do: value | |
| 978 | + def decode_title_align(_), do: {:error, "Unexpected type when decoding AxisConfig.title_align"} | |
| 979 | + | |
| 980 | + def encode_title_align(value) when is_binary(value), do: value | |
| 981 | + def encode_title_align(_), do: {:error, "Unexpected type when encoding AxisConfig.title_align"} | |
| 982 | + | |
| 983 | + def decode_title_baseline(value) when is_binary(value), do: value | |
| 984 | + def decode_title_baseline(_), do: {:error, "Unexpected type when decoding AxisConfig.title_baseline"} | |
| 985 | + | |
| 986 | + def encode_title_baseline(value) when is_binary(value), do: value | |
| 987 | + def encode_title_baseline(_), do: {:error, "Unexpected type when encoding AxisConfig.title_baseline"} | |
| 988 | + | |
| 989 | + def decode_title_color(value) when is_binary(value), do: value | |
| 990 | + def decode_title_color(_), do: {:error, "Unexpected type when decoding AxisConfig.title_color"} | |
| 991 | + | |
| 992 | + def encode_title_color(value) when is_binary(value), do: value | |
| 993 | + def encode_title_color(_), do: {:error, "Unexpected type when encoding AxisConfig.title_color"} | |
| 994 | + | |
| 995 | + def decode_title_font(value) when is_binary(value), do: value | |
| 996 | + def decode_title_font(_), do: {:error, "Unexpected type when decoding AxisConfig.title_font"} | |
| 997 | + | |
| 998 | + def encode_title_font(value) when is_binary(value), do: value | |
| 999 | + def encode_title_font(_), do: {:error, "Unexpected type when encoding AxisConfig.title_font"} | |
| 1000 | + | |
| 905 | 1001 | def from_map(m) do |
| 906 | 1002 | %AxisConfig{ |
| 907 | 1003 | band_position: m["bandPosition"], |
| 908 | 1004 | domain: m["domain"], |
| 909 | - domain_color: m["domainColor"], | |
| 1005 | + domain_color: m["domainColor"] && decode_domain_color(m["domainColor"]), | |
| 910 | 1006 | domain_width: m["domainWidth"], |
| 911 | 1007 | grid: m["grid"], |
| 912 | - grid_color: m["gridColor"], | |
| 1008 | + grid_color: m["gridColor"] && decode_grid_color(m["gridColor"]), | |
| 913 | 1009 | grid_dash: m["gridDash"], |
| 914 | 1010 | grid_opacity: m["gridOpacity"], |
| 915 | 1011 | grid_width: m["gridWidth"], |
| 916 | 1012 | label_angle: m["labelAngle"], |
| 917 | 1013 | label_bound: m["labelBound"], |
| 918 | - label_color: m["labelColor"], | |
| 1014 | + label_color: m["labelColor"] && decode_label_color(m["labelColor"]), | |
| 919 | 1015 | label_flush: m["labelFlush"], |
| 920 | - label_font: m["labelFont"], | |
| 1016 | + label_font: m["labelFont"] && decode_label_font(m["labelFont"]), | |
| 921 | 1017 | label_font_size: m["labelFontSize"], |
| 922 | 1018 | label_limit: m["labelLimit"], |
| 923 | 1019 | label_overlap: decode_label_overlap(m["labelOverlap"]), |
| @@ -926,16 +1022,16 @@ defmodule AxisConfig do | ||
| 926 | 1022 | max_extent: m["maxExtent"], |
| 927 | 1023 | min_extent: m["minExtent"], |
| 928 | 1024 | short_time_labels: m["shortTimeLabels"], |
| 929 | - tick_color: m["tickColor"], | |
| 1025 | + tick_color: m["tickColor"] && decode_tick_color(m["tickColor"]), | |
| 930 | 1026 | tick_round: m["tickRound"], |
| 931 | 1027 | ticks: m["ticks"], |
| 932 | 1028 | tick_size: m["tickSize"], |
| 933 | 1029 | tick_width: m["tickWidth"], |
| 934 | - title_align: m["titleAlign"], | |
| 1030 | + title_align: m["titleAlign"] && decode_title_align(m["titleAlign"]), | |
| 935 | 1031 | title_angle: m["titleAngle"], |
| 936 | - title_baseline: m["titleBaseline"], | |
| 937 | - title_color: m["titleColor"], | |
| 938 | - title_font: m["titleFont"], | |
| 1032 | + title_baseline: m["titleBaseline"] && decode_title_baseline(m["titleBaseline"]), | |
| 1033 | + title_color: m["titleColor"] && decode_title_color(m["titleColor"]), | |
| 1034 | + title_font: m["titleFont"] && decode_title_font(m["titleFont"]), | |
| 939 | 1035 | title_font_size: m["titleFontSize"], |
| 940 | 1036 | title_font_weight: m["titleFontWeight"], |
| 941 | 1037 | title_limit: m["titleLimit"], |
| @@ -1101,6 +1197,30 @@ defmodule VGAxisConfig do | ||
| 1101 | 1197 | title_y: float() | nil |
| 1102 | 1198 | } |
| 1103 | 1199 | |
| 1200 | + def decode_domain_color(value) when is_binary(value), do: value | |
| 1201 | + def decode_domain_color(_), do: {:error, "Unexpected type when decoding VGAxisConfig.domain_color"} | |
| 1202 | + | |
| 1203 | + def encode_domain_color(value) when is_binary(value), do: value | |
| 1204 | + def encode_domain_color(_), do: {:error, "Unexpected type when encoding VGAxisConfig.domain_color"} | |
| 1205 | + | |
| 1206 | + def decode_grid_color(value) when is_binary(value), do: value | |
| 1207 | + def decode_grid_color(_), do: {:error, "Unexpected type when decoding VGAxisConfig.grid_color"} | |
| 1208 | + | |
| 1209 | + def encode_grid_color(value) when is_binary(value), do: value | |
| 1210 | + def encode_grid_color(_), do: {:error, "Unexpected type when encoding VGAxisConfig.grid_color"} | |
| 1211 | + | |
| 1212 | + def decode_label_color(value) when is_binary(value), do: value | |
| 1213 | + def decode_label_color(_), do: {:error, "Unexpected type when decoding VGAxisConfig.label_color"} | |
| 1214 | + | |
| 1215 | + def encode_label_color(value) when is_binary(value), do: value | |
| 1216 | + def encode_label_color(_), do: {:error, "Unexpected type when encoding VGAxisConfig.label_color"} | |
| 1217 | + | |
| 1218 | + def decode_label_font(value) when is_binary(value), do: value | |
| 1219 | + def decode_label_font(_), do: {:error, "Unexpected type when decoding VGAxisConfig.label_font"} | |
| 1220 | + | |
| 1221 | + def encode_label_font(value) when is_binary(value), do: value | |
| 1222 | + def encode_label_font(_), do: {:error, "Unexpected type when encoding VGAxisConfig.label_font"} | |
| 1223 | + | |
| 1104 | 1224 | def decode_label_overlap(value) when is_boolean(value), do: value |
| 1105 | 1225 | def decode_label_overlap(value) when is_binary(value), do: LabelOverlapEnum.decode(value) |
| 1106 | 1226 | def decode_label_overlap(value) when is_nil(value), do: value |
| @@ -1111,22 +1231,52 @@ defmodule VGAxisConfig do | ||
| 1111 | 1231 | def encode_label_overlap(value) when is_nil(value), do: value |
| 1112 | 1232 | def encode_label_overlap(_), do: {:error, "Unexpected type when encoding VGAxisConfig.label_overlap"} |
| 1113 | 1233 | |
| 1234 | + def decode_tick_color(value) when is_binary(value), do: value | |
| 1235 | + def decode_tick_color(_), do: {:error, "Unexpected type when decoding VGAxisConfig.tick_color"} | |
| 1236 | + | |
| 1237 | + def encode_tick_color(value) when is_binary(value), do: value | |
| 1238 | + def encode_tick_color(_), do: {:error, "Unexpected type when encoding VGAxisConfig.tick_color"} | |
| 1239 | + | |
| 1240 | + def decode_title_align(value) when is_binary(value), do: value | |
| 1241 | + def decode_title_align(_), do: {:error, "Unexpected type when decoding VGAxisConfig.title_align"} | |
| 1242 | + | |
| 1243 | + def encode_title_align(value) when is_binary(value), do: value | |
| 1244 | + def encode_title_align(_), do: {:error, "Unexpected type when encoding VGAxisConfig.title_align"} | |
| 1245 | + | |
| 1246 | + def decode_title_baseline(value) when is_binary(value), do: value | |
| 1247 | + def decode_title_baseline(_), do: {:error, "Unexpected type when decoding VGAxisConfig.title_baseline"} | |
| 1248 | + | |
| 1249 | + def encode_title_baseline(value) when is_binary(value), do: value | |
| 1250 | + def encode_title_baseline(_), do: {:error, "Unexpected type when encoding VGAxisConfig.title_baseline"} | |
| 1251 | + | |
| 1252 | + def decode_title_color(value) when is_binary(value), do: value | |
| 1253 | + def decode_title_color(_), do: {:error, "Unexpected type when decoding VGAxisConfig.title_color"} | |
| 1254 | + | |
| 1255 | + def encode_title_color(value) when is_binary(value), do: value | |
| 1256 | + def encode_title_color(_), do: {:error, "Unexpected type when encoding VGAxisConfig.title_color"} | |
| 1257 | + | |
| 1258 | + def decode_title_font(value) when is_binary(value), do: value | |
| 1259 | + def decode_title_font(_), do: {:error, "Unexpected type when decoding VGAxisConfig.title_font"} | |
| 1260 | + | |
| 1261 | + def encode_title_font(value) when is_binary(value), do: value | |
| 1262 | + def encode_title_font(_), do: {:error, "Unexpected type when encoding VGAxisConfig.title_font"} | |
| 1263 | + | |
| 1114 | 1264 | def from_map(m) do |
| 1115 | 1265 | %VGAxisConfig{ |
| 1116 | 1266 | band_position: m["bandPosition"], |
| 1117 | 1267 | domain: m["domain"], |
| 1118 | - domain_color: m["domainColor"], | |
| 1268 | + domain_color: m["domainColor"] && decode_domain_color(m["domainColor"]), | |
| 1119 | 1269 | domain_width: m["domainWidth"], |
| 1120 | 1270 | grid: m["grid"], |
| 1121 | - grid_color: m["gridColor"], | |
| 1271 | + grid_color: m["gridColor"] && decode_grid_color(m["gridColor"]), | |
| 1122 | 1272 | grid_dash: m["gridDash"], |
| 1123 | 1273 | grid_opacity: m["gridOpacity"], |
| 1124 | 1274 | grid_width: m["gridWidth"], |
| 1125 | 1275 | label_angle: m["labelAngle"], |
| 1126 | 1276 | label_bound: m["labelBound"], |
| 1127 | - label_color: m["labelColor"], | |
| 1277 | + label_color: m["labelColor"] && decode_label_color(m["labelColor"]), | |
| 1128 | 1278 | label_flush: m["labelFlush"], |
| 1129 | - label_font: m["labelFont"], | |
| 1279 | + label_font: m["labelFont"] && decode_label_font(m["labelFont"]), | |
| 1130 | 1280 | label_font_size: m["labelFontSize"], |
| 1131 | 1281 | label_limit: m["labelLimit"], |
| 1132 | 1282 | label_overlap: decode_label_overlap(m["labelOverlap"]), |
| @@ -1134,16 +1284,16 @@ defmodule VGAxisConfig do | ||
| 1134 | 1284 | labels: m["labels"], |
| 1135 | 1285 | max_extent: m["maxExtent"], |
| 1136 | 1286 | min_extent: m["minExtent"], |
| 1137 | - tick_color: m["tickColor"], | |
| 1287 | + tick_color: m["tickColor"] && decode_tick_color(m["tickColor"]), | |
| 1138 | 1288 | tick_round: m["tickRound"], |
| 1139 | 1289 | ticks: m["ticks"], |
| 1140 | 1290 | tick_size: m["tickSize"], |
| 1141 | 1291 | tick_width: m["tickWidth"], |
| 1142 | - title_align: m["titleAlign"], | |
| 1292 | + title_align: m["titleAlign"] && decode_title_align(m["titleAlign"]), | |
| 1143 | 1293 | title_angle: m["titleAngle"], |
| 1144 | - title_baseline: m["titleBaseline"], | |
| 1145 | - title_color: m["titleColor"], | |
| 1146 | - title_font: m["titleFont"], | |
| 1294 | + title_baseline: m["titleBaseline"] && decode_title_baseline(m["titleBaseline"]), | |
| 1295 | + title_color: m["titleColor"] && decode_title_color(m["titleColor"]), | |
| 1296 | + title_font: m["titleFont"] && decode_title_font(m["titleFont"]), | |
| 1147 | 1297 | title_font_size: m["titleFontSize"], |
| 1148 | 1298 | title_font_weight: m["titleFontWeight"], |
| 1149 | 1299 | title_limit: m["titleLimit"], |
| @@ -1286,6 +1436,24 @@ defmodule BarConfig do | ||
| 1286 | 1436 | theta: float() | nil |
| 1287 | 1437 | } |
| 1288 | 1438 | |
| 1439 | + def decode_color(value) when is_binary(value), do: value | |
| 1440 | + def decode_color(_), do: {:error, "Unexpected type when decoding BarConfig.color"} | |
| 1441 | + | |
| 1442 | + def encode_color(value) when is_binary(value), do: value | |
| 1443 | + def encode_color(_), do: {:error, "Unexpected type when encoding BarConfig.color"} | |
| 1444 | + | |
| 1445 | + def decode_fill(value) when is_binary(value), do: value | |
| 1446 | + def decode_fill(_), do: {:error, "Unexpected type when decoding BarConfig.fill"} | |
| 1447 | + | |
| 1448 | + def encode_fill(value) when is_binary(value), do: value | |
| 1449 | + def encode_fill(_), do: {:error, "Unexpected type when encoding BarConfig.fill"} | |
| 1450 | + | |
| 1451 | + def decode_font(value) when is_binary(value), do: value | |
| 1452 | + def decode_font(_), do: {:error, "Unexpected type when decoding BarConfig.font"} | |
| 1453 | + | |
| 1454 | + def encode_font(value) when is_binary(value), do: value | |
| 1455 | + def encode_font(_), do: {:error, "Unexpected type when encoding BarConfig.font"} | |
| 1456 | + | |
| 1289 | 1457 | def decode_font_weight(value) when is_binary(value), do: FontWeight.decode(value) |
| 1290 | 1458 | def decode_font_weight(value) when is_float(value), do: value |
| 1291 | 1459 | def decode_font_weight(value) when is_integer(value), do: value |
| @@ -1298,40 +1466,64 @@ defmodule BarConfig do | ||
| 1298 | 1466 | def encode_font_weight(value) when is_nil(value), do: value |
| 1299 | 1467 | def encode_font_weight(_), do: {:error, "Unexpected type when encoding BarConfig.font_weight"} |
| 1300 | 1468 | |
| 1469 | + def decode_href(value) when is_binary(value), do: value | |
| 1470 | + def decode_href(_), do: {:error, "Unexpected type when decoding BarConfig.href"} | |
| 1471 | + | |
| 1472 | + def encode_href(value) when is_binary(value), do: value | |
| 1473 | + def encode_href(_), do: {:error, "Unexpected type when encoding BarConfig.href"} | |
| 1474 | + | |
| 1475 | + def decode_shape(value) when is_binary(value), do: value | |
| 1476 | + def decode_shape(_), do: {:error, "Unexpected type when decoding BarConfig.shape"} | |
| 1477 | + | |
| 1478 | + def encode_shape(value) when is_binary(value), do: value | |
| 1479 | + def encode_shape(_), do: {:error, "Unexpected type when encoding BarConfig.shape"} | |
| 1480 | + | |
| 1481 | + def decode_stroke(value) when is_binary(value), do: value | |
| 1482 | + def decode_stroke(_), do: {:error, "Unexpected type when decoding BarConfig.stroke"} | |
| 1483 | + | |
| 1484 | + def encode_stroke(value) when is_binary(value), do: value | |
| 1485 | + def encode_stroke(_), do: {:error, "Unexpected type when encoding BarConfig.stroke"} | |
| 1486 | + | |
| 1487 | + def decode_text(value) when is_binary(value), do: value | |
| 1488 | + def decode_text(_), do: {:error, "Unexpected type when decoding BarConfig.text"} | |
| 1489 | + | |
| 1490 | + def encode_text(value) when is_binary(value), do: value | |
| 1491 | + def encode_text(_), do: {:error, "Unexpected type when encoding BarConfig.text"} | |
| 1492 | + | |
| 1301 | 1493 | def from_map(m) do |
| 1302 | 1494 | %BarConfig{ |
| 1303 | 1495 | align: m["align"] && HorizontalAlign.decode(m["align"]), |
| 1304 | 1496 | angle: m["angle"], |
| 1305 | 1497 | baseline: m["baseline"] && VerticalAlign.decode(m["baseline"]), |
| 1306 | 1498 | bin_spacing: m["binSpacing"], |
| 1307 | - color: m["color"], | |
| 1499 | + color: m["color"] && decode_color(m["color"]), | |
| 1308 | 1500 | continuous_band_size: m["continuousBandSize"], |
| 1309 | 1501 | cursor: m["cursor"] && Cursor.decode(m["cursor"]), |
| 1310 | 1502 | discrete_band_size: m["discreteBandSize"], |
| 1311 | 1503 | dx: m["dx"], |
| 1312 | 1504 | dy: m["dy"], |
| 1313 | - fill: m["fill"], | |
| 1505 | + fill: m["fill"] && decode_fill(m["fill"]), | |
| 1314 | 1506 | filled: m["filled"], |
| 1315 | 1507 | fill_opacity: m["fillOpacity"], |
| 1316 | - font: m["font"], | |
| 1508 | + font: m["font"] && decode_font(m["font"]), | |
| 1317 | 1509 | font_size: m["fontSize"], |
| 1318 | 1510 | font_style: m["fontStyle"] && FontStyle.decode(m["fontStyle"]), |
| 1319 | 1511 | font_weight: decode_font_weight(m["fontWeight"]), |
| 1320 | - href: m["href"], | |
| 1512 | + href: m["href"] && decode_href(m["href"]), | |
| 1321 | 1513 | interpolate: m["interpolate"] && Interpolate.decode(m["interpolate"]), |
| 1322 | 1514 | limit: m["limit"], |
| 1323 | 1515 | opacity: m["opacity"], |
| 1324 | 1516 | orient: m["orient"] && Orient.decode(m["orient"]), |
| 1325 | 1517 | radius: m["radius"], |
| 1326 | - shape: m["shape"], | |
| 1518 | + shape: m["shape"] && decode_shape(m["shape"]), | |
| 1327 | 1519 | size: m["size"], |
| 1328 | - stroke: m["stroke"], | |
| 1520 | + stroke: m["stroke"] && decode_stroke(m["stroke"]), | |
| 1329 | 1521 | stroke_dash: m["strokeDash"], |
| 1330 | 1522 | stroke_dash_offset: m["strokeDashOffset"], |
| 1331 | 1523 | stroke_opacity: m["strokeOpacity"], |
| 1332 | 1524 | stroke_width: m["strokeWidth"], |
| 1333 | 1525 | tension: m["tension"], |
| 1334 | - text: m["text"], | |
| 1526 | + text: m["text"] && decode_text(m["text"]), | |
| 1335 | 1527 | theta: m["theta"], |
| 1336 | 1528 | } |
| 1337 | 1529 | end |
| @@ -1637,22 +1829,106 @@ defmodule LegendConfig do | ||
| 1637 | 1829 | title_padding: float() | nil |
| 1638 | 1830 | } |
| 1639 | 1831 | |
| 1832 | + def decode_fill_color(value) when is_binary(value), do: value | |
| 1833 | + def decode_fill_color(_), do: {:error, "Unexpected type when decoding LegendConfig.fill_color"} | |
| 1834 | + | |
| 1835 | + def encode_fill_color(value) when is_binary(value), do: value | |
| 1836 | + def encode_fill_color(_), do: {:error, "Unexpected type when encoding LegendConfig.fill_color"} | |
| 1837 | + | |
| 1838 | + def decode_gradient_label_baseline(value) when is_binary(value), do: value | |
| 1839 | + def decode_gradient_label_baseline(_), do: {:error, "Unexpected type when decoding LegendConfig.gradient_label_baseline"} | |
| 1840 | + | |
| 1841 | + def encode_gradient_label_baseline(value) when is_binary(value), do: value | |
| 1842 | + def encode_gradient_label_baseline(_), do: {:error, "Unexpected type when encoding LegendConfig.gradient_label_baseline"} | |
| 1843 | + | |
| 1844 | + def decode_gradient_stroke_color(value) when is_binary(value), do: value | |
| 1845 | + def decode_gradient_stroke_color(_), do: {:error, "Unexpected type when decoding LegendConfig.gradient_stroke_color"} | |
| 1846 | + | |
| 1847 | + def encode_gradient_stroke_color(value) when is_binary(value), do: value | |
| 1848 | + def encode_gradient_stroke_color(_), do: {:error, "Unexpected type when encoding LegendConfig.gradient_stroke_color"} | |
| 1849 | + | |
| 1850 | + def decode_label_align(value) when is_binary(value), do: value | |
| 1851 | + def decode_label_align(_), do: {:error, "Unexpected type when decoding LegendConfig.label_align"} | |
| 1852 | + | |
| 1853 | + def encode_label_align(value) when is_binary(value), do: value | |
| 1854 | + def encode_label_align(_), do: {:error, "Unexpected type when encoding LegendConfig.label_align"} | |
| 1855 | + | |
| 1856 | + def decode_label_baseline(value) when is_binary(value), do: value | |
| 1857 | + def decode_label_baseline(_), do: {:error, "Unexpected type when decoding LegendConfig.label_baseline"} | |
| 1858 | + | |
| 1859 | + def encode_label_baseline(value) when is_binary(value), do: value | |
| 1860 | + def encode_label_baseline(_), do: {:error, "Unexpected type when encoding LegendConfig.label_baseline"} | |
| 1861 | + | |
| 1862 | + def decode_label_color(value) when is_binary(value), do: value | |
| 1863 | + def decode_label_color(_), do: {:error, "Unexpected type when decoding LegendConfig.label_color"} | |
| 1864 | + | |
| 1865 | + def encode_label_color(value) when is_binary(value), do: value | |
| 1866 | + def encode_label_color(_), do: {:error, "Unexpected type when encoding LegendConfig.label_color"} | |
| 1867 | + | |
| 1868 | + def decode_label_font(value) when is_binary(value), do: value | |
| 1869 | + def decode_label_font(_), do: {:error, "Unexpected type when decoding LegendConfig.label_font"} | |
| 1870 | + | |
| 1871 | + def encode_label_font(value) when is_binary(value), do: value | |
| 1872 | + def encode_label_font(_), do: {:error, "Unexpected type when encoding LegendConfig.label_font"} | |
| 1873 | + | |
| 1874 | + def decode_stroke_color(value) when is_binary(value), do: value | |
| 1875 | + def decode_stroke_color(_), do: {:error, "Unexpected type when decoding LegendConfig.stroke_color"} | |
| 1876 | + | |
| 1877 | + def encode_stroke_color(value) when is_binary(value), do: value | |
| 1878 | + def encode_stroke_color(_), do: {:error, "Unexpected type when encoding LegendConfig.stroke_color"} | |
| 1879 | + | |
| 1880 | + def decode_symbol_color(value) when is_binary(value), do: value | |
| 1881 | + def decode_symbol_color(_), do: {:error, "Unexpected type when decoding LegendConfig.symbol_color"} | |
| 1882 | + | |
| 1883 | + def encode_symbol_color(value) when is_binary(value), do: value | |
| 1884 | + def encode_symbol_color(_), do: {:error, "Unexpected type when encoding LegendConfig.symbol_color"} | |
| 1885 | + | |
| 1886 | + def decode_symbol_type(value) when is_binary(value), do: value | |
| 1887 | + def decode_symbol_type(_), do: {:error, "Unexpected type when decoding LegendConfig.symbol_type"} | |
| 1888 | + | |
| 1889 | + def encode_symbol_type(value) when is_binary(value), do: value | |
| 1890 | + def encode_symbol_type(_), do: {:error, "Unexpected type when encoding LegendConfig.symbol_type"} | |
| 1891 | + | |
| 1892 | + def decode_title_align(value) when is_binary(value), do: value | |
| 1893 | + def decode_title_align(_), do: {:error, "Unexpected type when decoding LegendConfig.title_align"} | |
| 1894 | + | |
| 1895 | + def encode_title_align(value) when is_binary(value), do: value | |
| 1896 | + def encode_title_align(_), do: {:error, "Unexpected type when encoding LegendConfig.title_align"} | |
| 1897 | + | |
| 1898 | + def decode_title_baseline(value) when is_binary(value), do: value | |
| 1899 | + def decode_title_baseline(_), do: {:error, "Unexpected type when decoding LegendConfig.title_baseline"} | |
| 1900 | + | |
| 1901 | + def encode_title_baseline(value) when is_binary(value), do: value | |
| 1902 | + def encode_title_baseline(_), do: {:error, "Unexpected type when encoding LegendConfig.title_baseline"} | |
| 1903 | + | |
| 1904 | + def decode_title_color(value) when is_binary(value), do: value | |
| 1905 | + def decode_title_color(_), do: {:error, "Unexpected type when decoding LegendConfig.title_color"} | |
| 1906 | + | |
| 1907 | + def encode_title_color(value) when is_binary(value), do: value | |
| 1908 | + def encode_title_color(_), do: {:error, "Unexpected type when encoding LegendConfig.title_color"} | |
| 1909 | + | |
| 1910 | + def decode_title_font(value) when is_binary(value), do: value | |
| 1911 | + def decode_title_font(_), do: {:error, "Unexpected type when decoding LegendConfig.title_font"} | |
| 1912 | + | |
| 1913 | + def encode_title_font(value) when is_binary(value), do: value | |
| 1914 | + def encode_title_font(_), do: {:error, "Unexpected type when encoding LegendConfig.title_font"} | |
| 1915 | + | |
| 1640 | 1916 | def from_map(m) do |
| 1641 | 1917 | %LegendConfig{ |
| 1642 | 1918 | corner_radius: m["cornerRadius"], |
| 1643 | 1919 | entry_padding: m["entryPadding"], |
| 1644 | - fill_color: m["fillColor"], | |
| 1920 | + fill_color: m["fillColor"] && decode_fill_color(m["fillColor"]), | |
| 1645 | 1921 | gradient_height: m["gradientHeight"], |
| 1646 | - gradient_label_baseline: m["gradientLabelBaseline"], | |
| 1922 | + gradient_label_baseline: m["gradientLabelBaseline"] && decode_gradient_label_baseline(m["gradientLabelBaseline"]), | |
| 1647 | 1923 | gradient_label_limit: m["gradientLabelLimit"], |
| 1648 | 1924 | gradient_label_offset: m["gradientLabelOffset"], |
| 1649 | - gradient_stroke_color: m["gradientStrokeColor"], | |
| 1925 | + gradient_stroke_color: m["gradientStrokeColor"] && decode_gradient_stroke_color(m["gradientStrokeColor"]), | |
| 1650 | 1926 | gradient_stroke_width: m["gradientStrokeWidth"], |
| 1651 | 1927 | gradient_width: m["gradientWidth"], |
| 1652 | - label_align: m["labelAlign"], | |
| 1653 | - label_baseline: m["labelBaseline"], | |
| 1654 | - label_color: m["labelColor"], | |
| 1655 | - label_font: m["labelFont"], | |
| 1928 | + label_align: m["labelAlign"] && decode_label_align(m["labelAlign"]), | |
| 1929 | + label_baseline: m["labelBaseline"] && decode_label_baseline(m["labelBaseline"]), | |
| 1930 | + label_color: m["labelColor"] && decode_label_color(m["labelColor"]), | |
| 1931 | + label_font: m["labelFont"] && decode_label_font(m["labelFont"]), | |
| 1656 | 1932 | label_font_size: m["labelFontSize"], |
| 1657 | 1933 | label_limit: m["labelLimit"], |
| 1658 | 1934 | label_offset: m["labelOffset"], |
| @@ -1660,17 +1936,17 @@ defmodule LegendConfig do | ||
| 1660 | 1936 | orient: m["orient"] && LegendOrient.decode(m["orient"]), |
| 1661 | 1937 | padding: m["padding"], |
| 1662 | 1938 | short_time_labels: m["shortTimeLabels"], |
| 1663 | - stroke_color: m["strokeColor"], | |
| 1939 | + stroke_color: m["strokeColor"] && decode_stroke_color(m["strokeColor"]), | |
| 1664 | 1940 | stroke_dash: m["strokeDash"], |
| 1665 | 1941 | stroke_width: m["strokeWidth"], |
| 1666 | - symbol_color: m["symbolColor"], | |
| 1942 | + symbol_color: m["symbolColor"] && decode_symbol_color(m["symbolColor"]), | |
| 1667 | 1943 | symbol_size: m["symbolSize"], |
| 1668 | 1944 | symbol_stroke_width: m["symbolStrokeWidth"], |
| 1669 | - symbol_type: m["symbolType"], | |
| 1670 | - title_align: m["titleAlign"], | |
| 1671 | - title_baseline: m["titleBaseline"], | |
| 1672 | - title_color: m["titleColor"], | |
| 1673 | - title_font: m["titleFont"], | |
| 1945 | + symbol_type: m["symbolType"] && decode_symbol_type(m["symbolType"]), | |
| 1946 | + title_align: m["titleAlign"] && decode_title_align(m["titleAlign"]), | |
| 1947 | + title_baseline: m["titleBaseline"] && decode_title_baseline(m["titleBaseline"]), | |
| 1948 | + title_color: m["titleColor"] && decode_title_color(m["titleColor"]), | |
| 1949 | + title_font: m["titleFont"] && decode_title_font(m["titleFont"]), | |
| 1674 | 1950 | title_font_size: m["titleFontSize"], |
| 1675 | 1951 | title_font_weight: m["titleFontWeight"], |
| 1676 | 1952 | title_limit: m["titleLimit"], |
| @@ -1949,11 +2225,17 @@ defmodule VGScheme do | ||
| 1949 | 2225 | step: float() | nil |
| 1950 | 2226 | } |
| 1951 | 2227 | |
| 2228 | + def decode_scheme(value) when is_binary(value), do: value | |
| 2229 | + def decode_scheme(_), do: {:error, "Unexpected type when decoding VGScheme.scheme"} | |
| 2230 | + | |
| 2231 | + def encode_scheme(value) when is_binary(value), do: value | |
| 2232 | + def encode_scheme(_), do: {:error, "Unexpected type when encoding VGScheme.scheme"} | |
| 2233 | + | |
| 1952 | 2234 | def from_map(m) do |
| 1953 | 2235 | %VGScheme{ |
| 1954 | 2236 | count: m["count"], |
| 1955 | 2237 | extent: m["extent"], |
| 1956 | - scheme: m["scheme"], | |
| 2238 | + scheme: m["scheme"] && decode_scheme(m["scheme"]), | |
| 1957 | 2239 | step: m["step"], |
| 1958 | 2240 | } |
| 1959 | 2241 | end |
| @@ -2274,11 +2556,23 @@ defmodule BrushConfig do | ||
| 2274 | 2556 | stroke_width: float() | nil |
| 2275 | 2557 | } |
| 2276 | 2558 | |
| 2559 | + def decode_fill(value) when is_binary(value), do: value | |
| 2560 | + def decode_fill(_), do: {:error, "Unexpected type when decoding BrushConfig.fill"} | |
| 2561 | + | |
| 2562 | + def encode_fill(value) when is_binary(value), do: value | |
| 2563 | + def encode_fill(_), do: {:error, "Unexpected type when encoding BrushConfig.fill"} | |
| 2564 | + | |
| 2565 | + def decode_stroke(value) when is_binary(value), do: value | |
| 2566 | + def decode_stroke(_), do: {:error, "Unexpected type when decoding BrushConfig.stroke"} | |
| 2567 | + | |
| 2568 | + def encode_stroke(value) when is_binary(value), do: value | |
| 2569 | + def encode_stroke(_), do: {:error, "Unexpected type when encoding BrushConfig.stroke"} | |
| 2570 | + | |
| 2277 | 2571 | def from_map(m) do |
| 2278 | 2572 | %BrushConfig{ |
| 2279 | - fill: m["fill"], | |
| 2573 | + fill: m["fill"] && decode_fill(m["fill"]), | |
| 2280 | 2574 | fill_opacity: m["fillOpacity"], |
| 2281 | - stroke: m["stroke"], | |
| 2575 | + stroke: m["stroke"] && decode_stroke(m["stroke"]), | |
| 2282 | 2576 | stroke_dash: m["strokeDash"], |
| 2283 | 2577 | stroke_dash_offset: m["strokeDashOffset"], |
| 2284 | 2578 | stroke_opacity: m["strokeOpacity"], |
| @@ -2516,6 +2810,12 @@ defmodule VGBinding do | ||
| 2516 | 2810 | step: float() | nil |
| 2517 | 2811 | } |
| 2518 | 2812 | |
| 2813 | + def decode_element(value) when is_binary(value), do: value | |
| 2814 | + def decode_element(_), do: {:error, "Unexpected type when decoding VGBinding.element"} | |
| 2815 | + | |
| 2816 | + def encode_element(value) when is_binary(value), do: value | |
| 2817 | + def encode_element(_), do: {:error, "Unexpected type when encoding VGBinding.element"} | |
| 2818 | + | |
| 2519 | 2819 | def decode_input(value) when is_binary(value), do: value |
| 2520 | 2820 | def decode_input(_), do: {:error, "Unexpected type when decoding VGBinding.input"} |
| 2521 | 2821 | |
| @@ -2524,7 +2824,7 @@ defmodule VGBinding do | ||
| 2524 | 2824 | |
| 2525 | 2825 | def from_map(m) do |
| 2526 | 2826 | %VGBinding{ |
| 2527 | - element: m["element"], | |
| 2827 | + element: m["element"] && decode_element(m["element"]), | |
| 2528 | 2828 | input: decode_input(m["input"]), |
| 2529 | 2829 | options: m["options"], |
| 2530 | 2830 | max: m["max"], |
| @@ -2785,6 +3085,18 @@ defmodule VGMarkConfig do | ||
| 2785 | 3085 | theta: float() | nil |
| 2786 | 3086 | } |
| 2787 | 3087 | |
| 3088 | + def decode_fill(value) when is_binary(value), do: value | |
| 3089 | + def decode_fill(_), do: {:error, "Unexpected type when decoding VGMarkConfig.fill"} | |
| 3090 | + | |
| 3091 | + def encode_fill(value) when is_binary(value), do: value | |
| 3092 | + def encode_fill(_), do: {:error, "Unexpected type when encoding VGMarkConfig.fill"} | |
| 3093 | + | |
| 3094 | + def decode_font(value) when is_binary(value), do: value | |
| 3095 | + def decode_font(_), do: {:error, "Unexpected type when decoding VGMarkConfig.font"} | |
| 3096 | + | |
| 3097 | + def encode_font(value) when is_binary(value), do: value | |
| 3098 | + def encode_font(_), do: {:error, "Unexpected type when encoding VGMarkConfig.font"} | |
| 3099 | + | |
| 2788 | 3100 | def decode_font_weight(value) when is_binary(value), do: FontWeight.decode(value) |
| 2789 | 3101 | def decode_font_weight(value) when is_float(value), do: value |
| 2790 | 3102 | def decode_font_weight(value) when is_integer(value), do: value |
| @@ -2797,6 +3109,30 @@ defmodule VGMarkConfig do | ||
| 2797 | 3109 | def encode_font_weight(value) when is_nil(value), do: value |
| 2798 | 3110 | def encode_font_weight(_), do: {:error, "Unexpected type when encoding VGMarkConfig.font_weight"} |
| 2799 | 3111 | |
| 3112 | + def decode_href(value) when is_binary(value), do: value | |
| 3113 | + def decode_href(_), do: {:error, "Unexpected type when decoding VGMarkConfig.href"} | |
| 3114 | + | |
| 3115 | + def encode_href(value) when is_binary(value), do: value | |
| 3116 | + def encode_href(_), do: {:error, "Unexpected type when encoding VGMarkConfig.href"} | |
| 3117 | + | |
| 3118 | + def decode_shape(value) when is_binary(value), do: value | |
| 3119 | + def decode_shape(_), do: {:error, "Unexpected type when decoding VGMarkConfig.shape"} | |
| 3120 | + | |
| 3121 | + def encode_shape(value) when is_binary(value), do: value | |
| 3122 | + def encode_shape(_), do: {:error, "Unexpected type when encoding VGMarkConfig.shape"} | |
| 3123 | + | |
| 3124 | + def decode_stroke(value) when is_binary(value), do: value | |
| 3125 | + def decode_stroke(_), do: {:error, "Unexpected type when decoding VGMarkConfig.stroke"} | |
| 3126 | + | |
| 3127 | + def encode_stroke(value) when is_binary(value), do: value | |
| 3128 | + def encode_stroke(_), do: {:error, "Unexpected type when encoding VGMarkConfig.stroke"} | |
| 3129 | + | |
| 3130 | + def decode_text(value) when is_binary(value), do: value | |
| 3131 | + def decode_text(_), do: {:error, "Unexpected type when decoding VGMarkConfig.text"} | |
| 3132 | + | |
| 3133 | + def encode_text(value) when is_binary(value), do: value | |
| 3134 | + def encode_text(_), do: {:error, "Unexpected type when encoding VGMarkConfig.text"} | |
| 3135 | + | |
| 2800 | 3136 | def from_map(m) do |
| 2801 | 3137 | %VGMarkConfig{ |
| 2802 | 3138 | align: m["align"] && HorizontalAlign.decode(m["align"]), |
| @@ -2805,27 +3141,27 @@ defmodule VGMarkConfig do | ||
| 2805 | 3141 | cursor: m["cursor"] && Cursor.decode(m["cursor"]), |
| 2806 | 3142 | dx: m["dx"], |
| 2807 | 3143 | dy: m["dy"], |
| 2808 | - fill: m["fill"], | |
| 3144 | + fill: m["fill"] && decode_fill(m["fill"]), | |
| 2809 | 3145 | fill_opacity: m["fillOpacity"], |
| 2810 | - font: m["font"], | |
| 3146 | + font: m["font"] && decode_font(m["font"]), | |
| 2811 | 3147 | font_size: m["fontSize"], |
| 2812 | 3148 | font_style: m["fontStyle"] && FontStyle.decode(m["fontStyle"]), |
| 2813 | 3149 | font_weight: decode_font_weight(m["fontWeight"]), |
| 2814 | - href: m["href"], | |
| 3150 | + href: m["href"] && decode_href(m["href"]), | |
| 2815 | 3151 | interpolate: m["interpolate"] && Interpolate.decode(m["interpolate"]), |
| 2816 | 3152 | limit: m["limit"], |
| 2817 | 3153 | opacity: m["opacity"], |
| 2818 | 3154 | orient: m["orient"] && Orient.decode(m["orient"]), |
| 2819 | 3155 | radius: m["radius"], |
| 2820 | - shape: m["shape"], | |
| 3156 | + shape: m["shape"] && decode_shape(m["shape"]), | |
| 2821 | 3157 | size: m["size"], |
| 2822 | - stroke: m["stroke"], | |
| 3158 | + stroke: m["stroke"] && decode_stroke(m["stroke"]), | |
| 2823 | 3159 | stroke_dash: m["strokeDash"], |
| 2824 | 3160 | stroke_dash_offset: m["strokeDashOffset"], |
| 2825 | 3161 | stroke_opacity: m["strokeOpacity"], |
| 2826 | 3162 | stroke_width: m["strokeWidth"], |
| 2827 | 3163 | tension: m["tension"], |
| 2828 | - text: m["text"], | |
| 3164 | + text: m["text"] && decode_text(m["text"]), | |
| 2829 | 3165 | theta: m["theta"], |
| 2830 | 3166 | } |
| 2831 | 3167 | end |
| @@ -2948,6 +3284,24 @@ defmodule TextConfig do | ||
| 2948 | 3284 | theta: float() | nil |
| 2949 | 3285 | } |
| 2950 | 3286 | |
| 3287 | + def decode_color(value) when is_binary(value), do: value | |
| 3288 | + def decode_color(_), do: {:error, "Unexpected type when decoding TextConfig.color"} | |
| 3289 | + | |
| 3290 | + def encode_color(value) when is_binary(value), do: value | |
| 3291 | + def encode_color(_), do: {:error, "Unexpected type when encoding TextConfig.color"} | |
| 3292 | + | |
| 3293 | + def decode_fill(value) when is_binary(value), do: value | |
| 3294 | + def decode_fill(_), do: {:error, "Unexpected type when decoding TextConfig.fill"} | |
| 3295 | + | |
| 3296 | + def encode_fill(value) when is_binary(value), do: value | |
| 3297 | + def encode_fill(_), do: {:error, "Unexpected type when encoding TextConfig.fill"} | |
| 3298 | + | |
| 3299 | + def decode_font(value) when is_binary(value), do: value | |
| 3300 | + def decode_font(_), do: {:error, "Unexpected type when decoding TextConfig.font"} | |
| 3301 | + | |
| 3302 | + def encode_font(value) when is_binary(value), do: value | |
| 3303 | + def encode_font(_), do: {:error, "Unexpected type when encoding TextConfig.font"} | |
| 3304 | + | |
| 2951 | 3305 | def decode_font_weight(value) when is_binary(value), do: FontWeight.decode(value) |
| 2952 | 3306 | def decode_font_weight(value) when is_float(value), do: value |
| 2953 | 3307 | def decode_font_weight(value) when is_integer(value), do: value |
| @@ -2960,38 +3314,62 @@ defmodule TextConfig do | ||
| 2960 | 3314 | def encode_font_weight(value) when is_nil(value), do: value |
| 2961 | 3315 | def encode_font_weight(_), do: {:error, "Unexpected type when encoding TextConfig.font_weight"} |
| 2962 | 3316 | |
| 3317 | + def decode_href(value) when is_binary(value), do: value | |
| 3318 | + def decode_href(_), do: {:error, "Unexpected type when decoding TextConfig.href"} | |
| 3319 | + | |
| 3320 | + def encode_href(value) when is_binary(value), do: value | |
| 3321 | + def encode_href(_), do: {:error, "Unexpected type when encoding TextConfig.href"} | |
| 3322 | + | |
| 3323 | + def decode_shape(value) when is_binary(value), do: value | |
| 3324 | + def decode_shape(_), do: {:error, "Unexpected type when decoding TextConfig.shape"} | |
| 3325 | + | |
| 3326 | + def encode_shape(value) when is_binary(value), do: value | |
| 3327 | + def encode_shape(_), do: {:error, "Unexpected type when encoding TextConfig.shape"} | |
| 3328 | + | |
| 3329 | + def decode_stroke(value) when is_binary(value), do: value | |
| 3330 | + def decode_stroke(_), do: {:error, "Unexpected type when decoding TextConfig.stroke"} | |
| 3331 | + | |
| 3332 | + def encode_stroke(value) when is_binary(value), do: value | |
| 3333 | + def encode_stroke(_), do: {:error, "Unexpected type when encoding TextConfig.stroke"} | |
| 3334 | + | |
| 3335 | + def decode_text(value) when is_binary(value), do: value | |
| 3336 | + def decode_text(_), do: {:error, "Unexpected type when decoding TextConfig.text"} | |
| 3337 | + | |
| 3338 | + def encode_text(value) when is_binary(value), do: value | |
| 3339 | + def encode_text(_), do: {:error, "Unexpected type when encoding TextConfig.text"} | |
| 3340 | + | |
| 2963 | 3341 | def from_map(m) do |
| 2964 | 3342 | %TextConfig{ |
| 2965 | 3343 | align: m["align"] && HorizontalAlign.decode(m["align"]), |
| 2966 | 3344 | angle: m["angle"], |
| 2967 | 3345 | baseline: m["baseline"] && VerticalAlign.decode(m["baseline"]), |
| 2968 | - color: m["color"], | |
| 3346 | + color: m["color"] && decode_color(m["color"]), | |
| 2969 | 3347 | cursor: m["cursor"] && Cursor.decode(m["cursor"]), |
| 2970 | 3348 | dx: m["dx"], |
| 2971 | 3349 | dy: m["dy"], |
| 2972 | - fill: m["fill"], | |
| 3350 | + fill: m["fill"] && decode_fill(m["fill"]), | |
| 2973 | 3351 | filled: m["filled"], |
| 2974 | 3352 | fill_opacity: m["fillOpacity"], |
| 2975 | - font: m["font"], | |
| 3353 | + font: m["font"] && decode_font(m["font"]), | |
| 2976 | 3354 | font_size: m["fontSize"], |
| 2977 | 3355 | font_style: m["fontStyle"] && FontStyle.decode(m["fontStyle"]), |
| 2978 | 3356 | font_weight: decode_font_weight(m["fontWeight"]), |
| 2979 | - href: m["href"], | |
| 3357 | + href: m["href"] && decode_href(m["href"]), | |
| 2980 | 3358 | interpolate: m["interpolate"] && Interpolate.decode(m["interpolate"]), |
| 2981 | 3359 | limit: m["limit"], |
| 2982 | 3360 | opacity: m["opacity"], |
| 2983 | 3361 | orient: m["orient"] && Orient.decode(m["orient"]), |
| 2984 | 3362 | radius: m["radius"], |
| 2985 | - shape: m["shape"], | |
| 3363 | + shape: m["shape"] && decode_shape(m["shape"]), | |
| 2986 | 3364 | short_time_labels: m["shortTimeLabels"], |
| 2987 | 3365 | size: m["size"], |
| 2988 | - stroke: m["stroke"], | |
| 3366 | + stroke: m["stroke"] && decode_stroke(m["stroke"]), | |
| 2989 | 3367 | stroke_dash: m["strokeDash"], |
| 2990 | 3368 | stroke_dash_offset: m["strokeDashOffset"], |
| 2991 | 3369 | stroke_opacity: m["strokeOpacity"], |
| 2992 | 3370 | stroke_width: m["strokeWidth"], |
| 2993 | 3371 | tension: m["tension"], |
| 2994 | - text: m["text"], | |
| 3372 | + text: m["text"] && decode_text(m["text"]), | |
| 2995 | 3373 | theta: m["theta"], |
| 2996 | 3374 | } |
| 2997 | 3375 | end |
| @@ -3119,6 +3497,24 @@ defmodule TickConfig do | ||
| 3119 | 3497 | thickness: float() | nil |
| 3120 | 3498 | } |
| 3121 | 3499 | |
| 3500 | + def decode_color(value) when is_binary(value), do: value | |
| 3501 | + def decode_color(_), do: {:error, "Unexpected type when decoding TickConfig.color"} | |
| 3502 | + | |
| 3503 | + def encode_color(value) when is_binary(value), do: value | |
| 3504 | + def encode_color(_), do: {:error, "Unexpected type when encoding TickConfig.color"} | |
| 3505 | + | |
| 3506 | + def decode_fill(value) when is_binary(value), do: value | |
| 3507 | + def decode_fill(_), do: {:error, "Unexpected type when decoding TickConfig.fill"} | |
| 3508 | + | |
| 3509 | + def encode_fill(value) when is_binary(value), do: value | |
| 3510 | + def encode_fill(_), do: {:error, "Unexpected type when encoding TickConfig.fill"} | |
| 3511 | + | |
| 3512 | + def decode_font(value) when is_binary(value), do: value | |
| 3513 | + def decode_font(_), do: {:error, "Unexpected type when decoding TickConfig.font"} | |
| 3514 | + | |
| 3515 | + def encode_font(value) when is_binary(value), do: value | |
| 3516 | + def encode_font(_), do: {:error, "Unexpected type when encoding TickConfig.font"} | |
| 3517 | + | |
| 3122 | 3518 | def decode_font_weight(value) when is_binary(value), do: FontWeight.decode(value) |
| 3123 | 3519 | def decode_font_weight(value) when is_float(value), do: value |
| 3124 | 3520 | def decode_font_weight(value) when is_integer(value), do: value |
| @@ -3131,38 +3527,62 @@ defmodule TickConfig do | ||
| 3131 | 3527 | def encode_font_weight(value) when is_nil(value), do: value |
| 3132 | 3528 | def encode_font_weight(_), do: {:error, "Unexpected type when encoding TickConfig.font_weight"} |
| 3133 | 3529 | |
| 3530 | + def decode_href(value) when is_binary(value), do: value | |
| 3531 | + def decode_href(_), do: {:error, "Unexpected type when decoding TickConfig.href"} | |
| 3532 | + | |
| 3533 | + def encode_href(value) when is_binary(value), do: value | |
| 3534 | + def encode_href(_), do: {:error, "Unexpected type when encoding TickConfig.href"} | |
| 3535 | + | |
| 3536 | + def decode_shape(value) when is_binary(value), do: value | |
| 3537 | + def decode_shape(_), do: {:error, "Unexpected type when decoding TickConfig.shape"} | |
| 3538 | + | |
| 3539 | + def encode_shape(value) when is_binary(value), do: value | |
| 3540 | + def encode_shape(_), do: {:error, "Unexpected type when encoding TickConfig.shape"} | |
| 3541 | + | |
| 3542 | + def decode_stroke(value) when is_binary(value), do: value | |
| 3543 | + def decode_stroke(_), do: {:error, "Unexpected type when decoding TickConfig.stroke"} | |
| 3544 | + | |
| 3545 | + def encode_stroke(value) when is_binary(value), do: value | |
| 3546 | + def encode_stroke(_), do: {:error, "Unexpected type when encoding TickConfig.stroke"} | |
| 3547 | + | |
| 3548 | + def decode_text(value) when is_binary(value), do: value | |
| 3549 | + def decode_text(_), do: {:error, "Unexpected type when decoding TickConfig.text"} | |
| 3550 | + | |
| 3551 | + def encode_text(value) when is_binary(value), do: value | |
| 3552 | + def encode_text(_), do: {:error, "Unexpected type when encoding TickConfig.text"} | |
| 3553 | + | |
| 3134 | 3554 | def from_map(m) do |
| 3135 | 3555 | %TickConfig{ |
| 3136 | 3556 | align: m["align"] && HorizontalAlign.decode(m["align"]), |
| 3137 | 3557 | angle: m["angle"], |
| 3138 | 3558 | band_size: m["bandSize"], |
| 3139 | 3559 | baseline: m["baseline"] && VerticalAlign.decode(m["baseline"]), |
| 3140 | - color: m["color"], | |
| 3560 | + color: m["color"] && decode_color(m["color"]), | |
| 3141 | 3561 | cursor: m["cursor"] && Cursor.decode(m["cursor"]), |
| 3142 | 3562 | dx: m["dx"], |
| 3143 | 3563 | dy: m["dy"], |
| 3144 | - fill: m["fill"], | |
| 3564 | + fill: m["fill"] && decode_fill(m["fill"]), | |
| 3145 | 3565 | filled: m["filled"], |
| 3146 | 3566 | fill_opacity: m["fillOpacity"], |
| 3147 | - font: m["font"], | |
| 3567 | + font: m["font"] && decode_font(m["font"]), | |
| 3148 | 3568 | font_size: m["fontSize"], |
| 3149 | 3569 | font_style: m["fontStyle"] && FontStyle.decode(m["fontStyle"]), |
| 3150 | 3570 | font_weight: decode_font_weight(m["fontWeight"]), |
| 3151 | - href: m["href"], | |
| 3571 | + href: m["href"] && decode_href(m["href"]), | |
| 3152 | 3572 | interpolate: m["interpolate"] && Interpolate.decode(m["interpolate"]), |
| 3153 | 3573 | limit: m["limit"], |
| 3154 | 3574 | opacity: m["opacity"], |
| 3155 | 3575 | orient: m["orient"] && Orient.decode(m["orient"]), |
| 3156 | 3576 | radius: m["radius"], |
| 3157 | - shape: m["shape"], | |
| 3577 | + shape: m["shape"] && decode_shape(m["shape"]), | |
| 3158 | 3578 | size: m["size"], |
| 3159 | - stroke: m["stroke"], | |
| 3579 | + stroke: m["stroke"] && decode_stroke(m["stroke"]), | |
| 3160 | 3580 | stroke_dash: m["strokeDash"], |
| 3161 | 3581 | stroke_dash_offset: m["strokeDashOffset"], |
| 3162 | 3582 | stroke_opacity: m["strokeOpacity"], |
| 3163 | 3583 | stroke_width: m["strokeWidth"], |
| 3164 | 3584 | tension: m["tension"], |
| 3165 | - text: m["text"], | |
| 3585 | + text: m["text"] && decode_text(m["text"]), | |
| 3166 | 3586 | theta: m["theta"], |
| 3167 | 3587 | thickness: m["thickness"], |
| 3168 | 3588 | } |
| @@ -3369,6 +3789,18 @@ defmodule VGTitleConfig do | ||
| 3369 | 3789 | orient: TitleOrient.t() | nil |
| 3370 | 3790 | } |
| 3371 | 3791 | |
| 3792 | + def decode_color(value) when is_binary(value), do: value | |
| 3793 | + def decode_color(_), do: {:error, "Unexpected type when decoding VGTitleConfig.color"} | |
| 3794 | + | |
| 3795 | + def encode_color(value) when is_binary(value), do: value | |
| 3796 | + def encode_color(_), do: {:error, "Unexpected type when encoding VGTitleConfig.color"} | |
| 3797 | + | |
| 3798 | + def decode_font(value) when is_binary(value), do: value | |
| 3799 | + def decode_font(_), do: {:error, "Unexpected type when decoding VGTitleConfig.font"} | |
| 3800 | + | |
| 3801 | + def encode_font(value) when is_binary(value), do: value | |
| 3802 | + def encode_font(_), do: {:error, "Unexpected type when encoding VGTitleConfig.font"} | |
| 3803 | + | |
| 3372 | 3804 | def decode_font_weight(value) when is_binary(value), do: FontWeight.decode(value) |
| 3373 | 3805 | def decode_font_weight(value) when is_float(value), do: value |
| 3374 | 3806 | def decode_font_weight(value) when is_integer(value), do: value |
| @@ -3386,8 +3818,8 @@ defmodule VGTitleConfig do | ||
| 3386 | 3818 | anchor: m["anchor"] && Anchor.decode(m["anchor"]), |
| 3387 | 3819 | angle: m["angle"], |
| 3388 | 3820 | baseline: m["baseline"] && VerticalAlign.decode(m["baseline"]), |
| 3389 | - color: m["color"], | |
| 3390 | - font: m["font"], | |
| 3821 | + color: m["color"] && decode_color(m["color"]), | |
| 3822 | + font: m["font"] && decode_font(m["font"]), | |
| 3391 | 3823 | font_size: m["fontSize"], |
| 3392 | 3824 | font_weight: decode_font_weight(m["fontWeight"]), |
| 3393 | 3825 | limit: m["limit"], |
| @@ -3454,13 +3886,25 @@ defmodule ViewConfig do | ||
| 3454 | 3886 | width: float() | nil |
| 3455 | 3887 | } |
| 3456 | 3888 | |
| 3889 | + def decode_fill(value) when is_binary(value), do: value | |
| 3890 | + def decode_fill(_), do: {:error, "Unexpected type when decoding ViewConfig.fill"} | |
| 3891 | + | |
| 3892 | + def encode_fill(value) when is_binary(value), do: value | |
| 3893 | + def encode_fill(_), do: {:error, "Unexpected type when encoding ViewConfig.fill"} | |
| 3894 | + | |
| 3895 | + def decode_stroke(value) when is_binary(value), do: value | |
| 3896 | + def decode_stroke(_), do: {:error, "Unexpected type when decoding ViewConfig.stroke"} | |
| 3897 | + | |
| 3898 | + def encode_stroke(value) when is_binary(value), do: value | |
| 3899 | + def encode_stroke(_), do: {:error, "Unexpected type when encoding ViewConfig.stroke"} | |
| 3900 | + | |
| 3457 | 3901 | def from_map(m) do |
| 3458 | 3902 | %ViewConfig{ |
| 3459 | 3903 | clip: m["clip"], |
| 3460 | - fill: m["fill"], | |
| 3904 | + fill: m["fill"] && decode_fill(m["fill"]), | |
| 3461 | 3905 | fill_opacity: m["fillOpacity"], |
| 3462 | 3906 | height: m["height"], |
| 3463 | - stroke: m["stroke"], | |
| 3907 | + stroke: m["stroke"] && decode_stroke(m["stroke"]), | |
| 3464 | 3908 | stroke_dash: m["strokeDash"], |
| 3465 | 3909 | stroke_dash_offset: m["strokeDashOffset"], |
| 3466 | 3910 | stroke_opacity: m["strokeOpacity"], |
| @@ -3592,6 +4036,24 @@ defmodule ConfigClass do | ||
| 3592 | 4036 | def encode_autosize(value) when is_nil(value), do: value |
| 3593 | 4037 | def encode_autosize(_), do: {:error, "Unexpected type when encoding ConfigClass.autosize"} |
| 3594 | 4038 | |
| 4039 | + def decode_background(value) when is_binary(value), do: value | |
| 4040 | + def decode_background(_), do: {:error, "Unexpected type when decoding ConfigClass.background"} | |
| 4041 | + | |
| 4042 | + def encode_background(value) when is_binary(value), do: value | |
| 4043 | + def encode_background(_), do: {:error, "Unexpected type when encoding ConfigClass.background"} | |
| 4044 | + | |
| 4045 | + def decode_count_title(value) when is_binary(value), do: value | |
| 4046 | + def decode_count_title(_), do: {:error, "Unexpected type when decoding ConfigClass.count_title"} | |
| 4047 | + | |
| 4048 | + def encode_count_title(value) when is_binary(value), do: value | |
| 4049 | + def encode_count_title(_), do: {:error, "Unexpected type when encoding ConfigClass.count_title"} | |
| 4050 | + | |
| 4051 | + def decode_number_format(value) when is_binary(value), do: value | |
| 4052 | + def decode_number_format(_), do: {:error, "Unexpected type when decoding ConfigClass.number_format"} | |
| 4053 | + | |
| 4054 | + def encode_number_format(value) when is_binary(value), do: value | |
| 4055 | + def encode_number_format(_), do: {:error, "Unexpected type when encoding ConfigClass.number_format"} | |
| 4056 | + | |
| 3595 | 4057 | def decode_padding(%{} = value), do: PaddingClass.from_map(value) |
| 3596 | 4058 | def decode_padding(value) when is_float(value), do: value |
| 3597 | 4059 | def decode_padding(value) when is_integer(value), do: value |
| @@ -3612,6 +4074,12 @@ defmodule ConfigClass do | ||
| 3612 | 4074 | def encode_range_value(value) when is_list(value), do: value |
| 3613 | 4075 | def encode_range_value(_), do: {:error, "Unexpected type when encoding ConfigClass.range"} |
| 3614 | 4076 | |
| 4077 | + def decode_time_format(value) when is_binary(value), do: value | |
| 4078 | + def decode_time_format(_), do: {:error, "Unexpected type when decoding ConfigClass.time_format"} | |
| 4079 | + | |
| 4080 | + def encode_time_format(value) when is_binary(value), do: value | |
| 4081 | + def encode_time_format(_), do: {:error, "Unexpected type when encoding ConfigClass.time_format"} | |
| 4082 | + | |
| 3615 | 4083 | def from_map(m) do |
| 3616 | 4084 | %ConfigClass{ |
| 3617 | 4085 | area: m["area"] && MarkConfig.from_map(m["area"]), |
| @@ -3624,17 +4092,17 @@ defmodule ConfigClass do | ||
| 3624 | 4092 | axis_top: m["axisTop"] && VGAxisConfig.from_map(m["axisTop"]), |
| 3625 | 4093 | axis_x: m["axisX"] && VGAxisConfig.from_map(m["axisX"]), |
| 3626 | 4094 | axis_y: m["axisY"] && VGAxisConfig.from_map(m["axisY"]), |
| 3627 | - background: m["background"], | |
| 4095 | + background: m["background"] && decode_background(m["background"]), | |
| 3628 | 4096 | bar: m["bar"] && BarConfig.from_map(m["bar"]), |
| 3629 | 4097 | circle: m["circle"] && MarkConfig.from_map(m["circle"]), |
| 3630 | - count_title: m["countTitle"], | |
| 4098 | + count_title: m["countTitle"] && decode_count_title(m["countTitle"]), | |
| 3631 | 4099 | field_title: m["fieldTitle"] && FieldTitle.decode(m["fieldTitle"]), |
| 3632 | 4100 | geoshape: m["geoshape"] && MarkConfig.from_map(m["geoshape"]), |
| 3633 | 4101 | invalid_values: m["invalidValues"] && InvalidValues.decode(m["invalidValues"]), |
| 3634 | 4102 | legend: m["legend"] && LegendConfig.from_map(m["legend"]), |
| 3635 | 4103 | line: m["line"] && MarkConfig.from_map(m["line"]), |
| 3636 | 4104 | mark: m["mark"] && MarkConfig.from_map(m["mark"]), |
| 3637 | - number_format: m["numberFormat"], | |
| 4105 | + number_format: m["numberFormat"] && decode_number_format(m["numberFormat"]), | |
| 3638 | 4106 | padding: decode_padding(m["padding"]), |
| 3639 | 4107 | point: m["point"] && MarkConfig.from_map(m["point"]), |
| 3640 | 4108 | projection: m["projection"] && ProjectionConfig.from_map(m["projection"]), |
| @@ -3650,7 +4118,7 @@ defmodule ConfigClass do | ||
| 3650 | 4118 | |> Map.new(fn {key, value} -> {key, VGMarkConfig.from_map(value)} end), |
| 3651 | 4119 | text: m["text"] && TextConfig.from_map(m["text"]), |
| 3652 | 4120 | tick: m["tick"] && TickConfig.from_map(m["tick"]), |
| 3653 | - time_format: m["timeFormat"], | |
| 4121 | + time_format: m["timeFormat"] && decode_time_format(m["timeFormat"]), | |
| 3654 | 4122 | title: m["title"] && VGTitleConfig.from_map(m["title"]), |
| 3655 | 4123 | view: m["view"] && ViewConfig.from_map(m["view"]), |
| 3656 | 4124 | } |
| @@ -3845,13 +4313,31 @@ defmodule DataFormat do | ||
| 3845 | 4313 | def encode_parse(value) when is_nil(value), do: value |
| 3846 | 4314 | def encode_parse(_), do: {:error, "Unexpected type when encoding DataFormat.parse"} |
| 3847 | 4315 | |
| 4316 | + def decode_property(value) when is_binary(value), do: value | |
| 4317 | + def decode_property(_), do: {:error, "Unexpected type when decoding DataFormat.property"} | |
| 4318 | + | |
| 4319 | + def encode_property(value) when is_binary(value), do: value | |
| 4320 | + def encode_property(_), do: {:error, "Unexpected type when encoding DataFormat.property"} | |
| 4321 | + | |
| 4322 | + def decode_feature(value) when is_binary(value), do: value | |
| 4323 | + def decode_feature(_), do: {:error, "Unexpected type when decoding DataFormat.feature"} | |
| 4324 | + | |
| 4325 | + def encode_feature(value) when is_binary(value), do: value | |
| 4326 | + def encode_feature(_), do: {:error, "Unexpected type when encoding DataFormat.feature"} | |
| 4327 | + | |
| 4328 | + def decode_mesh(value) when is_binary(value), do: value | |
| 4329 | + def decode_mesh(_), do: {:error, "Unexpected type when decoding DataFormat.mesh"} | |
| 4330 | + | |
| 4331 | + def encode_mesh(value) when is_binary(value), do: value | |
| 4332 | + def encode_mesh(_), do: {:error, "Unexpected type when encoding DataFormat.mesh"} | |
| 4333 | + | |
| 3848 | 4334 | def from_map(m) do |
| 3849 | 4335 | %DataFormat{ |
| 3850 | 4336 | parse: decode_parse(m["parse"]), |
| 3851 | 4337 | type: m["type"] && DataFormatType.decode(m["type"]), |
| 3852 | - property: m["property"], | |
| 3853 | - feature: m["feature"], | |
| 3854 | - mesh: m["mesh"], | |
| 4338 | + property: m["property"] && decode_property(m["property"]), | |
| 4339 | + feature: m["feature"] && decode_feature(m["feature"]), | |
| 4340 | + mesh: m["mesh"] && decode_mesh(m["mesh"]), | |
| 3855 | 4341 | } |
| 3856 | 4342 | end |
| 3857 | 4343 | |
| @@ -3898,6 +4384,12 @@ defmodule Data do | ||
| 3898 | 4384 | name: String.t() | nil |
| 3899 | 4385 | } |
| 3900 | 4386 | |
| 4387 | + def decode_url(value) when is_binary(value), do: value | |
| 4388 | + def decode_url(_), do: {:error, "Unexpected type when decoding Data.url"} | |
| 4389 | + | |
| 4390 | + def encode_url(value) when is_binary(value), do: value | |
| 4391 | + def encode_url(_), do: {:error, "Unexpected type when encoding Data.url"} | |
| 4392 | + | |
| 3901 | 4393 | def decode_values(value) when is_binary(value), do: value |
| 3902 | 4394 | def decode_values(value) when is_list(value), do: value |
| 3903 | 4395 | def decode_values(value) when is_map(value), do: value |
| @@ -3910,12 +4402,18 @@ defmodule Data do | ||
| 3910 | 4402 | def encode_values(value) when is_nil(value), do: value |
| 3911 | 4403 | def encode_values(_), do: {:error, "Unexpected type when encoding Data.values"} |
| 3912 | 4404 | |
| 4405 | + def decode_name(value) when is_binary(value), do: value | |
| 4406 | + def decode_name(_), do: {:error, "Unexpected type when decoding Data.name"} | |
| 4407 | + | |
| 4408 | + def encode_name(value) when is_binary(value), do: value | |
| 4409 | + def encode_name(_), do: {:error, "Unexpected type when encoding Data.name"} | |
| 4410 | + | |
| 3913 | 4411 | def from_map(m) do |
| 3914 | 4412 | %Data{ |
| 3915 | 4413 | format: m["format"] && DataFormat.from_map(m["format"]), |
| 3916 | - url: m["url"], | |
| 4414 | + url: m["url"] && decode_url(m["url"]), | |
| 3917 | 4415 | values: decode_values(m["values"]), |
| 3918 | - name: m["name"], | |
| 4416 | + name: m["name"] && decode_name(m["name"]), | |
| 3919 | 4417 | } |
| 3920 | 4418 | end |
| 3921 | 4419 | |
| @@ -4397,6 +4895,12 @@ defmodule Predicate do | ||
| 4397 | 4895 | def encode_equal(value) when is_nil(value), do: value |
| 4398 | 4896 | def encode_equal(_), do: {:error, "Unexpected type when encoding Predicate.equal"} |
| 4399 | 4897 | |
| 4898 | + def decode_field(value) when is_binary(value), do: value | |
| 4899 | + def decode_field(_), do: {:error, "Unexpected type when decoding Predicate.field"} | |
| 4900 | + | |
| 4901 | + def encode_field(value) when is_binary(value), do: value | |
| 4902 | + def encode_field(_), do: {:error, "Unexpected type when encoding Predicate.field"} | |
| 4903 | + | |
| 4400 | 4904 | def decode_range_element(%{} = value), do: DateTimeClass.from_map(value) |
| 4401 | 4905 | def decode_range_element(value) when is_float(value), do: value |
| 4402 | 4906 | def decode_range_element(value) when is_integer(value), do: value |
| @@ -4439,7 +4943,7 @@ defmodule Predicate do | ||
| 4439 | 4943 | predicate_and: m["and"] && Enum.map(m["and"], &decode_predicate_and_element/1), |
| 4440 | 4944 | predicate_or: m["or"] && Enum.map(m["or"], &decode_predicate_or_element/1), |
| 4441 | 4945 | equal: decode_equal(m["equal"]), |
| 4442 | - field: m["field"], | |
| 4946 | + field: m["field"] && decode_field(m["field"]), | |
| 4443 | 4947 | time_unit: m["timeUnit"] && TimeUnit.decode(m["timeUnit"]), |
| 4444 | 4948 | range: m["range"] && Enum.map(m["range"], &decode_range_element/1), |
| 4445 | 4949 | one_of: m["oneOf"] && Enum.map(m["oneOf"], &decode_one_of_element/1), |
| @@ -4704,6 +5208,12 @@ defmodule Legend do | ||
| 4704 | 5208 | zindex: float() | nil |
| 4705 | 5209 | } |
| 4706 | 5210 | |
| 5211 | + def decode_format(value) when is_binary(value), do: value | |
| 5212 | + def decode_format(_), do: {:error, "Unexpected type when decoding Legend.format"} | |
| 5213 | + | |
| 5214 | + def encode_format(value) when is_binary(value), do: value | |
| 5215 | + def encode_format(_), do: {:error, "Unexpected type when encoding Legend.format"} | |
| 5216 | + | |
| 4707 | 5217 | def decode_values_element(%{} = value), do: DateTimeClass.from_map(value) |
| 4708 | 5218 | def decode_values_element(value) when is_float(value), do: value |
| 4709 | 5219 | def decode_values_element(value) when is_integer(value), do: value |
| @@ -4719,7 +5229,7 @@ defmodule Legend do | ||
| 4719 | 5229 | def from_map(m) do |
| 4720 | 5230 | %Legend{ |
| 4721 | 5231 | entry_padding: m["entryPadding"], |
| 4722 | - format: m["format"], | |
| 5232 | + format: m["format"] && decode_format(m["format"]), | |
| 4723 | 5233 | offset: m["offset"], |
| 4724 | 5234 | orient: m["orient"] && LegendOrient.decode(m["orient"]), |
| 4725 | 5235 | padding: m["padding"], |
| @@ -4775,17 +5285,29 @@ defmodule DomainClass do | ||
| 4775 | 5285 | encoding: String.t() | nil |
| 4776 | 5286 | } |
| 4777 | 5287 | |
| 5288 | + def decode_field(value) when is_binary(value), do: value | |
| 5289 | + def decode_field(_), do: {:error, "Unexpected type when decoding DomainClass.field"} | |
| 5290 | + | |
| 5291 | + def encode_field(value) when is_binary(value), do: value | |
| 5292 | + def encode_field(_), do: {:error, "Unexpected type when encoding DomainClass.field"} | |
| 5293 | + | |
| 4778 | 5294 | def decode_selection(value) when is_binary(value), do: value |
| 4779 | 5295 | def decode_selection(_), do: {:error, "Unexpected type when decoding DomainClass.selection"} |
| 4780 | 5296 | |
| 4781 | 5297 | def encode_selection(value) when is_binary(value), do: value |
| 4782 | 5298 | def encode_selection(_), do: {:error, "Unexpected type when encoding DomainClass.selection"} |
| 4783 | 5299 | |
| 5300 | + def decode_encoding(value) when is_binary(value), do: value | |
| 5301 | + def decode_encoding(_), do: {:error, "Unexpected type when decoding DomainClass.encoding"} | |
| 5302 | + | |
| 5303 | + def encode_encoding(value) when is_binary(value), do: value | |
| 5304 | + def encode_encoding(_), do: {:error, "Unexpected type when encoding DomainClass.encoding"} | |
| 5305 | + | |
| 4784 | 5306 | def from_map(m) do |
| 4785 | 5307 | %DomainClass{ |
| 4786 | - field: m["field"], | |
| 5308 | + field: m["field"] && decode_field(m["field"]), | |
| 4787 | 5309 | selection: decode_selection(m["selection"]), |
| 4788 | - encoding: m["encoding"], | |
| 5310 | + encoding: m["encoding"] && decode_encoding(m["encoding"]), | |
| 4789 | 5311 | } |
| 4790 | 5312 | end |
| 4791 | 5313 | |
| @@ -5772,9 +6294,15 @@ defmodule Header do | ||
| 5772 | 6294 | title: nil | String.t() | nil |
| 5773 | 6295 | } |
| 5774 | 6296 | |
| 6297 | + def decode_format(value) when is_binary(value), do: value | |
| 6298 | + def decode_format(_), do: {:error, "Unexpected type when decoding Header.format"} | |
| 6299 | + | |
| 6300 | + def encode_format(value) when is_binary(value), do: value | |
| 6301 | + def encode_format(_), do: {:error, "Unexpected type when encoding Header.format"} | |
| 6302 | + | |
| 5775 | 6303 | def from_map(m) do |
| 5776 | 6304 | %Header{ |
| 5777 | - format: m["format"], | |
| 6305 | + format: m["format"] && decode_format(m["format"]), | |
| 5778 | 6306 | label_angle: m["labelAngle"], |
| 5779 | 6307 | title: m["title"], |
| 5780 | 6308 | } |
| @@ -6309,6 +6837,12 @@ defmodule ConditionalPredicateTextFieldDefClass do | ||
| 6309 | 6837 | def encode_field(value) when is_nil(value), do: value |
| 6310 | 6838 | def encode_field(_), do: {:error, "Unexpected type when encoding ConditionalPredicateTextFieldDefClass.field"} |
| 6311 | 6839 | |
| 6840 | + def decode_format(value) when is_binary(value), do: value | |
| 6841 | + def decode_format(_), do: {:error, "Unexpected type when decoding ConditionalPredicateTextFieldDefClass.format"} | |
| 6842 | + | |
| 6843 | + def encode_format(value) when is_binary(value), do: value | |
| 6844 | + def encode_format(_), do: {:error, "Unexpected type when encoding ConditionalPredicateTextFieldDefClass.format"} | |
| 6845 | + | |
| 6312 | 6846 | def from_map(m) do |
| 6313 | 6847 | %ConditionalPredicateTextFieldDefClass{ |
| 6314 | 6848 | test: decode_test(m["test"]), |
| @@ -6317,7 +6851,7 @@ defmodule ConditionalPredicateTextFieldDefClass do | ||
| 6317 | 6851 | aggregate: m["aggregate"] && AggregateOp.decode(m["aggregate"]), |
| 6318 | 6852 | bin: decode_bin(m["bin"]), |
| 6319 | 6853 | field: decode_field(m["field"]), |
| 6320 | - format: m["format"], | |
| 6854 | + format: m["format"] && decode_format(m["format"]), | |
| 6321 | 6855 | time_unit: m["timeUnit"] && TimeUnit.decode(m["timeUnit"]), |
| 6322 | 6856 | type: m["type"] && Type.decode(m["type"]), |
| 6323 | 6857 | } |
| @@ -6421,13 +6955,19 @@ defmodule TextDefWithCondition do | ||
| 6421 | 6955 | def encode_field(value) when is_nil(value), do: value |
| 6422 | 6956 | def encode_field(_), do: {:error, "Unexpected type when encoding TextDefWithCondition.field"} |
| 6423 | 6957 | |
| 6958 | + def decode_format(value) when is_binary(value), do: value | |
| 6959 | + def decode_format(_), do: {:error, "Unexpected type when decoding TextDefWithCondition.format"} | |
| 6960 | + | |
| 6961 | + def encode_format(value) when is_binary(value), do: value | |
| 6962 | + def encode_format(_), do: {:error, "Unexpected type when encoding TextDefWithCondition.format"} | |
| 6963 | + | |
| 6424 | 6964 | def from_map(m) do |
| 6425 | 6965 | %TextDefWithCondition{ |
| 6426 | 6966 | aggregate: m["aggregate"] && AggregateOp.decode(m["aggregate"]), |
| 6427 | 6967 | bin: decode_bin(m["bin"]), |
| 6428 | 6968 | condition: decode_condition(m["condition"]), |
| 6429 | 6969 | field: decode_field(m["field"]), |
| 6430 | - format: m["format"], | |
| 6970 | + format: m["format"] && decode_format(m["format"]), | |
| 6431 | 6971 | time_unit: m["timeUnit"] && TimeUnit.decode(m["timeUnit"]), |
| 6432 | 6972 | type: m["type"] && Type.decode(m["type"]), |
| 6433 | 6973 | value: m["value"], |
| @@ -6513,6 +7053,12 @@ defmodule Axis do | ||
| 6513 | 7053 | zindex: float() | nil |
| 6514 | 7054 | } |
| 6515 | 7055 | |
| 7056 | + def decode_format(value) when is_binary(value), do: value | |
| 7057 | + def decode_format(_), do: {:error, "Unexpected type when decoding Axis.format"} | |
| 7058 | + | |
| 7059 | + def encode_format(value) when is_binary(value), do: value | |
| 7060 | + def encode_format(_), do: {:error, "Unexpected type when encoding Axis.format"} | |
| 7061 | + | |
| 6516 | 7062 | def decode_label_overlap(value) when is_boolean(value), do: value |
| 6517 | 7063 | def decode_label_overlap(value) when is_binary(value), do: LabelOverlapEnum.decode(value) |
| 6518 | 7064 | def decode_label_overlap(value) when is_nil(value), do: value |
| @@ -6536,7 +7082,7 @@ defmodule Axis do | ||
| 6536 | 7082 | def from_map(m) do |
| 6537 | 7083 | %Axis{ |
| 6538 | 7084 | domain: m["domain"], |
| 6539 | - format: m["format"], | |
| 7085 | + format: m["format"] && decode_format(m["format"]), | |
| 6540 | 7086 | grid: m["grid"], |
| 6541 | 7087 | label_angle: m["labelAngle"], |
| 6542 | 7088 | label_bound: m["labelBound"], |
| @@ -7188,6 +7734,24 @@ defmodule MarkDef do | ||
| 7188 | 7734 | type: Mark.t() |
| 7189 | 7735 | } |
| 7190 | 7736 | |
| 7737 | + def decode_color(value) when is_binary(value), do: value | |
| 7738 | + def decode_color(_), do: {:error, "Unexpected type when decoding MarkDef.color"} | |
| 7739 | + | |
| 7740 | + def encode_color(value) when is_binary(value), do: value | |
| 7741 | + def encode_color(_), do: {:error, "Unexpected type when encoding MarkDef.color"} | |
| 7742 | + | |
| 7743 | + def decode_fill(value) when is_binary(value), do: value | |
| 7744 | + def decode_fill(_), do: {:error, "Unexpected type when decoding MarkDef.fill"} | |
| 7745 | + | |
| 7746 | + def encode_fill(value) when is_binary(value), do: value | |
| 7747 | + def encode_fill(_), do: {:error, "Unexpected type when encoding MarkDef.fill"} | |
| 7748 | + | |
| 7749 | + def decode_font(value) when is_binary(value), do: value | |
| 7750 | + def decode_font(_), do: {:error, "Unexpected type when decoding MarkDef.font"} | |
| 7751 | + | |
| 7752 | + def encode_font(value) when is_binary(value), do: value | |
| 7753 | + def encode_font(_), do: {:error, "Unexpected type when encoding MarkDef.font"} | |
| 7754 | + | |
| 7191 | 7755 | def decode_font_weight(value) when is_binary(value), do: FontWeight.decode(value) |
| 7192 | 7756 | def decode_font_weight(value) when is_float(value), do: value |
| 7193 | 7757 | def decode_font_weight(value) when is_integer(value), do: value |
| @@ -7200,6 +7764,24 @@ defmodule MarkDef do | ||
| 7200 | 7764 | def encode_font_weight(value) when is_nil(value), do: value |
| 7201 | 7765 | def encode_font_weight(_), do: {:error, "Unexpected type when encoding MarkDef.font_weight"} |
| 7202 | 7766 | |
| 7767 | + def decode_href(value) when is_binary(value), do: value | |
| 7768 | + def decode_href(_), do: {:error, "Unexpected type when decoding MarkDef.href"} | |
| 7769 | + | |
| 7770 | + def encode_href(value) when is_binary(value), do: value | |
| 7771 | + def encode_href(_), do: {:error, "Unexpected type when encoding MarkDef.href"} | |
| 7772 | + | |
| 7773 | + def decode_shape(value) when is_binary(value), do: value | |
| 7774 | + def decode_shape(_), do: {:error, "Unexpected type when decoding MarkDef.shape"} | |
| 7775 | + | |
| 7776 | + def encode_shape(value) when is_binary(value), do: value | |
| 7777 | + def encode_shape(_), do: {:error, "Unexpected type when encoding MarkDef.shape"} | |
| 7778 | + | |
| 7779 | + def decode_stroke(value) when is_binary(value), do: value | |
| 7780 | + def decode_stroke(_), do: {:error, "Unexpected type when decoding MarkDef.stroke"} | |
| 7781 | + | |
| 7782 | + def encode_stroke(value) when is_binary(value), do: value | |
| 7783 | + def encode_stroke(_), do: {:error, "Unexpected type when encoding MarkDef.stroke"} | |
| 7784 | + | |
| 7203 | 7785 | def decode_style(value) when is_binary(value), do: value |
| 7204 | 7786 | def decode_style(value) when is_list(value), do: value |
| 7205 | 7787 | def decode_style(value) when is_nil(value), do: value |
| @@ -7210,39 +7792,45 @@ defmodule MarkDef do | ||
| 7210 | 7792 | def encode_style(value) when is_nil(value), do: value |
| 7211 | 7793 | def encode_style(_), do: {:error, "Unexpected type when encoding MarkDef.style"} |
| 7212 | 7794 | |
| 7795 | + def decode_text(value) when is_binary(value), do: value | |
| 7796 | + def decode_text(_), do: {:error, "Unexpected type when decoding MarkDef.text"} | |
| 7797 | + | |
| 7798 | + def encode_text(value) when is_binary(value), do: value | |
| 7799 | + def encode_text(_), do: {:error, "Unexpected type when encoding MarkDef.text"} | |
| 7800 | + | |
| 7213 | 7801 | def from_map(m) do |
| 7214 | 7802 | %MarkDef{ |
| 7215 | 7803 | align: m["align"] && HorizontalAlign.decode(m["align"]), |
| 7216 | 7804 | angle: m["angle"], |
| 7217 | 7805 | baseline: m["baseline"] && VerticalAlign.decode(m["baseline"]), |
| 7218 | 7806 | clip: m["clip"], |
| 7219 | - color: m["color"], | |
| 7807 | + color: m["color"] && decode_color(m["color"]), | |
| 7220 | 7808 | cursor: m["cursor"] && Cursor.decode(m["cursor"]), |
| 7221 | 7809 | dx: m["dx"], |
| 7222 | 7810 | dy: m["dy"], |
| 7223 | - fill: m["fill"], | |
| 7811 | + fill: m["fill"] && decode_fill(m["fill"]), | |
| 7224 | 7812 | filled: m["filled"], |
| 7225 | 7813 | fill_opacity: m["fillOpacity"], |
| 7226 | - font: m["font"], | |
| 7814 | + font: m["font"] && decode_font(m["font"]), | |
| 7227 | 7815 | font_size: m["fontSize"], |
| 7228 | 7816 | font_style: m["fontStyle"] && FontStyle.decode(m["fontStyle"]), |
| 7229 | 7817 | font_weight: decode_font_weight(m["fontWeight"]), |
| 7230 | - href: m["href"], | |
| 7818 | + href: m["href"] && decode_href(m["href"]), | |
| 7231 | 7819 | interpolate: m["interpolate"] && Interpolate.decode(m["interpolate"]), |
| 7232 | 7820 | limit: m["limit"], |
| 7233 | 7821 | opacity: m["opacity"], |
| 7234 | 7822 | orient: m["orient"] && Orient.decode(m["orient"]), |
| 7235 | 7823 | radius: m["radius"], |
| 7236 | - shape: m["shape"], | |
| 7824 | + shape: m["shape"] && decode_shape(m["shape"]), | |
| 7237 | 7825 | size: m["size"], |
| 7238 | - stroke: m["stroke"], | |
| 7826 | + stroke: m["stroke"] && decode_stroke(m["stroke"]), | |
| 7239 | 7827 | stroke_dash: m["strokeDash"], |
| 7240 | 7828 | stroke_dash_offset: m["strokeDashOffset"], |
| 7241 | 7829 | stroke_opacity: m["strokeOpacity"], |
| 7242 | 7830 | stroke_width: m["strokeWidth"], |
| 7243 | 7831 | style: decode_style(m["style"]), |
| 7244 | 7832 | tension: m["tension"], |
| 7245 | - text: m["text"], | |
| 7833 | + text: m["text"] && decode_text(m["text"]), | |
| 7246 | 7834 | theta: m["theta"], |
| 7247 | 7835 | type: Mark.decode(m["type"]), |
| 7248 | 7836 | } |
| @@ -7986,6 +8574,24 @@ defmodule Transform do | ||
| 7986 | 8574 | def encode_as(value) when is_nil(value), do: value |
| 7987 | 8575 | def encode_as(_), do: {:error, "Unexpected type when encoding Transform.as"} |
| 7988 | 8576 | |
| 8577 | + def decode_calculate(value) when is_binary(value), do: value | |
| 8578 | + def decode_calculate(_), do: {:error, "Unexpected type when decoding Transform.calculate"} | |
| 8579 | + | |
| 8580 | + def encode_calculate(value) when is_binary(value), do: value | |
| 8581 | + def encode_calculate(_), do: {:error, "Unexpected type when encoding Transform.calculate"} | |
| 8582 | + | |
| 8583 | + def decode_default(value) when is_binary(value), do: value | |
| 8584 | + def decode_default(_), do: {:error, "Unexpected type when decoding Transform.default"} | |
| 8585 | + | |
| 8586 | + def encode_default(value) when is_binary(value), do: value | |
| 8587 | + def encode_default(_), do: {:error, "Unexpected type when encoding Transform.default"} | |
| 8588 | + | |
| 8589 | + def decode_lookup(value) when is_binary(value), do: value | |
| 8590 | + def decode_lookup(_), do: {:error, "Unexpected type when decoding Transform.lookup"} | |
| 8591 | + | |
| 8592 | + def encode_lookup(value) when is_binary(value), do: value | |
| 8593 | + def encode_lookup(_), do: {:error, "Unexpected type when encoding Transform.lookup"} | |
| 8594 | + | |
| 7989 | 8595 | def decode_bin(%{} = value), do: BinParams.from_map(value) |
| 7990 | 8596 | def decode_bin(value) when is_boolean(value), do: value |
| 7991 | 8597 | def decode_bin(value) when is_nil(value), do: value |
| @@ -7996,16 +8602,22 @@ defmodule Transform do | ||
| 7996 | 8602 | def encode_bin(value) when is_nil(value), do: value |
| 7997 | 8603 | def encode_bin(_), do: {:error, "Unexpected type when encoding Transform.bin"} |
| 7998 | 8604 | |
| 8605 | + def decode_field(value) when is_binary(value), do: value | |
| 8606 | + def decode_field(_), do: {:error, "Unexpected type when decoding Transform.field"} | |
| 8607 | + | |
| 8608 | + def encode_field(value) when is_binary(value), do: value | |
| 8609 | + def encode_field(_), do: {:error, "Unexpected type when encoding Transform.field"} | |
| 8610 | + | |
| 7999 | 8611 | def from_map(m) do |
| 8000 | 8612 | %Transform{ |
| 8001 | 8613 | filter: decode_filter(m["filter"]), |
| 8002 | 8614 | as: decode_as(m["as"]), |
| 8003 | - calculate: m["calculate"], | |
| 8004 | - default: m["default"], | |
| 8615 | + calculate: m["calculate"] && decode_calculate(m["calculate"]), | |
| 8616 | + default: m["default"] && decode_default(m["default"]), | |
| 8005 | 8617 | from: m["from"] && LookupData.from_map(m["from"]), |
| 8006 | - lookup: m["lookup"], | |
| 8618 | + lookup: m["lookup"] && decode_lookup(m["lookup"]), | |
| 8007 | 8619 | bin: decode_bin(m["bin"]), |
| 8008 | - field: m["field"], | |
| 8620 | + field: m["field"] && decode_field(m["field"]), | |
| 8009 | 8621 | time_unit: m["timeUnit"] && TimeUnit.decode(m["timeUnit"]), |
| 8010 | 8622 | aggregate: m["aggregate"] && Enum.map(m["aggregate"], &AggregatedFieldDef.from_map/1), |
| 8011 | 8623 | groupby: m["groupby"], |
| @@ -8077,6 +8689,18 @@ defmodule LayerSpec do | ||
| 8077 | 8689 | selection: %{String.t() => SelectionDef.t()} | nil |
| 8078 | 8690 | } |
| 8079 | 8691 | |
| 8692 | + def decode_description(value) when is_binary(value), do: value | |
| 8693 | + def decode_description(_), do: {:error, "Unexpected type when decoding LayerSpec.description"} | |
| 8694 | + | |
| 8695 | + def encode_description(value) when is_binary(value), do: value | |
| 8696 | + def encode_description(_), do: {:error, "Unexpected type when encoding LayerSpec.description"} | |
| 8697 | + | |
| 8698 | + def decode_name(value) when is_binary(value), do: value | |
| 8699 | + def decode_name(_), do: {:error, "Unexpected type when decoding LayerSpec.name"} | |
| 8700 | + | |
| 8701 | + def encode_name(value) when is_binary(value), do: value | |
| 8702 | + def encode_name(_), do: {:error, "Unexpected type when encoding LayerSpec.name"} | |
| 8703 | + | |
| 8080 | 8704 | def decode_title(%{"text" => _,} = value), do: TitleParams.from_map(value) |
| 8081 | 8705 | def decode_title(value) when is_binary(value), do: value |
| 8082 | 8706 | def decode_title(value) when is_nil(value), do: value |
| @@ -8100,10 +8724,10 @@ defmodule LayerSpec do | ||
| 8100 | 8724 | def from_map(m) do |
| 8101 | 8725 | %LayerSpec{ |
| 8102 | 8726 | data: m["data"] && Data.from_map(m["data"]), |
| 8103 | - description: m["description"], | |
| 8727 | + description: m["description"] && decode_description(m["description"]), | |
| 8104 | 8728 | height: m["height"], |
| 8105 | 8729 | layer: m["layer"] && Enum.map(m["layer"], &LayerSpec.from_map/1), |
| 8106 | - name: m["name"], | |
| 8730 | + name: m["name"] && decode_name(m["name"]), | |
| 8107 | 8731 | resolve: m["resolve"] && Resolve.from_map(m["resolve"]), |
| 8108 | 8732 | title: decode_title(m["title"]), |
| 8109 | 8733 | transform: m["transform"] && Enum.map(m["transform"], &Transform.from_map/1), |
| @@ -8236,6 +8860,18 @@ defmodule Spec do | ||
| 8236 | 8860 | hconcat: [Spec.t()] | nil |
| 8237 | 8861 | } |
| 8238 | 8862 | |
| 8863 | + def decode_description(value) when is_binary(value), do: value | |
| 8864 | + def decode_description(_), do: {:error, "Unexpected type when decoding Spec.description"} | |
| 8865 | + | |
| 8866 | + def encode_description(value) when is_binary(value), do: value | |
| 8867 | + def encode_description(_), do: {:error, "Unexpected type when encoding Spec.description"} | |
| 8868 | + | |
| 8869 | + def decode_name(value) when is_binary(value), do: value | |
| 8870 | + def decode_name(_), do: {:error, "Unexpected type when decoding Spec.name"} | |
| 8871 | + | |
| 8872 | + def encode_name(value) when is_binary(value), do: value | |
| 8873 | + def encode_name(_), do: {:error, "Unexpected type when encoding Spec.name"} | |
| 8874 | + | |
| 8239 | 8875 | def decode_title(%{"text" => _,} = value), do: TitleParams.from_map(value) |
| 8240 | 8876 | def decode_title(value) when is_binary(value), do: value |
| 8241 | 8877 | def decode_title(value) when is_nil(value), do: value |
| @@ -8259,10 +8895,10 @@ defmodule Spec do | ||
| 8259 | 8895 | def from_map(m) do |
| 8260 | 8896 | %Spec{ |
| 8261 | 8897 | data: m["data"] && Data.from_map(m["data"]), |
| 8262 | - description: m["description"], | |
| 8898 | + description: m["description"] && decode_description(m["description"]), | |
| 8263 | 8899 | height: m["height"], |
| 8264 | 8900 | layer: m["layer"] && Enum.map(m["layer"], &LayerSpec.from_map/1), |
| 8265 | - name: m["name"], | |
| 8901 | + name: m["name"] && decode_name(m["name"]), | |
| 8266 | 8902 | resolve: m["resolve"] && Resolve.from_map(m["resolve"]), |
| 8267 | 8903 | title: decode_title(m["title"]), |
| 8268 | 8904 | transform: m["transform"] && Enum.map(m["transform"], &Transform.from_map/1), |
| @@ -8372,6 +9008,12 @@ defmodule TopLevel do | ||
| 8372 | 9008 | hconcat: [Spec.t()] | nil |
| 8373 | 9009 | } |
| 8374 | 9010 | |
| 9011 | + def decode_schema(value) when is_binary(value), do: value | |
| 9012 | + def decode_schema(_), do: {:error, "Unexpected type when decoding TopLevel.schema"} | |
| 9013 | + | |
| 9014 | + def encode_schema(value) when is_binary(value), do: value | |
| 9015 | + def encode_schema(_), do: {:error, "Unexpected type when encoding TopLevel.schema"} | |
| 9016 | + | |
| 8375 | 9017 | def decode_autosize(%{} = value), do: AutoSizeParams.from_map(value) |
| 8376 | 9018 | def decode_autosize(value) when is_binary(value), do: AutosizeType.decode(value) |
| 8377 | 9019 | def decode_autosize(value) when is_nil(value), do: value |
| @@ -8382,6 +9024,18 @@ defmodule TopLevel do | ||
| 8382 | 9024 | def encode_autosize(value) when is_nil(value), do: value |
| 8383 | 9025 | def encode_autosize(_), do: {:error, "Unexpected type when encoding TopLevel.autosize"} |
| 8384 | 9026 | |
| 9027 | + def decode_background(value) when is_binary(value), do: value | |
| 9028 | + def decode_background(_), do: {:error, "Unexpected type when decoding TopLevel.background"} | |
| 9029 | + | |
| 9030 | + def encode_background(value) when is_binary(value), do: value | |
| 9031 | + def encode_background(_), do: {:error, "Unexpected type when encoding TopLevel.background"} | |
| 9032 | + | |
| 9033 | + def decode_description(value) when is_binary(value), do: value | |
| 9034 | + def decode_description(_), do: {:error, "Unexpected type when decoding TopLevel.description"} | |
| 9035 | + | |
| 9036 | + def encode_description(value) when is_binary(value), do: value | |
| 9037 | + def encode_description(_), do: {:error, "Unexpected type when encoding TopLevel.description"} | |
| 9038 | + | |
| 8385 | 9039 | def decode_mark(%{"type" => _,} = value), do: MarkDef.from_map(value) |
| 8386 | 9040 | def decode_mark(value) when is_binary(value), do: Mark.decode(value) |
| 8387 | 9041 | def decode_mark(value) when is_nil(value), do: value |
| @@ -8392,6 +9046,12 @@ defmodule TopLevel do | ||
| 8392 | 9046 | def encode_mark(value) when is_nil(value), do: value |
| 8393 | 9047 | def encode_mark(_), do: {:error, "Unexpected type when encoding TopLevel.mark"} |
| 8394 | 9048 | |
| 9049 | + def decode_name(value) when is_binary(value), do: value | |
| 9050 | + def decode_name(_), do: {:error, "Unexpected type when decoding TopLevel.name"} | |
| 9051 | + | |
| 9052 | + def encode_name(value) when is_binary(value), do: value | |
| 9053 | + def encode_name(_), do: {:error, "Unexpected type when encoding TopLevel.name"} | |
| 9054 | + | |
| 8395 | 9055 | def decode_padding(%{} = value), do: PaddingClass.from_map(value) |
| 8396 | 9056 | def decode_padding(value) when is_float(value), do: value |
| 8397 | 9057 | def decode_padding(value) when is_integer(value), do: value |
| @@ -8416,16 +9076,16 @@ defmodule TopLevel do | ||
| 8416 | 9076 | |
| 8417 | 9077 | def from_map(m) do |
| 8418 | 9078 | %TopLevel{ |
| 8419 | - schema: m["$schema"], | |
| 9079 | + schema: m["$schema"] && decode_schema(m["$schema"]), | |
| 8420 | 9080 | autosize: decode_autosize(m["autosize"]), |
| 8421 | - background: m["background"], | |
| 9081 | + background: m["background"] && decode_background(m["background"]), | |
| 8422 | 9082 | config: m["config"] && ConfigClass.from_map(m["config"]), |
| 8423 | 9083 | data: m["data"] && Data.from_map(m["data"]), |
| 8424 | - description: m["description"], | |
| 9084 | + description: m["description"] && decode_description(m["description"]), | |
| 8425 | 9085 | encoding: m["encoding"] && EncodingWithFacet.from_map(m["encoding"]), |
| 8426 | 9086 | height: m["height"], |
| 8427 | 9087 | mark: decode_mark(m["mark"]), |
| 8428 | - name: m["name"], | |
| 9088 | + name: m["name"] && decode_name(m["name"]), | |
| 8429 | 9089 | padding: decode_padding(m["padding"]), |
| 8430 | 9090 | projection: m["projection"] && Projection.from_map(m["projection"]), |
| 8431 | 9091 | selection: m["selection"] |
No generated files match these filters.