Skip to content

Commit

Permalink
Merge pull request #285 from jacob-alford/ja/fix-annotation
Browse files Browse the repository at this point in the history
Fix: partially annotated json-schema
  • Loading branch information
jacob-alford committed Aug 6, 2023
2 parents 1ec0ccd + a34f322 commit 90f84b0
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 19 deletions.
30 changes: 15 additions & 15 deletions docs/schemata/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,23 @@ has_children: true

### String (17)

* Ascii ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Ascii.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Ascii.ts)) (e.g: `z%{(q XT`, `{{~S'l`, `VFGvdT!rFe`)
* Base64 ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Base64.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Base64.ts)) (e.g: `+/lq++//B7WT/W++c+Y8/987Hi1+w14e7y/8`, `Iq+3Eb==`, `Oj+D+R+AJKv+l/+/x+j+FR==`)
* Base64Url ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Base64Url.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Base64Url.ts)) (e.g: `-_-B-_-7_f`, `691-I99azX`, `8_--7ab-`)
* BitcoinAddress ([docs](https://jacob-alford.github.io/schemata-ts/schemata/BitcoinAddress.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/BitcoinAddress.ts)) (e.g: `3CDa8udNY32CHLB8KMMUuhRaaXX7VprRz3LxL`, `bc19f7v6fnn0ttwn00439153858w0z`, `bc1d7cawacasdacx8w58bw06za7r5a`)
* Ascii ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Ascii.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Ascii.ts)) (e.g: `Ly<<\"uw)^`, `Ye0_3`, `zLWIn_`)
* Base64 ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Base64.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Base64.ts)) (e.g: `X5++1/06/qUT/+6+++/SY62/d++2xr/c+96j+i/+`, `gS+/q+5/Q5NT6y5jxqE//++0/r/1R+/7`, `++2D/y0W8+cX`)
* Base64Url ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Base64Url.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Base64Url.ts)) (e.g: `_f__0C1P`, `_-xC--W`, `--hgy4-6`)
* BitcoinAddress ([docs](https://jacob-alford.github.io/schemata-ts/schemata/BitcoinAddress.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/BitcoinAddress.ts)) (e.g: `2PZMzG4Lj3thyJFiC2SXHj6Ki9Bec2x5`, `bc16i1qtok0p2c4175i5uwlhyhm54bdoprt`, `2Zv7S96f4FRJApCmF4FZKmKn3t`)
* CamelCaseString ([docs](https://jacob-alford.github.io/schemata-ts/schemata/CamelCaseString.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/CamelCaseString.ts)) (e.g: `Camel_case-string``camelCaseString`)
* CreditCard ([docs](https://jacob-alford.github.io/schemata-ts/schemata/CreditCard.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/CreditCard.ts)) (e.g: `50809617009210500`, `35282361350364379`, `355003168179566112`)
* EmailAddress ([docs](https://jacob-alford.github.io/schemata-ts/schemata/EmailAddress.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/EmailAddress.ts)) (e.g: `~*./}!.{'~.*&|#/{~*'.!/++*&^=*$4@[50.9.328.283]`, `1~.?B}^}@7--0.EyD`, `"뽁洽焏夡䖼䓉"@[1.560.21.01]`)
* EthereumAddress ([docs](https://jacob-alford.github.io/schemata-ts/schemata/EthereumAddress.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/EthereumAddress.ts)) (e.g: `0xed30ebaA6bFEeCbc9C9eC812CB3bAa2Bf5a19BdE`, `0xCde66aBaBF7bad77bB7C2FAfacB1ce98fEf2ebcb`, `0x91C1BD9bC6BCDAccedbC3cafeb3c7AaD2dEc03fa`)
* HexColor ([docs](https://jacob-alford.github.io/schemata-ts/schemata/HexColor.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/HexColor.ts)) (e.g: `77eDA79e`, `60a2DDaa`, `#AED09b`)
* Hexadecimal ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Hexadecimal.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Hexadecimal.ts)) (e.g: `0xa7BdF758`, `c0BBFE8e`, `DafDEEff`)
* HslColor ([docs](https://jacob-alford.github.io/schemata-ts/schemata/HslColor.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/HslColor.ts)) (e.g: `hsl(.99turn+0090%+000.2e31558%)`, `hsla(606792987.8731e89turn,00000.38089343726%,+0.6047367792%,700)`, `hsla(+1958.088009894100.3759564%+00094%)`)
* Jwt ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Jwt.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Jwt.ts)) (e.g: `-Z0_y_Z.d`, `_P--z-__.7._j-6`, `P_5PT_._dD_-3-_.d-a_--0-i`)
* LatLong ([docs](https://jacob-alford.github.io/schemata-ts/schemata/LatLong.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/LatLong.ts)) (e.g: `(90,-96.52)`, `2,-171`, `-90,-136`)
* NonEmptyString ([docs](https://jacob-alford.github.io/schemata-ts/schemata/NonEmptyString.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/NonEmptyString.ts)) (e.g: `CallFue=`, `nrabca==`, `V$L_(`)
* RGB ([docs](https://jacob-alford.github.io/schemata-ts/schemata/RGB.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/RGB.ts)) (e.g: `rgba(92%,100%,92%,1.0)`, `rgb(99,192,163)`, `rgba(7%,90%,68%,0.0163)`)
* CreditCard ([docs](https://jacob-alford.github.io/schemata-ts/schemata/CreditCard.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/CreditCard.ts)) (e.g: `3879120218342341`, `35847025514861707`, `65481870723977630`)
* EmailAddress ([docs](https://jacob-alford.github.io/schemata-ts/schemata/EmailAddress.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/EmailAddress.ts)) (e.g: `"漲ሀ洄酭ᐆ鞱"@9..a0d71.Vb-r--.HtUjHelKOuir`, `"�陶"@4e77EGNKJ.-.-7-Xr.U-sZ-a35.ab-1B-d.d.-3.qk181-.-92pl-.-X95ur--.1-rOql-.eDE`, `"㍃ꠌ鎉￶頚￰昐￷⅍㵴픺"@[66.45.253.60]`)
* EthereumAddress ([docs](https://jacob-alford.github.io/schemata-ts/schemata/EthereumAddress.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/EthereumAddress.ts)) (e.g: `0xbcc0eDCF1cDCbbacd7b8dCa969Ac30a83bE0A133`, `0x0bAd6FafFECCb357B92DaACBbfc9aCf2b631CFE5`, `0x7A69C2DebaBFD2BfbAcFAeA0fcEc0cADeDDA450F`)
* HexColor ([docs](https://jacob-alford.github.io/schemata-ts/schemata/HexColor.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/HexColor.ts)) (e.g: `#f7CD6FcA`, `#B3EbA4Ba`, `b0C5c0B9`)
* Hexadecimal ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Hexadecimal.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Hexadecimal.ts)) (e.g: `0xDc1ad`, `9584eAf1f`, `0haE943E4`)
* HslColor ([docs](https://jacob-alford.github.io/schemata-ts/schemata/HslColor.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/HslColor.ts)) (e.g: `hsl(.90,0.08157545814%,+000.698088872e-000%,512.67899580e-032%)`, `hsla(92.343e4000.358195e73213027%00090e190%/1016995836e+8517%)`, `hsla(+117,000.80e+54%,000.895%,76)`)
* Jwt ([docs](https://jacob-alford.github.io/schemata-ts/schemata/Jwt.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/Jwt.ts)) (e.g: `c9_S8d4_-D.G._`, `0c.-6-9Y-AV3b.uD-4Y`, `-C_.dY-`)
* LatLong ([docs](https://jacob-alford.github.io/schemata-ts/schemata/LatLong.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/LatLong.ts)) (e.g: `(90,23)`, `90,180.0000000`, `90,180.00`)
* NonEmptyString ([docs](https://jacob-alford.github.io/schemata-ts/schemata/NonEmptyString.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/NonEmptyString.ts)) (e.g: `l6/FQ4saJNfEkt==`, `194d8fbe93c2`, `DFkgzVTV`)
* RGB ([docs](https://jacob-alford.github.io/schemata-ts/schemata/RGB.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/RGB.ts)) (e.g: `rgba(254,252,228,1.0)`, `rgba(11,233,180,1.0)`, `rgba(100%,100%,100%,1.0)`)
* String ([docs](https://jacob-alford.github.io/schemata-ts/schemata/String.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/String.ts))
* UUID ([docs](https://jacob-alford.github.io/schemata-ts/schemata/UUID.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/UUID.ts)) (e.g: `64f0c8A6-C7c5-a3Ed-De5A-Db7EE1c1A70D`, `cd1dd2aC-EEbb-caB6-F4aD-2F2BEAdc61aB`, `BEDccAFA-69CC-efF0-DBcC-c9A182aBAE8D`)
* UUID ([docs](https://jacob-alford.github.io/schemata-ts/schemata/UUID.html)) ([source](https://github.com/jacob-alford/schemata-ts/tree/main/src/schemata/UUID.ts)) (e.g: `3DFead8c-ca28-CAFC-811D-bEeFa5CBcffE`, `7dEBCb7C-9cbF-E0b9-AeaE-cAAEdAaA98ED`, `fbbad0Cf-bb97-6D3e-6aaa-9FcaDB393bAc`)

### Unknown (3)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "schemata-ts",
"version": "2.0.3",
"version": "2.0.4",
"description": "An all-inclusive schema engine featuring schemata inspired by io-ts and validators.js. Written for TypeScript with fp-ts",
"homepage": "https://jacob-alford.github.io/schemata-ts/",
"repository": {
Expand Down
9 changes: 6 additions & 3 deletions src/schemables/annotate/instances/json-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ export const AnnotateJsonSchema: WithAnnotate<JS.SchemableLambda> = {
params =>
<O>(inner: Const<JS.JsonSchema, O>): Const<JS.JsonSchema, O> => {
const { title, description, references, deprecated, readOnly } = params
if (title === undefined && description === undefined && references === undefined)
return inner
const hasChanged =
title !== undefined ||
description !== undefined ||
deprecated !== undefined ||
readOnly !== undefined
return pipe(
inner,
title !== undefined || description !== undefined
hasChanged
? JS.addDescription({
...(title === undefined ? {} : { title }),
...(description === undefined ? {} : { description }),
Expand Down
60 changes: 60 additions & 0 deletions tests/issues/annotation-description.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import * as S from 'schemata-ts'

import { runStandardTestSuite } from '../../test-utils/test-suite'

const Titled = S.Annotate({ title: 'Titled' })(S.String())
const Described = S.Annotate({ description: 'Described' })(S.String())
const Deprecated = S.Annotate({ deprecated: true })(S.String())
const ReadOnly = S.Readonly(S.String())

runStandardTestSuite(Titled, () => ({
jsonSchema: {
type: 'string',
title: 'Titled',
},
jsonSchema2007: {
type: 'string',
title: 'Titled',
},
jsonSchema2020: {
type: 'string',
title: 'Titled',
},
}))()

runStandardTestSuite(Described, () => ({
jsonSchema: {
type: 'string',
description: 'Described',
},
jsonSchema2007: {
type: 'string',
description: 'Described',
},
}))()

runStandardTestSuite(Deprecated, () => ({
jsonSchema: {
type: 'string',
deprecated: true,
},
jsonSchema2007: {
type: 'string',
deprecated: true,
},
}))()

runStandardTestSuite(ReadOnly, () => ({
jsonSchema: {
type: 'string',
readOnly: true,
},
jsonSchema2007: {
type: 'string',
readOnly: true,
},
jsonSchema2020: {
type: 'string',
readOnly: true,
},
}))()
9 changes: 9 additions & 0 deletions tests/json-schema-projection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ runStandardTestSuite(Schema, () => ({
minimum: -9007199254740991,
},
minItems: 1,
readOnly: true,
},
tup: {
type: 'array',
Expand All @@ -103,10 +104,12 @@ runStandardTestSuite(Schema, () => ({
{
type: 'integer',
minimum: 0,
deprecated: true,
},
],
maxItems: 2,
minItems: 2,
deprecated: false,
},
},
required: ['arr', 'tup'],
Expand Down Expand Up @@ -161,6 +164,7 @@ runStandardTestSuite(Schema, () => ({
minimum: -9007199254740991,
},
minItems: 1,
readOnly: true,
},
tup: {
type: 'array',
Expand All @@ -174,8 +178,10 @@ runStandardTestSuite(Schema, () => ({
{
type: 'integer',
minimum: 0,
deprecated: true,
},
],
deprecated: false,
maxItems: 2,
minItems: 2,
},
Expand Down Expand Up @@ -234,6 +240,7 @@ runStandardTestSuite(Schema, () => ({
minimum: -9007199254740991,
},
minItems: 1,
readOnly: true,
},
tup: {
type: 'array',
Expand All @@ -248,8 +255,10 @@ runStandardTestSuite(Schema, () => ({
{
type: 'integer',
minimum: 0,
deprecated: true,
},
],
deprecated: false,
maxItems: 2,
minItems: 2,
},
Expand Down

0 comments on commit 90f84b0

Please sign in to comment.