@tsed/schema 7.0.0-beta.4 → 7.0.0-beta.7

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 CHANGED
@@ -5,10 +5,10 @@ module.exports = {
5
5
  ...require("@tsed/jest-config")(__dirname, "schema"),
6
6
  coverageThreshold: {
7
7
  global: {
8
- statements: 99.73,
9
- branches: 91.15,
8
+ statements: 98.68,
9
+ branches: 89.91,
10
10
  functions: 99.54,
11
- lines: 99.86
11
+ lines: 98.77
12
12
  }
13
13
  }
14
14
  };
package/lib/cjs/index.js CHANGED
@@ -150,4 +150,5 @@ tslib_1.__exportStar(require("./utils/ref"), exports);
150
150
  tslib_1.__exportStar(require("./utils/serializeEnumValues"), exports);
151
151
  tslib_1.__exportStar(require("./utils/toJsonMapCollection"), exports);
152
152
  tslib_1.__exportStar(require("./utils/toJsonRegex"), exports);
153
+ tslib_1.__exportStar(require("./utils/transformToOS2"), exports);
153
154
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,iEAAuC;AACvC,mEAAyC;AACzC,sEAA4C;AAC5C,4EAAkD;AAClD,kEAAwC;AACxC,qEAA2C;AAC3C,iEAAuC;AACvC,oEAA0C;AAC1C,gEAAsC;AACtC,wEAA8C;AAC9C,oEAA0C;AAC1C,kEAAwC;AACxC,yEAA+C;AAC/C,sEAA4C;AAC5C,sFAA4D;AAC5D,gFAAsD;AACtD,4EAAkD;AAClD,iFAAuD;AACvD,4EAAkD;AAClD,iFAAuD;AACvD,+EAAqD;AACrD,mFAAyD;AACzD,oEAA0C;AAC1C,oEAA0C;AAC1C,kEAAwC;AACxC,oEAA0C;AAC1C,oEAA0C;AAC1C,wEAA8C;AAC9C,sEAA4C;AAC5C,0EAAgD;AAChD,mEAAyC;AACzC,sEAA4C;AAC5C,uEAA6C;AAC7C,+EA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DAA6B;AAC7B,+DAAqC;AACrC,2DAAiC;AACjC,kEAAwC;AACxC,qEAA2C;AAC3C,qEAA2C;AAC3C,wEAA8C;AAC9C,gEAAsC;AACtC,8DAAoC;AACpC,sEAA4C;AAC5C,sEAA4C;AAC5C,sEAA4C;AAC5C,wEAA8C;AAC9C,0DAAgC;AAChC,8DAAoC;AACpC,kEAAwC;AACxC,6DAAmC;AACnC,kEAAwC;AACxC,8DAAoC;AACpC,+DAAqC;AACrC,+DAAqC;AACrC,kEAAwC;AACxC,kEAAwC;AACxC,8DAAoC;AACpC,iEAAuC;AACvC,4DAAkC;AAClC,uEAA6C;AAC7C,sDAA4B;AAC5B,sEAA4C;AAC5C,sEAA4C;AAC5C,8DAAoC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./components/anyMapper\";\nexport * from \"./components/classMapper\";\nexport * from \"./components/genericsMapper\";\nexport * from \"./components/inheritedClassMapper\";\nexport * from \"./components/itemMapper\";\nexport * from \"./components/lazyRefMapper\";\nexport * from \"./components/mapMapper\";\nexport * from \"./components/objectMapper\";\nexport * from \"./components/ofMapper\";\nexport * from \"./components/propertiesMapper\";\nexport * from \"./components/schemaMapper\";\nexport * from \"./constants/httpMethods\";\nexport * from \"./constants/httpStatusMessages\";\nexport * from \"./decorators/class/children\";\nexport * from \"./decorators/collections/collectionContains\";\nexport * from \"./decorators/collections/collectionOf\";\nexport * from \"./decorators/collections/maxItems\";\nexport * from \"./decorators/collections/maxProperties\";\nexport * from \"./decorators/collections/minItems\";\nexport * from \"./decorators/collections/minProperties\";\nexport * from \"./decorators/collections/uniqueItems\";\nexport * from \"./decorators/common/additionalProperties\";\nexport * from \"./decorators/common/allOf\";\nexport * from \"./decorators/common/allow\";\nexport * from \"./decorators/common/any\";\nexport * from \"./decorators/common/anyOf\";\nexport * from \"./decorators/common/const\";\nexport * from \"./decorators/common/customKey\";\nexport * from \"./decorators/common/default\";\nexport * from \"./decorators/common/description\";\nexport * from \"./decorators/common/enum\";\nexport * from \"./decorators/common/example\";\nexport * from \"./decorators/common/examples\";\nexport * from \"./decorators/common/exclusiveMaximum\";\nexport * from \"./decorators/common/exclusiveMinimum\";\nexport * from \"./decorators/common/format\";\nexport * from \"./decorators/common/forwardGroups\";\nexport * from \"./decorators/common/groups\";\nexport * from \"./decorators/common/hidden\";\nexport * from \"./decorators/common/ignore\";\nexport * from \"./decorators/common/integer\";\nexport * from \"./decorators/common/jsonEntityFn\";\nexport * from \"./decorators/common/maxLength\";\nexport * from \"./decorators/common/maximum\";\nexport * from \"./decorators/common/minLength\";\nexport * from \"./decorators/common/minimum\";\nexport * from \"./decorators/common/multipleOf\";\nexport * from \"./decorators/common/name\";\nexport * from \"./decorators/common/nullable\";\nexport * from \"./decorators/common/oneOf\";\nexport * from \"./decorators/common/optional\";\nexport * from \"./decorators/common/pattern\";\nexport * from \"./decorators/common/property\";\nexport * from \"./decorators/common/readOnly\";\nexport * from \"./decorators/common/recordOf\";\nexport * from \"./decorators/common/required\";\nexport * from \"./decorators/common/requiredGroups\";\nexport * from \"./decorators/common/schema\";\nexport * from \"./decorators/common/title\";\nexport * from \"./decorators/common/writeOnly\";\nexport * from \"./decorators/config/jsonEntityComponent\";\nexport * from \"./decorators/generics/genericOf\";\nexport * from \"./decorators/generics/generics\";\nexport * from \"./decorators/operations/acceptMime\";\nexport * from \"./decorators/operations/consumes\";\nexport * from \"./decorators/operations/contentType\";\nexport * from \"./decorators/operations/deprecated\";\nexport * from \"./decorators/operations/header\";\nexport * from \"./decorators/operations/in\";\nexport * from \"./decorators/operations/inFile\";\nexport * from \"./decorators/operations/location\";\nexport * from \"./decorators/operations/operationId\";\nexport * from \"./decorators/operations/operationPath\";\nexport * from \"./decorators/operations/partial\";\nexport * from \"./decorators/operations/path\";\nexport * from \"./decorators/operations/produces\";\nexport * from \"./decorators/operations/redirect\";\nexport * from \"./decorators/operations/returns\";\nexport * from \"./decorators/operations/route\";\nexport * from \"./decorators/operations/security\";\nexport * from \"./decorators/operations/status\";\nexport * from \"./decorators/operations/summary\";\nexport * from \"./decorators/operations/tags\";\nexport * from \"./decorators/operations/view\";\nexport * from \"./domain/DecoratorContext\";\nexport * from \"./domain/JsonAliasMap\";\nexport * from \"./domain/JsonClassStore\";\nexport * from \"./domain/JsonEntityStore\";\nexport * from \"./domain/JsonFormatTypes\";\nexport * from \"./domain/JsonLazyRef\";\nexport * from \"./domain/JsonMap\";\nexport * from \"./domain/JsonMethodStore\";\nexport * from \"./domain/JsonOperation\";\nexport * from \"./domain/JsonOperationPathsMap\";\nexport * from \"./domain/JsonOperationRoute\";\nexport * from \"./domain/JsonParameter\";\nexport * from \"./domain/JsonParameterStore\";\nexport * from \"./domain/JsonParameterTypes\";\nexport * from \"./domain/JsonPropertyStore\";\nexport * from \"./domain/JsonRequestBody\";\nexport * from \"./domain/JsonResponse\";\nexport * from \"./domain/JsonSchema\";\nexport * from \"./domain/SpecTypes\";\nexport * from \"./hooks/alterIgnore\";\nexport * from \"./hooks/alterOneOf\";\nexport * from \"./hooks/alterRequiredGroups\";\nexport * from \"./interfaces/IgnoreCallback\";\nexport * from \"./interfaces/JsonHookContext\";\nexport * from \"./interfaces/JsonOpenSpec\";\nexport * from \"./interfaces/JsonSchemaOptions\";\nexport * from \"./registries/JsonSchemaMapperContainer\";\nexport * from \"./utils/buildPath\";\nexport * from \"./utils/concatParameters\";\nexport * from \"./utils/concatPath\";\nexport * from \"./utils/defineStatusModel\";\nexport * from \"./utils/from\";\nexport * from \"./utils/generateSpec\";\nexport * from \"./utils/generics\";\nexport * from \"./utils/getComputedType\";\nexport * from \"./utils/getInheritedStores\";\nexport * from \"./utils/getJsonEntityStore\";\nexport * from \"./utils/getJsonPathParameters\";\nexport * from \"./utils/getJsonSchema\";\nexport * from \"./utils/getJsonType\";\nexport * from \"./utils/getOperationsRoutes\";\nexport * from \"./utils/getOperationsStores\";\nexport * from \"./utils/getPropertiesStores\";\nexport * from \"./utils/getRequiredProperties\";\nexport * from \"./utils/getSpec\";\nexport * from \"./utils/getSpecType\";\nexport * from \"./utils/isSuccessStatus\";\nexport * from \"./utils/mapHeaders\";\nexport * from \"./utils/mapNullableType\";\nexport * from \"./utils/mapOpenSpec\";\nexport * from \"./utils/mapOpenSpec2\";\nexport * from \"./utils/mapOpenSpec3\";\nexport * from \"./utils/mapOpenSpecInfo\";\nexport * from \"./utils/mapRouteOptions\";\nexport * from \"./utils/matchGroups\";\nexport * from \"./utils/mergeOperation\";\nexport * from \"./utils/mergeSpec\";\nexport * from \"./utils/operationIdFormatter\";\nexport * from \"./utils/ref\";\nexport * from \"./utils/serializeEnumValues\";\nexport * from \"./utils/toJsonMapCollection\";\nexport * from \"./utils/toJsonRegex\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,iEAAuC;AACvC,mEAAyC;AACzC,sEAA4C;AAC5C,4EAAkD;AAClD,kEAAwC;AACxC,qEAA2C;AAC3C,iEAAuC;AACvC,oEAA0C;AAC1C,gEAAsC;AACtC,wEAA8C;AAC9C,oEAA0C;AAC1C,kEAAwC;AACxC,yEAA+C;AAC/C,sEAA4C;AAC5C,sFAA4D;AAC5D,gFAAsD;AACtD,4EAAkD;AAClD,iFAAuD;AACvD,4EAAkD;AAClD,iFAAuD;AACvD,+EAAqD;AACrD,mFAAyD;AACzD,oEAA0C;AAC1C,oEAA0C;AAC1C,kEAAwC;AACxC,oEAA0C;AAC1C,oEAA0C;AAC1C,wEAA8C;AAC9C,sEAA4C;AAC5C,0EAAgD;AAChD,mEAAyC;AACzC,sEAA4C;AAC5C,uEAA6C;AAC7C,+EAAqD;AACrD,+EAAqD;AACrD,qEAA2C;AAC3C,4EAAkD;AAClD,qEAA2C;AAC3C,qEAA2C;AAC3C,qEAA2C;AAC3C,sEAA4C;AAC5C,2EAAiD;AACjD,wEAA8C;AAC9C,sEAA4C;AAC5C,wEAA8C;AAC9C,sEAA4C;AAC5C,yEAA+C;AA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AChC,8DAAoC;AACpC,kEAAwC;AACxC,6DAAmC;AACnC,kEAAwC;AACxC,8DAAoC;AACpC,+DAAqC;AACrC,+DAAqC;AACrC,kEAAwC;AACxC,kEAAwC;AACxC,8DAAoC;AACpC,iEAAuC;AACvC,4DAAkC;AAClC,uEAA6C;AAC7C,sDAA4B;AAC5B,sEAA4C;AAC5C,sEAA4C;AAC5C,8DAAoC;AACpC,iEAAuC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./components/anyMapper\";\nexport * from \"./components/classMapper\";\nexport * from \"./components/genericsMapper\";\nexport * from \"./components/inheritedClassMapper\";\nexport * from \"./components/itemMapper\";\nexport * from \"./components/lazyRefMapper\";\nexport * from \"./components/mapMapper\";\nexport * from \"./components/objectMapper\";\nexport * from \"./components/ofMapper\";\nexport * from \"./components/propertiesMapper\";\nexport * from \"./components/schemaMapper\";\nexport * from \"./constants/httpMethods\";\nexport * from \"./constants/httpStatusMessages\";\nexport * from \"./decorators/class/children\";\nexport * from \"./decorators/collections/collectionContains\";\nexport * from \"./decorators/collections/collectionOf\";\nexport * from \"./decorators/collections/maxItems\";\nexport * from \"./decorators/collections/maxProperties\";\nexport * from \"./decorators/collections/minItems\";\nexport * from \"./decorators/collections/minProperties\";\nexport * from \"./decorators/collections/uniqueItems\";\nexport * from \"./decorators/common/additionalProperties\";\nexport * from \"./decorators/common/allOf\";\nexport * from \"./decorators/common/allow\";\nexport * from \"./decorators/common/any\";\nexport * from \"./decorators/common/anyOf\";\nexport * from \"./decorators/common/const\";\nexport * from \"./decorators/common/customKey\";\nexport * from \"./decorators/common/default\";\nexport * from \"./decorators/common/description\";\nexport * from \"./decorators/common/enum\";\nexport * from \"./decorators/common/example\";\nexport * from \"./decorators/common/examples\";\nexport * from \"./decorators/common/exclusiveMaximum\";\nexport * from \"./decorators/common/exclusiveMinimum\";\nexport * from \"./decorators/common/format\";\nexport * from \"./decorators/common/forwardGroups\";\nexport * from \"./decorators/common/groups\";\nexport * from \"./decorators/common/hidden\";\nexport * from \"./decorators/common/ignore\";\nexport * from \"./decorators/common/integer\";\nexport * from \"./decorators/common/jsonEntityFn\";\nexport * from \"./decorators/common/maxLength\";\nexport * from \"./decorators/common/maximum\";\nexport * from \"./decorators/common/minLength\";\nexport * from \"./decorators/common/minimum\";\nexport * from \"./decorators/common/multipleOf\";\nexport * from \"./decorators/common/name\";\nexport * from \"./decorators/common/nullable\";\nexport * from \"./decorators/common/oneOf\";\nexport * from \"./decorators/common/optional\";\nexport * from \"./decorators/common/pattern\";\nexport * from \"./decorators/common/property\";\nexport * from \"./decorators/common/readOnly\";\nexport * from \"./decorators/common/recordOf\";\nexport * from \"./decorators/common/required\";\nexport * from \"./decorators/common/requiredGroups\";\nexport * from \"./decorators/common/schema\";\nexport * from \"./decorators/common/title\";\nexport * from \"./decorators/common/writeOnly\";\nexport * from \"./decorators/config/jsonEntityComponent\";\nexport * from \"./decorators/generics/genericOf\";\nexport * from \"./decorators/generics/generics\";\nexport * from \"./decorators/operations/acceptMime\";\nexport * from \"./decorators/operations/consumes\";\nexport * from \"./decorators/operations/contentType\";\nexport * from \"./decorators/operations/deprecated\";\nexport * from \"./decorators/operations/header\";\nexport * from \"./decorators/operations/in\";\nexport * from \"./decorators/operations/inFile\";\nexport * from \"./decorators/operations/location\";\nexport * from \"./decorators/operations/operationId\";\nexport * from \"./decorators/operations/operationPath\";\nexport * from \"./decorators/operations/partial\";\nexport * from \"./decorators/operations/path\";\nexport * from \"./decorators/operations/produces\";\nexport * from \"./decorators/operations/redirect\";\nexport * from \"./decorators/operations/returns\";\nexport * from \"./decorators/operations/route\";\nexport * from \"./decorators/operations/security\";\nexport * from \"./decorators/operations/status\";\nexport * from \"./decorators/operations/summary\";\nexport * from \"./decorators/operations/tags\";\nexport * from \"./decorators/operations/view\";\nexport * from \"./domain/DecoratorContext\";\nexport * from \"./domain/JsonAliasMap\";\nexport * from \"./domain/JsonClassStore\";\nexport * from \"./domain/JsonEntityStore\";\nexport * from \"./domain/JsonFormatTypes\";\nexport * from \"./domain/JsonLazyRef\";\nexport * from \"./domain/JsonMap\";\nexport * from \"./domain/JsonMethodStore\";\nexport * from \"./domain/JsonOperation\";\nexport * from \"./domain/JsonOperationPathsMap\";\nexport * from \"./domain/JsonOperationRoute\";\nexport * from \"./domain/JsonParameter\";\nexport * from \"./domain/JsonParameterStore\";\nexport * from \"./domain/JsonParameterTypes\";\nexport * from \"./domain/JsonPropertyStore\";\nexport * from \"./domain/JsonRequestBody\";\nexport * from \"./domain/JsonResponse\";\nexport * from \"./domain/JsonSchema\";\nexport * from \"./domain/SpecTypes\";\nexport * from \"./hooks/alterIgnore\";\nexport * from \"./hooks/alterOneOf\";\nexport * from \"./hooks/alterRequiredGroups\";\nexport * from \"./interfaces/IgnoreCallback\";\nexport * from \"./interfaces/JsonHookContext\";\nexport * from \"./interfaces/JsonOpenSpec\";\nexport * from \"./interfaces/JsonSchemaOptions\";\nexport * from \"./registries/JsonSchemaMapperContainer\";\nexport * from \"./utils/buildPath\";\nexport * from \"./utils/concatParameters\";\nexport * from \"./utils/concatPath\";\nexport * from \"./utils/defineStatusModel\";\nexport * from \"./utils/from\";\nexport * from \"./utils/generateSpec\";\nexport * from \"./utils/generics\";\nexport * from \"./utils/getComputedType\";\nexport * from \"./utils/getInheritedStores\";\nexport * from \"./utils/getJsonEntityStore\";\nexport * from \"./utils/getJsonPathParameters\";\nexport * from \"./utils/getJsonSchema\";\nexport * from \"./utils/getJsonType\";\nexport * from \"./utils/getOperationsRoutes\";\nexport * from \"./utils/getOperationsStores\";\nexport * from \"./utils/getPropertiesStores\";\nexport * from \"./utils/getRequiredProperties\";\nexport * from \"./utils/getSpec\";\nexport * from \"./utils/getSpecType\";\nexport * from \"./utils/isSuccessStatus\";\nexport * from \"./utils/mapHeaders\";\nexport * from \"./utils/mapNullableType\";\nexport * from \"./utils/mapOpenSpec\";\nexport * from \"./utils/mapOpenSpec2\";\nexport * from \"./utils/mapOpenSpec3\";\nexport * from \"./utils/mapOpenSpecInfo\";\nexport * from \"./utils/mapRouteOptions\";\nexport * from \"./utils/matchGroups\";\nexport * from \"./utils/mergeOperation\";\nexport * from \"./utils/mergeSpec\";\nexport * from \"./utils/operationIdFormatter\";\nexport * from \"./utils/ref\";\nexport * from \"./utils/serializeEnumValues\";\nexport * from \"./utils/toJsonMapCollection\";\nexport * from \"./utils/toJsonRegex\";\nexport * from \"./utils/transformToOS2\";\n"]}
@@ -9,6 +9,7 @@ const getSpec_1 = require("./getSpec");
9
9
  const getSpecType_1 = require("./getSpecType");
