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.

fix: address code smells in NestJS example

Remove unnecessary type casts in pets controller, add ValidationPipe and
HttpExceptionFilter to test setup to match production, guard top-level
side effect in main.ts, move eslint ignores before rules, and remove
unused supertest dependency.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

+30 -93
+3 -3
examples/openapi-ts-nestjs/eslint.config.js
··· 2 2 import tseslint from 'typescript-eslint'; 3 3 4 4 export default [ 5 + { 6 + ignores: ['src/client/**'], 7 + }, 5 8 ...tseslint.configs.recommended, 6 9 nestjsTyped.flatRecommended, 7 10 { ··· 11 14 project: './tsconfig.json', 12 15 }, 13 16 }, 14 - }, 15 - { 16 - ignores: ['src/client/**'], 17 17 }, 18 18 ];
-1
examples/openapi-ts-nestjs/package.json
··· 25 25 "@swc/core": "^1.11.29", 26 26 "eslint": "^9.18.0", 27 27 "oxfmt": "^0.27.0", 28 - "supertest": "^7.1.0", 29 28 "typescript": "^5.9.3", 30 29 "typescript-eslint": "^8.20.0", 31 30 "unplugin-swc": "^1.5.5",
+8 -5
examples/openapi-ts-nestjs/src/main.ts
··· 30 30 return app; 31 31 }; 32 32 33 - buildApp().then((app) => { 34 - app.listen(3000).catch((err: unknown) => { 35 - console.error(err); 36 - process.exit(1); 33 + const isEntryPoint = process.argv[1]?.includes('main'); 34 + if (isEntryPoint) { 35 + buildApp().then((app) => { 36 + app.listen(3000).catch((err: unknown) => { 37 + console.error(err); 38 + process.exit(1); 39 + }); 37 40 }); 38 - }); 41 + }
+7 -9
examples/openapi-ts-nestjs/src/pets/pets.controller.ts
··· 14 14 15 15 import type { PetsControllerMethods } from '../client/nestjs.gen'; 16 16 import type { 17 - CreatePetData, 18 17 DeletePetData, 19 18 ListPetsData, 20 19 Pet, ··· 63 62 id: crypto.randomUUID(), 64 63 name: body.name, 65 64 status: 'available', 66 - tag: (body as CreatePetData['body']).tag, 65 + tag: body.tag, 67 66 }; 68 67 this.pets.push(pet); 69 68 return pet; ··· 91 90 if (!pet) { 92 91 throw new NotFoundException(`Pet ${path.petId} not found`); 93 92 } 94 - const update = body as UpdatePetData['body']; 95 - if (update.name !== undefined) { 96 - pet.name = update.name; 93 + if (body.name !== undefined) { 94 + pet.name = body.name; 97 95 } 98 - if (update.tag !== undefined) { 99 - pet.tag = update.tag; 96 + if (body.tag !== undefined) { 97 + pet.tag = body.tag; 100 98 } 101 - if (update.status !== undefined) { 102 - pet.status = update.status; 99 + if (body.status !== undefined) { 100 + pet.status = body.status; 103 101 } 104 102 return pet; 105 103 }
+10
examples/openapi-ts-nestjs/test/pets.test.ts
··· 1 1 import type { INestApplication } from '@nestjs/common'; 2 + import { ValidationPipe } from '@nestjs/common'; 2 3 import { Test } from '@nestjs/testing'; 3 4 import type { AddressInfo } from 'net'; 4 5 import { AppModule } from 'src/app.module'; 5 6 import { createPet, deletePet, getInventory, listPets, showPetById, updatePet } from 'src/client'; 6 7 import { client } from 'src/client/client.gen'; 8 + import { HttpExceptionFilter } from 'src/common/filters/http-exception.filter'; 7 9 8 10 let app: INestApplication; 9 11 ··· 13 15 }).compile(); 14 16 15 17 app = moduleRef.createNestApplication(); 18 + app.useGlobalPipes( 19 + new ValidationPipe({ 20 + forbidUnknownValues: true, 21 + transform: true, 22 + whitelist: true, 23 + }), 24 + ); 25 + app.useGlobalFilters(new HttpExceptionFilter()); 16 26 await app.init(); 17 27 await app.listen(0); 18 28
+2 -75
pnpm-lock.yaml
··· 642 642 oxfmt: 643 643 specifier: ^0.27.0 644 644 version: 0.27.0 645 - supertest: 646 - specifier: ^7.1.0 647 - version: 7.1.0 648 645 typescript: 649 646 specifier: ^5.9.3 650 647 version: 5.9.3 ··· 5773 5770 cpu: [x64] 5774 5771 os: [win32] 5775 5772 5776 - '@paralleldrive/cuid2@2.3.1': 5777 - resolution: {integrity: sha512-XO7cAxhnTZl0Yggq6jOgjiOHhbgcO4NqFqwSmQpjK3b6TEE6Uj/jfSk6wzYyemh3+I0sHirKSetjQwn5cZktFw==} 5778 - 5779 5773 '@parcel/watcher-android-arm64@2.5.1': 5780 5774 resolution: {integrity: sha512-KF8+j9nNbUN8vzOFDpRMsaKBHZ/mcjEjMToVMJOhTozkDonQFFrRcfdLWn6yWKCmJKmdVxSgHiYvTCef4/qcBA==} 5781 5775 engines: {node: '>= 10.0.0'} ··· 8513 8507 resolution: {integrity: sha512-BNoCY6SXXPQ7gF2opIP4GBE+Xw7U+pHMYKuzjgCN3GwiaIR09UUeKfheyIry77QtrCBlC0KK0q5/TER/tYh3PQ==} 8514 8508 engines: {node: '>= 0.4'} 8515 8509 8516 - asap@2.0.6: 8517 - resolution: {integrity: sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==} 8518 - 8519 8510 ast-kit@1.4.3: 8520 8511 resolution: {integrity: sha512-MdJqjpodkS5J149zN0Po+HPshkTdUyrvF7CKTafUgv69vBSPtncrj+3IiUgqdd7ElIEkbeXCsEouBUwLrw9Ilg==} 8521 8512 engines: {node: '>=16.14.0'} ··· 9071 9062 compatx@0.2.0: 9072 9063 resolution: {integrity: sha512-6gLRNt4ygsi5NyMVhceOCFv14CIdDFN7fQjX1U4+47qVE/+kjPoXMK65KWK+dWxmFzMTuKazoQ9sch6pM0p5oA==} 9073 9064 9074 - component-emitter@1.3.1: 9075 - resolution: {integrity: sha512-T0+barUSQRTUQASh8bx02dl+DhF54GtIDY13Y3m9oWTklKbb3Wv974meRpeZ3lp1JpLVECWWNHC4vaG2XHXouQ==} 9076 - 9077 9065 compress-commons@6.0.2: 9078 9066 resolution: {integrity: sha512-6FqVXeETqWPoGcfzrXb37E50NP0LXT8kAMu5ooZayhWWdgEY4lBEEcbQNXtkuKQsGduxiIcI4gOTsxTmuq/bSg==} 9079 9067 engines: {node: '>= 14'} ··· 9161 9149 resolution: {integrity: sha512-9Kr/j4O16ISv8zBBhJoi4bXOYNTkFLOqSL3UDB0njXxCXNezjeyVrJyGOWtgfs/q2km1gwBcfH8q1yEGoMYunA==} 9162 9150 engines: {node: '>=18'} 9163 9151 9164 - cookiejar@2.1.4: 9165 - resolution: {integrity: sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==} 9166 - 9167 9152 copy-anything@2.0.6: 9168 9153 resolution: {integrity: sha512-1j20GZTsvKNkc4BY3NpMOM8tt///wY3FpIzozTOFO2ffuZcV61nojHXVKIy3WM+7ADCy5FVhdZYHYDdgTU0yJw==} 9169 9154 ··· 9609 9594 9610 9595 devlop@1.1.0: 9611 9596 resolution: {integrity: sha512-RWmIqhcFf1lRYBvNmr7qTNuyCt/7/ns2jbpp1+PalgE/rDQcBT0fioSMUpJ93irlUhC5hrg4cYqe6U+0ImW0rA==} 9612 - 9613 - dezalgo@1.0.4: 9614 - resolution: {integrity: sha512-rXSP0bf+5n0Qonsb+SVVfNfIsimO4HEtmnIpPHY8Q1UCzKlQrDMfdobr8nJOOsRgWCyMRqeSBQzmWUMq7zvVig==} 9615 9597 9616 9598 di@0.0.1: 9617 9599 resolution: {integrity: sha512-uJaamHkagcZtHPqCIHZxnFrXlunQXgBOsZSUOWwFw31QJCAbyTBoHMW75YOTur5ZNx8pIeAKgf6GWIgaqqiLhA==} ··· 10462 10444 resolution: {integrity: sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==} 10463 10445 engines: {node: '>=12.20.0'} 10464 10446 10465 - formidable@3.5.4: 10466 - resolution: {integrity: sha512-YikH+7CUTOtP44ZTnUhR7Ic2UASBPOqmaRkRKxRbywPTe5VxF7RRCck4af9wutiZ/QKM5nME9Bie2fFaPz5Gug==} 10467 - engines: {node: '>=14.0.0'} 10468 - 10469 10447 forwarded@0.2.0: 10470 10448 resolution: {integrity: sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==} 10471 10449 engines: {node: '>= 0.6'} ··· 14424 14402 engines: {node: '>=16 || 14 >=14.17'} 14425 14403 hasBin: true 14426 14404 14427 - superagent@9.0.2: 14428 - resolution: {integrity: sha512-xuW7dzkUpcJq7QnhOsnNUgtYp3xRwpt2F7abdRYIpCsAt0hhUqia0EdxyXZQQpNmGtsCzYHryaKSV3q3GJnq7w==} 14429 - engines: {node: '>=14.18.0'} 14430 - deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net 14431 - 14432 14405 superjson@2.2.2: 14433 14406 resolution: {integrity: sha512-5JRxVqC8I8NuOUjzBbvVJAKNM8qoVuH0O77h4WInc/qC2q5IreqKxYwgkga3PfA22OayK2ikceb/B26dztPl+Q==} 14434 14407 engines: {node: '>=16'} 14435 - 14436 - supertest@7.1.0: 14437 - resolution: {integrity: sha512-5QeSO8hSrKghtcWEoPiO036fxH0Ii2wVQfFZSP0oqQhmjk8bOLhDFXr4JrvaFmPuEWUoq4znY3uSi8UzLKxGqw==} 14438 - engines: {node: '>=14.18.0'} 14439 - deprecated: Please upgrade to supertest v7.1.3+, see release notes at https://github.com/forwardemail/supertest/releases/tag/v7.1.3 - maintenance is supported by Forward Email @ https://forwardemail.net 14440 14408 14441 14409 supports-color@10.2.0: 14442 14410 resolution: {integrity: sha512-5eG9FQjEjDbAlI5+kdpdyPIBMRH4GfTVDGREVupaZHmVoppknhM29b/S9BkQz7cathp85BVgRi/As3Siln7e0Q==} ··· 20045 20013 typescript: 5.9.3 20046 20014 webpack: 5.104.1(@swc/core@1.11.29)(esbuild@0.27.2) 20047 20015 20048 - '@noble/hashes@1.8.0': {} 20016 + '@noble/hashes@1.8.0': 20017 + optional: true 20049 20018 20050 20019 '@nodelib/fs.scandir@2.1.5': 20051 20020 dependencies: ··· 21200 21169 21201 21170 '@oxfmt/win32-x64@0.28.0': 21202 21171 optional: true 21203 - 21204 - '@paralleldrive/cuid2@2.3.1': 21205 - dependencies: 21206 - '@noble/hashes': 1.8.0 21207 21172 21208 21173 '@parcel/watcher-android-arm64@2.5.1': 21209 21174 optional: true ··· 24284 24249 get-intrinsic: 1.3.0 24285 24250 is-array-buffer: 3.0.5 24286 24251 24287 - asap@2.0.6: {} 24288 - 24289 24252 ast-kit@1.4.3: 24290 24253 dependencies: 24291 24254 '@babel/parser': 7.29.0 ··· 24950 24913 24951 24914 compatx@0.2.0: {} 24952 24915 24953 - component-emitter@1.3.1: {} 24954 - 24955 24916 compress-commons@6.0.2: 24956 24917 dependencies: 24957 24918 crc-32: 1.2.2 ··· 25034 24995 cookie@0.7.2: {} 25035 24996 25036 24997 cookie@1.0.2: {} 25037 - 25038 - cookiejar@2.1.4: {} 25039 24998 25040 24999 copy-anything@2.0.6: 25041 25000 dependencies: ··· 25462 25421 devlop@1.1.0: 25463 25422 dependencies: 25464 25423 dequal: 2.0.3 25465 - 25466 - dezalgo@1.0.4: 25467 - dependencies: 25468 - asap: 2.0.6 25469 - wrappy: 1.0.2 25470 25424 25471 25425 di@0.0.1: {} 25472 25426 ··· 26807 26761 formdata-polyfill@4.0.10: 26808 26762 dependencies: 26809 26763 fetch-blob: 3.2.0 26810 - 26811 - formidable@3.5.4: 26812 - dependencies: 26813 - '@paralleldrive/cuid2': 2.3.1 26814 - dezalgo: 1.0.4 26815 - once: 1.4.0 26816 26764 26817 26765 forwarded@0.2.0: {} 26818 26766 ··· 32333 32281 pirates: 4.0.7 32334 32282 ts-interface-checker: 0.1.13 32335 32283 32336 - superagent@9.0.2: 32337 - dependencies: 32338 - component-emitter: 1.3.1 32339 - cookiejar: 2.1.4 32340 - debug: 4.4.3 32341 - fast-safe-stringify: 2.1.1 32342 - form-data: 4.0.4 32343 - formidable: 3.5.4 32344 - methods: 1.1.2 32345 - mime: 2.6.0 32346 - qs: 6.14.1 32347 - transitivePeerDependencies: 32348 - - supports-color 32349 - 32350 32284 superjson@2.2.2: 32351 32285 dependencies: 32352 32286 copy-anything: 3.0.5 32353 - 32354 - supertest@7.1.0: 32355 - dependencies: 32356 - methods: 1.1.2 32357 - superagent: 9.0.2 32358 - transitivePeerDependencies: 32359 - - supports-color 32360 32287 32361 32288 supports-color@10.2.0: {} 32362 32289