UNPKG

openapi-codegen-typescript

Version:

OpenApi codegen for generating types an mocks from swagger json file

165 lines (164 loc) 6.59 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); var getResultStringForAdditionalPropertiesType_1 = require("./getResultStringForAdditionalPropertiesType"); var getDictionaryValueResultString_1 = require("./getDictionaryValueResultString"); jest.mock('./getDictionaryValueResultString', function () { return ({ getDictionaryValueResultString: jest.fn(), }); }); beforeEach(function () { jest.clearAllMocks(); }); var scenarios = [ [ 'Boolean additional properties type', { input: { additionalProperties: { type: 'boolean' }, description: 'description mocked', propertyName: 'propertyName mocked', }, outputString: "/**\n * description mocked\n */\n\tpropertyName mocked: {\n\t[key: string]: boolean;\n};\n", outputParams: { description: 'description mocked', propertyName: 'propertyName mocked', dictionaryRef: 'ref-value', value: 'boolean', }, }, ], [ 'Integer additional properties type', { input: { additionalProperties: { type: 'integer' }, description: 'description mocked', propertyName: 'propertyName mocked', }, outputString: "/**\n * description mocked\n */\n\tpropertyName mocked: {\n\t[key: string]: number;\n};\n", outputParams: { description: 'description mocked', propertyName: 'propertyName mocked', dictionaryRef: 'ref-value', value: 'number', }, }, ], [ 'Number additional properties type', { input: { additionalProperties: { type: 'number' }, description: 'description mocked', propertyName: 'propertyName mocked', }, outputString: "/**\n * description mocked\n */\n\tpropertyName mocked: {\n\t[key: string]: number;\n};\n", outputParams: { description: 'description mocked', propertyName: 'propertyName mocked', dictionaryRef: 'ref-value', value: 'number', }, }, ], [ 'String additional properties type', { input: { additionalProperties: { type: 'string' }, description: 'description mocked', propertyName: 'propertyName mocked', }, outputString: "/**\n * description mocked\n */\n\tpropertyName mocked: {\n\t[key: string]: string;\n};\n", outputParams: { description: 'description mocked', propertyName: 'propertyName mocked', dictionaryRef: 'ref-value', value: 'string', }, }, ], [ 'Array additional properties type without item ref', { input: { additionalProperties: { type: 'array', items: { type: 'string', }, }, description: 'description mocked', propertyName: 'propertyName mocked', }, outputString: "/**\n * description mocked\n */\n\tpropertyName mocked: {\n\t[key: string]: \"// Error: The additionalProperties items or the items ref is missing\";\n};\n", outputParams: { description: 'description mocked', propertyName: 'propertyName mocked', dictionaryRef: 'ref-value', value: '"// Error: The additionalProperties items or the items ref is missing"', }, }, ], [ 'Array additional properties type with item ref', { input: { additionalProperties: { type: 'array', items: { $ref: '#/components/schemas/AssetFileDto', }, }, description: 'description mocked', propertyName: 'propertyName mocked', }, outputString: "/**\n * description mocked\n */\n\tpropertyName mocked: {\n\t[key: string]: AssetFileDto[];\n};\n", outputParams: { description: 'description mocked', propertyName: 'propertyName mocked', dictionaryRef: 'ref-value', value: 'AssetFileDto[]', }, }, ], [ 'Invalid additional properties type', { input: { additionalProperties: { type: 'test' }, description: 'description mocked', propertyName: 'propertyName mocked', }, outputString: "/**\n * description mocked\n */\n\tpropertyName mocked: {\n\t[key: string]: \"// Error: test is not supported\";\n};\n", outputParams: { description: 'description mocked', propertyName: 'propertyName mocked', dictionaryRef: 'ref-value', value: '"// Error: test is not supported"', }, }, ], ]; it.each(scenarios)("should return expected result when props is %s and xDictionaryKey is undefined", function (_, _a) { var input = _a.input, outputString = _a.outputString; var result = getResultStringForAdditionalPropertiesType_1.getResultStringForAdditionalPropertiesType(__assign(__assign({}, input), { xDictionaryKey: undefined })); expect(result).toBe(outputString); }); it.each(scenarios)("should return expected result when props is %s and xDictionaryKey is defined", function (_, _a) { var input = _a.input, outputParams = _a.outputParams; getResultStringForAdditionalPropertiesType_1.getResultStringForAdditionalPropertiesType(__assign(__assign({}, input), { xDictionaryKey: { $ref: 'path/ref-value', } })); expect(getDictionaryValueResultString_1.getDictionaryValueResultString).toHaveBeenCalledWith(outputParams); });