|
115 | 115 | | field_schema_fun().
|
116 | 116 |
|
117 | 117 | -type field_schema_fun() :: fun((_) -> _).
|
118 |
| --type field_schema_map() :: |
119 |
| - #{ |
120 |
| - type := type(), |
121 |
| - default => term(), |
122 |
| - examples => term(), |
123 |
| - mapping => undefined | string(), |
124 |
| - converter => undefined | translationfunc(), |
125 |
| - validator => undefined | validationfun(), |
126 |
| - %% set false if a field is allowed to be `undefined` |
127 |
| - %% NOTE: has no point setting it to `true` if field has a default value |
128 |
| - |
129 |
| - % default = false |
130 |
| - required => boolean() | {false, recursively}, |
131 |
| - %% for sensitive data obfuscation (password, token) |
132 |
| - sensitive => boolean(), |
133 |
| - desc => desc(), |
134 |
| - %% hide it from doc generation |
135 |
| - importance => importance(), |
136 |
| - %% Set to {since, Version} to mark field as deprecated. |
137 |
| - %% deprecated field can not be removed due to compatibility reasons. |
138 |
| - %% The value will be dropped, |
139 |
| - %% Deprecated fields are treated as required => {false, recursively} |
140 |
| - deprecated => {since, binary() | string()} | false, |
141 |
| - %% Other names to reference this field. |
142 |
| - %% this can be useful when we need to rename some filed names |
143 |
| - %% while keeping backward compatibility. |
144 |
| - %% For one struct, no duplication is allowed in the collection of |
145 |
| - %% all field names and aliases. |
146 |
| - %% The no-duplication assertion is made when dumping the schema to JSON. |
147 |
| - %% see `hocon_schema_json'. |
148 |
| - %% When checking values against the schema, the look up is first |
149 |
| - %% done with the current field name, if not found, try the aliases |
150 |
| - %% in the defined order until one is found (i.e. first match wins). |
151 |
| - aliases => [name()], |
152 |
| - %% transparent metadata |
153 |
| - extra => map() |
154 |
| - }. |
| 118 | + |
| 119 | +-define(FIELD_SCHEMA_MAP(TYPE_KV), #{ |
| 120 | + TYPE_KV, |
| 121 | + default => term(), |
| 122 | + examples => term(), |
| 123 | + mapping => undefined | string(), |
| 124 | + converter => undefined | translationfunc(), |
| 125 | + validator => undefined | validationfun(), |
| 126 | + %% set false if a field is allowed to be `undefined` |
| 127 | + %% NOTE: has no point setting it to `true` if field has a default value |
| 128 | + |
| 129 | + % default = false |
| 130 | + required => boolean() | {false, recursively}, |
| 131 | + %% for sensitive data obfuscation (password, token) |
| 132 | + sensitive => boolean(), |
| 133 | + desc => desc(), |
| 134 | + %% hide it from doc generation |
| 135 | + importance => importance(), |
| 136 | + %% Set to {since, Version} to mark field as deprecated. |
| 137 | + %% deprecated field can not be removed due to compatibility reasons. |
| 138 | + %% The value will be dropped, |
| 139 | + %% Deprecated fields are treated as required => {false, recursively} |
| 140 | + deprecated => {since, binary() | string()} | false, |
| 141 | + %% Other names to reference this field. |
| 142 | + %% this can be useful when we need to rename some filed names |
| 143 | + %% while keeping backward compatibility. |
| 144 | + %% For one struct, no duplication is allowed in the collection of |
| 145 | + %% all field names and aliases. |
| 146 | + %% The no-duplication assertion is made when dumping the schema to JSON. |
| 147 | + %% see `hocon_schema_json'. |
| 148 | + %% When checking values against the schema, the look up is first |
| 149 | + %% done with the current field name, if not found, try the aliases |
| 150 | + %% in the defined order until one is found (i.e. first match wins). |
| 151 | + aliases => [name()], |
| 152 | + %% transparent metadata |
| 153 | + extra => map() |
| 154 | +}). |
| 155 | + |
| 156 | +-type field_schema_map() :: ?FIELD_SCHEMA_MAP(type := type()). |
| 157 | + |
| 158 | +%% Same as `field_schema_map/0`, but `type` is optional when overriding... |
| 159 | +-type field_schema_map_override() :: ?FIELD_SCHEMA_MAP(type => type()). |
155 | 160 |
|
156 | 161 | -type field() :: {name(), typefunc() | field_schema()}.
|
157 | 162 | -type fields() ::
|
@@ -216,7 +221,7 @@ validations(Sc) ->
|
216 | 221 | maps:get(validations, Sc, []).
|
217 | 222 |
|
218 | 223 | %% @doc Make a higher order schema by overriding `Base' with `OnTop'
|
219 |
| --spec override(field_schema(), field_schema_map()) -> field_schema_fun(). |
| 224 | +-spec override(field_schema(), field_schema_map_override()) -> field_schema_fun(). |
220 | 225 | override(Base, OnTop) ->
|
221 | 226 | fun(SchemaKey) ->
|
222 | 227 | case maps:is_key(SchemaKey, OnTop) of
|
|
0 commit comments