@tsed/schema 6.96.1 → 6.97.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/jest.config.js +14 -0
- package/lib/cjs/components/objectMapper.js +6 -3
- package/lib/cjs/components/objectMapper.js.map +1 -1
- package/lib/cjs/components/schemaMapper.js +1 -1
- package/lib/cjs/components/schemaMapper.js.map +1 -1
- package/lib/cjs/domain/JsonOperation.js +5 -9
- package/lib/cjs/domain/JsonOperation.js.map +1 -1
- package/lib/cjs/domain/JsonSchema.js +78 -60
- package/lib/cjs/domain/JsonSchema.js.map +1 -1
- package/lib/cjs/domain/SpecTypes.js +3 -0
- package/lib/cjs/domain/SpecTypes.js.map +1 -1
- package/lib/cjs/utils/getSpec.js +3 -3
- package/lib/cjs/utils/getSpec.js.map +1 -1
- package/lib/cjs/utils/mapNullableType.js +30 -11
- package/lib/cjs/utils/mapNullableType.js.map +1 -1
- package/lib/cjs/utils/ref.js +13 -10
- package/lib/cjs/utils/ref.js.map +1 -1
- package/lib/esm/components/objectMapper.js +6 -3
- package/lib/esm/components/objectMapper.js.map +1 -1
- package/lib/esm/components/schemaMapper.js +1 -1
- package/lib/esm/components/schemaMapper.js.map +1 -1
- package/lib/esm/domain/JsonOperation.js +5 -9
- package/lib/esm/domain/JsonOperation.js.map +1 -1
- package/lib/esm/domain/JsonSchema.js +78 -60
- package/lib/esm/domain/JsonSchema.js.map +1 -1
- package/lib/esm/domain/SpecTypes.js +3 -0
- package/lib/esm/domain/SpecTypes.js.map +1 -1
- package/lib/esm/utils/getSpec.js +3 -3
- package/lib/esm/utils/getSpec.js.map +1 -1
- package/lib/esm/utils/mapNullableType.js +31 -12
- package/lib/esm/utils/mapNullableType.js.map +1 -1
- package/lib/esm/utils/ref.js +13 -10
- package/lib/esm/utils/ref.js.map +1 -1
- package/lib/types/domain/JsonSchema.d.ts +5 -11
- package/lib/types/domain/SpecTypes.d.ts +3 -0
- package/package.json +6 -6
- package/.mocharc.js +0 -5
- package/.nycrc +0 -27
- package/lib/cjs/utils/isJsonClass.js +0 -12
- package/lib/cjs/utils/isJsonClass.js.map +0 -1
- package/lib/esm/utils/isJsonClass.js +0 -8
- package/lib/esm/utils/isJsonClass.js.map +0 -1
- package/lib/types/utils/isJsonClass.d.ts +0 -4
package/lib/esm/utils/getSpec.js
CHANGED
|
@@ -28,9 +28,9 @@ function get(model, options, cb) {
|
|
|
28
28
|
* @param model
|
|
29
29
|
* @param options
|
|
30
30
|
*/
|
|
31
|
-
export function getSpec(model, options = {
|
|
31
|
+
export function getSpec(model, options = {}) {
|
|
32
32
|
if (!options.specType) {
|
|
33
|
-
options.specType = SpecTypes.
|
|
33
|
+
options.specType = SpecTypes.OPENAPI;
|
|
34
34
|
}
|
|
35
35
|
options = {
|
|
36
36
|
...options,
|
|
@@ -40,7 +40,7 @@ export function getSpec(model, options = { specType: SpecTypes.SWAGGER }) {
|
|
|
40
40
|
};
|
|
41
41
|
return get(model, options, () => {
|
|
42
42
|
const store = getJsonEntityStore(model);
|
|
43
|
-
const { specType = SpecTypes.
|
|
43
|
+
const { specType = SpecTypes.OPENAPI, schemas = {}, paths = {}, rootPath = "/", tags = [] } = options;
|
|
44
44
|
const ctrlPath = store.path;
|
|
45
45
|
const defaultTags = cleanObject({
|
|
46
46
|
name: store.schema.getName(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSpec.js","sourceRoot":"","sources":["../../../src/utils/getSpec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAQ,MAAM,EAAC,MAAM,YAAY,CAAC;AAErD,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AACtC,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAC,cAAc,EAAC,MA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AAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE;YAC/B,IAAI,QAAQ,KAAK,SAAS,CAAC,OAAO,EAAE;gBAClC,QAAQ,CAAC,UAAU,GAAG;oBACpB,OAAO;iBACR,CAAC;aACH;iBAAM;gBACL,QAAQ,CAAC,WAAW,GAAG,OAAO,CAAC;aAChC;SACF;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {cleanObject, Type, uniqBy} from \"@tsed/core\";\nimport {OpenSpec2, OpenSpec3} from \"@tsed/openspec\";\nimport {SpecTypes} from \"../domain/SpecTypes\";\nimport {JsonSchemaOptions} from \"../interfaces\";\nimport {buildPath} from \"./buildPath\";\nimport {getJsonEntityStore} from \"./getJsonEntityStore\";\nimport {getOperationsStores} from \"./getOperationsStores\";\nimport {mergeOperation} from \"./mergeOperation\";\nimport {operationIdFormatter} from \"./operationIdFormatter\";\n\nexport interface SpecSerializerOptions extends JsonSchemaOptions {\n specType?: SpecTypes.SWAGGER | SpecTypes.OPENAPI;\n /**\n * Paths\n */\n paths?: any;\n /**\n * Root path. This paths will be added to all generated paths Object.\n */\n rootPath?: string;\n /**\n * A function to generate the operationId.\n */\n operationIdFormatter?: (name: string, propertyKey: string, path: string) => string;\n /**\n * A pattern to generate the operationId.\n */\n operationIdPattern?: string;\n}\n\nexport interface OS3SpecSerializerOptions extends SpecSerializerOptions {\n /**\n * Define Spec types level\n */\n specType: SpecTypes.OPENAPI;\n}\n\nexport interface OS2SpecSerializerOptions extends SpecSerializerOptions {\n /**\n * Define Spec types level\n */\n specType: SpecTypes.SWAGGER;\n}\n\n/**\n * @ignore\n */\nconst caches: Map<Type<any>, Map<string, any>> = new Map();\n\n/**\n * @ignore\n */\nfunction get(model: Type<any>, options: any, cb: any) {\n if (!caches.has(model)) {\n caches.set(model, new Map());\n }\n\n const cache = caches.get(model)!;\n const key = JSON.stringify(options);\n\n if (!cache.has(key)) {\n cache.set(key, cb());\n }\n\n return cache.get(key);\n}\n\n/**\n * Return the swagger or open spec for the given class.\n * @param model\n * @param options\n */\nexport function getSpec(model: Type<any>, options: OS2SpecSerializerOptions): Partial<OpenSpec2>;\nexport function getSpec(model: Type<any>): Partial<OpenSpec2>;\nexport function getSpec(model: Type<any>, options: SpecSerializerOptions): Partial<OpenSpec2>;\n/**\n * Return the swagger or open spec for the given class.\n * @param model\n * @param options\n */\nexport function getSpec(model: Type<any>, options: OS3SpecSerializerOptions): Partial<OpenSpec3>;\n/**\n * Return the swagger or open spec for the given class.\n * @param model\n * @param options\n */\nexport function getSpec(model: Type<any>, options: SpecSerializerOptions = {}): Partial<OpenSpec2 | OpenSpec3> {\n if (!options.specType) {\n options.specType = SpecTypes.OPENAPI;\n }\n\n options = {\n ...options,\n operationIdFormatter: options.operationIdFormatter || operationIdFormatter(options.operationIdPattern),\n root: false,\n specType: options.specType\n };\n\n return get(model, options, () => {\n const store = getJsonEntityStore(model);\n const {specType = SpecTypes.OPENAPI, schemas = {}, paths = {}, rootPath = \"/\", tags = []} = options;\n const ctrlPath = store.path;\n const defaultTags = cleanObject({\n name: store.schema.getName(),\n description: store.schema.get(\"description\")\n });\n\n const specJson: any = {paths};\n\n getOperationsStores(model).forEach((operationStore) => {\n if (operationStore.store.get(\"hidden\")) {\n return;\n }\n\n const operation = operationStore.operation!.toJSON({...options, specType, schemas});\n\n operationStore.operation!.operationPaths.forEach(({path, method}: {path: string; method: string}) => {\n if (method) {\n mergeOperation(specJson, operation, {\n rootPath: buildPath(rootPath + ctrlPath),\n path,\n method,\n defaultTags,\n tags,\n specType,\n operationId: (path: string) =>\n options.operationIdFormatter!(\n operationStore.parent.schema.get(\"name\") || operationStore.parent.targetName,\n operationStore.propertyName,\n path\n )\n });\n }\n });\n });\n\n specJson.tags = uniqBy(tags, \"name\");\n\n if (Object.keys(schemas).length) {\n if (specType === SpecTypes.OPENAPI) {\n specJson.components = {\n schemas\n };\n } else {\n specJson.definitions = schemas;\n }\n }\n\n return specJson;\n });\n}\n"]}
|
|
@@ -1,25 +1,44 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { uniq } from "@tsed/core";
|
|
2
2
|
import { SpecTypes } from "../domain/SpecTypes";
|
|
3
|
+
function hasNullable(obj) {
|
|
4
|
+
return obj.oneOf.find((o) => o.type === "null");
|
|
5
|
+
}
|
|
3
6
|
export function mapNullableType(obj, schema, options) {
|
|
4
|
-
if (!schema.
|
|
7
|
+
if (!schema.isNullable) {
|
|
5
8
|
return obj;
|
|
6
9
|
}
|
|
7
|
-
let types = [].concat(obj.type).filter(
|
|
10
|
+
let types = [].concat(obj.type).filter(Boolean);
|
|
8
11
|
switch (options.specType) {
|
|
9
12
|
case SpecTypes.SWAGGER:
|
|
10
|
-
|
|
11
|
-
|
|
13
|
+
if (!obj.allOf && !obj.$ref) {
|
|
14
|
+
obj.type = uniq(["null", ...types]);
|
|
15
|
+
}
|
|
12
16
|
break;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
default:
|
|
18
|
+
case SpecTypes.JSON:
|
|
19
|
+
if (obj.oneOf) {
|
|
20
|
+
if (!hasNullable(obj)) {
|
|
21
|
+
obj.oneOf.unshift({
|
|
22
|
+
type: "null"
|
|
23
|
+
});
|
|
24
|
+
}
|
|
18
25
|
}
|
|
19
26
|
else {
|
|
20
|
-
obj.type = types
|
|
21
|
-
obj.nullable = true;
|
|
27
|
+
obj.type = uniq(["null", ...types]);
|
|
22
28
|
}
|
|
29
|
+
break;
|
|
30
|
+
case SpecTypes.OPENAPI:
|
|
31
|
+
obj.nullable = true;
|
|
32
|
+
if (!obj.oneOf) {
|
|
33
|
+
if (types.length > 1) {
|
|
34
|
+
obj.oneOf = types.map((type) => ({ type }));
|
|
35
|
+
delete obj.type;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
obj.type = types[0];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
break;
|
|
23
42
|
}
|
|
24
43
|
return obj;
|
|
25
44
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapNullableType.js","sourceRoot":"","sources":["../../../src/utils/mapNullableType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"mapNullableType.js","sourceRoot":"","sources":["../../../src/utils/mapNullableType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,YAAY,CAAC;AAEhC,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAG9C,SAAS,WAAW,CAAC,GAAQ;IAC3B,OAAO,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,GAAQ,EAAE,MAAkB,EAAE,OAA0B;IACtF,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE;QACtB,OAAO,GAAG,CAAC;KACZ;IACD,IAAI,KAAK,GAAa,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAE1D,QAAQ,OAAO,CAAC,QAAQ,EAAE;QACxB,KAAK,SAAS,CAAC,OAAO;YACpB,IAAI,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE;gBAC3B,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC;aACrC;YACD,MAAM;QACR,QAAQ;QACR,KAAK,SAAS,CAAC,IAAI;YACjB,IAAI,GAAG,CAAC,KAAK,EAAE;gBACb,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE;oBACrB,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC;wBAChB,IAAI,EAAE,MAAM;qBACb,CAAC,CAAC;iBACJ;aACF;iBAAM;gBACL,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC;aACrC;YACD,MAAM;QAER,KAAK,SAAS,CAAC,OAAO;YACpB,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC;YAEpB,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE;gBACd,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;oBACpB,GAAG,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAC,IAAI,EAAC,CAAC,CAAC,CAAC;oBAC1C,OAAO,GAAG,CAAC,IAAI,CAAC;iBACjB;qBAAM;oBACL,GAAG,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;iBACrB;aACF;YACD,MAAM;KACT;IAED,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import {uniq} from \"@tsed/core\";\nimport type {JsonSchema} from \"../domain/JsonSchema\";\nimport {SpecTypes} from \"../domain/SpecTypes\";\nimport type {JsonSchemaOptions} from \"../interfaces/JsonSchemaOptions\";\n\nfunction hasNullable(obj: any) {\n return obj.oneOf.find((o: any) => o.type === \"null\");\n}\n\nexport function mapNullableType(obj: any, schema: JsonSchema, options: JsonSchemaOptions) {\n if (!schema.isNullable) {\n return obj;\n }\n let types: string[] = [].concat(obj.type).filter(Boolean);\n\n switch (options.specType) {\n case SpecTypes.SWAGGER:\n if (!obj.allOf && !obj.$ref) {\n obj.type = uniq([\"null\", ...types]);\n }\n break;\n default:\n case SpecTypes.JSON:\n if (obj.oneOf) {\n if (!hasNullable(obj)) {\n obj.oneOf.unshift({\n type: \"null\"\n });\n }\n } else {\n obj.type = uniq([\"null\", ...types]);\n }\n break;\n\n case SpecTypes.OPENAPI:\n obj.nullable = true;\n\n if (!obj.oneOf) {\n if (types.length > 1) {\n obj.oneOf = types.map((type) => ({type}));\n delete obj.type;\n } else {\n obj.type = types[0];\n }\n }\n break;\n }\n\n return obj;\n}\n"]}
|
package/lib/esm/utils/ref.js
CHANGED
|
@@ -26,29 +26,32 @@ export function createRef(name, schema, options) {
|
|
|
26
26
|
const ref = {
|
|
27
27
|
$ref: `${host}/${name}`
|
|
28
28
|
};
|
|
29
|
-
const nullable = schema.
|
|
30
|
-
const readOnly = schema.
|
|
31
|
-
|
|
29
|
+
const nullable = schema.isNullable;
|
|
30
|
+
const readOnly = schema.isReadOnly;
|
|
31
|
+
const writeOnly = schema.isWriteOnly;
|
|
32
|
+
if (nullable || readOnly || writeOnly) {
|
|
32
33
|
switch (options.specType) {
|
|
33
34
|
case SpecTypes.OPENAPI:
|
|
34
35
|
return cleanObject({
|
|
35
36
|
nullable: nullable ? true : undefined,
|
|
36
37
|
readOnly: readOnly ? true : undefined,
|
|
37
|
-
|
|
38
|
+
writeOnly: writeOnly ? true : undefined,
|
|
39
|
+
oneOf: [ref]
|
|
38
40
|
});
|
|
39
41
|
case SpecTypes.JSON:
|
|
40
42
|
return cleanObject({
|
|
41
43
|
readOnly,
|
|
42
|
-
|
|
44
|
+
writeOnly,
|
|
45
|
+
oneOf: [ref]
|
|
43
46
|
});
|
|
44
|
-
case SpecTypes.SWAGGER: // unsupported
|
|
45
|
-
if (readOnly) {
|
|
46
|
-
return {
|
|
47
|
+
case SpecTypes.SWAGGER: // TODO unsupported feature
|
|
48
|
+
if (readOnly || writeOnly) {
|
|
49
|
+
return cleanObject({
|
|
47
50
|
readOnly,
|
|
51
|
+
writeOnly,
|
|
48
52
|
allOf: [ref]
|
|
49
|
-
};
|
|
53
|
+
});
|
|
50
54
|
}
|
|
51
|
-
break;
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
57
|
return ref;
|
package/lib/esm/utils/ref.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ref.js","sourceRoot":"","sources":["../../../src/utils/ref.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EA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ACjB,QAAQ;oBACR,SAAS;oBACT,KAAK,EAAE,CAAC,GAAG,CAAC;iBACb,CAAC,CAAC;YACL,KAAK,SAAS,CAAC,OAAO,EAAE,2BAA2B;gBACjD,IAAI,QAAQ,IAAI,SAAS,EAAE;oBACzB,OAAO,WAAW,CAAC;wBACjB,QAAQ;wBACR,SAAS;wBACT,KAAK,EAAE,CAAC,GAAG,CAAC;qBACb,CAAC,CAAC;iBACJ;SACJ;KACF;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,KAAK,CAAC,KAAiB,EAAE,MAAW,EAAE,OAA0B;IAC9E,MAAM,IAAI,GAAG,aAAa,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;IAErD,OAAO,CAAC,OAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,GAAG,MAAM,CAAC;IAE3C,OAAO,SAAS,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC","sourcesContent":["import {pascalCase} from \"pascal-case\";\nimport type {JsonSchema} from \"../domain/JsonSchema\";\nimport {SpecTypes} from \"../domain/SpecTypes\";\nimport {JsonSchemaOptions} from \"../interfaces/JsonSchemaOptions\";\nimport {cleanObject} from \"@tsed/core\";\n\n/**\n * ignore\n * @param options\n */\nfunction getHost(options: JsonSchemaOptions) {\n const {host = `#/${options.specType === \"openapi3\" ? \"components/schemas\" : \"definitions\"}`} = options;\n\n return host;\n}\n\n/**\n * @ignore\n */\nexport function createRefName(name: string, options: JsonSchemaOptions) {\n if (options.groups && options.groups.length) {\n return pascalCase(`${name} ${options.groups.join(\" \")}`);\n }\n\n return name;\n}\n\n/**\n * @ignore\n */\nexport function createRef(name: string, schema: JsonSchema, options: JsonSchemaOptions) {\n const host = getHost(options);\n const ref = {\n $ref: `${host}/${name}`\n };\n\n const nullable = schema.isNullable;\n const readOnly = schema.isReadOnly;\n const writeOnly = schema.isWriteOnly;\n\n if (nullable || readOnly || writeOnly) {\n switch (options.specType) {\n case SpecTypes.OPENAPI:\n return cleanObject({\n nullable: nullable ? true : undefined,\n readOnly: readOnly ? true : undefined,\n writeOnly: writeOnly ? true : undefined,\n oneOf: [ref]\n });\n case SpecTypes.JSON:\n return cleanObject({\n readOnly,\n writeOnly,\n oneOf: [ref]\n });\n case SpecTypes.SWAGGER: // TODO unsupported feature\n if (readOnly || writeOnly) {\n return cleanObject({\n readOnly,\n writeOnly,\n allOf: [ref]\n });\n }\n }\n }\n\n return ref;\n}\n\n/**\n * @ignore\n */\nexport function toRef(value: JsonSchema, schema: any, options: JsonSchemaOptions) {\n const name = createRefName(value.getName(), options);\n\n options.schemas![value.getName()] = schema;\n\n return createRef(name, value, options);\n}\n"]}
|
|
@@ -14,29 +14,19 @@ export interface JsonSchemaObject extends JSONSchema6, Record<string, any> {
|
|
|
14
14
|
}
|
|
15
15
|
export declare type AnyJsonSchema = Partial<JsonSchemaObject> | JsonSchema | JsonLazyRef | any;
|
|
16
16
|
export declare class JsonSchema extends Map<string, any> implements NestedGenerics {
|
|
17
|
+
#private;
|
|
17
18
|
readonly isJsonSchema = true;
|
|
18
19
|
readonly $hooks: Hooks;
|
|
19
20
|
readonly $required: Set<string>;
|
|
20
21
|
readonly $allow: any[];
|
|
21
22
|
$selfRequired: boolean;
|
|
22
23
|
$forwardGroups: boolean;
|
|
23
|
-
protected _nullable: boolean;
|
|
24
|
-
protected _genericLabels: string[];
|
|
25
|
-
protected _nestedGenerics: Type<any>[][];
|
|
26
|
-
protected _alias: AliasMap;
|
|
27
|
-
protected _itemSchema: JsonSchema;
|
|
28
|
-
protected _target: Type<any>;
|
|
29
|
-
protected _isGeneric: boolean;
|
|
30
|
-
protected _isCollection: boolean;
|
|
31
|
-
protected _ref: boolean;
|
|
32
24
|
constructor(obj?: JsonSchema | Partial<JsonSchemaObject>);
|
|
33
25
|
get alias(): AliasMap;
|
|
34
26
|
get nestedGenerics(): any[];
|
|
35
27
|
set nestedGenerics(value: any[]);
|
|
36
28
|
get genericLabels(): string[];
|
|
37
29
|
set genericLabels(value: string[]);
|
|
38
|
-
get nullable(): boolean;
|
|
39
|
-
set nullable(value: boolean);
|
|
40
30
|
get isClass(): boolean;
|
|
41
31
|
/**
|
|
42
32
|
* Current schema is a collection
|
|
@@ -53,7 +43,11 @@ export declare class JsonSchema extends Map<string, any> implements NestedGeneri
|
|
|
53
43
|
get genericType(): string;
|
|
54
44
|
get class(): any;
|
|
55
45
|
get canRef(): boolean;
|
|
46
|
+
get isNullable(): boolean;
|
|
47
|
+
get isReadOnly(): any;
|
|
48
|
+
get isWriteOnly(): any;
|
|
56
49
|
static from(obj?: Partial<JsonSchemaObject>): JsonSchema;
|
|
50
|
+
nullable(value: boolean): void;
|
|
57
51
|
itemSchema(obj?: AnyJsonSchema): JsonSchema;
|
|
58
52
|
getAliasOf(property: AliasType): AliasType | undefined;
|
|
59
53
|
addAlias(property: AliasType, alias: AliasType): this;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/schema",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.97.2",
|
|
4
4
|
"description": "JsonSchema module for Ts.ED Framework",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"build": "yarn run build:esm && yarn run build:cjs",
|
|
17
17
|
"build:cjs": "tsc --build tsconfig.compile.json",
|
|
18
18
|
"build:esm": "tsc --build tsconfig.compile.esm.json",
|
|
19
|
-
"test": "cross-env NODE_ENV=test
|
|
19
|
+
"test": "cross-env NODE_ENV=test yarn jest --max-workers=2 --coverage"
|
|
20
20
|
},
|
|
21
21
|
"keywords": [
|
|
22
22
|
"TypeScript",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"tsed"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@tsed/core": "6.
|
|
33
|
-
"@tsed/openspec": "6.
|
|
32
|
+
"@tsed/core": "6.97.2",
|
|
33
|
+
"@tsed/openspec": "6.97.2",
|
|
34
34
|
"camel-case": "4.1.2",
|
|
35
35
|
"json-schema": "0.4.0",
|
|
36
36
|
"micromatch": "4.0.2",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"fs-extra": "9.0.1"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@tsed/core": "^6.
|
|
49
|
-
"@tsed/openspec": "^6.
|
|
48
|
+
"@tsed/core": "^6.97.2",
|
|
49
|
+
"@tsed/openspec": "^6.97.2"
|
|
50
50
|
},
|
|
51
51
|
"repository": "https://github.com/tsedio/tsed",
|
|
52
52
|
"bugs": {
|
package/.mocharc.js
DELETED
package/.nycrc
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"include": [
|
|
3
|
-
"src/**/*.ts"
|
|
4
|
-
],
|
|
5
|
-
"exclude": [
|
|
6
|
-
"**/*.d.ts",
|
|
7
|
-
"node_modules",
|
|
8
|
-
"**/interfaces/**",
|
|
9
|
-
"**/index.ts",
|
|
10
|
-
"**/*.spec.ts"
|
|
11
|
-
],
|
|
12
|
-
"extension": [
|
|
13
|
-
".ts"
|
|
14
|
-
],
|
|
15
|
-
"require": [],
|
|
16
|
-
"reporter": [
|
|
17
|
-
"text-summary",
|
|
18
|
-
"html",
|
|
19
|
-
"lcov",
|
|
20
|
-
"json"
|
|
21
|
-
],
|
|
22
|
-
"check-coverage": true,
|
|
23
|
-
"statements": 99.67,
|
|
24
|
-
"branches": 91.32,
|
|
25
|
-
"functions": 99.51,
|
|
26
|
-
"lines": 99.81
|
|
27
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isJsonClass = void 0;
|
|
4
|
-
const core_1 = require("@tsed/core");
|
|
5
|
-
/**
|
|
6
|
-
* @ignore
|
|
7
|
-
*/
|
|
8
|
-
function isJsonClass(type) {
|
|
9
|
-
return (0, core_1.isClass)(type) && ![Map, Array, Set, Object, Date, Boolean, Number, String].includes(this._target);
|
|
10
|
-
}
|
|
11
|
-
exports.isJsonClass = isJsonClass;
|
|
12
|
-
//# sourceMappingURL=isJsonClass.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isJsonClass.js","sourceRoot":"","sources":["../../../src/utils/isJsonClass.ts"],"names":[],"mappings":";;;AAAA,qCAAmC;AAEnC;;GAEG;AACH,SAAgB,WAAW,CAAC,IAAS;IACnC,OAAO,IAAA,cAAO,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAc,CAAC,CAAC;AAClH,CAAC;AAFD,kCAEC","sourcesContent":["import {isClass} from \"@tsed/core\";\n\n/**\n * @ignore\n */\nexport function isJsonClass(type: any) {\n return isClass(type) && ![Map, Array, Set, Object, Date, Boolean, Number, String].includes(this._target as any);\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isJsonClass.js","sourceRoot":"","sources":["../../../src/utils/isJsonClass.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,YAAY,CAAC;AAEnC;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,IAAS;IACnC,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAc,CAAC,CAAC;AAClH,CAAC","sourcesContent":["import {isClass} from \"@tsed/core\";\n\n/**\n * @ignore\n */\nexport function isJsonClass(type: any) {\n return isClass(type) && ![Map, Array, Set, Object, Date, Boolean, Number, String].includes(this._target as any);\n}\n"]}
|