Skip to content

Commit 7ccbb54

Browse files
committed
feat: update to latest openapi-police
BREAKING CHANGE: json schema format clauses are now validated and validated and can produce errors in existing code
1 parent eff9647 commit 7ccbb54

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
"luxon": "^2.3.1",
128128
"mongodb": "^4.4.0",
129129
"needle": "^3.0.0",
130-
"openapi-police": "^2.0.0",
130+
"openapi-police": "^3.0.0",
131131
"rql": "^0.3.3",
132132
"semver": "^7.3.5"
133133
},

test/ts/mongo.test.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import * as express from 'express';
66
import * as _ from 'lodash';
77
import { CollectionOptions, MongoClient, ReadPreference } from 'mongodb';
88
import { DokiConfiguration, Mongodoki } from 'mongodoki';
9+
import { OpenAPIV3 } from 'openapi-police';
910
import * as supertest from 'supertest';
1011
import { API } from '../../dist/api';
11-
import { MongoJob, MongoOperation, MongoResource, PatchMongoOperation, QueryMongoOperation } from '../../dist/mongo/index';
12+
import { CreateMongoOperation, MongoJob, MongoOperation, MongoResource, PatchMongoOperation, QueryMongoOperation } from '../../dist/mongo/index';
1213
import { APIRequest, APIResponse, Method } from '../../dist/types';
1314

1415
const should = chai.should();
@@ -195,7 +196,21 @@ describe('mongo', function () {
195196
}
196197
}
197198

198-
let db, id, coll, coll2, r1, r2, r3, r4, r5, r6, r7, server;
199+
class DateOp extends CreateMongoOperation {
200+
get requestSchema(): OpenAPIV3.SchemaObject {
201+
return {
202+
type: 'object',
203+
properties: {
204+
ts: {
205+
type: 'string',
206+
format: 'date-time',
207+
},
208+
},
209+
};
210+
}
211+
}
212+
213+
let db, id, coll, coll2, r1, r2, r3, r4, r5, r6, r7, r8, server;
199214

200215
before(async function () {
201216
db = await MongoClient.connect('mongodb://localhost:27017/local').then((c) => c.db());
@@ -206,13 +221,15 @@ describe('mongo', function () {
206221
r5 = new MongoResource(db, { name: 'Aggregation', collection: collectionName }, { '/': { get: Aggregation } });
207222
r6 = new MongoResource(db, { name: 'Escape', collection: collectionName, id: 'myid', escapeProperties: true });
208223
r7 = new MongoResource(db, { name: 'SecondaryAggregation', collection: collectionName }, { '/': { get: AggregationFromSecondary } });
224+
r8 = new MongoResource(db, { name: 'Date', collection: collectionName }, { '/': { post: DateOp } });
209225
api.addResource(r1);
210226
api.addResource(r2);
211227
api.addResource(r3);
212228
api.addResource(r4);
213229
api.addResource(r5);
214230
api.addResource(r6);
215231
api.addResource(r7);
232+
api.addResource(r8);
216233

217234
let router = await api.router();
218235
app.use(router);
@@ -331,6 +348,20 @@ describe('mongo', function () {
331348
data.should.deep.equal({ myid: 'bbb', 'a.b.c.d': 1 });
332349
});
333350
});
351+
352+
it('should create a record with a date preserving its type', function () {
353+
debugger;
354+
return request
355+
.post('/dates')
356+
.send({ myid: 'ts', ts: new Date() })
357+
.expect(201)
358+
.expect('Content-Type', /json/)
359+
.then(async ({ body: data }) => {
360+
const ref = await coll.findOne({}, { sort: { _id: -1 } });
361+
await coll.remove({ myid: 'ts' });
362+
ref.ts.should.be.a('Date');
363+
});
364+
});
334365
});
335366

336367
describe('collection', function () {

0 commit comments

Comments
 (0)