@tsed/schema 6.105.4 → 6.107.1

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.
Files changed (76) hide show
  1. package/jest.config.js +4 -4
  2. package/lib/cjs/components/schemaMapper.js +1 -3
  3. package/lib/cjs/components/schemaMapper.js.map +1 -1
  4. package/lib/cjs/decorators/common/recordOf.js +63 -0
  5. package/lib/cjs/decorators/common/recordOf.js.map +1 -0
  6. package/lib/cjs/domain/JsonOperation.js +3 -18
  7. package/lib/cjs/domain/JsonOperation.js.map +1 -1
  8. package/lib/cjs/domain/JsonParameter.js +8 -54
  9. package/lib/cjs/domain/JsonParameter.js.map +1 -1
  10. package/lib/cjs/domain/JsonResponse.js +1 -11
  11. package/lib/cjs/domain/JsonResponse.js.map +1 -1
  12. package/lib/cjs/domain/SpecTypes.js +0 -3
  13. package/lib/cjs/domain/SpecTypes.js.map +1 -1
  14. package/lib/cjs/index.js +7 -0
  15. package/lib/cjs/index.js.map +1 -1
  16. package/lib/cjs/utils/generateSpec.js +55 -0
  17. package/lib/cjs/utils/generateSpec.js.map +1 -0
  18. package/lib/cjs/utils/getSpec.js +58 -43
  19. package/lib/cjs/utils/getSpec.js.map +1 -1
  20. package/lib/cjs/utils/getSpecType.js +21 -0
  21. package/lib/cjs/utils/getSpecType.js.map +1 -0
  22. package/lib/cjs/utils/mapNullableType.js +0 -5
  23. package/lib/cjs/utils/mapNullableType.js.map +1 -1
  24. package/lib/cjs/utils/mapOpenSpec.js +41 -0
  25. package/lib/cjs/utils/mapOpenSpec.js.map +1 -0
  26. package/lib/cjs/utils/mapOpenSpec2.js +34 -0
  27. package/lib/cjs/utils/mapOpenSpec2.js.map +1 -0
  28. package/lib/cjs/utils/mapOpenSpec3.js +26 -0
  29. package/lib/cjs/utils/mapOpenSpec3.js.map +1 -0
  30. package/lib/cjs/utils/mapOpenSpecInfo.js +21 -0
  31. package/lib/cjs/utils/mapOpenSpecInfo.js.map +1 -0
  32. package/lib/cjs/utils/mergeOperation.js +1 -0
  33. package/lib/cjs/utils/mergeOperation.js.map +1 -1
  34. package/lib/esm/components/schemaMapper.js +1 -3
  35. package/lib/esm/components/schemaMapper.js.map +1 -1
  36. package/lib/esm/decorators/common/recordOf.js +59 -0
  37. package/lib/esm/decorators/common/recordOf.js.map +1 -0
  38. package/lib/esm/domain/JsonOperation.js +3 -18
  39. package/lib/esm/domain/JsonOperation.js.map +1 -1
  40. package/lib/esm/domain/JsonParameter.js +8 -54
  41. package/lib/esm/domain/JsonParameter.js.map +1 -1
  42. package/lib/esm/domain/JsonResponse.js +1 -11
  43. package/lib/esm/domain/JsonResponse.js.map +1 -1
  44. package/lib/esm/domain/SpecTypes.js +0 -3
  45. package/lib/esm/domain/SpecTypes.js.map +1 -1
  46. package/lib/esm/index.js +7 -0
  47. package/lib/esm/index.js.map +1 -1
  48. package/lib/esm/utils/generateSpec.js +50 -0
  49. package/lib/esm/utils/generateSpec.js.map +1 -0
  50. package/lib/esm/utils/getSpec.js +59 -44
  51. package/lib/esm/utils/getSpec.js.map +1 -1
  52. package/lib/esm/utils/getSpecType.js +16 -0
  53. package/lib/esm/utils/getSpecType.js.map +1 -0
  54. package/lib/esm/utils/mapNullableType.js +0 -5
  55. package/lib/esm/utils/mapNullableType.js.map +1 -1
  56. package/lib/esm/utils/mapOpenSpec.js +37 -0
  57. package/lib/esm/utils/mapOpenSpec.js.map +1 -0
  58. package/lib/esm/utils/mapOpenSpec2.js +30 -0
  59. package/lib/esm/utils/mapOpenSpec2.js.map +1 -0
  60. package/lib/esm/utils/mapOpenSpec3.js +22 -0
  61. package/lib/esm/utils/mapOpenSpec3.js.map +1 -0
  62. package/lib/esm/utils/mapOpenSpecInfo.js +17 -0
  63. package/lib/esm/utils/mapOpenSpecInfo.js.map +1 -0
  64. package/lib/esm/utils/mergeOperation.js +1 -0
  65. package/lib/esm/utils/mergeOperation.js.map +1 -1
  66. package/lib/types/decorators/common/recordOf.d.ts +46 -0
  67. package/lib/types/domain/SpecTypes.d.ts +0 -3
  68. package/lib/types/index.d.ts +7 -0
  69. package/lib/types/utils/generateSpec.d.ts +16 -0
  70. package/lib/types/utils/getSpec.d.ts +5 -24
  71. package/lib/types/utils/getSpecType.d.ts +12 -0
  72. package/lib/types/utils/mapOpenSpec.d.ts +10 -0
  73. package/lib/types/utils/mapOpenSpec2.d.ts +9 -0
  74. package/lib/types/utils/mapOpenSpec3.d.ts +8 -0
  75. package/lib/types/utils/mapOpenSpecInfo.d.ts +6 -0
  76. package/package.json +9 -8
