diff --git a/test/issue_589.spec.ts b/test/issue_589.spec.ts new file mode 100644 index 00000000..45847e92 --- /dev/null +++ b/test/issue_589.spec.ts @@ -0,0 +1,35 @@ +import * as path from 'path'; +import * as express from 'express'; +import * as request from 'supertest'; +import * as assert from 'assert'; +import { createApp } from './common/app'; + +describe("DateFormats", () => { + let app = null; + + before(async () => { + // Set up the express app + const apiSpec = path.join('test', 'resources', 'issue_589.yaml'); + app = await createApp({ apiSpec }, 1996, (app) => + app.use( + `${app.basePath}`, + express.Router().get(`/user`, (req, res) => res.json({id: 0, name: "Nick", date: new Date("1996-01-03T22:00:00.000Z")})), + ), + ); + }); + + after(() => { + app.server.close(); + }); + + it('should get the correct date', async () => + request(app) + .get(`${app.basePath}/user`) + .expect(200).then((res)=> + { + assert.strictEqual(res.body.id, 0); + assert.strictEqual(res.body.name, "Nick"); + assert.strictEqual(res.body.date, "1996-01-04"); + }) + ); +}); diff --git a/test/resources/issue_589.yaml b/test/resources/issue_589.yaml new file mode 100644 index 00000000..b45e0cd9 --- /dev/null +++ b/test/resources/issue_589.yaml @@ -0,0 +1,54 @@ +openapi: 3.0.0 +servers: + # Added by API Auto Mocking Plugin + - description: SwaggerHub API Auto Mocking + url: https://virtserver.swaggerhub.com/babaliaris/test/1.0.0 + - description: My Computer + url: http://localhost:1996 + - description: Express Open Api Validator + url: /v1/ +info: + description: This is a simple API + version: "1.0.0" + title: Simple Inventory API + contact: + email: you@your-company.com + license: + name: Apache 2.0 + url: 'http://www.apache.org/licenses/LICENSE-2.0.html' + +paths: + /user: + get: + tags: + - Users + summary: Get a user. + operationId: getUser + + responses: + + '200': + description: Get the json user data. + content: + application/json: + schema: + $ref: '#/components/schemas/User' + default: + description: Something went wrong. + +components: + schemas: + User: + type: object + required: + - id + - name + - date + properties: + id: + type: integer + name: + type: string + date: + type: string + format: date \ No newline at end of file