Skip to content

Fix/iso time types tests #277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ The length of a string instance is defined as the number of its characters as de
<p><a href="https://tools.ietf.org/id/draft-handrews-json-schema-validation-01.html#rfc.section.6.3.1">reference</a></p>
</dd>
<dt><a href="#format">format(format)</a> ⇒ <code><a href="#StringSchema">StringSchema</a></code></dt>
<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>
<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>
<p><a href="https://tools.ietf.org/id/draft-handrews-json-schema-validation-01.html#rfc.section.7.3">reference</a></p>
</dd>
<dt><a href="#pattern">pattern(pattern)</a> ⇒ <code><a href="#StringSchema">StringSchema</a></code></dt>
Expand Down Expand Up @@ -1200,7 +1200,7 @@ The length of a string instance is defined as the number of its characters as de
<a name="format"></a>

## format(format) ⇒ [<code>StringSchema</code>](#StringSchema)
A string value can be RELATIVE_JSON_POINTER, JSON_POINTER, UUID, REGEX, IPV6, IPV4, HOSTNAME, EMAIL, URL, URI_TEMPLATE, URI_REFERENCE, URI, TIME, DATE,
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.

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

Expand Down
9 changes: 9 additions & 0 deletions src/StringSchema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ describe('StringSchema', () => {
}
)
})
it('valid FORMATS.ISO_TIME', () => {
assert.deepStrictEqual(
StringSchema().format(FORMATS.ISO_TIME).valueOf(),
{
type: 'string',
format: 'iso-time'
}
)
})
it('invalid', () => {
assert.throws(
() => StringSchema().format('invalid'),
Expand Down
2 changes: 2 additions & 0 deletions types/FluentJSONSchema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type FORMATS = {
TIME: 'time'
DATE: 'date'
DATE_TIME: 'date-time'
ISO_TIME: 'iso-time'
ISO_DATE_TIME: 'iso-date-time'
}

export type JSONSchema =
Expand Down
7 changes: 7 additions & 0 deletions types/FluentJSONSchema.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,10 @@ const deepTestOnTypes = S.object<ReallyLongType>()
.valueOf()

console.log('deepTestOnTypes:\n', JSON.stringify(deepTestOnTypes))

const tsIsoSchema = S.object()
.prop('createdAt', S.string().format('iso-time'))
.prop('updatedAt', S.string().format('iso-date-time'))
.valueOf()

console.log('ISO schema OK:', JSON.stringify(tsIsoSchema))