-
-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIx serialization/deserialization in additionalProperties (#822)
- Loading branch information
1 parent
1a1b2cc
commit a9067b8
Showing
3 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import * as express from 'express'; | ||
import { Server } from 'http'; | ||
import * as request from 'supertest'; | ||
import * as OpenApiValidator from '../src'; | ||
import { OpenAPIV3 } from '../src/framework/types'; | ||
import { startServer } from './common/app.common'; | ||
import { deepStrictEqual } from 'assert'; | ||
import * as path from 'path'; | ||
|
||
|
||
const apiSpecPath = path.join('test', 'resources', '699.yaml'); | ||
|
||
const date = new Date() | ||
describe('issue #821 - serialization inside addiotionalProperties', () => { | ||
it('serializa both outer and inner date in addiotionalProperties', async () => { | ||
|
||
const app = await createApp(apiSpecPath); | ||
await request(app).get('/test').expect(200, | ||
{ | ||
outer_date: date.toISOString(), | ||
other_info: { | ||
something: { | ||
inner_date: date.toISOString() | ||
} | ||
} | ||
} | ||
); | ||
app.server!.close(); | ||
}); | ||
}); | ||
|
||
async function createApp( | ||
apiSpec: OpenAPIV3.Document | string, | ||
): Promise<express.Express & { server?: Server }> { | ||
const app = express(); | ||
|
||
app.use( | ||
OpenApiValidator.middleware({ | ||
apiSpec: apiSpecPath, | ||
validateRequests: true, | ||
validateResponses: true, | ||
}), | ||
); | ||
app.get('/test', (req, res) => { | ||
return res.status(200).json({ | ||
outer_date: date, | ||
other_info: { | ||
something: { | ||
inner_date: date | ||
} | ||
} | ||
}) | ||
|
||
}) | ||
|
||
app.use((err, req, res, next) => { | ||
console.error(err); // dump error to console for debug | ||
res.status(err.status || 500).json({ | ||
message: err.message, | ||
errors: err.errors, | ||
}); | ||
}); | ||
|
||
await startServer(app, 3001); | ||
return app; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
openapi: 3.0.3 | ||
info: | ||
version: 1.0.0 | ||
title: Test additionalProperties date-time | ||
paths: | ||
/test: | ||
get: | ||
responses: | ||
'200': | ||
description: foo | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
outer_date: | ||
type: string | ||
format: date-time | ||
other_info: | ||
type: object | ||
additionalProperties: | ||
type: object | ||
properties: | ||
inner_date: | ||
type: string | ||
format: date-time |