@@ -1,10 +1,11 @@
1
- import { cleanObject, uniqBy } from "@tsed/core";
1
+ import { cleanObject, isArray, uniqBy } from "@tsed/core";
2
2
  import { SpecTypes } from "../domain/SpecTypes.js";
3
3
  import { buildPath } from "./buildPath.js";
4
4
  import { getJsonEntityStore } from "./getJsonEntityStore.js";
5
5
  import { getOperationsStores } from "./getOperationsStores.js";
6
6
  import { mergeOperation } from "./mergeOperation.js";
7
7
  import { operationIdFormatter } from "./operationIdFormatter.js";
8
+ import { mergeSpec } from "./mergeSpec.js";
8
9
  /**
9
10
  * @ignore
10
11
  */
@@ -23,61 +24,75 @@ function get(model, options, cb) {
23
24
  }
24
25
  return cache.get(key);
25
26
  }
27
+ function generate(model, options) {
28
+ const store = getJsonEntityStore(model);
29
+ const { schemas = {}, paths = {}, rootPath = "/", tags = [] } = options;
30
+ const specType = SpecTypes.OPENAPI;
31
+ const ctrlPath = store.path;
32
+ const defaultTags = cleanObject({
33
+ name: store.schema.getName(),
34
+ description: store.schema.get("description")
35
+ });
36
+ const specJson = { paths };
37
+ getOperationsStores(model).forEach((operationStore) => {
38
+ if (operationStore.store.get("hidden")) {
39
+ return;
40
+ }
41
+ const operation = operationStore.operation.toJSON({ ...options, specType, schemas });
42
+ operationStore.operation.operationPaths.forEach(({ path, method }) => {
43
+ if (method) {
44
+ mergeOperation(specJson, operation, {
45
+ rootPath: buildPath(rootPath + ctrlPath),
46
+ path,
47
+ method,
48
+ defaultTags,
49
+ tags,
50
+ specType,
51
+ operationId: (path) => options.operationIdFormatter(operationStore.parent.schema.get("name") || operationStore.parent.targetName, operationStore.propertyName, path)
52
+ });
53
+ }
54
+ });
55
+ });
56
+ specJson.tags = uniqBy(tags, "name");
57
+ if (Object.keys(schemas).length) {
58
+ specJson.components = {
59
+ schemas
60
+ };
61
+ }
62
+ return specJson;
63
+ }
26
64
  /**
27
65
  * Return the swagger or open spec for the given class.
28
66
  * @param model
29
67
  * @param options
30
68
  */
