Skip to content

Commit 4482baa

Browse files
committed
Improve format schema
1 parent abdd27a commit 4482baa

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

lib/schemas.ex

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule ValueFormatters.Schemas do
66
description: "Number of decimal places"
77
},
88
unit: %{
9-
type: :string,
9+
type: [:string, :null],
1010
description: "If set, the formatter appends ' ' + unit to the display value"
1111
}
1212
}
@@ -84,7 +84,7 @@ defmodule ValueFormatters.Schemas.Format do
8484
description: "Formats for value formatting",
8585
oneOf: [
8686
%{
87-
const: nil,
87+
type: :null,
8888
description: "Skip formatting and return raw value."
8989
},
9090
%{
@@ -109,6 +109,11 @@ defmodule ValueFormatters.Schemas.Format do
109109
const: "string",
110110
description:
111111
"Use to explicitly disable any kind of formatting that would otherwise take place, but still return a string."
112+
},
113+
field: %{
114+
type: :string,
115+
description:
116+
"If the value is an object, the field to extract the formattable entity from."
112117
}
113118
},
114119
required: [:format],
@@ -124,6 +129,11 @@ defmodule ValueFormatters.Schemas.Format do
124129
const: "number",
125130
description:
126131
"Use to display numeric values and format them according to the user's locale."
132+
},
133+
field: %{
134+
type: :string,
135+
description:
136+
"If the value is an object, the field to extract the formattable entity from."
127137
}
128138
},
129139
number_options()
@@ -141,6 +151,11 @@ defmodule ValueFormatters.Schemas.Format do
141151
const: "date",
142152
description:
143153
"Use to display date-time values and format them according to the user's locale."
154+
},
155+
field: %{
156+
type: :string,
157+
description:
158+
"If the value is an object, the field to extract the formattable entity from."
144159
}
145160
},
146161
date_options()
@@ -161,6 +176,11 @@ defmodule ValueFormatters.Schemas.Format do
161176
162177
This format currently doesn't support any options.
163178
"""
179+
},
180+
field: %{
181+
type: :string,
182+
description:
183+
"If the value is an object, the field to extract the formattable entity from."
164184
}
165185
},
166186
required: [:format],
@@ -173,6 +193,11 @@ defmodule ValueFormatters.Schemas.Format do
173193
format: %{
174194
const: "date_iso",
175195
description: "Use to display date-time values in ISO 8601 extended format."
196+
},
197+
field: %{
198+
type: :string,
199+
description:
200+
"If the value is an object, the field to extract the formattable entity from."
176201
}
177202
},
178203
required: [:format],
@@ -187,6 +212,11 @@ defmodule ValueFormatters.Schemas.Format do
187212
format: %{
188213
const: "date_unix",
189214
description: "Use to display date-time values in seconds since unix epoch."
215+
},
216+
field: %{
217+
type: :string,
218+
description:
219+
"If the value is an object, the field to extract the formattable entity from."
190220
}
191221
},
192222
date_unix_options()
@@ -203,12 +233,30 @@ defmodule ValueFormatters.Schemas.Format do
203233
format: %{
204234
const: "coordinates",
205235
description: "Use to display latitude & longitude information."
236+
},
237+
field: %{
238+
type: :string,
239+
description:
240+
"If the value is an object, the field to extract the formattable entity from."
206241
}
207242
},
208243
coordinates_options()
209244
),
210245
required: [:format],
211246
additionalProperties: false
247+
},
248+
%{
249+
type: "object",
250+
title: "field",
251+
properties: %{
252+
field: %{
253+
type: :string,
254+
description:
255+
"If the value is an object, the field to extract the formattable entity from."
256+
}
257+
},
258+
required: [:field],
259+
additionalProperties: false
212260
}
213261
]
214262
}

0 commit comments

Comments
 (0)