|
| 1 | +import * as express from 'express'; |
| 2 | +import { Server } from 'http'; |
| 3 | +import * as request from 'supertest'; |
| 4 | +import * as OpenApiValidator from '../src'; |
| 5 | +import { OpenAPIV3 } from '../src/framework/types'; |
| 6 | +import { startServer } from './common/app.common'; |
| 7 | +import { deepStrictEqual } from 'assert'; |
| 8 | +import * as path from 'path'; |
| 9 | + |
| 10 | + |
| 11 | +const apiSpecPath = path.join('test', 'resources', '699.yaml'); |
| 12 | + |
| 13 | +const date = new Date() |
| 14 | +describe('issue #821 - serialization inside addiotionalProperties', () => { |
| 15 | + it('serializa both outer and inner date in addiotionalProperties', async () => { |
| 16 | + |
| 17 | + const app = await createApp(apiSpecPath); |
| 18 | + await request(app).get('/test').expect(200, |
| 19 | + { |
| 20 | + outer_date: date.toISOString(), |
| 21 | + other_info: { |
| 22 | + something: { |
| 23 | + inner_date: date.toISOString() |
| 24 | + } |
| 25 | + } |
| 26 | + } |
| 27 | + ); |
| 28 | + app.server!.close(); |
| 29 | + }); |
| 30 | +}); |
| 31 | + |
| 32 | +async function createApp( |
| 33 | + apiSpec: OpenAPIV3.Document | string, |
| 34 | +): Promise<express.Express & { server?: Server }> { |
| 35 | + const app = express(); |
| 36 | + |
| 37 | + app.use( |
| 38 | + OpenApiValidator.middleware({ |
| 39 | + apiSpec: apiSpecPath, |
| 40 | + validateRequests: true, |
| 41 | + validateResponses: true, |
| 42 | + }), |
| 43 | + ); |
| 44 | + app.get('/test', (req, res) => { |
| 45 | + return res.status(200).json({ |
| 46 | + outer_date: date, |
| 47 | + other_info: { |
| 48 | + something: { |
| 49 | + inner_date: date |
| 50 | + } |
| 51 | + } |
| 52 | + }) |
| 53 | + |
| 54 | + }) |
| 55 | + |
| 56 | + app.use((err, req, res, next) => { |
| 57 | + console.error(err); // dump error to console for debug |
| 58 | + res.status(err.status || 500).json({ |
| 59 | + message: err.message, |
| 60 | + errors: err.errors, |
| 61 | + }); |
| 62 | + }); |
| 63 | + |
| 64 | + await startServer(app, 3001); |
| 65 | + return app; |
| 66 | +} |
| 67 | + |
| 68 | + |
0 commit comments