31
69
  export function getSpec(model, options = {}) {
32
- if (!options.specType) {
33
- options.specType = SpecTypes.OPENAPI;
34
- }
35
70
  options = {
36
71
  ...options,
37
72
  operationIdFormatter: options.operationIdFormatter || operationIdFormatter(options.operationIdPattern),
38
- root: false,
39
- specType: options.specType
73
+ root: false
40
74
  };
41
- return get(model, options, () => {
42
- const store = getJsonEntityStore(model);
43
- const { specType = SpecTypes.OPENAPI, schemas = {}, paths = {}, rootPath = "/", tags = [] } = options;
44
- const ctrlPath = store.path;
45
- const defaultTags = cleanObject({
46
- name: store.schema.getName(),
47
- description: store.schema.get("description")
48
- });
49
- const specJson = { paths };
50
- getOperationsStores(model).forEach((operationStore) => {
51
- if (operationStore.store.get("hidden")) {
52
- return;
75
+ if (isArray(model)) {
76
+ let finalSpec = {};
77
+ options = {
78
+ ...options,
79
+ specType: SpecTypes.OPENAPI,
80
+ paths: {},
81
+ tags: [],
82
+ schemas: {},
83
+ append(spec) {
84
+ finalSpec = mergeSpec(finalSpec, spec);
53
85
  }
54
- const operation = operationStore.operation.toJSON({ ...options, specType, schemas });
55
- operationStore.operation.operationPaths.forEach(({ path, method }) => {
56
- if (method) {
57
- mergeOperation(specJson, operation, {
58
- rootPath: buildPath(rootPath + ctrlPath),
59
- path,
60
- method,
61
- defaultTags,
62
- tags,
63
- specType,
64
- operationId: (path) => options.operationIdFormatter(operationStore.parent.schema.get("name") || operationStore.parent.targetName, operationStore.propertyName, path)
65
- });
66
- }
86
+ };
87
+ model.forEach(({ token, ...opts }) => {
88
+ const spec = getSpec(token, {
89
+ ...options,
90
+ ...opts
67
91
  });
92
+ options.append(spec);
68
93
  });
69
- specJson.tags = uniqBy(tags, "name");
70
- if (Object.keys(schemas).length) {
71
- if (specType === SpecTypes.OPENAPI) {
72
- specJson.components = {
73
- schemas
74
- };
75
- }
76
- else {
77
- specJson.definitions = schemas;
78
- }
79
- }
80
- return specJson;
81
- });
94
+ return finalSpec;
95
+ }
96
+ return get(model, options, () => generate(model, options));
82
97
  }
83
98
  //# sourceMappingURL=getSpec.js.map
@@ -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,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAC,oBAAoB,EAAC,MAAM,wBAAwB,CAAC;AAoC5D;;GAEG;AACH,MAAM,MAAM,GAAqC,IAAI,GAAG,EAAE,CAAC;AAE3D;;GAEG;AACH,SAAS,GAAG,CAAC,KAAgB,EAAE,OAAY,EAAE,EAAO;IAClD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;QACtB,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;KAC9B;IAED,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAE,CAAC;IACjC,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IAEpC,IAAI,CAAC,KAAK,CAAC,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";\nimport {JsonSchemaOptions} from \"../interfaces/JsonSchemaOptions\";\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
+ {"version":3,"file":"getSpec.js","sourceRoot":"","sources":["../../../src/utils/getSpec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,OAAO,EAAQ,MAAM,EAAC,MAAM,YAAY,CAAC;AAE9D,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,OA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,UAAiC,EAAE;IAC9F,OAAO,GAAG;QACR,GAAG,OAAO;QACV,oBAAoB,EAAE,OAAO,CAAC,oBAAoB,IAAI,oBAAoB,CAAC,OAAO,CAAC,kBAAkB,CAAC;QACtG,IAAI,EAAE,KAAK;KACZ,CAAC;IAEF,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE;QAClB,IAAI,SAAS,GAAQ,EAAE,CAAC;QAExB,OAAO,GAAG;YACR,GAAG,OAAO;YACV,QAAQ,EAAE,SAAS,CAAC,OAAO;YAC3B,KAAK,EAAE,EAAE;YACT,IAAI,EAAE,EAAE;YACR,OAAO,EAAE,EAAE;YACX,MAAM,CAAC,IAAS;gBACd,SAAS,GAAG,SAAS,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;YACzC,CAAC;SACF,CAAC;QAEF,KAAK,CAAC,OAAO,CAAC,CAAC,EAAC,KAAK,EAAE,GAAG,IAAI,EAAC,EAAE,EAAE;YACjC,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,EAAE;gBAC1B,GAAG,OAAO;gBACV,GAAG,IAAI;aACR,CAAC,CAAC;YAEH,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;QAEH,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;AAC7D,CAAC","sourcesContent":["import {cleanObject, isArray, Type, uniqBy} from \"@tsed/core\";\nimport {OpenSpec3} from \"@tsed/openspec\";\nimport {SpecTypes} from \"../domain/SpecTypes\";\nimport {JsonSchemaOptions} from \"../interfaces/JsonSchemaOptions\";\nimport {buildPath} from \"./buildPath\";\nimport {getJsonEntityStore} from \"./getJsonEntityStore\";\nimport {getOperationsStores} from \"./getOperationsStores\";\nimport {mergeOperation} from \"./mergeOperation\";\nimport {operationIdFormatter} from \"./operationIdFormatter\";\nimport {mergeSpec} from \"./mergeSpec\";\n\nexport type JsonTokenOptions = ({token: Type<any>} & Partial<SpecSerializerOptions>)[];\n\nexport interface SpecSerializerOptions extends JsonSchemaOptions {\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\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\nfunction generate(model: Type<any>, options: SpecSerializerOptions) {\n const store = getJsonEntityStore(model);\n const {schemas = {}, paths = {}, rootPath = \"/\", tags = []} = options;\n const specType = SpecTypes.OPENAPI;\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 specJson.components = {\n schemas\n };\n }\n\n return specJson;\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> | JsonTokenOptions, options: SpecSerializerOptions = {}): Partial<OpenSpec3> {\n options = {\n ...options,\n operationIdFormatter: options.operationIdFormatter || operationIdFormatter(options.operationIdPattern),\n root: false\n };\n\n if (isArray(model)) {\n let finalSpec: any = {};\n\n options = {\n ...options,\n specType: SpecTypes.OPENAPI,\n paths: {},\n tags: [],\n schemas: {},\n append(spec: any) {\n finalSpec = mergeSpec(finalSpec, spec);\n }\n };\n\n model.forEach(({token, ...opts}) => {\n const spec = getSpec(token, {\n ...options,\n ...opts\n });\n\n options.append(spec);\n });\n\n return finalSpec;\n }\n\n return get(model, options, () => generate(model, options));\n}\n"]}
@@ -0,0 +1,16 @@
1
+ import { SpecTypes } from "../domain/SpecTypes.js";
2
+ /**
3
+ * @ignore
4
+ * @param version
5
+ */
6
+ export function getSpecType(version) {
7
+ return version.startsWith("3.") ? SpecTypes.OPENAPI : SpecTypes.SWAGGER;
8
+ }
9
+ /**
10
+ * @ignore
11
+ * @param spec
12
+ */
13
+ export function getSpecTypeFromSpec(spec) {
14
+ return "openapi" in spec ? SpecTypes.OPENAPI : SpecTypes.SWAGGER;
15
+ }
16
+ //# sourceMappingURL=getSpecType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSpecType.js","sourceRoot":"","sources":["../../../src/utils/getSpecType.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAE9C;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,OAAe;IACzC,OAAO,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC;AAC1E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAoC;IACtE,OAAO,SAAS,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC;AACnE,CAAC","sourcesContent":["import {OpenSpec2, OpenSpec3} from \"@tsed/openspec\";\nimport {SpecTypes} from \"../domain/SpecTypes\";\n\n/**\n * @ignore\n * @param version\n */\nexport function getSpecType(version: string) {\n return version.startsWith(\"3.\") ? SpecTypes.OPENAPI : SpecTypes.SWAGGER;\n}\n\n/**\n * @ignore\n * @param spec\n */\nexport function getSpecTypeFromSpec(spec: Partial<OpenSpec2 | OpenSpec3>) {\n return \"openapi\" in spec ? SpecTypes.OPENAPI : SpecTypes.SWAGGER;\n}\n"]}
@@ -9,11 +9,6 @@ export function mapNullableType(obj, schema, options) {
9
9
  }
10
10
  let types = [].concat(obj.type).filter(Boolean);
11
11
  switch (options.specType) {
12
- case SpecTypes.SWAGGER:
13
- if (!obj.allOf && !obj.$ref) {
14
- obj.type = uniq(["null", ...types]);
15
- }
16
- break;
17
12
  default:
18
13
  case SpecTypes.JSON:
19
14
  if (obj.oneOf) {
@@ -1 +1 @@
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,MAAyB,EAAE,OAA0B;IAC7F,IAAI,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,UAAU,CAAA,EAAE;QACvB,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 | null, 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"]}
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,MAAyB,EAAE,OAA0B;IAC7F,IAAI,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,UAAU,CAAA,EAAE;QACvB,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,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 | null, 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 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"]}
@@ -0,0 +1,37 @@
1
+ import { getValue, setValue } from "@tsed/core";
2
+ import { getSpecType } from "./getSpecType.js";
3
+ import { mapOpenSpec2 } from "./mapOpenSpec2.js";
4
+ import { SpecTypes } from "../domain/SpecTypes.js";
5
+ import { mapOpenSpec3 } from "./mapOpenSpec3.js";
6
+ import { mergeSpec } from "./mergeSpec.js";
7
+ /**
8
+ * @ignore
9
+ * @param spec
10
+ * @param fileSpec
11
+ * @param version
12
+ * @param acceptMimes
13
+ * @param specVersion
14
+ */
15
+ export function mapOpenSpec(spec, { fileSpec, acceptMimes, specVersion, version }) {
16
+ specVersion = specVersion || getValue(spec, "openapi", getValue(spec, "swagger", "2.0"));
17
+ const options = {
18
+ specVersion,
19
+ acceptMimes
20
+ };
21
+ switch (getSpecType(specVersion)) {
22
+ case SpecTypes.OPENAPI:
23
+ spec = mapOpenSpec3(spec, options);
24
+ fileSpec = fileSpec ? mapOpenSpec3(fileSpec, options) : fileSpec;
25
+ break;
26
+ default:
27
+ case SpecTypes.SWAGGER:
28
+ spec = mapOpenSpec2(spec, options);
29
+ fileSpec = fileSpec ? mapOpenSpec2(fileSpec, options) : fileSpec;
30
+ break;
31
+ }
32
+ spec = mergeSpec(spec, fileSpec);
33
+ setValue(spec, "info.title", getValue(spec, "info.title", "Api documentation"));
34
+ setValue(spec, "info.version", getValue(spec, "info.version", version));
35
+ return spec;
36
+ }
37
+ //# sourceMappingURL=mapOpenSpec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapOpenSpec.js","sourceRoot":"","sources":["../../../src/utils/mapOpenSpec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAC;AAE9C,OAA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EAAE,cAAc,EAAE,QAAQ,CAAC,IAAI,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC;IAExE,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import {getValue, setValue} from \"@tsed/core\";\nimport {OpenSpec2, OpenSpec3, OpenSpecVersions} from \"@tsed/openspec\";\nimport {getSpecType} from \"./getSpecType\";\nimport {mapOpenSpec2} from \"./mapOpenSpec2\";\nimport {SpecTypes} from \"../domain/SpecTypes\";\nimport {mapOpenSpec3} from \"./mapOpenSpec3\";\nimport {mergeSpec} from \"./mergeSpec\";\n\n/**\n * @ignore\n * @param spec\n * @param fileSpec\n * @param version\n * @param acceptMimes\n * @param specVersion\n */\nexport function mapOpenSpec(spec: any, {fileSpec, acceptMimes, specVersion, version}: any): Partial<OpenSpec2 | OpenSpec3> {\n specVersion = specVersion || getValue<OpenSpecVersions>(spec, \"openapi\", getValue(spec, \"swagger\", \"2.0\"));\n\n const options = {\n specVersion,\n acceptMimes\n };\n\n switch (getSpecType(specVersion)) {\n case SpecTypes.OPENAPI:\n spec = mapOpenSpec3(spec, options);\n fileSpec = fileSpec ? mapOpenSpec3(fileSpec, options) : fileSpec;\n break;\n default:\n case SpecTypes.SWAGGER:\n spec = mapOpenSpec2(spec, options);\n fileSpec = fileSpec ? mapOpenSpec2(fileSpec, options) : fileSpec;\n break;\n }\n\n spec = mergeSpec(spec, fileSpec);\n\n setValue(spec, \"info.title\", getValue(spec, \"info.title\", \"Api documentation\"));\n setValue(spec, \"info.version\", getValue(spec, \"info.version\", version));\n\n return spec;\n}\n"]}
@@ -0,0 +1,30 @@
1
+ import { getValue, uniq } from "@tsed/core";
2
+ import { mapOpenSpecInfo } from "./mapOpenSpecInfo.js";
3
+ /**
4
+ * @ignore
5
+ * @param spec
6
+ * @param version
7
+ * @param specVersion
8
+ * @param acceptMimes
9
+ */
10
+ export function mapOpenSpec2(spec, { version, specVersion, acceptMimes = ["application/json"] }) {
11
+ const { paths, security, tags, host, basePath, schemes, consumes = [], produces = ["application/json"], definitions, parameters, responses, securityDefinitions, externalDocs } = spec;
12
+ return {
13
+ swagger: specVersion,
14
+ consumes: uniq([...acceptMimes, ...consumes]),
15
+ produces: uniq([...produces]),
16
+ info: mapOpenSpecInfo(getValue(spec, "info", {})),
17
+ paths,
18
+ host,
19
+ basePath,
20
+ schemes,
21
+ definitions,
22
+ parameters,
23
+ responses,
24
+ security,
25
+ securityDefinitions,
26
+ tags,
27
+ externalDocs
28
+ };
29
+ }
30
+ //# sourceMappingURL=mapOpenSpec2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapOpenSpec2.js","sourceRoot":"","sources":["../../../src/utils/mapOpenSpec2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,IAAI,EAAC,MAAM,YAAY,CAAC;AAE1C,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAC1B,IAAwB,EACxB,EAAC,OAAO,EAAE,WAAW,EAAE,WAAW,GAAG,CAAC,kBAAkB,CAAC,EAAM;IAE/D,MAAM,EACJ,KAAK,EACL,QAAQ,EACR,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,QAAQ,GAAG,EAAE,EACb,QAAQ,GAAG,CAAC,kBAAkB,CAAC,EAC/B,WAAW,EACX,UAAU,EACV,SAAS,EACT,mBAAmB,EACnB,YAAY,EACb,GAAG,IAAI,CAAC;IAET,OAAO;QACL,OAAO,EAAE,WAAW;QACpB,QAAQ,EAAE,IAAI,CAAC,CAAC,GAAG,WAAW,EAAE,GAAG,QAAQ,CAAC,CAAC;QAC7C,QAAQ,EAAE,IAAI,CAAS,CAAC,GAAG,QAAQ,CAAC,CAAC;QACrC,IAAI,EAAE,eAAe,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;QACjD,KAAK;QACL,IAAI;QACJ,QAAQ;QACR,OAAO;QACP,WAAW;QACX,UAAU;QACV,SAAS;QACT,QAAQ;QACR,mBAAmB;QACnB,IAAI;QACJ,YAAY;KACb,CAAC;AACJ,CAAC","sourcesContent":["import {getValue, uniq} from \"@tsed/core\";\nimport {OpenSpec2} from \"@tsed/openspec\";\nimport {mapOpenSpecInfo} from \"./mapOpenSpecInfo\";\n\n/**\n * @ignore\n * @param spec\n * @param version\n * @param specVersion\n * @param acceptMimes\n */\nexport function mapOpenSpec2(\n spec: Partial<OpenSpec2>,\n {version, specVersion, acceptMimes = [\"application/json\"]}: any\n): Partial<OpenSpec2> {\n const {\n paths,\n security,\n tags,\n host,\n basePath,\n schemes,\n consumes = [],\n produces = [\"application/json\"],\n definitions,\n parameters,\n responses,\n securityDefinitions,\n externalDocs\n } = spec;\n\n return {\n swagger: specVersion,\n consumes: uniq([...acceptMimes, ...consumes]),\n produces: uniq<string>([...produces]),\n info: mapOpenSpecInfo(getValue(spec, \"info\", {})),\n paths,\n host,\n basePath,\n schemes,\n definitions,\n parameters,\n responses,\n security,\n securityDefinitions,\n tags,\n externalDocs\n };\n}\n"]}
@@ -0,0 +1,22 @@
1
+ import { getValue } from "@tsed/core";
2
+ import { mapOpenSpecInfo } from "./mapOpenSpecInfo.js";
3
+ /**
4
+ * @ignore
5
+ * @param spec
6
+ * @param version
7
+ * @param specVersion
8
+ */
9
+ export function mapOpenSpec3(spec, { specVersion }) {
10
+ const { servers, paths, components, security, tags, externalDocs } = spec;
11
+ return {
12
+ openapi: specVersion,
13
+ info: mapOpenSpecInfo(getValue(spec, "info", {})),
14
+ servers,
15
+ paths,
16
+ components,
17
+ security,
18
+ tags,
19
+ externalDocs
20
+ };
21
+ }
22
+ //# sourceMappingURL=mapOpenSpec3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapOpenSpec3.js","sourceRoot":"","sources":["../../../src/utils/mapOpenSpec3.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAC,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAElD;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,IAAS,EAAE,EAAC,WAAW,EAAM;IACxD,MAAM,EAAC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAC,GAAG,IAAI,CAAC;IAExE,OAAO;QACL,OAAO,EAAE,WAAW;QACpB,IAAI,EAAE,eAAe,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;QACjD,OAAO;QACP,KAAK;QACL,UAAU;QACV,QAAQ;QACR,IAAI;QACJ,YAAY;KACb,CAAC;AACJ,CAAC","sourcesContent":["import {getValue} from \"@tsed/core\";\nimport {OpenSpec3} from \"@tsed/openspec\";\nimport {mapOpenSpecInfo} from \"./mapOpenSpecInfo\";\n\n/**\n * @ignore\n * @param spec\n * @param version\n * @param specVersion\n */\nexport function mapOpenSpec3(spec: any, {specVersion}: any): Partial<OpenSpec3> {\n const {servers, paths, components, security, tags, externalDocs} = spec;\n\n return {\n openapi: specVersion,\n info: mapOpenSpecInfo(getValue(spec, \"info\", {})),\n servers,\n paths,\n components,\n security,\n tags,\n externalDocs\n };\n}\n"]}
@@ -0,0 +1,17 @@
1
+ import { cleanObject } from "@tsed/core";
2
+ /**
3
+ * @ignore
4
+ * @param info
5
+ */
6
+ export function mapOpenSpecInfo(info) {
7
+ const { title, description, version, termsOfService, contact, license } = info;
8
+ return cleanObject({
9
+ version,
10
+ title,
11
+ description,
12
+ termsOfService,
13
+ contact,
14
+ license
15
+ });
16
+ }
17
+ //# sourceMappingURL=mapOpenSpecInfo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapOpenSpecInfo.js","sourceRoot":"","sources":["../../../src/utils/mapOpenSpecInfo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,YAAY,CAAC;AAGvC;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,IAA2B;IACzD,MAAM,EAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,EAAC,GAAG,IAAI,CAAC;IAE7E,OAAO,WAAW,CAAC;QACjB,OAAO;QACP,KAAK;QACL,WAAW;QACX,cAAc;QACd,OAAO;QACP,OAAO;KACR,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {cleanObject} from \"@tsed/core\";\nimport {OpenSpecInfo} from \"@tsed/openspec\";\n\n/**\n * @ignore\n * @param info\n */\nexport function mapOpenSpecInfo(info: Partial<OpenSpecInfo>): OpenSpecInfo {\n const {title, description, version, termsOfService, contact, license} = info;\n\n return cleanObject({\n version,\n title,\n description,\n termsOfService,\n contact,\n license\n });\n}\n"]}
@@ -7,6 +7,7 @@ import { getJsonPathParameters } from "./getJsonPathParameters.js";
7
7
  export function mergeOperation(obj, operation, { rootPath, specType, operationId, defaultTags, tags, path, method }) {
8
8
  const pathParameters = getJsonPathParameters(rootPath, path).map(({ path, parameters }) => {
9
9
  path = path ? path : "/";
10
+ // FIXME not on the right place
10
11
  if (specType === SpecTypes.OPENAPI) {
11
12
  parameters = parameters.map(({ type, ...param }) => {
12
13
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"mergeOperation.js","sourceRoot":"","sources":["../../../src/utils/mergeOperation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAC,qBAAqB,EAAC,MAAM,yBAAyB,CAAC;AAe9D;;GAEG;AACH,MAAM,UAAU,cAAc,CAC5B,GAAQ,EACR,SAAc,EACd,EAAC,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAwB;IAEzF,MAAM,cAAc,GAAG,qBAAqB,CAAC,QAAQ,EAAE,IAAI,CAAC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CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,CAAC;QAE5B,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,GAAG,CAAC,CAAC;AACV,CAAC","sourcesContent":["import {SpecTypes} from \"../domain/SpecTypes\";\nimport {concatParameters} from \"./concatParameters\";\nimport {getJsonPathParameters} from \"./getJsonPathParameters\";\n\n/**\n * @ignore\n */\nexport interface MergeOperationOptions {\n rootPath: string;\n specType: SpecTypes;\n operationId: (path: string) => string | undefined;\n defaultTags: string[];\n tags: string[];\n path: string;\n method: string;\n}\n\n/**\n * @ignore\n */\nexport function mergeOperation(\n obj: any,\n operation: any,\n {rootPath, specType, operationId, defaultTags, tags, path, method}: MergeOperationOptions\n) {\n const pathParameters = getJsonPathParameters(rootPath, path).map(({path, parameters}) => {\n path = path ? path : \"/\";\n\n if (specType === SpecTypes.OPENAPI) {\n parameters = parameters.map(({type, ...param}) => {\n return {\n ...param,\n schema: {\n type\n }\n };\n });\n }\n\n return {path, parameters};\n });\n\n return pathParameters.reduce((obj, {path, parameters}) => {\n parameters = concatParameters(parameters, operation);\n path = path ? path : \"/\";\n\n const operationTags = operation.tags?.length ? operation.tags : [defaultTags];\n\n obj.paths[path] = {\n ...obj.paths[path],\n [method.toLowerCase()]: {\n operationId: operation.operationId || operationId(path),\n ...operation,\n tags: operationTags.map(({name}: any) => name),\n parameters\n }\n };\n\n tags.push(...operationTags);\n\n return obj;\n }, obj);\n}\n"]}
1
+ {"version":3,"file":"mergeOperation.js","sourceRoot":"","sources":["../../../src/utils/mergeOperation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAC,qBAAqB,EAAC,MAAM,yBAAyB,CAAC;AAe9D;;GAEG;AACH,MAAM,UAAU,cAAc,CAC5B,GAAQ,EACR,SAAc,EACd,EAAC,QAAQ,EAAE,QAAQ,EAAE,W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gBACZ,IAAI,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC,EAAC,IAAI,EAAM,EAAE,EAAE,CAAC,IAAI,CAAC;gBAC9C,UAAU;aACX;SACF,CAAC;QAEF,IAAI,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,CAAC;QAE5B,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,GAAG,CAAC,CAAC;AACV,CAAC","sourcesContent":["import {SpecTypes} from \"../domain/SpecTypes\";\nimport {concatParameters} from \"./concatParameters\";\nimport {getJsonPathParameters} from \"./getJsonPathParameters\";\n\n/**\n * @ignore\n */\nexport interface MergeOperationOptions {\n rootPath: string;\n specType: SpecTypes;\n operationId: (path: string) => string | undefined;\n defaultTags: string[];\n tags: string[];\n path: string;\n method: string;\n}\n\n/**\n * @ignore\n */\nexport function mergeOperation(\n obj: any,\n operation: any,\n {rootPath, specType, operationId, defaultTags, tags, path, method}: MergeOperationOptions\n) {\n const pathParameters = getJsonPathParameters(rootPath, path).map(({path, parameters}) => {\n path = path ? path : \"/\";\n\n // FIXME not on the right place\n if (specType === SpecTypes.OPENAPI) {\n parameters = parameters.map(({type, ...param}) => {\n return {\n ...param,\n schema: {\n type\n }\n };\n });\n }\n\n return {path, parameters};\n });\n\n return pathParameters.reduce((obj, {path, parameters}) => {\n parameters = concatParameters(parameters, operation);\n path = path ? path : \"/\";\n\n const operationTags = operation.tags?.length ? operation.tags : [defaultTags];\n\n obj.paths[path] = {\n ...obj.paths[path],\n [method.toLowerCase()]: {\n operationId: operation.operationId || operationId(path),\n ...operation,\n tags: operationTags.map(({name}: any) => name),\n parameters\n }\n };\n\n tags.push(...operationTags);\n\n return obj;\n }, obj);\n}\n"]}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Constructs a json schema object type whose property keys are keys and whose property values are type.
3
+ *
4
+ * ## Example
5
+ *
6
+ * ```typescript
7
+ * type keys = 'one' | 'two';
8
+ *
9
+ * class Part {
10
+ * prop: string;
11
+ * }
12
+ *
13
+ * type Parts = Record<keys, Part>;
14
+ *
15
+ * class Test {
16
+ * @RecordOf(Part, 'one', 'two')
17
+ * parts: Parts;
18
+ * }
19
+ * ```
20
+ *
21
+ * Will produce:
22
+ *
23
+ * ```json
24
+ * {
25
+ * "type": "object",
26
+ * "properties": {
27
+ * "one": {
28
+ * "$ref": "#/components/schemas/Part"
29
+ * },
30
+ * "two": {
31
+ * "$ref": "#/components/schemas/Part"
32
+ * },
33
+ * },
34
+ * }
35
+ * ```
36
+ *
37
+ * @param model
38
+ * @param keys
39
+ * @decorator
40
+ * @validation
41
+ * @swagger
42
+ * @schema
43
+ * @classDecorator
44
+ * @input
45
+ */
46
+ export declare function RecordOf(model: any, ...keys: string[]): (...args: any[]) => any;
@@ -1,8 +1,5 @@
1
1
  export declare enum SpecTypes {
2
2
  JSON = "jsonschema",
3
- /**
4
- * @deprecated
5
- */
6
3
  SWAGGER = "swagger2",
7
4
  OPENAPI = "openapi3"
8
5
  }
@@ -55,6 +55,7 @@ export * from "./decorators/common/optional";
55
55
  export * from "./decorators/common/pattern";
56
56
  export * from "./decorators/common/property";
57
57
  export * from "./decorators/common/readOnly";
58
+ export * from "./decorators/common/recordOf";
58
59
  export * from "./decorators/common/required";
59
60
  export * from "./decorators/common/requiredGroups";
60
61
  export * from "./decorators/common/schema";
@@ -116,6 +117,7 @@ export * from "./utils/concatParameters";
116
117
  export * from "./utils/concatPath";
117
118
  export * from "./utils/defineStatusModel";
118
119
  export * from "./utils/from";
120
+ export * from "./utils/generateSpec";
119
121
  export * from "./utils/generics";
120
122
  export * from "./utils/getComputedType";
121
123
  export * from "./utils/getInheritedStores";
@@ -128,9 +130,14 @@ export * from "./utils/getOperationsStores";
128
130
  export * from "./utils/getPropertiesStores";
129
131
  export * from "./utils/getRequiredProperties";
130
132
  export * from "./utils/getSpec";
133
+ export * from "./utils/getSpecType";
131
134
  export * from "./utils/isSuccessStatus";
132
135
  export * from "./utils/mapHeaders";
133
136
  export * from "./utils/mapNullableType";
137
+ export * from "./utils/mapOpenSpec";
138
+ export * from "./utils/mapOpenSpec2";
139
+ export * from "./utils/mapOpenSpec3";
140
+ export * from "./utils/mapOpenSpecInfo";
134
141
  export * from "./utils/mapRouteOptions";
135
142
  export * from "./utils/matchGroups";
136
143
  export * from "./utils/mergeOperation";
@@ -0,0 +1,16 @@
1
+ import { OpenSpec2, OpenSpec3 } from "@tsed/openspec";
2
+ import { JsonTokenOptions, SpecSerializerOptions } from "./getSpec";
3
+ export interface GenerateSpecOptions extends Omit<SpecSerializerOptions, "specType"> {
4
+ tokens: JsonTokenOptions;
5
+ version?: string;
6
+ acceptMimes?: string;
7
+ specPath?: string;
8
+ specVersion?: string;
9
+ spec?: any;
10
+ }
11
+ /**
12
+ * Generate OpenAPI spec from multiple sources (models, files, conf)
13
+ * @param tokens
14
+ * @param options
15
+ */
16
+ export declare function generateSpec({ tokens, ...options }: GenerateSpecOptions): Promise<OpenSpec2 | OpenSpec3>;
@@ -1,9 +1,10 @@
1
1
  import { Type } from "@tsed/core";
2
- import { OpenSpec2, OpenSpec3 } from "@tsed/openspec";
3
- import { SpecTypes } from "../domain/SpecTypes";
2
+ import { OpenSpec3 } from "@tsed/openspec";
4
3
  import { JsonSchemaOptions } from "../interfaces/JsonSchemaOptions";
4
+ export declare type JsonTokenOptions = ({
5
+ token: Type<any>;
6
+ } & Partial<SpecSerializerOptions>)[];
5
7
  export interface SpecSerializerOptions extends JsonSchemaOptions {
6
- specType?: SpecTypes.SWAGGER | SpecTypes.OPENAPI;
7
8
  /**
8
9
  * Paths
9
10
  */
@@ -21,29 +22,9 @@ export interface SpecSerializerOptions extends JsonSchemaOptions {
21
22
  */
22
23
  operationIdPattern?: string;
23
24
  }
24
- export interface OS3SpecSerializerOptions extends SpecSerializerOptions {
25
- /**
26
- * Define Spec types level
27
- */
28
- specType: SpecTypes.OPENAPI;
29
- }
30
- export interface OS2SpecSerializerOptions extends SpecSerializerOptions {
31
- /**
32
- * Define Spec types level
33
- */
34
- specType: SpecTypes.SWAGGER;
35
- }
36
- /**
37
- * Return the swagger or open spec for the given class.
38
- * @param model
39
- * @param options
40
- */
41
- export declare function getSpec(model: Type<any>, options: OS2SpecSerializerOptions): Partial<OpenSpec2>;
42
- export declare function getSpec(model: Type<any>): Partial<OpenSpec2>;
43
- export declare function getSpec(model: Type<any>, options: SpecSerializerOptions): Partial<OpenSpec2>;
44
25
  /**
45
26
  * Return the swagger or open spec for the given class.
46
27
  * @param model
47
28
  * @param options
48
29
  */
49
- export declare function getSpec(model: Type<any>, options: OS3SpecSerializerOptions): Partial<OpenSpec3>;
30
+ export declare function getSpec(model: Type<any> | JsonTokenOptions, options?: SpecSerializerOptions): Partial<OpenSpec3>;
@@ -0,0 +1,12 @@
1
+ import { OpenSpec2, OpenSpec3 } from "@tsed/openspec";
2
+ import { SpecTypes } from "../domain/SpecTypes";
3
+ /**
4
+ * @ignore
5
+ * @param version
6
+ */
7
+ export declare function getSpecType(version: string): SpecTypes.SWAGGER | SpecTypes.OPENAPI;
8
+ /**
9
+ * @ignore
10
+ * @param spec
11
+ */
12
+ export declare function getSpecTypeFromSpec(spec: Partial<OpenSpec2 | OpenSpec3>): SpecTypes.SWAGGER | SpecTypes.OPENAPI;
@@ -0,0 +1,10 @@
1
+ import { OpenSpec2, OpenSpec3 } from "@tsed/openspec";
2
+ /**
3
+ * @ignore
4
+ * @param spec
5
+ * @param fileSpec
6
+ * @param version
7
+ * @param acceptMimes
8
+ * @param specVersion
9
+ */
10
+ export declare function mapOpenSpec(spec: any, { fileSpec, acceptMimes, specVersion, version }: any): Partial<OpenSpec2 | OpenSpec3>;
@@ -0,0 +1,9 @@
1
+ import { OpenSpec2 } from "@tsed/openspec";
2
+ /**
3
+ * @ignore
4
+ * @param spec
5
+ * @param version
6
+ * @param specVersion
7
+ * @param acceptMimes
8
+ */
9
+ export declare function mapOpenSpec2(spec: Partial<OpenSpec2>, { version, specVersion, acceptMimes }: any): Partial<OpenSpec2>;
@@ -0,0 +1,8 @@
1
+ import { OpenSpec3 } from "@tsed/openspec";
2
+ /**
3
+ * @ignore
4
+ * @param spec
5
+ * @param version
6
+ * @param specVersion
7
+ */
8
+ export declare function mapOpenSpec3(spec: any, { specVersion }: any): Partial<OpenSpec3>;
@@ -0,0 +1,6 @@
1
+ import { OpenSpecInfo } from "@tsed/openspec";
2
+ /**
3
+ * @ignore
4
+ * @param info
5
+ */
6
+ export declare function mapOpenSpecInfo(info: Partial<OpenSpecInfo>): OpenSpecInfo;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/schema",
3
- "version": "6.105.4",
3
+ "version": "6.107.1",
4
4
  "description": "JsonSchema module for Ts.ED Framework",
5
5
  "private": false,
6
6
  "source": "./src/index.ts",
@@ -32,8 +32,10 @@
32
32
  "tsed"
33
33
  ],
34
34
  "dependencies": {
35
- "@tsed/openspec": "6.105.4",
35
+ "@tsed/openspec": "6.107.1",
36
+ "api-spec-converter": "2.12.0",
36
37
  "camel-case": "4.1.2",
38
+ "fs-extra": "^10.0.1",
37
39
  "json-schema": "0.4.0",
38
40
  "micromatch": "4.0.4",
39
41
  "pascal-case": "3.1.2",
@@ -42,19 +44,18 @@
42
44
  },
43
45
  "devDependencies": {
44
46
  "@apidevtools/swagger-parser": "10.0.2",
45
- "@tsed/core": "6.105.4",
46
- "@tsed/openspec": "6.105.4",
47
+ "@tsed/core": "6.107.1",
48
+ "@tsed/openspec": "6.107.1",
47
49
  "@types/fs-extra": "9.0.6",
48
50
  "@types/json-schema": "7.0.7",
49
51
  "@types/micromatch": "4.0.1",
50
- "@types/statuses": "2.0.0",
51
- "fs-extra": "9.0.1"
52
+ "@types/statuses": "2.0.0"
52
53
  },
53
54
  "peerDependencies": {
54
- "@tsed/core": "^6.105.4"
55
+ "@tsed/core": "^6.107.1"
55
56
  },
56
57
  "peerDependenciesMeta": {
57
- "@tsed/code": {
58
+ "@tsed/core": {
58
59
  "optional": false
59
60
  }
60
61
  },