10
10
  const mergeSpec_1 = require("./mergeSpec");
11
11
  const SpecTypes_1 = require("../domain/SpecTypes");
12
+ const transformToOS2_1 = require("./transformToOS2");
12
13
  async function readSpec(path) {
13
14
  if (fs_extra_1.default.existsSync(path)) {
14
15
  try {
@@ -35,21 +36,11 @@ async function generateSpec({ tokens, ...options }) {
35
36
  });
36
37
  const specType = (0, getSpecType_1.getSpecTypeFromSpec)(defaultSpec);
37
38
  let controllersSpec = (0, getSpec_1.getSpec)(tokens, options);
39
+ const spec = (0, mergeSpec_1.mergeSpec)(defaultSpec, controllersSpec);
38
40
  if (specType === SpecTypes_1.SpecTypes.SWAGGER) {
39
- // @ts-ignore
40
- const { convert } = await Promise.resolve().then(() => tslib_1.__importStar(require("api-spec-converter")));
41
- const { spec } = await convert({
42
- from: "openapi_3",
43
- to: "swagger_2",
44
- source: {
45
- ...controllersSpec,
46
- openapi: "3.0.1"
47
- }
48
- });
49
- controllersSpec = spec;
50
- delete controllersSpec["x-components"];
41
+ return (0, transformToOS2_1.transformToOS2)(spec);
51
42
  }
52
- return (0, mergeSpec_1.mergeSpec)(defaultSpec, controllersSpec);
43
+ return spec;
53
44
  }
54
45
  exports.generateSpec = generateSpec;
55
46
  //# sourceMappingURL=generateSpec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"generateSpec.js","sourceRoot":"","sources":["../../../src/utils/generateSpec.ts"],"names":[],"mappings":";;;;AAAA,gEAA0B;A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E;gBACN,GAAG,eAAe;gBAClB,OAAO,EAAE,OAAO;aACjB;SACF,CAAC,CAAC;QACH,eAAe,GAAG,IAAI,CAAC;QACvB,OAAQ,eAAuB,CAAC,cAAc,CAAC,CAAC;KACjD;IAED,OAAO,IAAA,qBAAS,EAAC,WAAW,EAAE,eAAe,CAAQ,CAAC;AACxD,CAAC;AA/BD,oCA+BC","sourcesContent":["import fs from \"fs-extra\";\nimport {getValue} from \"@tsed/core\";\nimport {OpenSpec2, OpenSpec3} from \"@tsed/openspec\";\nimport {mapOpenSpec} from \"./mapOpenSpec\";\nimport {getSpec, JsonTokenOptions, SpecSerializerOptions} from \"./getSpec\";\nimport {getSpecTypeFromSpec} from \"./getSpecType\";\nimport {mergeSpec} from \"./mergeSpec\";\nimport {SpecTypes} from \"../domain/SpecTypes\";\n\nexport interface GenerateSpecOptions extends Omit<SpecSerializerOptions, \"specType\"> {\n tokens: JsonTokenOptions;\n version?: string;\n acceptMimes?: string;\n specPath?: string;\n specVersion?: string;\n spec?: any;\n}\n\nasync function readSpec(path: string) {\n if (fs.existsSync(path)) {\n try {\n return await fs.readJSON(path, {encoding: \"utf8\"});\n } catch (e) {}\n }\n\n /* istanbul ignore next */\n return {};\n}\n\n/**\n * Generate OpenAPI spec from multiple sources (models, files, conf)\n * @param tokens\n * @param options\n */\nexport async function generateSpec({tokens, ...options}: GenerateSpecOptions): Promise<OpenSpec2 | OpenSpec3> {\n const {version = \"1.0.0\", acceptMimes, specPath, specVersion} = options;\n const fileSpec: Partial<OpenSpec2 | OpenSpec3> = specPath ? await readSpec(specPath) : {};\n\n const defaultSpec = mapOpenSpec(getValue(options, \"spec\", {}), {\n fileSpec,\n version,\n specVersion,\n acceptMimes\n });\n\n const specType = getSpecTypeFromSpec(defaultSpec);\n\n let controllersSpec = getSpec(tokens, options);\n\n if (specType === SpecTypes.SWAGGER) {\n // @ts-ignore\n const {convert} = await import(\"api-spec-converter\");\n const {spec} = await convert({\n from: \"openapi_3\",\n to: \"swagger_2\",\n source: {\n ...controllersSpec,\n openapi: \"3.0.1\"\n }\n });\n controllersSpec = spec;\n delete (controllersSpec as any)[\"x-components\"];\n }\n\n return mergeSpec(defaultSpec, controllersSpec) as any;\n}\n"]}
1
+ {"version":3,"file":"generateSpec.js","sourceRoot":"","sources":["../../../src/utils/generateSpec.ts"],"names":[],"mappings":";;;;AAAA,gEAA0B;AAC1B,qCAAoC;AAEpC,+CAA0C;AAC1C,uCAA2E;AAC3E,+CAAkD;AAClD,2CAAsC;AACtC,mDAA8C;AAC9C,qDAAgD;AAWhD,KAAK,UAAU,QAAQ,CAAC,IAAY;IAClC,IAAI,kBAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QACvB,IAAI;YACF,OAAO,MAAM,kBAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAC,CAAC;SACpD;QAAC,OAAO,CAAC,EAAE,GAAE;KACf;IAED,0BAA0B;IAC1B,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;;;GAIG;AACI,KAAK,UAAU,YAAY,CAAC,EAAC,MAAM,EAAE,GAAG,OAAO,EAAsB;IAC1E,MAAM,EAAC,OAAO,GAAG,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAC,GAAG,OAAO,CAAC;IACxE,MAAM,QAAQ,GAAmC,QAAQ,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAE1F,MAAM,WAAW,GAAG,IAAA,yBAAW,EAAC,IAAA,eAAQ,EAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE;QAC7D,QAAQ;QACR,OAAO;QACP,WAAW;QACX,WAAW;KACZ,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,IAAA,iCAAmB,EAAC,WAAW,CAAC,CAAC;IAElD,IAAI,eAAe,GAAQ,IAAA,iBAAO,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpD,MAAM,IAAI,GAAQ,IAAA,qBAAS,EAAC,WAAW,EAAE,eAAe,CAAC,CAAC;IAE1D,IAAI,QAAQ,KAAK,qBAAS,CAAC,OAAO,EAAE;QAClC,OAAO,IAAA,+BAAc,EAAC,IAAI,CAAQ,CAAC;KACpC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AArBD,oCAqBC","sourcesContent":["import fs from \"fs-extra\";\nimport {getValue} from \"@tsed/core\";\nimport {OpenSpec2, OpenSpec3} from \"@tsed/openspec\";\nimport {mapOpenSpec} from \"./mapOpenSpec\";\nimport {getSpec, JsonTokenOptions, SpecSerializerOptions} from \"./getSpec\";\nimport {getSpecTypeFromSpec} from \"./getSpecType\";\nimport {mergeSpec} from \"./mergeSpec\";\nimport {SpecTypes} from \"../domain/SpecTypes\";\nimport {transformToOS2} from \"./transformToOS2\";\n\nexport interface GenerateSpecOptions extends Omit<SpecSerializerOptions, \"specType\"> {\n tokens: JsonTokenOptions;\n version?: string;\n acceptMimes?: string;\n specPath?: string;\n specVersion?: string;\n spec?: any;\n}\n\nasync function readSpec(path: string) {\n if (fs.existsSync(path)) {\n try {\n return await fs.readJSON(path, {encoding: \"utf8\"});\n } catch (e) {}\n }\n\n /* istanbul ignore next */\n return {};\n}\n\n/**\n * Generate OpenAPI spec from multiple sources (models, files, conf)\n * @param tokens\n * @param options\n */\nexport async function generateSpec({tokens, ...options}: GenerateSpecOptions): Promise<OpenSpec2 | OpenSpec3> {\n const {version = \"1.0.0\", acceptMimes, specPath, specVersion} = options;\n const fileSpec: Partial<OpenSpec2 | OpenSpec3> = specPath ? await readSpec(specPath) : {};\n\n const defaultSpec = mapOpenSpec(getValue(options, \"spec\", {}), {\n fileSpec,\n version,\n specVersion,\n acceptMimes\n });\n\n const specType = getSpecTypeFromSpec(defaultSpec);\n\n let controllersSpec: any = getSpec(tokens, options);\n const spec: any = mergeSpec(defaultSpec, controllersSpec);\n\n if (specType === SpecTypes.SWAGGER) {\n return transformToOS2(spec) as any;\n }\n\n return spec;\n}\n"]}
@@ -0,0 +1,510 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformToOS2 = exports.Converter = exports.transformInformation = exports.transformSecurity = void 0;
4
+ const core_1 = require("@tsed/core");
5
+ const HTTP_METHODS = ["get", "put", "post", "delete", "options", "head", "patch", "trace"];
6
+ const SCHEMA_PROPERTIES = [
7
+ "format",
8
+ "minimum",
9
+ "maximum",
10
+ "exclusiveMinimum",
11
+ "exclusiveMaximum",
12
+ "minLength",
13
+ "maxLength",
14
+ "multipleOf",
15
+ "minItems",
16
+ "maxItems",
17
+ "uniqueItems",
18
+ "minProperties",
19
+ "maxProperties",
20
+ "additionalProperties",
21
+ "pattern",
22
+ "enum",
23
+ "default"
24
+ ];
25
+ const ARRAY_PROPERTIES = ["type", "items"];
26
+ const APPLICATION_JSON_REGEX = /^(application\/json|[^;\/ \t]+\/[^;\/ \t]+[+]json)[ \t]*(;.*)?$/;
27
+ const SUPPORTED_MIME_TYPES = {
28
+ APPLICATION_X_WWW_URLENCODED: "application/x-www-form-urlencoded",
29
+ MULTIPART_FORM_DATA: "multipart/form-data"
30
+ };
31
+ function fixRef(ref) {
32
+ return ref.replace("#/components/schemas/", "#/definitions/").replace("#/components/", "#/x-components/");
33
+ }
34
+ function fixRefs(obj) {
35
+ if (Array.isArray(obj)) {
36
+ obj.forEach(fixRefs);
37
+ }
38
+ else if (typeof obj === "object") {
39
+ for (let key in obj) {
40
+ if (key === "$ref") {
41
+ obj.$ref = fixRef(obj.$ref);
42
+ }
43
+ else {
44
+ fixRefs(obj[key]);
45
+ }
46
+ }
47
+ }
48
+ }
49
+ function isJsonMimeType(type) {
50
+ return new RegExp(APPLICATION_JSON_REGEX, "i").test(type);
51
+ }
52
+ function getSupportedMimeTypes(content) {
53
+ const MIME_VALUES = Object.keys(SUPPORTED_MIME_TYPES).map((key) => {
54
+ return SUPPORTED_MIME_TYPES[key];
55
+ });
56
+ return Object.keys(content).filter((key) => {
57
+ return MIME_VALUES.indexOf(key) > -1 || isJsonMimeType(key);
58
+ });
59
+ }
60
+ function transformSecurity(securitySchemes) {
61
+ function map(security) {
62
+ const { scheme, type, name, bearerFormat, flows, ...props } = security;
63
+ switch (type) {
64
+ case "http":
65
+ if (scheme === "basic") {
66
+ return {
67
+ ...props,
68
+ type: scheme
69
+ };
70
+ }
71
+ if (scheme === "bearer") {
72
+ return {
73
+ ...props,
74
+ type: "apiKey",
75
+ name: "Authorization",
76
+ in: "header"
77
+ };
78
+ }
79
+ break;
80
+ case "oauth2":
81
+ const flowName = Object.keys(flows)[0];
82
+ const flow = flows[flowName];
83
+ let flowType = flowName;
84
+ if (flowType === "clientCredentials") {
85
+ flowType = "application";
86
+ }
87
+ else if (flowType === "authorizationCode") {
88
+ flowType = "accessCode";
89
+ }
90
+ return {
91
+ type,
92
+ flow: flowType,
93
+ authorizationUrl: flow.authorizationUrl,
94
+ tokenUrl: flow.tokenUrl,
95
+ scopes: flow.scopes
96
+ };
97
+ }
98
+ }
99
+ return Object.entries(securitySchemes).reduce((securityDefinitions, [key, security]) => {
100
+ return {
101
+ ...securityDefinitions,
102
+ [key]: map(security)
103
+ };
104
+ }, {});
105
+ }
106
+ exports.transformSecurity = transformSecurity;
107
+ function transformInformation(server) {
108
+ let serverUrl = server.url;
109
+ const variables = server["variables"] || {};
110
+ for (const variable in variables) {
111
+ const variableObject = variables[variable] || {};
112
+ if (variableObject["default"]) {
113
+ const re = RegExp(`{${variable}}`, "g");
114
+ serverUrl = serverUrl.replace(re, variableObject["default"]);
115
+ }
116
+ }
117
+ const url = new URL(serverUrl);
118
+ return {
119
+ host: url.host ? url.host : undefined,
120
+ basePath: url.pathname,
121
+ schemes: url.protocol !== null ? [url.protocol.substring(0, url.protocol.length - 1)] : undefined
122
+ };
123
+ }
124
+ exports.transformInformation = transformInformation;
125
+ class Converter {
126
+ constructor(spec) {
127
+ this.spec = JSON.parse(JSON.stringify(spec));
128
+ }
129
+ convertInfos() {
130
+ const server = this.spec.servers && this.spec.servers[0];
131
+ if (server) {
132
+ return transformInformation(server);
133
+ }
134
+ return {};
135
+ }
136
+ resolveReference(base, obj, shouldClone) {
137
+ if (!obj || !obj.$ref) {
138
+ return obj;
139
+ }
140
+ const ref = obj.$ref;
141
+ if (ref.startsWith("#")) {
142
+ const keys = ref.split("/").map((k) => k.replace(/~1/g, "/").replace(/~0/g, "~"));
143
+ keys.shift();
144
+ let cur = base;
145
+ keys.forEach((k) => {
146
+ cur = cur[k];
147
+ });
148
+ return shouldClone ? JSON.parse(JSON.stringify(cur)) : cur;
149
+ }
150
+ }
151
+ convert() {
152
+ const spec = {
153
+ swagger: "2.0",
154
+ ...this.convertInfos(),
155
+ paths: this.spec.paths ? this.convertOperations(this.spec.paths, this.spec) : undefined
156
+ };
157
+ if (this.spec.components) {
158
+ this.convertSchemas();
159
+ this.convertSecurityDefinitions();
160
+ this.spec["x-components"] = this.spec.components;
161
+ delete this.spec.components;
162
+ fixRefs(this.spec);
163
+ }
164
+ delete this.spec.servers;
165
+ delete this.spec.openapi;
166
+ delete this.spec["x-components"];
167
+ return (0, core_1.cleanObject)({
168
+ ...spec,
169
+ ...this.spec
170
+ });
171
+ }
172
+ convertOperations(paths, spec) {
173
+ return Object.entries(paths).reduce((paths, [path, operation]) => {
174
+ const pathObject = (paths[path] = this.resolveReference({ ...spec, paths }, operation, true));
175
+ this.convertParameters(pathObject); // converts common parameters
176
+ Object.keys(pathObject).forEach((method) => {
177
+ if (HTTP_METHODS.indexOf(method) >= 0) {
178
+ const operation = (pathObject[method] = this.resolveReference({ ...spec, paths }, pathObject[method], true));
179
+ this.convertOperationParameters(operation);
180
+ this.convertResponses(operation);
181
+ }
182
+ });
183
+ return paths;
184
+ }, paths);
185
+ }
186
+ convertOperationParameters(operation) {
187
+ let content, contentKey, mediaRanges, mediaTypes;
188
+ operation.parameters = operation.parameters || [];
189
+ if (operation.requestBody) {
190
+ let param = this.resolveReference(this.spec, operation.requestBody, true);
191
+ // fixing external $ref in body
192
+ if (operation.requestBody.content) {
193
+ const type = getSupportedMimeTypes(operation.requestBody.content)[0];
194
+ const structuredObj = { content: {} };
195
+ const data = operation.requestBody.content[type];
196
+ if (data && data.schema && data.schema.$ref && !data.schema.$ref.startsWith("#")) {
197
+ param = this.resolveReference(this.spec, data.schema, true);
198
+ structuredObj["content"][`${type}`] = { schema: param };
199
+ param = structuredObj;
200
+ }
201
+ }
202
+ param.name = "body";
203
+ content = param.content;
204
+ if (content && Object.keys(content).length) {
205
+ mediaRanges = Object.keys(content).filter((mediaRange) => mediaRange.indexOf("/") > 0);
206
+ mediaTypes = mediaRanges.filter((range) => range.indexOf("*") < 0);
207
+ contentKey = getSupportedMimeTypes(content)[0];
208
+ delete param.content;
209
+ if ([SUPPORTED_MIME_TYPES.APPLICATION_X_WWW_URLENCODED, SUPPORTED_MIME_TYPES.MULTIPART_FORM_DATA].includes(contentKey)) {
210
+ operation.consumes = mediaTypes;
211
+ param.in = "formData";
212
+ param.schema = content[contentKey].schema;
213
+ param.schema = this.resolveReference(this.spec, param.schema, true);
214
+ if (param.schema.type === "object" && param.schema.properties) {
215
+ const required = param.schema.required || [];
216
+ Object.keys(param.schema.properties).forEach((name) => {
217
+ var _a;
218
+ const schema = param.schema.properties[name];
219
+ // readOnly properties should not be sent in requests
220
+ if (!schema.readOnly) {
221
+ const formDataParam = {
222
+ name,
223
+ in: "formData",
224
+ schema
225
+ };
226
+ if (required.indexOf(name) >= 0) {
227
+ formDataParam.required = true;
228
+ }
229
+ (_a = operation.parameters) === null || _a === void 0 ? void 0 : _a.push(formDataParam);
230
+ }
231
+ });
232
+ }
233
+ else {
234
+ operation.parameters.push(param);
235
+ }
236
+ }
237
+ else if (contentKey) {
238
+ operation.consumes = mediaTypes;
239
+ param.in = "body";
240
+ param.schema = content[contentKey].schema;
241
+ operation.parameters.push(param);
242
+ }
243
+ else if (mediaRanges) {
244
+ operation.consumes = mediaTypes || ["application/octet-stream"];
245
+ param.in = "body";
246
+ param.name = param.name || "file";
247
+ delete param.type;
248
+ param.schema = content[mediaRanges[0]].schema || {
249
+ type: "string",
250
+ format: "binary"
251
+ };
252
+ operation.parameters.push(param);
253
+ }
254
+ if (param.schema) {
255
+ this.convertSchema(param.schema, "request");
256
+ }
257
+ }
258
+ delete operation.requestBody;
259
+ }
260
+ this.convertParameters(operation);
261
+ }
262
+ convertParameters(obj) {
263
+ if (obj.parameters === undefined) {
264
+ return;
265
+ }
266
+ obj.parameters = obj.parameters || [];
267
+ (obj.parameters || []).forEach((param, i) => {
268
+ param = obj.parameters[i] = this.resolveReference(this.spec, param, false);
269
+ if (param.in !== "body") {
270
+ this.copySchemaProperties(param, SCHEMA_PROPERTIES);
271
+ this.copySchemaProperties(param, ARRAY_PROPERTIES);
272
+ this.copySchemaXProperties(param);
273
+ if (!param.description) {
274
+ const schema = this.resolveReference(this.spec, param.schema, false);
275
+ if (!!schema && schema.description) {
276
+ param.description = schema.description;
277
+ }
278
+ }
279
+ if (param.example !== undefined) {
280
+ param["x-example"] = param.example;
281
+ }
282
+ delete param.schema;
283
+ delete param.allowReserved;
284
+ delete param.example;
285
+ }
286
+ if (param.type === "array") {
287
+ let style = param.style || (param.in === "query" || param.in === "cookie" ? "form" : "simple");
288
+ switch (style) {
289
+ case "matrix":
290
+ param.collectionFormat = param.explode ? undefined : "csv";
291
+ break;
292
+ case "label":
293
+ param.collectionFormat = undefined;
294
+ break;
295
+ case "simple":
296
+ param.collectionFormat = "csv";
297
+ break;
298
+ case "spaceDelimited":
299
+ param.collectionFormat = "ssv";
300
+ break;
301
+ case "pipeDelimited":
302
+ param.collectionFormat = "pipes";
303
+ break;
304
+ case "deepOpbject":
305
+ param.collectionFormat = "multi";
306
+ break;
307
+ case "form":
308
+ param.collectionFormat = param.explode === false ? "csv" : "multi";
309
+ break;
310
+ }
311
+ }
312
+ delete param.style;
313
+ delete param.explode;
314
+ });
315
+ }
316
+ copySchemaProperties(obj, props) {
317
+ let schema = this.resolveReference(this.spec, obj.schema, true);
318
+ if (!schema) {
319
+ return;
320
+ }
321
+ props.forEach((prop) => {
322
+ const value = schema[prop];
323
+ if (prop === "additionalProperties" && typeof value === "boolean") {
324
+ return;
325
+ }
326
+ if (value !== undefined) {
327
+ obj[prop] = value;
328
+ }
329
+ });
330
+ }
331
+ copySchemaXProperties(obj) {
332
+ let schema = this.resolveReference(this.spec, obj.schema, true);
333
+ if (!schema) {
334
+ return;
335
+ }
336
+ Object.keys(schema).forEach((propName) => {
337
+ if (Reflect.hasOwnProperty.call(schema, propName) && !Reflect.hasOwnProperty.call(obj, propName) && propName.startsWith("x-")) {
338
+ obj[propName] = schema[propName];
339
+ }
340
+ });
341
+ }
342
+ convertResponses(operation) {
343
+ // var anySchema, code, content, jsonSchema, mediaRange, mediaType, response, resolved, headers
344
+ Object.keys(operation.responses || {}).forEach((code) => {
345
+ const response = (operation.responses[code] = this.resolveReference(this.spec, operation.responses[code], true));
346
+ if (response.content) {
347
+ let anySchema = null;
348
+ let jsonSchema = null;
349
+ Object.keys(response.content).forEach((mediaRange) => {
350
+ // produces and examples only allow media types, not ranges
351
+ // use application/octet-stream as a catch-all type
352
+ const mediaType = mediaRange.indexOf("*") < 0 ? mediaRange : "application/octet-stream";
353
+ if (!operation.produces) {
354
+ operation.produces = [mediaType];
355
+ }
356
+ else if (operation.produces.indexOf(mediaType) < 0) {
357
+ operation.produces.push(mediaType);
358
+ }
359
+ const content = response.content[mediaRange];
360
+ anySchema = anySchema || content.schema;
361
+ if (!jsonSchema && isJsonMimeType(mediaType)) {
362
+ jsonSchema = content.schema;
363
+ }
364
+ if (content.example) {
365
+ response.examples = response.examples || {};
366
+ response.examples[mediaType] = content.example;
367
+ }
368
+ });
369
+ if (anySchema) {
370
+ response.schema = jsonSchema || anySchema;
371
+ const resolved = this.resolveReference(this.spec, response.schema, true);
372
+ if (resolved && response.schema.$ref && !response.schema.$ref.startsWith("#")) {
373
+ response.schema = resolved;
374
+ }
375
+ this.convertSchema(response.schema, "response");
376
+ }
377
+ }
378
+ Object.keys(response.headers || {}).forEach((header) => {
379
+ // Always resolve headers when converting to v2.
380
+ const resolved = this.resolveReference(this.spec, response.headers[header], true);
381
+ // Headers should be converted like parameters.
382
+ if (resolved.schema) {
383
+ resolved.type = resolved.schema.type;
384
+ resolved.format = resolved.schema.format;
385
+ delete resolved.schema;
386
+ }
387
+ response.headers[header] = resolved;
388
+ });
389
+ delete response.content;
390
+ });
391
+ }
392
+ convertSchema(def, operationDirection) {
393
+ if (def.oneOf) {
394
+ delete def.oneOf;
395
+ if (def.discriminator) {
396
+ delete def.discriminator;
397
+ }
398
+ }
399
+ if (def.anyOf) {
400
+ delete def.anyOf;
401
+ if (def.discriminator) {
402
+ delete def.discriminator;
403
+ }
404
+ }
405
+ if (def.allOf) {
406
+ for (const i in def.allOf) {
407
+ this.convertSchema(def.allOf[i], operationDirection);
408
+ }
409
+ }
410
+ if (def.discriminator) {
411
+ if (def.discriminator.mapping) {
412
+ this.convertDiscriminatorMapping(def.discriminator.mapping);
413
+ }
414
+ def.discriminator = def.discriminator.propertyName;
415
+ }
416
+ switch (def.type) {
417
+ case "object":
418
+ if (def.properties) {
419
+ Object.keys(def.properties).forEach((propName) => {
420
+ if (def.properties[propName].writeOnly === true && operationDirection === "response") {
421
+ delete def.properties[propName];
422
+ }
423
+ else {
424
+ this.convertSchema(def.properties[propName], operationDirection);
425
+ delete def.properties[propName].writeOnly;
426
+ }
427
+ });
428
+ }
429
+ break;
430
+ case "array":
431
+ if (def.items) {
432
+ this.convertSchema(def.items, operationDirection);
433
+ }
434
+ }
435
+ if (def.nullable) {
436
+ def["x-nullable"] = true;
437
+ delete def.nullable;
438
+ }
439
+ // OpenAPI 3 has boolean "deprecated" on Schema, OpenAPI 2 does not
440
+ // Convert to x-deprecated for Autorest (and perhaps others)
441
+ if (def["deprecated"] !== undefined) {
442
+ // Move to x-deprecated, unless it is already defined
443
+ if (def["x-deprecated"] === undefined) {
444
+ def["x-deprecated"] = def.deprecated;
445
+ }
446
+ delete def.deprecated;
447
+ }
448
+ }
449
+ convertSchemas() {
450
+ this.spec.definitions = this.spec.components.schemas;
451
+ Object.keys(this.spec.definitions || {}).forEach((defName) => {
452
+ this.convertSchema(this.spec.definitions[defName]);
453
+ });
454
+ delete this.spec.components.schemas;
455
+ }
456
+ convertDiscriminatorMapping(mapping) {
457
+ Object.keys(mapping).forEach((payload) => {
458
+ const schemaNameOrRef = mapping[payload];
459
+ if (typeof schemaNameOrRef !== "string") {
460
+ console.warn(`Ignoring ${schemaNameOrRef} for ${payload} in discriminator.mapping.`);
461
+ return;
462
+ }
463
+ // payload may be a schema name or JSON Reference string.
464
+ // OAS3 spec limits schema names to ^[a-zA-Z0-9._-]+$
465
+ // Note: Valid schema name could be JSON file name without extension.
466
+ // Prefer schema name, with file name as fallback.
467
+ let schema;
468
+ if (/^[a-zA-Z0-9._-]+$/.test(schemaNameOrRef)) {
469
+ try {
470
+ schema = this.resolveReference(this.spec, { $ref: `#/components/schemas/${schemaNameOrRef}` }, false);
471
+ }
472
+ catch (err) {
473
+ console.debug(`Error resolving ${schemaNameOrRef} for ${payload} as schema name in discriminator.mapping: ${err}`);
474
+ }
475
+ }
476
+ // schemaNameRef is not a schema name. Try to resolve as JSON Ref.
477
+ if (!schema) {
478
+ try {
479
+ schema = this.resolveReference(this.spec, { $ref: schemaNameOrRef }, false);
480
+ }
481
+ catch (err) {
482
+ console.debug(`Error resolving ${schemaNameOrRef} for ${payload} in discriminator.mapping: ${err}`);
483
+ }
484
+ }
485
+ if (schema) {
486
+ // Swagger Codegen + OpenAPI Generator extension
487
+ // https://github.com/swagger-api/swagger-codegen/pull/4252
488
+ schema["x-discriminator-value"] = payload;
489
+ // AutoRest extension
490
+ // https://github.com/Azure/autorest/pull/474
491
+ schema["x-ms-discriminator-value"] = payload;
492
+ }
493
+ else {
494
+ console.warn(`Unable to resolve ${schemaNameOrRef} for ${payload} in discriminator.mapping.`);
495
+ }
496
+ });
497
+ }
498
+ convertSecurityDefinitions() {
499
+ if (this.spec.components.securitySchemes) {
500
+ this.spec.securityDefinitions = transformSecurity(this.spec.components.securitySchemes);
501
+ delete this.spec.components.securitySchemes;
502
+ }
503
+ }
504
+ }
505
+ exports.Converter = Converter;
506
+ function transformToOS2(spec) {
507
+ return new Converter(spec).convert();
508
+ }
509
+ exports.transformToOS2 = transformToOS2;
510
+ //# sourceMappingURL=transformToOS2.js.map