fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #219 from hey-api/chore/eslint-sort-keys

chore(lint): sort keys

authored by

Lubos and committed by
GitHub
60f1f737 08db39c2

+656 -580
+4
.gitignore
··· 12 12 dist 13 13 coverage 14 14 .env 15 + 16 + # test files 17 + test/generated 18 + test/e2e/generated
+60
package-lock.json
··· 7779 7779 "eslint": ">=5.0.0" 7780 7780 } 7781 7781 }, 7782 + "node_modules/eslint-plugin-sort-keys-fix": { 7783 + "version": "1.1.2", 7784 + "resolved": "https://registry.npmjs.org/eslint-plugin-sort-keys-fix/-/eslint-plugin-sort-keys-fix-1.1.2.tgz", 7785 + "integrity": "sha512-DNPHFGCA0/hZIsfODbeLZqaGY/+q3vgtshF85r+YWDNCQ2apd9PNs/zL6ttKm0nD1IFwvxyg3YOTI7FHl4unrw==", 7786 + "dev": true, 7787 + "dependencies": { 7788 + "espree": "^6.1.2", 7789 + "esutils": "^2.0.2", 7790 + "natural-compare": "^1.4.0", 7791 + "requireindex": "~1.2.0" 7792 + }, 7793 + "engines": { 7794 + "node": ">=0.10.0" 7795 + } 7796 + }, 7797 + "node_modules/eslint-plugin-sort-keys-fix/node_modules/acorn": { 7798 + "version": "7.4.1", 7799 + "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz", 7800 + "integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==", 7801 + "dev": true, 7802 + "bin": { 7803 + "acorn": "bin/acorn" 7804 + }, 7805 + "engines": { 7806 + "node": ">=0.4.0" 7807 + } 7808 + }, 7809 + "node_modules/eslint-plugin-sort-keys-fix/node_modules/eslint-visitor-keys": { 7810 + "version": "1.3.0", 7811 + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz", 7812 + "integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==", 7813 + "dev": true, 7814 + "engines": { 7815 + "node": ">=4" 7816 + } 7817 + }, 7818 + "node_modules/eslint-plugin-sort-keys-fix/node_modules/espree": { 7819 + "version": "6.2.1", 7820 + "resolved": "https://registry.npmjs.org/espree/-/espree-6.2.1.tgz", 7821 + "integrity": "sha512-ysCxRQY3WaXJz9tdbWOwuWr5Y/XrPTGX9Kiz3yoUXwW0VZ4w30HTkQLaGx/+ttFjF8i+ACbArnB4ce68a9m5hw==", 7822 + "dev": true, 7823 + "dependencies": { 7824 + "acorn": "^7.1.1", 7825 + "acorn-jsx": "^5.2.0", 7826 + "eslint-visitor-keys": "^1.1.0" 7827 + }, 7828 + "engines": { 7829 + "node": ">=6.0.0" 7830 + } 7831 + }, 7782 7832 "node_modules/eslint-scope": { 7783 7833 "version": "7.2.2", 7784 7834 "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.2.tgz", ··· 13288 13338 "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", 13289 13339 "dev": true 13290 13340 }, 13341 + "node_modules/requireindex": { 13342 + "version": "1.2.0", 13343 + "resolved": "https://registry.npmjs.org/requireindex/-/requireindex-1.2.0.tgz", 13344 + "integrity": "sha512-L9jEkOi3ASd9PYit2cwRfyppc9NoABujTP8/5gFcbERmo5jUoAKovIC3fsF17pkTnGsrByysqX+Kxd2OTNI1ww==", 13345 + "dev": true, 13346 + "engines": { 13347 + "node": ">=0.10.5" 13348 + } 13349 + }, 13291 13350 "node_modules/requires-port": { 13292 13351 "version": "1.0.0", 13293 13352 "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", ··· 16900 16959 "eslint-config-prettier": "9.1.0", 16901 16960 "eslint-plugin-prettier": "5.1.3", 16902 16961 "eslint-plugin-simple-import-sort": "12.0.0", 16962 + "eslint-plugin-sort-keys-fix": "1.1.2", 16903 16963 "express": "4.19.2", 16904 16964 "glob": "10.3.12", 16905 16965 "node-fetch": "3.3.2",
+10 -9
packages/openapi-ts/.eslintrc.json
··· 9 9 "es6": true, 10 10 "node": true 11 11 }, 12 - "plugins": ["simple-import-sort"], 12 + "plugins": ["simple-import-sort", "sort-keys-fix"], 13 13 "rules": { 14 - "@typescript-eslint/ban-ts-comment": 0, 15 - "@typescript-eslint/ban-ts-ignore": 0, 16 - "@typescript-eslint/explicit-function-return-type": 0, 17 - "@typescript-eslint/explicit-module-boundary-types": 0, 14 + "@typescript-eslint/ban-ts-comment": "off", 15 + "@typescript-eslint/ban-ts-ignore": "off", 16 + "@typescript-eslint/explicit-function-return-type": "off", 17 + "@typescript-eslint/explicit-module-boundary-types": "off", 18 18 "@typescript-eslint/no-explicit-any": "off", 19 - "@typescript-eslint/no-inferrable-types": 0, 20 - "@typescript-eslint/no-non-null-assertion": 0, 21 - "@typescript-eslint/no-var-requires": 0, 19 + "@typescript-eslint/no-inferrable-types": "off", 20 + "@typescript-eslint/no-non-null-assertion": "off", 21 + "@typescript-eslint/no-var-requires": "off", 22 22 "arrow-body-style": "error", 23 23 "import/order": "off", 24 24 "object-shorthand": "error", 25 25 "prettier/prettier": ["error"], 26 26 "simple-import-sort/exports": "error", 27 27 "simple-import-sort/imports": "error", 28 - "sort-imports": "off" 28 + "sort-imports": "off", 29 + "sort-keys-fix/sort-keys-fix": "warn" 29 30 } 30 31 }
+1
packages/openapi-ts/package.json
··· 95 95 "eslint-config-prettier": "9.1.0", 96 96 "eslint-plugin-prettier": "5.1.3", 97 97 "eslint-plugin-simple-import-sort": "12.0.0", 98 + "eslint-plugin-sort-keys-fix": "1.1.2", 98 99 "express": "4.19.2", 99 100 "glob": "10.3.12", 100 101 "node-fetch": "3.3.2",
+8 -8
packages/openapi-ts/rollup.config.ts
··· 18 18 */ 19 19 export function handlebarsPlugin(): Plugin { 20 20 return { 21 - name: 'handlebars', 22 - resolveId: (file: any, importer: any) => { 23 - if (path.extname(file) === '.hbs') { 24 - return path.resolve(path.dirname(importer), file); 25 - } 26 - return null; 27 - }, 28 21 load: (file: any) => { 29 22 if (path.extname(file) === '.hbs') { 30 23 const template = readFileSync(file, 'utf8').toString().trim(); ··· 41 34 escapeDescription: true, 42 35 escapeNewline: true, 43 36 exactArray: true, 44 - ifdef: true, 45 37 ifNotNullNotUndefined: true, 46 38 ifOperationDataOptional: true, 39 + ifdef: true, 47 40 intersection: true, 48 41 modelUnionType: true, 49 42 nameOperationDataType: true, ··· 57 50 strict: true, 58 51 }); 59 52 return `export default ${templateSpec};`; 53 + } 54 + return null; 55 + }, 56 + name: 'handlebars', 57 + resolveId: (file: any, importer: any) => { 58 + if (path.extname(file) === '.hbs') { 59 + return path.resolve(path.dirname(importer), file); 60 60 } 61 61 return null; 62 62 },
+1 -1
packages/openapi-ts/rollup.dts.config.ts
··· 8 8 const external = [/^node:*/, ...Object.keys(pkg.dependencies), ...Object.keys(pkg.devDependencies)]; 9 9 10 10 export default defineConfig({ 11 + external, 11 12 input: { 12 13 index: './temp/node/index.d.ts', 13 14 }, ··· 15 16 dir: './dist/node', 16 17 format: 'esm', 17 18 }, 18 - external, 19 19 plugins: [dts({ respectExternal: true })], 20 20 });
+9 -9
packages/openapi-ts/src/openApi/common/parser/__tests__/getPattern.spec.ts
··· 4 4 5 5 describe('getPattern', () => { 6 6 it.each([ 7 - { pattern: undefined, expected: undefined }, 8 - { pattern: '', expected: '' }, 9 - { pattern: '^[a-zA-Z]', expected: '^[a-zA-Z]' }, 10 - { pattern: '^\\w+$', expected: '^\\\\w+$' }, 11 - { pattern: '^\\d{3}-\\d{2}-\\d{4}$', expected: '^\\\\d{3}-\\\\d{2}-\\\\d{4}$' }, 12 - { pattern: '\\', expected: '\\\\' }, 13 - { pattern: '\\/', expected: '\\\\/' }, 14 - { pattern: '\\/\\/', expected: '\\\\/\\\\/' }, 15 - { pattern: "'", expected: "\\'" }, 7 + { expected: undefined, pattern: undefined }, 8 + { expected: '', pattern: '' }, 9 + { expected: '^[a-zA-Z]', pattern: '^[a-zA-Z]' }, 10 + { expected: '^\\\\w+$', pattern: '^\\w+$' }, 11 + { expected: '^\\\\d{3}-\\\\d{2}-\\\\d{4}$', pattern: '^\\d{3}-\\d{2}-\\d{4}$' }, 12 + { expected: '\\\\', pattern: '\\' }, 13 + { expected: '\\\\/', pattern: '\\/' }, 14 + { expected: '\\\\/\\\\/', pattern: '\\/\\/' }, 15 + { expected: "\\'", pattern: "'" }, 16 16 ])('getPattern($pattern) -> $expected', ({ pattern, expected }) => { 17 17 expect(getPattern(pattern)).toEqual(expected); 18 18 });
+18 -18
packages/openapi-ts/src/openApi/common/parser/__tests__/getRef.spec.ts
··· 7 7 expect( 8 8 getRef( 9 9 { 10 - swagger: '2.0', 11 - info: { 12 - title: 'dummy', 13 - version: '1.0', 14 - }, 15 - host: 'localhost:8080', 16 10 basePath: '/api', 17 - schemes: ['http', 'https'], 18 - paths: {}, 19 11 definitions: { 20 12 Example: { 21 13 description: 'This is an Example model ', 22 14 type: 'integer', 23 15 }, 24 16 }, 17 + host: 'localhost:8080', 18 + info: { 19 + title: 'dummy', 20 + version: '1.0', 21 + }, 22 + paths: {}, 23 + schemes: ['http', 'https'], 24 + swagger: '2.0', 25 25 }, 26 26 { 27 27 $ref: '#/definitions/Example', ··· 39 39 expect( 40 40 getRef( 41 41 { 42 - openapi: '3.0', 42 + components: { 43 + schemas: { 44 + Example: { 45 + description: 'This is an Example model ', 46 + type: 'integer', 47 + }, 48 + }, 49 + }, 43 50 info: { 44 51 title: 'dummy', 45 52 version: '1.0', 46 53 }, 54 + openapi: '3.0', 47 55 paths: {}, 48 56 servers: [ 49 57 { 50 58 url: 'https://localhost:8080/api', 51 59 }, 52 60 ], 53 - components: { 54 - schemas: { 55 - Example: { 56 - description: 'This is an Example model ', 57 - type: 'integer', 58 - }, 59 - }, 60 - }, 61 61 }, 62 62 { 63 63 $ref: '#/components/schemas/Example', ··· 73 73 expect( 74 74 getRef( 75 75 { 76 - openapi: '3.0', 77 76 info: { 78 77 title: 'dummy', 79 78 version: '1.0', 80 79 }, 80 + openapi: '3.0', 81 81 paths: { 82 82 '/api/user/{id}': { 83 83 description: 'This is an Example path',
+83 -83
packages/openapi-ts/src/openApi/common/parser/__tests__/operation.spec.ts
··· 13 13 14 14 it.each([ 15 15 { 16 - url: '/api/v{api-version}/users', 16 + expected: 'getAllUsers', 17 17 method: 'GET', 18 - options: options1, 19 18 operationId: 'GetAllUsers', 20 - expected: 'getAllUsers', 19 + options: options1, 20 + url: '/api/v{api-version}/users', 21 21 }, 22 22 { 23 - url: '/api/v{api-version}/users', 23 + expected: 'getApiUsers', 24 24 method: 'GET', 25 + operationId: undefined, 25 26 options: options1, 26 - operationId: undefined, 27 - expected: 'getApiUsers', 27 + url: '/api/v{api-version}/users', 28 28 }, 29 29 { 30 - url: '/api/v{api-version}/users', 30 + expected: 'postApiUsers', 31 31 method: 'POST', 32 - options: options1, 33 32 operationId: undefined, 34 - expected: 'postApiUsers', 33 + options: options1, 34 + url: '/api/v{api-version}/users', 35 35 }, 36 - { url: '/api/v1/users', method: 'GET', options: options1, operationId: 'GetAllUsers', expected: 'getAllUsers' }, 37 - { url: '/api/v1/users', method: 'GET', options: options1, operationId: undefined, expected: 'getApiV1Users' }, 38 - { url: '/api/v1/users', method: 'POST', options: options1, operationId: undefined, expected: 'postApiV1Users' }, 36 + { expected: 'getAllUsers', method: 'GET', operationId: 'GetAllUsers', options: options1, url: '/api/v1/users' }, 37 + { expected: 'getApiV1Users', method: 'GET', operationId: undefined, options: options1, url: '/api/v1/users' }, 38 + { expected: 'postApiV1Users', method: 'POST', operationId: undefined, options: options1, url: '/api/v1/users' }, 39 39 { 40 - url: '/api/v1/users/{id}', 40 + expected: 'getApiV1UsersById', 41 41 method: 'GET', 42 + operationId: undefined, 42 43 options: options1, 43 - operationId: undefined, 44 - expected: 'getApiV1UsersById', 44 + url: '/api/v1/users/{id}', 45 45 }, 46 46 { 47 - url: '/api/v1/users/{id}', 47 + expected: 'postApiV1UsersById', 48 48 method: 'POST', 49 + operationId: undefined, 49 50 options: options1, 50 - operationId: undefined, 51 - expected: 'postApiV1UsersById', 51 + url: '/api/v1/users/{id}', 52 52 }, 53 53 { 54 - url: '/api/v{api-version}/users', 54 + expected: 'fooBar', 55 55 method: 'GET', 56 + operationId: 'fooBar', 56 57 options: options1, 57 - operationId: 'fooBar', 58 - expected: 'fooBar', 58 + url: '/api/v{api-version}/users', 59 59 }, 60 60 { 61 - url: '/api/v{api-version}/users', 61 + expected: 'fooBar', 62 62 method: 'GET', 63 - options: options1, 64 63 operationId: 'FooBar', 65 - expected: 'fooBar', 64 + options: options1, 65 + url: '/api/v{api-version}/users', 66 66 }, 67 67 { 68 - url: '/api/v{api-version}/users', 68 + expected: 'fooBar', 69 69 method: 'GET', 70 + operationId: 'Foo Bar', 70 71 options: options1, 71 - operationId: 'Foo Bar', 72 - expected: 'fooBar', 72 + url: '/api/v{api-version}/users', 73 73 }, 74 74 { 75 - url: '/api/v{api-version}/users', 75 + expected: 'fooBar', 76 76 method: 'GET', 77 - options: options1, 78 77 operationId: 'foo bar', 79 - expected: 'fooBar', 78 + options: options1, 79 + url: '/api/v{api-version}/users', 80 80 }, 81 81 { 82 - url: '/api/v{api-version}/users', 82 + expected: 'fooBar', 83 83 method: 'GET', 84 + operationId: 'foo-bar', 84 85 options: options1, 85 - operationId: 'foo-bar', 86 - expected: 'fooBar', 86 + url: '/api/v{api-version}/users', 87 87 }, 88 88 { 89 - url: '/api/v{api-version}/users', 89 + expected: 'fooBar', 90 90 method: 'GET', 91 + operationId: 'foo_bar', 91 92 options: options1, 92 - operationId: 'foo_bar', 93 - expected: 'fooBar', 93 + url: '/api/v{api-version}/users', 94 94 }, 95 95 { 96 - url: '/api/v{api-version}/users', 96 + expected: 'fooBar', 97 97 method: 'GET', 98 + operationId: 'foo.bar', 98 99 options: options1, 99 - operationId: 'foo.bar', 100 - expected: 'fooBar', 100 + url: '/api/v{api-version}/users', 101 101 }, 102 102 { 103 - url: '/api/v{api-version}/users', 103 + expected: 'fooBar', 104 104 method: 'GET', 105 + operationId: '@foo.bar', 105 106 options: options1, 106 - operationId: '@foo.bar', 107 - expected: 'fooBar', 107 + url: '/api/v{api-version}/users', 108 108 }, 109 109 { 110 - url: '/api/v{api-version}/users', 110 + expected: 'fooBar', 111 111 method: 'GET', 112 + operationId: '$foo.bar', 112 113 options: options1, 113 - operationId: '$foo.bar', 114 - expected: 'fooBar', 114 + url: '/api/v{api-version}/users', 115 115 }, 116 116 { 117 - url: '/api/v{api-version}/users', 117 + expected: 'fooBar', 118 118 method: 'GET', 119 + operationId: '_foo.bar', 119 120 options: options1, 120 - operationId: '_foo.bar', 121 - expected: 'fooBar', 121 + url: '/api/v{api-version}/users', 122 122 }, 123 123 { 124 - url: '/api/v{api-version}/users', 124 + expected: 'fooBar', 125 125 method: 'GET', 126 - options: options1, 127 126 operationId: '-foo.bar', 128 - expected: 'fooBar', 127 + options: options1, 128 + url: '/api/v{api-version}/users', 129 129 }, 130 130 { 131 - url: '/api/v{api-version}/users', 131 + expected: 'fooBar', 132 132 method: 'GET', 133 - options: options1, 134 133 operationId: '123.foo.bar', 135 - expected: 'fooBar', 134 + options: options1, 135 + url: '/api/v{api-version}/users', 136 136 }, 137 137 { 138 - url: '/api/v1/users', 138 + expected: 'getApiV1Users', 139 139 method: 'GET', 140 + operationId: 'GetAllUsers', 140 141 options: options2, 141 - operationId: 'GetAllUsers', 142 - expected: 'getApiV1Users', 142 + url: '/api/v1/users', 143 143 }, 144 144 { 145 - url: '/api/v{api-version}/users', 145 + expected: 'getApiUsers', 146 146 method: 'GET', 147 + operationId: 'fooBar', 147 148 options: options2, 148 - operationId: 'fooBar', 149 - expected: 'getApiUsers', 149 + url: '/api/v{api-version}/users', 150 150 }, 151 151 { 152 - url: '/api/v{api-version}/users/{userId}/location/{locationId}', 152 + expected: 'getApiUsersByUserIdLocationByLocationId', 153 153 method: 'GET', 154 + operationId: 'fooBar', 154 155 options: options2, 155 - operationId: 'fooBar', 156 - expected: 'getApiUsersByUserIdLocationByLocationId', 156 + url: '/api/v{api-version}/users/{userId}/location/{locationId}', 157 157 }, 158 158 ])( 159 159 'getOperationName($url, $method, { operationId: $useOperationId }, $operationId) -> $expected', ··· 165 165 166 166 describe('getOperationParameterName', () => { 167 167 it.each([ 168 - { input: '', expected: '' }, 169 - { input: 'foobar', expected: 'foobar' }, 170 - { input: 'fooBar', expected: 'fooBar' }, 171 - { input: 'foo_bar', expected: 'fooBar' }, 172 - { input: 'foo-bar', expected: 'fooBar' }, 173 - { input: 'foo.bar', expected: 'fooBar' }, 174 - { input: '@foo.bar', expected: 'fooBar' }, 175 - { input: '$foo.bar', expected: 'fooBar' }, 176 - { input: '123.foo.bar', expected: 'fooBar' }, 177 - { input: 'Foo-Bar', expected: 'fooBar' }, 178 - { input: 'FOO-BAR', expected: 'fooBar' }, 179 - { input: 'foo[bar]', expected: 'fooBar' }, 180 - { input: 'foo.bar[]', expected: 'fooBarArray' }, 168 + { expected: '', input: '' }, 169 + { expected: 'foobar', input: 'foobar' }, 170 + { expected: 'fooBar', input: 'fooBar' }, 171 + { expected: 'fooBar', input: 'foo_bar' }, 172 + { expected: 'fooBar', input: 'foo-bar' }, 173 + { expected: 'fooBar', input: 'foo.bar' }, 174 + { expected: 'fooBar', input: '@foo.bar' }, 175 + { expected: 'fooBar', input: '$foo.bar' }, 176 + { expected: 'fooBar', input: '123.foo.bar' }, 177 + { expected: 'fooBar', input: 'Foo-Bar' }, 178 + { expected: 'fooBar', input: 'FOO-BAR' }, 179 + { expected: 'fooBar', input: 'foo[bar]' }, 180 + { expected: 'fooBarArray', input: 'foo.bar[]' }, 181 181 ])('getOperationParameterName($input) -> $expected', ({ input, expected }) => { 182 182 expect(getOperationParameterName(input)).toEqual(expected); 183 183 }); ··· 185 185 186 186 describe('getOperationResponseCode', () => { 187 187 it.each([ 188 - { input: '', expected: null }, 189 - { input: 'default', expected: 200 }, 190 - { input: '200', expected: 200 }, 191 - { input: '300', expected: 300 }, 192 - { input: '400', expected: 400 }, 193 - { input: 'abc', expected: null }, 194 - { input: '-100', expected: 100 }, 188 + { expected: null, input: '' }, 189 + { expected: 200, input: 'default' }, 190 + { expected: 200, input: '200' }, 191 + { expected: 300, input: '300' }, 192 + { expected: 400, input: '400' }, 193 + { expected: null, input: 'abc' }, 194 + { expected: 100, input: '-100' }, 195 195 ])('getOperationResponseCode($input) -> $expected', ({ input, expected }) => { 196 196 expect(getOperationResponseCode(input)).toEqual(expected); 197 197 });
+17 -17
packages/openapi-ts/src/openApi/common/parser/__tests__/sanitize.spec.ts
··· 9 9 10 10 describe('sanitizeOperationName', () => { 11 11 it.each([ 12 - { input: 'abc', expected: 'abc' }, 13 - { input: 'æbc', expected: 'æbc' }, 14 - { input: 'æb.c', expected: 'æb-c' }, 15 - { input: '1æb.c', expected: 'æb-c' }, 12 + { expected: 'abc', input: 'abc' }, 13 + { expected: 'æbc', input: 'æbc' }, 14 + { expected: 'æb-c', input: 'æb.c' }, 15 + { expected: 'æb-c', input: '1æb.c' }, 16 16 ])('sanitizeOperationName($input) -> $expected', ({ input, expected }) => { 17 17 expect(sanitizeOperationName(input)).toEqual(expected); 18 18 }); ··· 20 20 21 21 describe('sanitizeOperationParameterName', () => { 22 22 it.each([ 23 - { input: 'abc', expected: 'abc' }, 24 - { input: 'æbc', expected: 'æbc' }, 25 - { input: 'æb.c', expected: 'æb-c' }, 26 - { input: '1æb.c', expected: 'æb-c' }, 27 - { input: 'unknown[]', expected: 'unknownArray' }, 23 + { expected: 'abc', input: 'abc' }, 24 + { expected: 'æbc', input: 'æbc' }, 25 + { expected: 'æb-c', input: 'æb.c' }, 26 + { expected: 'æb-c', input: '1æb.c' }, 27 + { expected: 'unknownArray', input: 'unknown[]' }, 28 28 ])('sanitizeOperationParameterName($input) -> $expected', ({ input, expected }) => { 29 29 expect(sanitizeOperationParameterName(input)).toEqual(expected); 30 30 }); ··· 32 32 33 33 describe('sanitizeServiceName', () => { 34 34 it.each([ 35 - { input: 'abc', expected: 'abc' }, 36 - { input: 'æbc', expected: 'æbc' }, 37 - { input: 'æb.c', expected: 'æb-c' }, 38 - { input: '1æb.c', expected: 'æb-c' }, 35 + { expected: 'abc', input: 'abc' }, 36 + { expected: 'æbc', input: 'æbc' }, 37 + { expected: 'æb-c', input: 'æb.c' }, 38 + { expected: 'æb-c', input: '1æb.c' }, 39 39 ])('sanitizeServiceName($input) -> $expected', ({ input, expected }) => { 40 40 expect(sanitizeServiceName(input)).toEqual(expected); 41 41 }); ··· 43 43 44 44 describe('sanitizeTypeName', () => { 45 45 it.each([ 46 - { input: 'abc', expected: 'abc' }, 47 - { input: 'æbc', expected: 'æbc' }, 48 - { input: 'æb.c', expected: 'æb_c' }, 49 - { input: '1æb.c', expected: 'æb_c' }, 46 + { expected: 'abc', input: 'abc' }, 47 + { expected: 'æbc', input: 'æbc' }, 48 + { expected: 'æb_c', input: 'æb.c' }, 49 + { expected: 'æb_c', input: '1æb.c' }, 50 50 ])('sanitizeTypeName($input) -> $expected', ({ input, expected }) => { 51 51 expect(sanitizeTypeName(input)).toEqual(expected); 52 52 });
+11 -11
packages/openapi-ts/src/openApi/common/parser/__tests__/service.spec.ts
··· 4 4 5 5 describe('getServiceVersion', () => { 6 6 it.each([ 7 - { input: '1.0', expected: '1.0' }, 8 - { input: 'v1.2', expected: '1.2' }, 9 - { input: 'V2.4', expected: '2.4' }, 7 + { expected: '1.0', input: '1.0' }, 8 + { expected: '1.2', input: 'v1.2' }, 9 + { expected: '2.4', input: 'V2.4' }, 10 10 ])('should get $expected when version is $input', ({ input, expected }) => { 11 11 expect(getServiceVersion(input)).toEqual(expected); 12 12 }); ··· 14 14 15 15 describe('getServiceName', () => { 16 16 it.each([ 17 - { input: '', expected: '' }, 18 - { input: 'FooBar', expected: 'FooBar' }, 19 - { input: 'Foo Bar', expected: 'FooBar' }, 20 - { input: 'foo bar', expected: 'FooBar' }, 21 - { input: '@fooBar', expected: 'FooBar' }, 22 - { input: '$fooBar', expected: 'FooBar' }, 23 - { input: '123fooBar', expected: 'FooBar' }, 24 - { input: 'non-ascii-æøåÆØÅöôêÊ字符串', expected: 'NonAsciiÆøåÆøÅöôêÊ字符串' }, 17 + { expected: '', input: '' }, 18 + { expected: 'FooBar', input: 'FooBar' }, 19 + { expected: 'FooBar', input: 'Foo Bar' }, 20 + { expected: 'FooBar', input: 'foo bar' }, 21 + { expected: 'FooBar', input: '@fooBar' }, 22 + { expected: 'FooBar', input: '$fooBar' }, 23 + { expected: 'FooBar', input: '123fooBar' }, 24 + { expected: 'NonAsciiÆøåÆøÅöôêÊ字符串', input: 'non-ascii-æøåÆØÅöôêÊ字符串' }, 25 25 ])('getServiceName($input) -> $expected', ({ input, expected }) => { 26 26 expect(getServiceName(input)).toEqual(expected); 27 27 });
+8 -8
packages/openapi-ts/src/openApi/common/parser/__tests__/sort.spec.ts
··· 5 5 describe('sort', () => { 6 6 it.each([ 7 7 { 8 - input: [ 9 - { id: 'test', isRequired: false }, 8 + expected: [ 10 9 { id: 'test2', isRequired: true }, 11 10 { id: 'test3', isRequired: true }, 11 + { id: 'test', isRequired: false }, 12 12 ], 13 - expected: [ 13 + input: [ 14 + { id: 'test', isRequired: false }, 14 15 { id: 'test2', isRequired: true }, 15 16 { id: 'test3', isRequired: true }, 16 - { id: 'test', isRequired: false }, 17 17 ], 18 18 }, 19 19 { 20 - input: [ 20 + expected: [ 21 21 { id: 'test', isRequired: false }, 22 22 { id: 'test2', isRequired: false }, 23 - { id: 'test3', isRequired: true, default: 'something' }, 23 + { default: 'something', id: 'test3', isRequired: true }, 24 24 ], 25 - expected: [ 25 + input: [ 26 26 { id: 'test', isRequired: false }, 27 27 { id: 'test2', isRequired: false }, 28 - { id: 'test3', isRequired: true, default: 'something' }, 28 + { default: 'something', id: 'test3', isRequired: true }, 29 29 ], 30 30 }, 31 31 ])('should sort $input by required to produce $expected', ({ input, expected }) => {
+13 -13
packages/openapi-ts/src/openApi/common/parser/__tests__/stripNamespace.spec.ts
··· 4 4 5 5 describe('stripNamespace', () => { 6 6 it.each([ 7 - { input: '#/definitions/Item', expected: 'Item' }, 8 - { input: '#/parameters/Item', expected: 'Item' }, 9 - { input: '#/responses/Item', expected: 'Item' }, 10 - { input: '#/securityDefinitions/Item', expected: 'Item' }, 11 - { input: '#/components/schemas/Item', expected: 'Item' }, 12 - { input: '#/components/responses/Item', expected: 'Item' }, 13 - { input: '#/components/parameters/Item', expected: 'Item' }, 14 - { input: '#/components/examples/Item', expected: 'Item' }, 15 - { input: '#/components/requestBodies/Item', expected: 'Item' }, 16 - { input: '#/components/headers/Item', expected: 'Item' }, 17 - { input: '#/components/securitySchemes/Item', expected: 'Item' }, 18 - { input: '#/components/links/Item', expected: 'Item' }, 19 - { input: '#/components/callbacks/Item', expected: 'Item' }, 7 + { expected: 'Item', input: '#/definitions/Item' }, 8 + { expected: 'Item', input: '#/parameters/Item' }, 9 + { expected: 'Item', input: '#/responses/Item' }, 10 + { expected: 'Item', input: '#/securityDefinitions/Item' }, 11 + { expected: 'Item', input: '#/components/schemas/Item' }, 12 + { expected: 'Item', input: '#/components/responses/Item' }, 13 + { expected: 'Item', input: '#/components/parameters/Item' }, 14 + { expected: 'Item', input: '#/components/examples/Item' }, 15 + { expected: 'Item', input: '#/components/requestBodies/Item' }, 16 + { expected: 'Item', input: '#/components/headers/Item' }, 17 + { expected: 'Item', input: '#/components/securitySchemes/Item' }, 18 + { expected: 'Item', input: '#/components/links/Item' }, 19 + { expected: 'Item', input: '#/components/callbacks/Item' }, 20 20 ])('stripNamespace($input) -> $expected', ({ input, expected }) => { 21 21 expect(stripNamespace(input)).toEqual(expected); 22 22 });
+21 -21
packages/openapi-ts/src/openApi/common/parser/__tests__/type.spec.ts
··· 4 4 5 5 describe('getMappedType', () => { 6 6 it.each([ 7 - { type: '', expected: undefined }, 8 - { type: 'any', expected: 'unknown' }, 9 - { type: 'array', expected: 'unknown[]' }, 10 - { type: 'boolean', expected: 'boolean' }, 11 - { type: 'byte', expected: 'number' }, 12 - { type: 'char', expected: 'string' }, 13 - { type: 'date-time', expected: 'string' }, 14 - { type: 'date', expected: 'string' }, 15 - { type: 'double', expected: 'number' }, 16 - { type: 'file', expected: 'binary' }, 17 - { type: 'float', expected: 'number' }, 18 - { type: 'int', expected: 'number' }, 19 - { type: 'integer', expected: 'number' }, 20 - { type: 'long', expected: 'number' }, 21 - { type: 'null', expected: 'null' }, 22 - { type: 'number', expected: 'number' }, 23 - { type: 'object', expected: 'unknown' }, 24 - { type: 'password', expected: 'string' }, 25 - { type: 'short', expected: 'number' }, 26 - { type: 'string', expected: 'string' }, 27 - { type: 'void', expected: 'void' }, 7 + { expected: undefined, type: '' }, 8 + { expected: 'unknown', type: 'any' }, 9 + { expected: 'unknown[]', type: 'array' }, 10 + { expected: 'boolean', type: 'boolean' }, 11 + { expected: 'number', type: 'byte' }, 12 + { expected: 'string', type: 'char' }, 13 + { expected: 'string', type: 'date-time' }, 14 + { expected: 'string', type: 'date' }, 15 + { expected: 'number', type: 'double' }, 16 + { expected: 'binary', type: 'file' }, 17 + { expected: 'number', type: 'float' }, 18 + { expected: 'number', type: 'int' }, 19 + { expected: 'number', type: 'integer' }, 20 + { expected: 'number', type: 'long' }, 21 + { expected: 'null', type: 'null' }, 22 + { expected: 'number', type: 'number' }, 23 + { expected: 'unknown', type: 'object' }, 24 + { expected: 'string', type: 'password' }, 25 + { expected: 'number', type: 'short' }, 26 + { expected: 'string', type: 'string' }, 27 + { expected: 'void', type: 'void' }, 28 28 ])('should map type $type to $expected', ({ type, expected }) => { 29 29 expect(getMappedType(type)).toEqual(expected); 30 30 });
+2 -2
packages/openapi-ts/src/openApi/common/parser/getEnums.ts
··· 14 14 .filter(unique) 15 15 .filter(value => typeof value === 'number' || typeof value === 'string') 16 16 .map((value, index) => ({ 17 + description: undefined, 18 + value, 17 19 'x-enum-description': descriptions[index], 18 20 'x-enum-varname': names[index], 19 - description: undefined, 20 - value, 21 21 })); 22 22 };
+1 -1
packages/openapi-ts/src/openApi/v2/index.ts
··· 18 18 const models = getModels(openApi); 19 19 const services = getServices(openApi, options); 20 20 21 - return { version, server, models, services }; 21 + return { models, server, services, version }; 22 22 };
+4 -4
packages/openapi-ts/src/openApi/v2/parser/__tests__/getServer.spec.ts
··· 6 6 it('should produce correct result', () => { 7 7 expect( 8 8 getServer({ 9 - swagger: '2.0', 9 + basePath: '/api', 10 + host: 'localhost:8080', 10 11 info: { 11 12 title: 'dummy', 12 13 version: '1.0', 13 14 }, 14 - host: 'localhost:8080', 15 - basePath: '/api', 16 - schemes: ['http', 'https'], 17 15 paths: {}, 16 + schemes: ['http', 'https'], 17 + swagger: '2.0', 18 18 }) 19 19 ).toEqual('http://localhost:8080/api'); 20 20 });
+2 -2
packages/openapi-ts/src/openApi/v2/parser/__tests__/getServices.spec.ts
··· 27 27 }; 28 28 const services = getServices( 29 29 { 30 - swagger: '2.0', 31 30 info: { 32 31 title: 'x', 33 32 version: '1', ··· 35 34 paths: { 36 35 '/api/trips': { 37 36 get: { 38 - tags: [], 39 37 responses: { 40 38 200: { 41 39 description: 'x', ··· 44 42 description: 'default', 45 43 }, 46 44 }, 45 + tags: [], 47 46 }, 48 47 }, 49 48 }, 49 + swagger: '2.0', 50 50 }, 51 51 options 52 52 );
+2 -2
packages/openapi-ts/src/openApi/v2/parser/getModel.ts
··· 29 29 isReadOnly: definition.readOnly === true, 30 30 isRequired: false, 31 31 link: null, 32 - maximum: definition.maximum, 33 32 maxItems: definition.maxItems, 34 33 maxLength: definition.maxLength, 35 34 maxProperties: definition.maxProperties, 36 - minimum: definition.minimum, 35 + maximum: definition.maximum, 37 36 minItems: definition.minItems, 38 37 minLength: definition.minLength, 39 38 minProperties: definition.minProperties, 39 + minimum: definition.minimum, 40 40 multipleOf: definition.multipleOf, 41 41 name, 42 42 pattern: getPattern(definition.pattern),
+4 -4
packages/openapi-ts/src/openApi/v2/parser/getModelProperties.ts
··· 33 33 isReadOnly: property.readOnly === true, 34 34 isRequired: propertyRequired, 35 35 link: null, 36 - maximum: property.maximum, 37 36 maxItems: property.maxItems, 38 37 maxLength: property.maxLength, 39 38 maxProperties: property.maxProperties, 40 - minimum: property.minimum, 39 + maximum: property.maximum, 41 40 minItems: property.minItems, 42 41 minLength: property.minLength, 43 42 minProperties: property.minProperties, 43 + minimum: property.minimum, 44 44 multipleOf: property.multipleOf, 45 45 name: escapeName(propertyName), 46 46 pattern: getPattern(property.pattern), ··· 67 67 isReadOnly: property.readOnly === true, 68 68 isRequired: propertyRequired, 69 69 link: model.link, 70 - maximum: property.maximum, 71 70 maxItems: property.maxItems, 72 71 maxLength: property.maxLength, 73 72 maxProperties: property.maxProperties, 74 - minimum: property.minimum, 73 + maximum: property.maximum, 75 74 minItems: property.minItems, 76 75 minLength: property.minLength, 77 76 minProperties: property.minProperties, 77 + minimum: property.minimum, 78 78 multipleOf: property.multipleOf, 79 79 name: escapeName(propertyName), 80 80 pattern: getPattern(property.pattern),
+12 -12
packages/openapi-ts/src/openApi/v2/parser/getOperation.ts
··· 24 24 // Create a new operation object for this method. 25 25 const operation: Operation = { 26 26 $refs: [], 27 - service: serviceName, 28 - name, 29 - summary: op.summary || null, 27 + deprecated: op.deprecated === true, 30 28 description: op.description || null, 31 - deprecated: op.deprecated === true, 29 + errors: [], 30 + imports: [], 32 31 method: method.toUpperCase() as Operation['method'], 33 - path: url, 32 + name, 34 33 parameters: [...pathParams.parameters], 35 - parametersPath: [...pathParams.parametersPath], 36 - parametersQuery: [...pathParams.parametersQuery], 34 + parametersBody: pathParams.parametersBody, 35 + parametersCookie: [...pathParams.parametersCookie], 37 36 parametersForm: [...pathParams.parametersForm], 38 37 parametersHeader: [...pathParams.parametersHeader], 39 - parametersCookie: [...pathParams.parametersCookie], 40 - parametersBody: pathParams.parametersBody, 41 - imports: [], 42 - errors: [], 43 - results: [], 38 + parametersPath: [...pathParams.parametersPath], 39 + parametersQuery: [...pathParams.parametersQuery], 40 + path: url, 44 41 responseHeader: null, 42 + results: [], 43 + service: serviceName, 44 + summary: op.summary || null, 45 45 }; 46 46 47 47 // Parse the operation parameters (path, query, body, etc).
+2 -2
packages/openapi-ts/src/openApi/v2/parser/getOperationParameter.ts
··· 28 28 isReadOnly: false, 29 29 isRequired: parameter.required === true, 30 30 link: null, 31 - maximum: parameter.maximum, 32 31 maxItems: parameter.maxItems, 33 32 maxLength: parameter.maxLength, 33 + maximum: parameter.maximum, 34 34 mediaType: null, 35 - minimum: parameter.minimum, 36 35 minItems: parameter.minItems, 37 36 minLength: parameter.minLength, 37 + minimum: parameter.minimum, 38 38 multipleOf: parameter.multipleOf, 39 39 name: getOperationParameterName(parameter.name), 40 40 pattern: getPattern(parameter.pattern),
+4 -4
packages/openapi-ts/src/openApi/v2/parser/getOperationParameters.ts
··· 9 9 $refs: [], 10 10 imports: [], 11 11 parameters: [], 12 - parametersPath: [], 13 - parametersQuery: [], 14 - parametersForm: [], 12 + parametersBody: null, 15 13 parametersCookie: [], 14 + parametersForm: [], 16 15 parametersHeader: [], 17 - parametersBody: null, 16 + parametersPath: [], 17 + parametersQuery: [], 18 18 }; 19 19 20 20 // Iterate over the parameters
+1 -1
packages/openapi-ts/src/openApi/v2/parser/getServices.ts
··· 37 37 // append the new method to it. Otherwise we should create a new service object. 38 38 const service: Service = services.get(operation.service) || { 39 39 $refs: [], 40 + imports: [], 40 41 name: operation.service, 41 42 operations: [], 42 - imports: [], 43 43 }; 44 44 45 45 // Push the operation in the service
+38 -38
packages/openapi-ts/src/openApi/v3/parser/__tests__/getModel.spec.ts
··· 5 5 import { getModel } from '../getModel'; 6 6 7 7 const openApi = { 8 - openapi: '3.0', 9 - info: { 10 - title: 'dummy', 11 - version: '1.0', 12 - }, 13 - paths: {}, 14 - servers: [ 15 - { 16 - url: 'https://localhost:8080/api', 17 - }, 18 - ], 19 8 components: { 20 9 schemas: { 21 - Enum1: { 22 - enum: ['Bird', 'Dog'], 23 - type: 'string', 24 - }, 25 - ConstValue: { 26 - type: 'string', 27 - const: 'ConstValue', 28 - }, 29 - CompositionWithAnyOfAndNull: { 10 + CompositionWithAny: { 30 11 description: 31 12 "This is a model with one property with a 'any of' relationship where the options are not $ref", 32 - type: 'object', 33 13 properties: { 34 14 propA: { 35 15 anyOf: [ 36 16 { 37 - items: { 38 - anyOf: [ 39 - { 40 - $ref: '#/components/schemas/Enum1', 41 - }, 42 - { 43 - $ref: '#/components/schemas/ConstValue', 44 - }, 45 - ], 46 - }, 47 - type: 'array', 17 + $ref: '#/components/schemas/Enum1', 18 + }, 19 + { 20 + $ref: '#/components/schemas/ConstValue', 48 21 }, 49 22 { 50 23 type: 'null', ··· 52 25 ], 53 26 }, 54 27 }, 28 + type: 'object', 55 29 }, 56 - CompositionWithAny: { 30 + CompositionWithAnyOfAndNull: { 57 31 description: 58 32 "This is a model with one property with a 'any of' relationship where the options are not $ref", 59 - type: 'object', 60 33 properties: { 61 34 propA: { 62 35 anyOf: [ 63 36 { 64 - $ref: '#/components/schemas/Enum1', 65 - }, 66 - { 67 - $ref: '#/components/schemas/ConstValue', 37 + items: { 38 + anyOf: [ 39 + { 40 + $ref: '#/components/schemas/Enum1', 41 + }, 42 + { 43 + $ref: '#/components/schemas/ConstValue', 44 + }, 45 + ], 46 + }, 47 + type: 'array', 68 48 }, 69 49 { 70 50 type: 'null', ··· 72 52 ], 73 53 }, 74 54 }, 55 + type: 'object', 56 + }, 57 + ConstValue: { 58 + const: 'ConstValue', 59 + type: 'string', 60 + }, 61 + Enum1: { 62 + enum: ['Bird', 'Dog'], 63 + type: 'string', 75 64 }, 76 65 }, 77 66 }, 67 + info: { 68 + title: 'dummy', 69 + version: '1.0', 70 + }, 71 + openapi: '3.0', 72 + paths: {}, 73 + servers: [ 74 + { 75 + url: 'https://localhost:8080/api', 76 + }, 77 + ], 78 78 }; 79 79 80 80 describe('getModel', () => {
+5 -5
packages/openapi-ts/src/openApi/v3/parser/__tests__/getServer.spec.ts
··· 6 6 it('should produce correct result', () => { 7 7 expect( 8 8 getServer({ 9 - openapi: '3.0', 10 9 info: { 11 10 title: 'dummy', 12 11 version: '1.0', 13 12 }, 13 + openapi: '3.0', 14 14 paths: {}, 15 15 servers: [ 16 16 { ··· 24 24 it('should produce correct result with variables', () => { 25 25 expect( 26 26 getServer({ 27 - openapi: '3.0', 28 27 info: { 29 28 title: 'dummy', 30 29 version: '1.0', 31 30 }, 31 + openapi: '3.0', 32 32 paths: {}, 33 33 servers: [ 34 34 { 35 35 url: '{scheme}://localhost:{port}/api', 36 36 variables: { 37 - scheme: { 38 - default: 'https', 39 - }, 40 37 port: { 41 38 default: '8080', 39 + }, 40 + scheme: { 41 + default: 'https', 42 42 }, 43 43 }, 44 44 },
+2 -2
packages/openapi-ts/src/openApi/v3/parser/__tests__/getServices.spec.ts
··· 27 27 }; 28 28 const services = getServices( 29 29 { 30 - openapi: '3.0.0', 31 30 info: { 32 31 title: 'x', 33 32 version: '1', 34 33 }, 34 + openapi: '3.0.0', 35 35 paths: { 36 36 '/api/trips': { 37 37 get: { 38 - tags: [], 39 38 responses: { 40 39 200: { 41 40 description: 'x', ··· 44 43 description: 'default', 45 44 }, 46 45 }, 46 + tags: [], 47 47 }, 48 48 }, 49 49 },
+2 -2
packages/openapi-ts/src/openApi/v3/parser/getModel.ts
··· 34 34 isReadOnly: definition.readOnly === true, 35 35 isRequired: false, 36 36 link: null, 37 - maximum: definition.maximum, 38 37 maxItems: definition.maxItems, 39 38 maxLength: definition.maxLength, 40 39 maxProperties: definition.maxProperties, 41 - minimum: definition.minimum, 40 + maximum: definition.maximum, 42 41 minItems: definition.minItems, 43 42 minLength: definition.minLength, 44 43 minProperties: definition.minProperties, 44 + minimum: definition.minimum, 45 45 multipleOf: definition.multipleOf, 46 46 name, 47 47 pattern: getPattern(definition.pattern),
+4 -4
packages/openapi-ts/src/openApi/v3/parser/getModelProperties.ts
··· 76 76 | 'template' 77 77 | 'type' 78 78 > = { 79 + default: property.default, 79 80 deprecated: property.deprecated === true, 80 81 description: property.description || null, 81 - default: property.default, 82 82 exclusiveMaximum: property.exclusiveMaximum, 83 83 exclusiveMinimum: property.exclusiveMinimum, 84 84 format: property.format, 85 85 isDefinition: false, 86 86 isReadOnly: property.readOnly === true, 87 87 isRequired: propertyRequired, 88 - maximum: property.maximum, 89 88 maxItems: property.maxItems, 90 89 maxLength: property.maxLength, 91 90 maxProperties: property.maxProperties, 92 - minimum: property.minimum, 91 + maximum: property.maximum, 93 92 minItems: property.minItems, 94 93 minLength: property.minLength, 95 94 minProperties: property.minProperties, 95 + minimum: property.minimum, 96 96 multipleOf: property.multipleOf, 97 97 name: escapeName(propertyName), 98 98 pattern: getPattern(property.pattern), ··· 136 136 ...propertyValues, 137 137 $refs: model.$refs, 138 138 base: model.base, 139 + default: model.default, 139 140 enum: model.enum, 140 141 enums: model.enums, 141 142 export: model.export, 142 - default: model.default, 143 143 imports: model.imports, 144 144 isNullable: model.isNullable || property.nullable === true, 145 145 link: model.link,
+4 -4
packages/openapi-ts/src/openApi/v3/parser/getOperationParameters.ts
··· 11 11 $refs: [], 12 12 imports: [], 13 13 parameters: [], 14 - parametersPath: [], 15 - parametersQuery: [], 16 - parametersForm: [], 14 + parametersBody: null, 17 15 parametersCookie: [], 16 + parametersForm: [], 18 17 parametersHeader: [], 19 - parametersBody: null, // Not used in v3 -> @see requestBody 18 + parametersPath: [], 19 + parametersQuery: [], // Not used in v3 -> @see requestBody 20 20 }; 21 21 22 22 parameters.forEach(parameterOrReference => {
+15 -15
packages/openapi-ts/src/utils/__tests__/escapeName.spec.ts
··· 3 3 import { escapeName, unescapeName } from '../escapeName'; 4 4 5 5 const toCheck: { unescaped: string; escaped: string }[] = [ 6 - { unescaped: '', escaped: "''" }, 7 - { unescaped: 'fooBar', escaped: 'fooBar' }, 8 - { unescaped: 'Foo Bar', escaped: `'Foo Bar'` }, 9 - { unescaped: 'foo bar', escaped: `'foo bar'` }, 10 - { unescaped: 'foo-bar', escaped: `'foo-bar'` }, 11 - { unescaped: 'foo.bar', escaped: `'foo.bar'` }, 12 - { unescaped: 'foo_bar', escaped: 'foo_bar' }, 13 - { unescaped: '123foo.bar', escaped: `'123foo.bar'` }, 14 - { unescaped: '@foo.bar', escaped: `'@foo.bar'` }, 15 - { unescaped: '$foo.bar', escaped: `'$foo.bar'` }, 16 - { unescaped: '_foo.bar', escaped: `'_foo.bar'` }, 17 - { unescaped: '123foobar', escaped: `'123foobar'` }, 18 - { unescaped: '@foobar', escaped: `'@foobar'` }, 19 - { unescaped: '$foobar', escaped: '$foobar' }, 20 - { unescaped: '_foobar', escaped: '_foobar' }, 6 + { escaped: "''", unescaped: '' }, 7 + { escaped: 'fooBar', unescaped: 'fooBar' }, 8 + { escaped: `'Foo Bar'`, unescaped: 'Foo Bar' }, 9 + { escaped: `'foo bar'`, unescaped: 'foo bar' }, 10 + { escaped: `'foo-bar'`, unescaped: 'foo-bar' }, 11 + { escaped: `'foo.bar'`, unescaped: 'foo.bar' }, 12 + { escaped: 'foo_bar', unescaped: 'foo_bar' }, 13 + { escaped: `'123foo.bar'`, unescaped: '123foo.bar' }, 14 + { escaped: `'@foo.bar'`, unescaped: '@foo.bar' }, 15 + { escaped: `'$foo.bar'`, unescaped: '$foo.bar' }, 16 + { escaped: `'_foo.bar'`, unescaped: '_foo.bar' }, 17 + { escaped: `'123foobar'`, unescaped: '123foobar' }, 18 + { escaped: `'@foobar'`, unescaped: '@foobar' }, 19 + { escaped: '$foobar', unescaped: '$foobar' }, 20 + { escaped: '_foobar', unescaped: '_foobar' }, 21 21 ]; 22 22 23 23 describe('escapeName', () => {
+7 -7
packages/openapi-ts/src/utils/__tests__/unique.spec.ts
··· 4 4 5 5 describe('unique', () => { 6 6 it.each([ 7 - { value: 'a', index: 0, arr: ['a', 'b', 'c'], result: true }, 8 - { value: 'a', index: 1, arr: ['a', 'b', 'c'], result: false }, 9 - { value: 'a', index: 2, arr: ['a', 'b', 'c'], result: false }, 10 - { value: 'a', index: 1, arr: ['z', 'a', 'b'], result: true }, 11 - { value: 'a', index: 2, arr: ['y', 'z', 'a'], result: true }, 7 + { arr: ['a', 'b', 'c'], index: 0, result: true, value: 'a' }, 8 + { arr: ['a', 'b', 'c'], index: 1, result: false, value: 'a' }, 9 + { arr: ['a', 'b', 'c'], index: 2, result: false, value: 'a' }, 10 + { arr: ['z', 'a', 'b'], index: 1, result: true, value: 'a' }, 11 + { arr: ['y', 'z', 'a'], index: 2, result: true, value: 'a' }, 12 12 ])('unique($value, $index, $arr) -> $result', ({ value, index, arr, result }) => { 13 13 expect(unique(value, index, arr)).toEqual(result); 14 14 }); 15 15 16 16 it.each([ 17 - { input: ['a', 'a', 'b', 'c', 'b', 'b'], expected: ['a', 'b', 'c'] }, 18 - { input: [1, 2, 3, 4, 4, 5, 6, 3], expected: [1, 2, 3, 4, 5, 6] }, 17 + { expected: ['a', 'b', 'c'], input: ['a', 'a', 'b', 'c', 'b', 'b'] }, 18 + { expected: [1, 2, 3, 4, 5, 6], input: [1, 2, 3, 4, 4, 5, 6, 3] }, 19 19 ])('should filter: $input to the unique array: $expected', ({ input, expected }) => { 20 20 expect(input.filter(unique)).toEqual(expected); 21 21 });
+2 -2
packages/openapi-ts/src/utils/postprocess.ts
··· 23 23 export function postProcessModel(model: Model): Model { 24 24 return { 25 25 ...model, 26 - imports: postProcessModelImports(model), 27 - enums: postProcessModelEnums(model), 28 26 enum: postProcessModelEnum(model), 27 + enums: postProcessModelEnums(model), 28 + imports: postProcessModelImports(model), 29 29 }; 30 30 } 31 31
+2 -2
packages/openapi-ts/src/utils/write/__tests__/class.spec.ts
··· 10 10 describe('writeClientClass', () => { 11 11 it('should write to filesystem', async () => { 12 12 const client: Parameters<typeof writeClientClass>[0] = { 13 - server: 'http://localhost:8080', 14 - version: 'v1', 15 13 models: [], 14 + server: 'http://localhost:8080', 16 15 services: [], 16 + version: 'v1', 17 17 }; 18 18 19 19 await writeClientClass(client, mockTemplates, './dist', {
+2 -2
packages/openapi-ts/src/utils/write/__tests__/client.spec.ts
··· 10 10 describe('writeClient', () => { 11 11 it('should write to filesystem', async () => { 12 12 const client: Parameters<typeof writeClient>[0] = { 13 - server: 'http://localhost:8080', 14 - version: 'v1', 15 13 models: [], 14 + server: 'http://localhost:8080', 16 15 services: [], 16 + version: 'v1', 17 17 }; 18 18 19 19 await writeClient(client, mockTemplates, {
+2 -2
packages/openapi-ts/src/utils/write/__tests__/index.spec.ts
··· 11 11 describe('writeClientIndex', () => { 12 12 it('should write to filesystem', async () => { 13 13 const client: Parameters<typeof writeClientIndex>[0] = { 14 - server: 'http://localhost:8080', 15 - version: '1.0', 16 14 models: [], 15 + server: 'http://localhost:8080', 17 16 services: [], 17 + version: '1.0', 18 18 }; 19 19 20 20 await writeClientIndex(client, mockTemplates, '/', {
+2 -2
packages/openapi-ts/src/utils/write/__tests__/models.spec.ts
··· 11 11 describe('writeClientModels', () => { 12 12 it('should write to filesystem', async () => { 13 13 const client: Parameters<typeof writeClientModels>[0] = { 14 - server: 'http://localhost:8080', 15 - version: 'v1', 16 14 models: [ 17 15 { 18 16 $refs: [], ··· 33 31 type: 'User', 34 32 }, 35 33 ], 34 + server: 'http://localhost:8080', 36 35 services: [], 36 + version: 'v1', 37 37 }; 38 38 39 39 await writeClientModels(client, mockTemplates, '/', {
+2 -2
packages/openapi-ts/src/utils/write/__tests__/schemas.spec.ts
··· 11 11 describe('writeClientSchemas', () => { 12 12 it('should write to filesystem', async () => { 13 13 const client: Parameters<typeof writeClientSchemas>[0] = { 14 - server: 'http://localhost:8080', 15 - version: 'v1', 16 14 models: [ 17 15 { 18 16 $refs: [], ··· 33 31 type: 'User', 34 32 }, 35 33 ], 34 + server: 'http://localhost:8080', 36 35 services: [], 36 + version: 'v1', 37 37 }; 38 38 39 39 await writeClientSchemas(client, mockTemplates, '/', {
+2 -2
packages/openapi-ts/src/utils/write/__tests__/services.spec.ts
··· 10 10 describe('writeClientServices', () => { 11 11 it('should write to filesystem', async () => { 12 12 const client: Parameters<typeof writeClientServices>[0] = { 13 + models: [], 13 14 server: 'http://localhost:8080', 14 - version: 'v1', 15 - models: [], 16 15 services: [ 17 16 { 18 17 $refs: [], ··· 21 20 operations: [], 22 21 }, 23 22 ], 23 + version: 'v1', 24 24 }; 25 25 26 26 await writeClientServices(client, mockTemplates, '/', {
+4 -4
packages/openapi-ts/test/custom/request.ts
··· 10 10 // Do your request... 11 11 const timeout = setTimeout(() => { 12 12 resolve({ 13 - url, 14 - ok: true, 15 - status: 200, 16 - statusText: 'dummy', 17 13 body: { 18 14 ...options, 19 15 }, 16 + ok: true, 17 + status: 200, 18 + statusText: 'dummy', 19 + url, 20 20 }); 21 21 }, 500); 22 22
+2 -2
packages/openapi-ts/test/e2e/assets/main-angular-module.ts
··· 47 47 ) { 48 48 // @ts-ignore 49 49 window.api = { 50 - OpenAPI, 51 50 ApiModule, 52 51 CollectionFormatService: this.collectionFormatService, 53 52 ComplexService: this.complexService, ··· 60 59 MultipleTags2Service: this.multipleTags2Service, 61 60 MultipleTags3Service: this.multipleTags3Service, 62 61 NoContentService: this.noContentService, 62 + OpenAPI, 63 63 ParametersService: this.parametersService, 64 64 ResponseService: this.responseService, 65 65 SimpleService: this.simpleService, ··· 69 69 } 70 70 71 71 @NgModule({ 72 - imports: [BrowserModule, HttpClientModule, ApiModule], 73 72 bootstrap: [AppComponent], 73 + imports: [BrowserModule, HttpClientModule, ApiModule], 74 74 }) 75 75 export class AppModule {} 76 76
+2 -2
packages/openapi-ts/test/e2e/assets/main-angular.ts
··· 46 46 ) { 47 47 // @ts-ignore 48 48 window.api = { 49 - OpenAPI, 50 49 CollectionFormatService: this.collectionFormatService, 51 50 ComplexService: this.complexService, 52 51 DefaultService: this.defaultService, ··· 58 57 MultipleTags2Service: this.multipleTags2Service, 59 58 MultipleTags3Service: this.multipleTags3Service, 60 59 NoContentService: this.noContentService, 60 + OpenAPI, 61 61 ParametersService: this.parametersService, 62 62 ResponseService: this.responseService, 63 63 SimpleService: this.simpleService, ··· 67 67 } 68 68 69 69 @NgModule({ 70 + bootstrap: [AppComponent], 70 71 imports: [BrowserModule, HttpClientModule], 71 72 providers: [ 72 73 CollectionFormatService, ··· 85 86 SimpleService, 86 87 TypesService, 87 88 ], 88 - bootstrap: [AppComponent], 89 89 }) 90 90 export class AppModule {} 91 91
+29 -19
packages/openapi-ts/test/e2e/client.angular.spec.ts
··· 107 107 resolve( 108 108 JSON.stringify({ 109 109 // @ts-ignore 110 - name: e.name, 110 + body: e.body, 111 + 111 112 // @ts-ignore 112 113 message: e.message, 114 + 113 115 // @ts-ignore 114 - url: e.url, 116 + name: e.name, 117 + 115 118 // @ts-ignore 116 119 status: e.status, 120 + 117 121 // @ts-ignore 118 122 statusText: e.statusText, 123 + 119 124 // @ts-ignore 120 - body: e.body, 125 + url: e.url, 121 126 }) 122 127 ); 123 128 }, ··· 126 131 ); 127 132 expect(error).toBe( 128 133 JSON.stringify({ 129 - name: 'ApiError', 134 + body: { 135 + message: 'hello world', 136 + status: 500, 137 + }, 130 138 message: 'Custom message: Internal Server Error', 131 - url: 'http://localhost:3000/base/api/v1.0/error?status=500', 139 + name: 'ApiError', 132 140 status: 500, 133 141 statusText: 'Internal Server Error', 134 - body: { 135 - status: 500, 136 - message: 'hello world', 137 - }, 142 + url: 'http://localhost:3000/base/api/v1.0/error?status=500', 138 143 }) 139 144 ); 140 145 }); ··· 150 155 resolve( 151 156 JSON.stringify({ 152 157 // @ts-ignore 153 - name: e.name, 158 + body: e.body, 159 + 154 160 // @ts-ignore 155 161 message: e.message, 162 + 156 163 // @ts-ignore 157 - url: e.url, 164 + name: e.name, 165 + 158 166 // @ts-ignore 159 167 status: e.status, 168 + 160 169 // @ts-ignore 161 170 statusText: e.statusText, 171 + 162 172 // @ts-ignore 163 - body: e.body, 173 + url: e.url, 164 174 }) 165 175 ); 166 176 }, ··· 170 180 171 181 expect(error).toBe( 172 182 JSON.stringify({ 173 - name: 'ApiError', 174 - message: 175 - 'Generic Error: status: 599; status text: unknown; body: {\n "status": 599,\n "message": "hello world"\n}', 176 - url: 'http://localhost:3000/base/api/v1.0/error?status=599', 177 - status: 599, 178 - statusText: 'unknown', 179 183 body: { 184 + message: 'hello world', 180 185 status: 599, 181 - message: 'hello world', 182 186 }, 187 + message: 188 + 'Generic Error: status: 599; status text: unknown; body: {\n "message": "hello world",\n "status": 599\n}', 189 + name: 'ApiError', 190 + status: 599, 191 + statusText: 'unknown', 192 + url: 'http://localhost:3000/base/api/v1.0/error?status=599', 183 193 }) 184 194 ); 185 195 });
+21 -21
packages/openapi-ts/test/e2e/client.axios.spec.ts
··· 21 21 const { ApiClient } = await import('./generated/client/axios/index.js'); 22 22 const tokenRequest = vi.fn().mockResolvedValue('MY_TOKEN'); 23 23 const client = new ApiClient({ 24 + PASSWORD: undefined, 24 25 TOKEN: tokenRequest, 25 26 USERNAME: undefined, 26 - PASSWORD: undefined, 27 27 }); 28 28 const result = await client.simple.getCallWithoutParametersAndResponse(); 29 29 expect(tokenRequest.mock.calls.length).toBe(1); ··· 34 34 it('uses credentials', async () => { 35 35 const { ApiClient } = await import('./generated/client/axios/index.js'); 36 36 const client = new ApiClient({ 37 + PASSWORD: 'password', 37 38 TOKEN: undefined, 38 39 USERNAME: 'username', 39 - PASSWORD: 'password', 40 40 }); 41 41 const result = await client.simple.getCallWithoutParametersAndResponse(); 42 42 // @ts-ignore ··· 98 98 await client.error.testErrorCode(500); 99 99 } catch (err) { 100 100 error = JSON.stringify({ 101 + body: err.body, 102 + message: err.message, 101 103 name: err.name, 102 - message: err.message, 103 - url: err.url, 104 104 status: err.status, 105 105 statusText: err.statusText, 106 - body: err.body, 106 + url: err.url, 107 107 }); 108 108 } 109 109 expect(error).toBe( 110 110 JSON.stringify({ 111 - name: 'ApiError', 111 + body: { 112 + message: 'hello world', 113 + status: 500, 114 + }, 112 115 message: 'Custom message: Internal Server Error', 113 - url: 'http://localhost:3000/base/api/v1.0/error?status=500', 116 + name: 'ApiError', 114 117 status: 500, 115 118 statusText: 'Internal Server Error', 116 - body: { 117 - status: 500, 118 - message: 'hello world', 119 - }, 119 + url: 'http://localhost:3000/base/api/v1.0/error?status=500', 120 120 }) 121 121 ); 122 122 }); ··· 129 129 await client.error.testErrorCode(599); 130 130 } catch (err) { 131 131 error = JSON.stringify({ 132 + body: err.body, 133 + message: err.message, 132 134 name: err.name, 133 - message: err.message, 134 - url: err.url, 135 135 status: err.status, 136 136 statusText: err.statusText, 137 - body: err.body, 137 + url: err.url, 138 138 }); 139 139 } 140 140 expect(error).toBe( 141 141 JSON.stringify({ 142 + body: { 143 + message: 'hello world', 144 + status: 599, 145 + }, 146 + message: 147 + 'Generic Error: status: 599; status text: unknown; body: {\n "message": "hello world",\n "status": 599\n}', 142 148 name: 'ApiError', 143 - message: 144 - 'Generic Error: status: 599; status text: unknown; body: {\n "status": 599,\n "message": "hello world"\n}', 145 - url: 'http://localhost:3000/base/api/v1.0/error?status=599', 146 149 status: 599, 147 150 statusText: 'unknown', 148 - body: { 149 - status: 599, 150 - message: 'hello world', 151 - }, 151 + url: 'http://localhost:3000/base/api/v1.0/error?status=599', 152 152 }) 153 153 ); 154 154 });
+21 -21
packages/openapi-ts/test/e2e/client.fetch.spec.ts
··· 29 29 // @ts-ignore 30 30 const { ApiClient } = window.api; 31 31 const client = new ApiClient({ 32 + PASSWORD: undefined, 32 33 // @ts-ignore 33 34 TOKEN: window.tokenRequest, 34 35 USERNAME: undefined, 35 - PASSWORD: undefined, 36 36 }); 37 37 return await client.simple.getCallWithoutParametersAndResponse(); 38 38 }); ··· 45 45 // @ts-ignore 46 46 const { ApiClient } = window.api; 47 47 const client = new ApiClient({ 48 + PASSWORD: 'password', 48 49 TOKEN: undefined, 49 50 USERNAME: 'username', 50 - PASSWORD: 'password', 51 51 }); 52 52 return await client.simple.getCallWithoutParametersAndResponse(); 53 53 }); ··· 118 118 await client.error.testErrorCode(500); 119 119 } catch (error) { 120 120 return JSON.stringify({ 121 + body: error.body, 122 + message: error.message, 121 123 name: error.name, 122 - message: error.message, 123 - url: error.url, 124 124 status: error.status, 125 125 statusText: error.statusText, 126 - body: error.body, 126 + url: error.url, 127 127 }); 128 128 } 129 129 return; ··· 131 131 132 132 expect(error).toBe( 133 133 JSON.stringify({ 134 - name: 'ApiError', 134 + body: { 135 + message: 'hello world', 136 + status: 500, 137 + }, 135 138 message: 'Custom message: Internal Server Error', 136 - url: 'http://localhost:3000/base/api/v1.0/error?status=500', 139 + name: 'ApiError', 137 140 status: 500, 138 141 statusText: 'Internal Server Error', 139 - body: { 140 - status: 500, 141 - message: 'hello world', 142 - }, 142 + url: 'http://localhost:3000/base/api/v1.0/error?status=500', 143 143 }) 144 144 ); 145 145 }); ··· 153 153 await client.error.testErrorCode(599); 154 154 } catch (error) { 155 155 return JSON.stringify({ 156 + body: error.body, 157 + message: error.message, 156 158 name: error.name, 157 - message: error.message, 158 - url: error.url, 159 159 status: error.status, 160 160 statusText: error.statusText, 161 - body: error.body, 161 + url: error.url, 162 162 }); 163 163 } 164 164 return; 165 165 }); 166 166 expect(error).toBe( 167 167 JSON.stringify({ 168 + body: { 169 + message: 'hello world', 170 + status: 599, 171 + }, 172 + message: 173 + 'Generic Error: status: 599; status text: unknown; body: {\n "message": "hello world",\n "status": 599\n}', 168 174 name: 'ApiError', 169 - message: 170 - 'Generic Error: status: 599; status text: unknown; body: {\n "status": 599,\n "message": "hello world"\n}', 171 - url: 'http://localhost:3000/base/api/v1.0/error?status=599', 172 175 status: 599, 173 176 statusText: 'unknown', 174 - body: { 175 - status: 599, 176 - message: 'hello world', 177 - }, 177 + url: 'http://localhost:3000/base/api/v1.0/error?status=599', 178 178 }) 179 179 ); 180 180 });
+21 -21
packages/openapi-ts/test/e2e/client.node.spec.ts
··· 21 21 const { ApiClient } = await import('./generated/client/node/index.js'); 22 22 const tokenRequest = vi.fn().mockResolvedValue('MY_TOKEN'); 23 23 const client = new ApiClient({ 24 + PASSWORD: undefined, 24 25 TOKEN: tokenRequest, 25 26 USERNAME: undefined, 26 - PASSWORD: undefined, 27 27 }); 28 28 const result = await client.simple.getCallWithoutParametersAndResponse(); 29 29 expect(tokenRequest.mock.calls.length).toBe(1); ··· 34 34 it('uses credentials', async () => { 35 35 const { ApiClient } = await import('./generated/client/node/index.js'); 36 36 const client = new ApiClient({ 37 + PASSWORD: 'password', 37 38 TOKEN: undefined, 38 39 USERNAME: 'username', 39 - PASSWORD: 'password', 40 40 }); 41 41 const result = await client.simple.getCallWithoutParametersAndResponse(); 42 42 // @ts-ignore ··· 98 98 await client.error.testErrorCode(500); 99 99 } catch (err) { 100 100 error = JSON.stringify({ 101 + body: err.body, 102 + message: err.message, 101 103 name: err.name, 102 - message: err.message, 103 - url: err.url, 104 104 status: err.status, 105 105 statusText: err.statusText, 106 - body: err.body, 106 + url: err.url, 107 107 }); 108 108 } 109 109 expect(error).toBe( 110 110 JSON.stringify({ 111 - name: 'ApiError', 111 + body: { 112 + message: 'hello world', 113 + status: 500, 114 + }, 112 115 message: 'Custom message: Internal Server Error', 113 - url: 'http://localhost:3000/base/api/v1.0/error?status=500', 116 + name: 'ApiError', 114 117 status: 500, 115 118 statusText: 'Internal Server Error', 116 - body: { 117 - status: 500, 118 - message: 'hello world', 119 - }, 119 + url: 'http://localhost:3000/base/api/v1.0/error?status=500', 120 120 }) 121 121 ); 122 122 }); ··· 129 129 await client.error.testErrorCode(599); 130 130 } catch (err) { 131 131 error = JSON.stringify({ 132 + body: err.body, 133 + message: err.message, 132 134 name: err.name, 133 - message: err.message, 134 - url: err.url, 135 135 status: err.status, 136 136 statusText: err.statusText, 137 - body: err.body, 137 + url: err.url, 138 138 }); 139 139 } 140 140 expect(error).toBe( 141 141 JSON.stringify({ 142 + body: { 143 + message: 'hello world', 144 + status: 599, 145 + }, 146 + message: 147 + 'Generic Error: status: 599; status text: unknown; body: {\n "message": "hello world",\n "status": 599\n}', 142 148 name: 'ApiError', 143 - message: 144 - 'Generic Error: status: 599; status text: unknown; body: {\n "status": 599,\n "message": "hello world"\n}', 145 - url: 'http://localhost:3000/base/api/v1.0/error?status=599', 146 149 status: 599, 147 150 statusText: 'unknown', 148 - body: { 149 - status: 599, 150 - message: 'hello world', 151 - }, 151 + url: 'http://localhost:3000/base/api/v1.0/error?status=599', 152 152 }) 153 153 ); 154 154 });
+21 -21
packages/openapi-ts/test/e2e/client.xhr.spec.ts
··· 29 29 // @ts-ignore 30 30 const { ApiClient } = window.api; 31 31 const client = new ApiClient({ 32 + PASSWORD: undefined, 32 33 // @ts-ignore 33 34 TOKEN: window.tokenRequest, 34 35 USERNAME: undefined, 35 - PASSWORD: undefined, 36 36 }); 37 37 return await client.simple.getCallWithoutParametersAndResponse(); 38 38 }); ··· 45 45 // @ts-ignore 46 46 const { ApiClient } = window.api; 47 47 const client = new ApiClient({ 48 + PASSWORD: 'password', 48 49 TOKEN: undefined, 49 50 USERNAME: 'username', 50 - PASSWORD: 'password', 51 51 }); 52 52 return await client.simple.getCallWithoutParametersAndResponse(); 53 53 }); ··· 118 118 await client.error.testErrorCode(500); 119 119 } catch (error) { 120 120 return JSON.stringify({ 121 + body: error.body, 122 + message: error.message, 121 123 name: error.name, 122 - message: error.message, 123 - url: error.url, 124 124 status: error.status, 125 125 statusText: error.statusText, 126 - body: error.body, 126 + url: error.url, 127 127 }); 128 128 } 129 129 return; 130 130 }); 131 131 expect(error).toBe( 132 132 JSON.stringify({ 133 - name: 'ApiError', 133 + body: { 134 + message: 'hello world', 135 + status: 500, 136 + }, 134 137 message: 'Custom message: Internal Server Error', 135 - url: 'http://localhost:3000/base/api/v1.0/error?status=500', 138 + name: 'ApiError', 136 139 status: 500, 137 140 statusText: 'Internal Server Error', 138 - body: { 139 - status: 500, 140 - message: 'hello world', 141 - }, 141 + url: 'http://localhost:3000/base/api/v1.0/error?status=500', 142 142 }) 143 143 ); 144 144 }); ··· 152 152 await client.error.testErrorCode(599); 153 153 } catch (error) { 154 154 return JSON.stringify({ 155 + body: error.body, 156 + message: error.message, 155 157 name: error.name, 156 - message: error.message, 157 - url: error.url, 158 158 status: error.status, 159 159 statusText: error.statusText, 160 - body: error.body, 160 + url: error.url, 161 161 }); 162 162 } 163 163 return; 164 164 }); 165 165 expect(error).toBe( 166 166 JSON.stringify({ 167 + body: { 168 + message: 'hello world', 169 + status: 599, 170 + }, 171 + message: 172 + 'Generic Error: status: 599; status text: unknown; body: {\n "message": "hello world",\n "status": 599\n}', 167 173 name: 'ApiError', 168 - message: 169 - 'Generic Error: status: 599; status text: unknown; body: {\n "status": 599,\n "message": "hello world"\n}', 170 - url: 'http://localhost:3000/base/api/v1.0/error?status=599', 171 174 status: 599, 172 175 statusText: 'unknown', 173 - body: { 174 - status: 599, 175 - message: 'hello world', 176 - }, 176 + url: 'http://localhost:3000/base/api/v1.0/error?status=599', 177 177 }) 178 178 ); 179 179 });
+2 -2
packages/openapi-ts/test/e2e/scripts/browser.ts
··· 29 29 const exposeFunction = async (name: string, fn: Function) => await _page.exposeFunction(name, fn); 30 30 31 31 export default { 32 + evaluate, 33 + exposeFunction, 32 34 start, 33 35 stop, 34 - evaluate, 35 - exposeFunction, 36 36 };
+10 -10
packages/openapi-ts/test/e2e/scripts/compileWithTypescript.ts
··· 15 15 const cwd = `./test/e2e/generated/${dir}/`; 16 16 const tsconfig = { 17 17 compilerOptions: { 18 - target: 'es2020', 19 - module: 'es2020', 20 - moduleResolution: 'node', 21 - lib: ['es2020', 'dom'], 18 + allowSyntheticDefaultImports: true, 22 19 declaration: false, 23 20 declarationMap: false, 24 - sourceMap: false, 21 + experimentalDecorators: true, 22 + lib: ['es2020', 'dom'], 23 + module: 'es2020', 24 + moduleResolution: 'node', 25 + noImplicitAny: true, 25 26 noImplicitReturns: true, 26 27 noImplicitThis: true, 27 - noImplicitAny: true, 28 + skipLibCheck: true, 29 + sourceMap: false, 28 30 strict: true, 29 - skipLibCheck: true, 30 - allowSyntheticDefaultImports: true, 31 - experimentalDecorators: true, 31 + target: 'es2020', 32 32 }, 33 33 include: ['**/*.ts'], 34 34 }; ··· 50 50 const diagnostics = getPreEmitDiagnostics(compiler).concat(result.diagnostics); 51 51 if (diagnostics.length) { 52 52 const message = formatDiagnosticsWithColorAndContext(diagnostics, { 53 - getCurrentDirectory: () => sys.getCurrentDirectory(), 54 53 getCanonicalFileName: f => f, 54 + getCurrentDirectory: () => sys.getCurrentDirectory(), 55 55 getNewLine: () => EOL, 56 56 }); 57 57 console.log(message);
+7 -7
packages/openapi-ts/test/e2e/scripts/server.ts
··· 56 56 // status code from the query and return the default response (and text) from Express. 57 57 // See the spec files for more information. 58 58 _app.all('/base/api/v1.0/error', (req, res) => { 59 - const status = parseInt(String(req.query.status)); 59 + const status = Number.parseInt(String(req.query.status), 10); 60 60 res.status(status).json({ 61 - status, 62 61 message: 'hello world', 62 + status, 63 63 }); 64 64 }); 65 65 ··· 69 69 _app.all('/base/api/v1.0/*', (req, res) => { 70 70 setTimeout(() => { 71 71 res.json({ 72 - method: req.method, 73 - protocol: req.protocol, 72 + body: req.body, 73 + headers: req.headers, 74 74 hostname: req.hostname, 75 + method: req.method, 75 76 path: req.path, 77 + protocol: req.protocol, 78 + query: req.query, 76 79 url: req.url, 77 - query: req.query, 78 - body: req.body, 79 - headers: req.headers, 80 80 }); 81 81 }, 100); 82 82 });
+19 -19
packages/openapi-ts/test/e2e/v3.angular.spec.ts
··· 106 106 }); 107 107 } catch (error) { 108 108 return JSON.stringify({ 109 + body: error.body, 110 + message: error.message, 109 111 name: error.name, 110 - message: error.message, 111 - url: error.url, 112 112 status: error.status, 113 113 statusText: error.statusText, 114 - body: error.body, 114 + url: error.url, 115 115 }); 116 116 } 117 117 return; 118 118 }); 119 119 expect(error).toBe( 120 120 JSON.stringify({ 121 - name: 'ApiError', 121 + body: { 122 + message: 'hello world', 123 + status: 500, 124 + }, 122 125 message: 'Custom message: Internal Server Error', 123 - url: 'http://localhost:3000/base/api/v1.0/error?status=500', 126 + name: 'ApiError', 124 127 status: 500, 125 128 statusText: 'Internal Server Error', 126 - body: { 127 - status: 500, 128 - message: 'hello world', 129 - }, 129 + url: 'http://localhost:3000/base/api/v1.0/error?status=500', 130 130 }) 131 131 ); 132 132 }); ··· 142 142 }); 143 143 } catch (error) { 144 144 return JSON.stringify({ 145 - name: error.name, 145 + body: error.body, 146 146 message: error.message, 147 - url: error.url, 147 + name: error.name, 148 148 status: error.status, 149 149 statusText: error.statusText, 150 - body: error.body, 150 + url: error.url, 151 151 }); 152 152 } 153 153 return; 154 154 }); 155 155 expect(error).toBe( 156 156 JSON.stringify({ 157 + body: { 158 + message: 'hello world', 159 + status: 599, 160 + }, 161 + message: 162 + 'Generic Error: status: 599; status text: unknown; body: {\n "message": "hello world",\n "status": 599\n}', 157 163 name: 'ApiError', 158 - message: 159 - 'Generic Error: status: 599; status text: unknown; body: {\n "status": 599,\n "message": "hello world"\n}', 160 - url: 'http://localhost:3000/base/api/v1.0/error?status=599', 161 164 status: 599, 162 165 statusText: 'unknown', 163 - body: { 164 - status: 599, 165 - message: 'hello world', 166 - }, 166 + url: 'http://localhost:3000/base/api/v1.0/error?status=599', 167 167 }) 168 168 ); 169 169 });
+19 -19
packages/openapi-ts/test/e2e/v3.axios.spec.ts
··· 92 92 await ErrorService.testErrorCode(500); 93 93 } catch (err) { 94 94 error = JSON.stringify({ 95 + body: err.body, 96 + message: err.message, 95 97 name: err.name, 96 - message: err.message, 97 - url: err.url, 98 98 status: err.status, 99 99 statusText: err.statusText, 100 - body: err.body, 100 + url: err.url, 101 101 }); 102 102 } 103 103 expect(error).toBe( 104 104 JSON.stringify({ 105 - name: 'ApiError', 105 + body: { 106 + message: 'hello world', 107 + status: 500, 108 + }, 106 109 message: 'Custom message: Internal Server Error', 107 - url: 'http://localhost:3000/base/api/v1.0/error?status=500', 110 + name: 'ApiError', 108 111 status: 500, 109 112 statusText: 'Internal Server Error', 110 - body: { 111 - status: 500, 112 - message: 'hello world', 113 - }, 113 + url: 'http://localhost:3000/base/api/v1.0/error?status=500', 114 114 }) 115 115 ); 116 116 }); ··· 123 123 await ErrorService.testErrorCode(599); 124 124 } catch (err) { 125 125 error = JSON.stringify({ 126 - name: err.name, 126 + body: err.body, 127 127 message: err.message, 128 - url: err.url, 128 + name: err.name, 129 129 status: err.status, 130 130 statusText: err.statusText, 131 - body: err.body, 131 + url: err.url, 132 132 }); 133 133 } 134 134 expect(error).toBe( 135 135 JSON.stringify({ 136 + body: { 137 + message: 'hello world', 138 + status: 599, 139 + }, 140 + message: 141 + 'Generic Error: status: 599; status text: unknown; body: {\n "message": "hello world",\n "status": 599\n}', 136 142 name: 'ApiError', 137 - message: 138 - 'Generic Error: status: 599; status text: unknown; body: {\n "status": 599,\n "message": "hello world"\n}', 139 - url: 'http://localhost:3000/base/api/v1.0/error?status=599', 140 143 status: 599, 141 144 statusText: 'unknown', 142 - body: { 143 - status: 599, 144 - message: 'hello world', 145 - }, 145 + url: 'http://localhost:3000/base/api/v1.0/error?status=599', 146 146 }) 147 147 ); 148 148 });
+19 -19
packages/openapi-ts/test/e2e/v3.fetch.spec.ts
··· 119 119 await ErrorService.testErrorCode(500); 120 120 } catch (error) { 121 121 return JSON.stringify({ 122 + body: error.body, 123 + message: error.message, 122 124 name: error.name, 123 - message: error.message, 124 - url: error.url, 125 125 status: error.status, 126 126 statusText: error.statusText, 127 - body: error.body, 127 + url: error.url, 128 128 }); 129 129 } 130 130 return; ··· 132 132 133 133 expect(error).toBe( 134 134 JSON.stringify({ 135 - name: 'ApiError', 135 + body: { 136 + message: 'hello world', 137 + status: 500, 138 + }, 136 139 message: 'Custom message: Internal Server Error', 137 - url: 'http://localhost:3000/base/api/v1.0/error?status=500', 140 + name: 'ApiError', 138 141 status: 500, 139 142 statusText: 'Internal Server Error', 140 - body: { 141 - status: 500, 142 - message: 'hello world', 143 - }, 143 + url: 'http://localhost:3000/base/api/v1.0/error?status=500', 144 144 }) 145 145 ); 146 146 }); ··· 153 153 await ErrorService.testErrorCode(599); 154 154 } catch (error) { 155 155 return JSON.stringify({ 156 - name: error.name, 156 + body: error.body, 157 157 message: error.message, 158 - url: error.url, 158 + name: error.name, 159 159 status: error.status, 160 160 statusText: error.statusText, 161 - body: error.body, 161 + url: error.url, 162 162 }); 163 163 } 164 164 return; 165 165 }); 166 166 expect(error).toBe( 167 167 JSON.stringify({ 168 + body: { 169 + message: 'hello world', 170 + status: 599, 171 + }, 172 + message: 173 + 'Generic Error: status: 599; status text: unknown; body: {\n "message": "hello world",\n "status": 599\n}', 168 174 name: 'ApiError', 169 - message: 170 - 'Generic Error: status: 599; status text: unknown; body: {\n "status": 599,\n "message": "hello world"\n}', 171 - url: 'http://localhost:3000/base/api/v1.0/error?status=599', 172 175 status: 599, 173 176 statusText: 'unknown', 174 - body: { 175 - status: 599, 176 - message: 'hello world', 177 - }, 177 + url: 'http://localhost:3000/base/api/v1.0/error?status=599', 178 178 }) 179 179 ); 180 180 });
+19 -19
packages/openapi-ts/test/e2e/v3.node.spec.ts
··· 98 98 await ErrorService.testErrorCode(500); 99 99 } catch (err) { 100 100 error = JSON.stringify({ 101 + body: err.body, 102 + message: err.message, 101 103 name: err.name, 102 - message: err.message, 103 - url: err.url, 104 104 status: err.status, 105 105 statusText: err.statusText, 106 - body: err.body, 106 + url: err.url, 107 107 }); 108 108 } 109 109 expect(error).toBe( 110 110 JSON.stringify({ 111 - name: 'ApiError', 111 + body: { 112 + message: 'hello world', 113 + status: 500, 114 + }, 112 115 message: 'Custom message: Internal Server Error', 113 - url: 'http://localhost:3000/base/api/v1.0/error?status=500', 116 + name: 'ApiError', 114 117 status: 500, 115 118 statusText: 'Internal Server Error', 116 - body: { 117 - status: 500, 118 - message: 'hello world', 119 - }, 119 + url: 'http://localhost:3000/base/api/v1.0/error?status=500', 120 120 }) 121 121 ); 122 122 }); ··· 129 129 await ErrorService.testErrorCode(599); 130 130 } catch (err) { 131 131 error = JSON.stringify({ 132 - name: err.name, 132 + body: err.body, 133 133 message: err.message, 134 - url: err.url, 134 + name: err.name, 135 135 status: err.status, 136 136 statusText: err.statusText, 137 - body: err.body, 137 + url: err.url, 138 138 }); 139 139 } 140 140 expect(error).toBe( 141 141 JSON.stringify({ 142 + body: { 143 + message: 'hello world', 144 + status: 599, 145 + }, 146 + message: 147 + 'Generic Error: status: 599; status text: unknown; body: {\n "message": "hello world",\n "status": 599\n}', 142 148 name: 'ApiError', 143 - message: 144 - 'Generic Error: status: 599; status text: unknown; body: {\n "status": 599,\n "message": "hello world"\n}', 145 - url: 'http://localhost:3000/base/api/v1.0/error?status=599', 146 149 status: 599, 147 150 statusText: 'unknown', 148 - body: { 149 - status: 599, 150 - message: 'hello world', 151 - }, 151 + url: 'http://localhost:3000/base/api/v1.0/error?status=599', 152 152 }) 153 153 ); 154 154 });
+19 -19
packages/openapi-ts/test/e2e/v3.xhr.spec.ts
··· 110 110 await ErrorService.testErrorCode(500); 111 111 } catch (error) { 112 112 return JSON.stringify({ 113 + body: error.body, 114 + message: error.message, 113 115 name: error.name, 114 - message: error.message, 115 - url: error.url, 116 116 status: error.status, 117 117 statusText: error.statusText, 118 - body: error.body, 118 + url: error.url, 119 119 }); 120 120 } 121 121 return; 122 122 }); 123 123 expect(error).toBe( 124 124 JSON.stringify({ 125 - name: 'ApiError', 125 + body: { 126 + message: 'hello world', 127 + status: 500, 128 + }, 126 129 message: 'Custom message: Internal Server Error', 127 - url: 'http://localhost:3000/base/api/v1.0/error?status=500', 130 + name: 'ApiError', 128 131 status: 500, 129 132 statusText: 'Internal Server Error', 130 - body: { 131 - status: 500, 132 - message: 'hello world', 133 - }, 133 + url: 'http://localhost:3000/base/api/v1.0/error?status=500', 134 134 }) 135 135 ); 136 136 }); ··· 143 143 await ErrorService.testErrorCode(599); 144 144 } catch (error) { 145 145 return JSON.stringify({ 146 - name: error.name, 146 + body: error.body, 147 147 message: error.message, 148 - url: error.url, 148 + name: error.name, 149 149 status: error.status, 150 150 statusText: error.statusText, 151 - body: error.body, 151 + url: error.url, 152 152 }); 153 153 } 154 154 return; 155 155 }); 156 156 expect(error).toBe( 157 157 JSON.stringify({ 158 + body: { 159 + message: 'hello world', 160 + status: 599, 161 + }, 162 + message: 163 + 'Generic Error: status: 599; status text: unknown; body: {\n "message": "hello world",\n "status": 599\n}', 158 164 name: 'ApiError', 159 - message: 160 - 'Generic Error: status: 599; status text: unknown; body: {\n "status": 599,\n "message": "hello world"\n}', 161 - url: 'http://localhost:3000/base/api/v1.0/error?status=599', 162 165 status: 599, 163 166 statusText: 'unknown', 164 - body: { 165 - status: 599, 166 - message: 'hello world', 167 - }, 167 + url: 'http://localhost:3000/base/api/v1.0/error?status=599', 168 168 }) 169 169 ); 170 170 });
+28 -28
packages/openapi-ts/test/index.spec.ts
··· 16 16 describe('OpenAPI v2', () => { 17 17 it.each([ 18 18 { 19 - description: 'generate fetch client', 20 - name: 'v2', 21 19 config: { 22 20 client: 'fetch', 23 21 enums: 'javascript', ··· 27 25 exportServices: true, 28 26 useOptions: true, 29 27 } as UserConfig, 28 + description: 'generate fetch client', 29 + name: 'v2', 30 30 }, 31 31 ])('$description', async ({ name, config }) => { 32 32 const output = toOutputPath(name); ··· 45 45 describe('OpenAPI v3', () => { 46 46 it.each([ 47 47 { 48 - description: 'generate fetch client', 49 - name: 'v3', 50 48 config: { 51 49 client: 'fetch', 52 50 enums: 'javascript', ··· 56 54 exportServices: true, 57 55 useOptions: true, 58 56 } as UserConfig, 57 + description: 'generate fetch client', 58 + name: 'v3', 59 59 }, 60 60 { 61 - description: 'generate angular client', 62 - name: 'v3_angular', 63 61 config: { 64 62 client: 'angular', 65 63 enums: false, ··· 69 67 exportServices: true, 70 68 useOptions: true, 71 69 } as UserConfig, 70 + description: 'generate angular client', 71 + name: 'v3_angular', 72 72 }, 73 73 { 74 - description: 'generate node client', 75 - name: 'v3_node', 76 74 config: { 77 75 client: 'node', 78 76 enums: false, ··· 82 80 exportServices: false, 83 81 useOptions: true, 84 82 } as UserConfig, 83 + description: 'generate node client', 84 + name: 'v3_node', 85 85 }, 86 86 { 87 - description: 'generate axios client', 88 - name: 'v3_axios', 89 87 config: { 90 88 client: 'axios', 91 89 enums: false, ··· 95 93 exportServices: false, 96 94 useOptions: true, 97 95 } as UserConfig, 96 + description: 'generate axios client', 97 + name: 'v3_axios', 98 98 }, 99 99 { 100 - description: 'generate xhr client', 101 - name: 'v3_xhr', 102 100 config: { 103 101 client: 'xhr', 104 102 enums: false, ··· 108 106 exportServices: false, 109 107 useOptions: true, 110 108 } as UserConfig, 109 + description: 'generate xhr client', 110 + name: 'v3_xhr', 111 111 }, 112 112 { 113 - description: 'generate Date types', 114 - name: 'v3_date', 115 113 config: { 116 114 client: 'fetch', 117 115 enums: 'javascript', ··· 119 117 exportModels: '^ModelWithPattern', 120 118 exportSchemas: true, 121 119 exportServices: false, 122 - useOptions: true, 123 120 useDateType: true, 121 + useOptions: true, 124 122 } as UserConfig, 123 + description: 'generate Date types', 124 + name: 'v3_date', 125 125 }, 126 126 { 127 - description: 'generate optional arguments', 128 - name: 'v3_options', 129 127 config: { 130 128 client: 'fetch', 131 129 enums: 'javascript', ··· 133 131 exportModels: '^ModelWithString', 134 132 exportSchemas: false, 135 133 exportServices: '^Defaults', 136 - useOptions: true, 137 134 useDateType: true, 135 + useOptions: true, 138 136 } as UserConfig, 137 + description: 'generate optional arguments', 138 + name: 'v3_options', 139 139 }, 140 140 { 141 - description: 'generate client', 142 - name: 'v3_client', 143 141 config: { 144 142 client: 'fetch', 145 143 enums: 'javascript', ··· 147 145 exportModels: true, 148 146 exportSchemas: false, 149 147 exportServices: true, 150 - useOptions: true, 151 - useDateType: true, 152 148 name: 'ApiClient', 149 + useDateType: true, 150 + useOptions: true, 153 151 } as UserConfig, 152 + description: 'generate client', 153 + name: 'v3_client', 154 154 }, 155 155 { 156 - description: 'generate TypeScript enums', 157 - name: 'v3_enums_typescript', 158 156 config: { 159 157 client: 'fetch', 160 158 enums: 'typescript', ··· 164 162 exportServices: true, 165 163 useOptions: true, 166 164 } as UserConfig, 165 + description: 'generate TypeScript enums', 166 + name: 'v3_enums_typescript', 167 167 }, 168 168 { 169 - description: 'generate models', 170 - name: 'v3_models', 171 169 config: { 172 170 client: 'fetch', 173 171 exportCore: false, ··· 175 173 exportSchemas: false, 176 174 exportServices: false, 177 175 } as UserConfig, 176 + description: 'generate models', 177 + name: 'v3_models', 178 178 }, 179 179 { 180 - description: 'generate experimental build', 181 - name: 'v3_experimental', 182 180 config: { 183 181 client: 'fetch', 184 182 experimental: true, 185 183 } as UserConfig, 184 + description: 'generate experimental build', 185 + name: 'v3_experimental', 186 186 }, 187 187 ])('$description', async ({ name, config }) => { 188 188 const output = toOutputPath(name);
+4 -4
packages/openapi-ts/vitest.config.unit.ts
··· 7 7 export default defineConfig({ 8 8 plugins: [handlebarsPlugin()], 9 9 test: { 10 - exclude: [...configDefaults.exclude, 'test/e2e/**/*.spec.ts'], 11 - root: fileURLToPath(new URL('./', import.meta.url)), 12 10 coverage: { 13 - provider: 'v8', 14 - include: ['src/**/*.ts'], 15 11 exclude: ['bin', 'dist', 'src/**/*.d.ts'], 12 + include: ['src/**/*.ts'], 13 + provider: 'v8', 16 14 }, 15 + exclude: [...configDefaults.exclude, 'test/e2e/**/*.spec.ts'], 16 + root: fileURLToPath(new URL('./', import.meta.url)), 17 17 }, 18 18 });