Skip to content

Commit 819b9c2

Browse files
authored
types: added missing iso time types (#277)
* fix: add ISO time and date formats to FORMATS type and update tests * test: add validation for FORMATS.ISO_TIME in StringSchema tests * docs: update string format options to include DATE_TIME, ISO_TIME, and ISO_DATE_TIME
1 parent e17297b commit 819b9c2

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

docs/API.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ The length of a string instance is defined as the number of its characters as de
311311
<p><a href="https://tools.ietf.org/id/draft-handrews-json-schema-validation-01.html#rfc.section.6.3.1">reference</a></p>
312312
</dd>
313313
<dt><a href="#format">format(format)</a> ⇒ <code><a href="#StringSchema">StringSchema</a></code></dt>
314-
<dd><p>A string value can be RELATIVE_JSON_POINTER, JSON_POINTER, UUID, REGEX, IPV6, IPV4, HOSTNAME, EMAIL, URL, URI_TEMPLATE, URI_REFERENCE, URI, TIME, DATE,</p>
314+
<dd><p>A string value can be RELATIVE_JSON_POINTER, JSON_POINTER, UUID, REGEX, IPV6, IPV4, HOSTNAME, EMAIL, URL, URI_TEMPLATE, URI_REFERENCE, URI, TIME, DATE, DATE_TIME, ISO_TIME, ISO_DATE_TIME.</p>
315315
<p><a href="https://tools.ietf.org/id/draft-handrews-json-schema-validation-01.html#rfc.section.7.3">reference</a></p>
316316
</dd>
317317
<dt><a href="#pattern">pattern(pattern)</a> ⇒ <code><a href="#StringSchema">StringSchema</a></code></dt>
@@ -1200,7 +1200,7 @@ The length of a string instance is defined as the number of its characters as de
12001200
<a name="format"></a>
12011201

12021202
## format(format) ⇒ [<code>StringSchema</code>](#StringSchema)
1203-
A string value can be RELATIVE_JSON_POINTER, JSON_POINTER, UUID, REGEX, IPV6, IPV4, HOSTNAME, EMAIL, URL, URI_TEMPLATE, URI_REFERENCE, URI, TIME, DATE,
1203+
A string value can be RELATIVE_JSON_POINTER, JSON_POINTER, UUID, REGEX, IPV6, IPV4, HOSTNAME, EMAIL, URL, URI_TEMPLATE, URI_REFERENCE, URI, TIME, DATE, DATE_TIME, ISO_TIME, ISO_DATE_TIME.
12041204

12051205
[reference](https://tools.ietf.org/id/draft-handrews-json-schema-validation-01.html#rfc.section.7.3)
12061206

src/StringSchema.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ describe('StringSchema', () => {
101101
}
102102
)
103103
})
104+
it('valid FORMATS.ISO_TIME', () => {
105+
assert.deepStrictEqual(
106+
StringSchema().format(FORMATS.ISO_TIME).valueOf(),
107+
{
108+
type: 'string',
109+
format: 'iso-time'
110+
}
111+
)
112+
})
104113
it('invalid', () => {
105114
assert.throws(
106115
() => StringSchema().format('invalid'),

types/FluentJSONSchema.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ type FORMATS = {
5151
TIME: 'time'
5252
DATE: 'date'
5353
DATE_TIME: 'date-time'
54+
ISO_TIME: 'iso-time'
55+
ISO_DATE_TIME: 'iso-date-time'
5456
}
5557

5658
export type JSONSchema =

types/FluentJSONSchema.test-d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,10 @@ const deepTestOnTypes = S.object<ReallyLongType>()
197197
.valueOf()
198198

199199
console.log('deepTestOnTypes:\n', JSON.stringify(deepTestOnTypes))
200+
201+
const tsIsoSchema = S.object()
202+
.prop('createdAt', S.string().format('iso-time'))
203+
.prop('updatedAt', S.string().format('iso-date-time'))
204+
.valueOf()
205+
206+
console.log('ISO schema OK:', JSON.stringify(tsIsoSchema))

0 commit comments

Comments
 (0)