@naturalcycles/common-type
Advanced tools
Comparing version 1.5.0 to 1.6.0
@@ -0,1 +1,8 @@ | ||
# [1.6.0](https://github.com/NaturalCycles/common-type/compare/v1.5.0...v1.6.0) (2021-08-08) | ||
### Features | ||
* support `[@default](https://github.com/default)` keyword ([e0aa50c](https://github.com/NaturalCycles/common-type/commit/e0aa50c7fdd9b938d205fa4e5fc1d440b4b66111)) | ||
# [1.5.0](https://github.com/NaturalCycles/common-type/compare/v1.4.0...v1.5.0) (2021-08-08) | ||
@@ -2,0 +9,0 @@ |
import { CommonTypeCfg } from './commonTypeCfg'; | ||
import { commonTypeGenerate } from './commonTypeGenerate'; | ||
export type { CommonTypeCfg }; | ||
export { commonTypeGenerate }; | ||
import { commonTypeGenerate, generateSchemasFromFilePaths } from './commonTypeGenerate'; | ||
import { ArrayJsonSchema, BaseJsonSchema, BooleanJsonSchema, ConstJsonSchema, EnumItem, EnumJsonSchema, JsonSchema, NullJsonSchema, NumberJsonSchema, ObjectJsonSchema, RefJsonSchema, StringJsonSchema, TupleJsonSchema } from './model'; | ||
import { tsFilesToJsonSchemas } from './tsToJsonSchema'; | ||
export type { CommonTypeCfg, JsonSchema, BaseJsonSchema, RefJsonSchema, ConstJsonSchema, EnumJsonSchema, StringJsonSchema, NumberJsonSchema, BooleanJsonSchema, NullJsonSchema, ObjectJsonSchema, ArrayJsonSchema, TupleJsonSchema, EnumItem, }; | ||
export { commonTypeGenerate, tsFilesToJsonSchemas, generateSchemasFromFilePaths }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.commonTypeGenerate = void 0; | ||
exports.generateSchemasFromFilePaths = exports.tsFilesToJsonSchemas = exports.commonTypeGenerate = void 0; | ||
const commonTypeGenerate_1 = require("./commonTypeGenerate"); | ||
Object.defineProperty(exports, "commonTypeGenerate", { enumerable: true, get: function () { return commonTypeGenerate_1.commonTypeGenerate; } }); | ||
Object.defineProperty(exports, "generateSchemasFromFilePaths", { enumerable: true, get: function () { return commonTypeGenerate_1.generateSchemasFromFilePaths; } }); | ||
const tsToJsonSchema_1 = require("./tsToJsonSchema"); | ||
Object.defineProperty(exports, "tsFilesToJsonSchemas", { enumerable: true, get: function () { return tsToJsonSchema_1.tsFilesToJsonSchemas; } }); |
@@ -14,2 +14,4 @@ import { StringMap } from '@naturalcycles/js-lib'; | ||
writeOnly?: boolean; | ||
type?: string; | ||
default?: any; | ||
oneOf?: JsonSchema[]; | ||
@@ -16,0 +18,0 @@ allOf?: JsonSchema[]; |
@@ -84,4 +84,4 @@ "use strict"; | ||
additionalProperties: false, | ||
...parseJsdoc(n), | ||
}; | ||
processJsdoc(n, s); | ||
if (n.heritageClauses?.length) { | ||
@@ -110,4 +110,4 @@ const otherSchemas = n.heritageClauses[0].types.map(tt => tt.expression.text) | ||
...this.typeNodeToJsonSchema(n.type), | ||
...parseJsdoc(n), | ||
}; | ||
processJsdoc(n, s); | ||
schemas.push(s); | ||
@@ -163,3 +163,3 @@ } | ||
// console.log(schema) | ||
Object.assign(schema, parseJsdoc(n)); | ||
processJsdoc(n, schema); | ||
return schema; | ||
@@ -380,6 +380,8 @@ } | ||
]; | ||
function parseJsdoc(n) { | ||
/** | ||
* Processes jsdoc tags, mutates the schema as needed. | ||
*/ | ||
function processJsdoc(n, s) { | ||
if (!n.jsDoc?.length) | ||
return {}; | ||
const s = {}; | ||
return; | ||
const jsdoc = n.jsDoc[0]; | ||
@@ -394,3 +396,2 @@ if (jsdoc.comment) { | ||
if (comment === 'integer') { | ||
; | ||
s.type = comment; | ||
@@ -421,4 +422,21 @@ } | ||
} | ||
else if (tagNameText === 'default') { | ||
_assertIsString(comment); | ||
if (s.type === 'number') { | ||
s.default = Number(comment); | ||
} | ||
else if (s.type === 'integer') { | ||
s.default = parseInt(comment); | ||
} | ||
else if (s.type === 'boolean') { | ||
s.default = comment === 'true'; | ||
} | ||
else if (s.type === 'string') { | ||
s.default = comment; | ||
} | ||
else { | ||
s.default = JSON.parse(comment); | ||
} | ||
} | ||
}); | ||
return s; | ||
} | ||
@@ -425,0 +443,0 @@ function $idToRef($id) { |
@@ -40,3 +40,3 @@ { | ||
}, | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"description": "Common Type interface and generator", | ||
@@ -43,0 +43,0 @@ "author": "Natural Cycles Team", |
@@ -63,4 +63,4 @@ ## @naturalcycles/common-type | ||
- jsdoc tags: | ||
- `@validationType` to override `type`, e.g. `@validationType integer` | ||
- General: `deprecated`, `readOnly`, `writeOnly` | ||
- `validationType` to override `type`, e.g. `@validationType integer` | ||
- General: `deprecated`, `readOnly`, `writeOnly`, `default` | ||
- String: `pattern`, `format`, `minLength`, `maxLength` | ||
@@ -67,0 +67,0 @@ - Number: `multipleOf`, `minimum`, `exclusiveMinimum`, `maximum`, `exclusiveMaximum` |
33568
759