Skip to content

Commit 50ccf38

Browse files
committed
update schemas
1 parent 199c80f commit 50ccf38

File tree

1 file changed

+213
-93
lines changed

1 file changed

+213
-93
lines changed

lib/schemas.ex

Lines changed: 213 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
defmodule ValueFormatters.Schemas do
22
if Code.ensure_loaded?(JSV) do
3-
def format do
3+
def format() do
44
%{
55
type: :object,
66
description: "Formats for value formatting",
@@ -19,7 +19,131 @@ defmodule ValueFormatters.Schemas do
1919
"coordinates"
2020
]
2121
},
22-
available_formats_schema()
22+
%{
23+
type: :object,
24+
properties: %{
25+
format: %{
26+
const: "string",
27+
description:
28+
"Use to explicitly disable any kind of formatting that would otherwise take place."
29+
}
30+
}
31+
},
32+
%{
33+
type: :object,
34+
properties: %{
35+
format: %{
36+
const: "number",
37+
description:
38+
"Use to display numeric values and format them according to the user's locale."
39+
},
40+
precision: %{type: :number, description: "Number of decimal places"},
41+
unit: %{
42+
type: :string,
43+
description: "If set, the formatter appends ' ' + unit to the display value"
44+
}
45+
}
46+
},
47+
%{
48+
type: :object,
49+
properties: %{
50+
format: %{
51+
const: "date",
52+
description:
53+
"Use to display date-time values and format them according to the user's locale."
54+
},
55+
date_display: %{
56+
type: :string,
57+
description: """
58+
How the formatter should display the date portion:
59+
60+
- `full`: Wednesday, November 29, 2023
61+
62+
- `long`: November 29, 2023
63+
64+
- `medium`: Nov 29, 2023
65+
66+
- `short`: 11/29/23
67+
68+
- `none`: Don't display date
69+
""",
70+
enum: ["full", "long", "medium", "short", "none"],
71+
default: "medium"
72+
},
73+
time_display: %{
74+
type: :string,
75+
description: """
76+
How the formatter should display the time portion:
77+
78+
- `full`: 3:44:28 PM GMT
79+
80+
- `long`: 3:44:28 PM UTC
81+
82+
- `medium`: 3:44:28 PM
83+
84+
- `short`: 3:44 PM
85+
86+
- `none`: Don't display time
87+
""",
88+
enum: ["full", "long", "medium", "short", "none"],
89+
default: "medium"
90+
}
91+
}
92+
},
93+
%{
94+
type: :object,
95+
properties: %{
96+
format: %{
97+
const: "date_relative",
98+
description: """
99+
Use format: "date_relative" to display a relative date string (e.g. “2 days ago”) by comparing the given value against the current date & time. Only the largest sensible unit is displayed, e.g. the formatter will only display “days” even when other components such as hours, minutes etc. aren't equal to zero.
100+
101+
The implementation can choose to update the displayed value in appropriate intervals. Also, it can choose to display the absolute date on user interaction, e.g. in a tooltip.
102+
103+
This format currently doesn't support any options.
104+
"""
105+
}
106+
}
107+
},
108+
%{
109+
type: :object,
110+
properties: %{
111+
format: %{
112+
const: "date_iso",
113+
description: "Use to display date-time values in ISO 8601 extended format."
114+
}
115+
}
116+
},
117+
%{
118+
type: :object,
119+
properties: %{
120+
format: %{
121+
const: "date_unix",
122+
description: "Use to display date-time values in seconds since unix epoch."
123+
},
124+
milliseconds: %{
125+
type: :boolean,
126+
default: false,
127+
description:
128+
"Whether the formatter should output the values milliseconds (instead of seconds)."
129+
}
130+
}
131+
},
132+
%{
133+
type: :object,
134+
properties: %{
135+
format: %{
136+
const: "coordinate",
137+
description: "Use to display latitude & longitude information."
138+
},
139+
radius_display: %{
140+
type: :boolean,
141+
default: true,
142+
description:
143+
"Whether the formatter should include the radius/accuracy information (if present)."
144+
}
145+
}
146+
}
23147
]
24148
}
25149
}
@@ -29,110 +153,106 @@ defmodule ValueFormatters.Schemas do
29153
%{
30154
type: :object,
31155
description: "Default formats for value formatting",
32-
properties: available_formats_schema()
33-
}
34-
end
35-
36-
defp available_formats_schema() do
37-
%{
38-
number: %{
39-
type: :object,
40-
description:
41-
"Use to display numeric values and format them according to the user's locale.",
42-
properties: %{
43-
precision: %{type: :number, description: "Number of decimal places"},
44-
unit: %{
45-
type: :string,
46-
description: "If set, the formatter appends ' ' + unit to the display value"
156+
properties: %{
157+
number: %{
158+
type: :object,
159+
description:
160+
"Use to display numeric values and format them according to the user's locale.",
161+
properties: %{
162+
precision: %{type: :number, description: "Number of decimal places"},
163+
unit: %{
164+
type: :string,
165+
description: "If set, the formatter appends ' ' + unit to the display value"
166+
}
47167
}
48-
}
49-
},
50-
string: %{
51-
type: :object,
52-
description:
53-
"Use to explicitly disable any kind of formatting that would otherwise take place.",
54-
properties: %{}
55-
},
56-
date: %{
57-
type: :object,
58-
description:
59-
"Use to to display date-time values and format them according to the user's locale.",
60-
properties: %{
61-
date_display: %{
62-
type: :string,
63-
description: """
64-
How the formatter should display the date portion:
168+
},
169+
string: %{
170+
type: :object,
171+
description:
172+
"Use to explicitly disable any kind of formatting that would otherwise take place.",
173+
properties: %{}
174+
},
175+
date: %{
176+
type: :object,
177+
description:
178+
"Use to to display date-time values and format them according to the user's locale.",
179+
properties: %{
180+
date_display: %{
181+
type: :string,
182+
description: """
183+
How the formatter should display the date portion:
65184
66-
- `full`: Wednesday, November 29, 2023
185+
- `full`: Wednesday, November 29, 2023
67186
68-
- `long`: November 29, 2023
187+
- `long`: November 29, 2023
69188
70-
- `medium`: Nov 29, 2023
189+
- `medium`: Nov 29, 2023
71190
72-
- `short`: 11/29/23
191+
- `short`: 11/29/23
73192
74-
- `none`: Don't display date
75-
""",
76-
enum: ["full", "long", "medium", "short", "none"],
77-
default: "medium"
78-
},
79-
time_display: %{
80-
type: :string,
81-
description: """
82-
How the formatter should display the time portion:
193+
- `none`: Don't display date
194+
""",
195+
enum: ["full", "long", "medium", "short", "none"],
196+
default: "medium"
197+
},
198+
time_display: %{
199+
type: :string,
200+
description: """
201+
How the formatter should display the time portion:
83202
84-
- `full`: 3:44:28 PM GMT
203+
- `full`: 3:44:28 PM GMT
85204
86-
- `long`: 3:44:28 PM UTC
205+
- `long`: 3:44:28 PM UTC
87206
88-
- `medium`: 3:44:28 PM
207+
- `medium`: 3:44:28 PM
89208
90-
- `short`: 3:44 PM
209+
- `short`: 3:44 PM
91210
92-
- `none`: Don't display time
93-
""",
94-
enum: ["full", "long", "medium", "short", "none"],
95-
default: "medium"
211+
- `none`: Don't display time
212+
""",
213+
enum: ["full", "long", "medium", "short", "none"],
214+
default: "medium"
215+
}
96216
}
97-
}
98-
},
99-
date_relative: %{
100-
type: :object,
101-
description: """
102-
Use format: "date_relative" to display a relative date string (e.g. “2 days ago”) by comparing the given value against the current date & time. Only the largest sensible unit is displayed, e.g. the formatter will only display “days” even when other components such as hours, minutes etc. aren't equal to zero.
103-
104-
The implementation can choose to update the displayed value in appropriate intervals. Also, it can choose to display the absolute date on user interaction, e.g. in a tooltip.
105-
106-
This format currently doesn't support any options.
107-
""",
108-
properties: %{}
109-
},
110-
date_iso: %{
111-
type: :object,
112-
description: "Use to display date-time values in ISO 8601 extended format.",
113-
properties: %{}
114-
},
115-
date_unix: %{
116-
type: :object,
117-
description: "Use to display date-time values in seconds since unix epoch.",
118-
properties: %{
119-
milliseconds: %{
120-
type: :boolean,
121-
default: false,
122-
description:
123-
"Whether the formatter should output the values milliseconds (instead of seconds)."
217+
},
218+
date_relative: %{
219+
type: :object,
220+
description: """
221+
Use format: "date_relative" to display a relative date string (e.g. “2 days ago”) by comparing the given value against the current date & time. Only the largest sensible unit is displayed, e.g. the formatter will only display “days” even when other components such as hours, minutes etc. aren't equal to zero.
222+
223+
The implementation can choose to update the displayed value in appropriate intervals. Also, it can choose to display the absolute date on user interaction, e.g. in a tooltip.
224+
225+
This format currently doesn't support any options.
226+
""",
227+
properties: %{}
228+
},
229+
date_iso: %{
230+
type: :object,
231+
description: "Use to display date-time values in ISO 8601 extended format.",
232+
properties: %{}
233+
},
234+
date_unix: %{
235+
type: :object,
236+
description: "Use to display date-time values in seconds since unix epoch.",
237+
properties: %{
238+
milliseconds: %{
239+
type: :boolean,
240+
default: false,
241+
description:
242+
"Whether the formatter should output the values milliseconds (instead of seconds)."
243+
}
124244
}
125-
}
126-
},
127-
coordinates: %{
128-
type: :object,
129-
description: "Use to display latitude & longitude information.",
130-
properties: %{
131-
radius_display: %{
132-
type: :boolean,
133-
default: true,
134-
description:
135-
"Whether the formatter should include the radius/accuracy information (if present)."
245+
},
246+
coordinates: %{
247+
type: :object,
248+
description: "Use to display latitude & longitude information.",
249+
properties: %{
250+
radius_display: %{
251+
type: :boolean,
252+
default: true,
253+
description:
254+
"Whether the formatter should include the radius/accuracy information (if present)."
255+
}
136256
}
137257
}
138258
}

0 commit comments

Comments
 (0)