Skip to content

Commit

Permalink
feat(deps): Updated to latest jsonpolice to support the DynamicSchema…
Browse files Browse the repository at this point in the history
… class
  • Loading branch information
0xfede committed Apr 28, 2017
1 parent 7985c0e commit c3941b0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"decamelize": "^1.2.0",
"eredita": "^1.0.1",
"express": "^4.15.2",
"jsonpolice": "^5.1.1",
"jsonpolice": "^5.2.0",
"jsonref": "^3.5.0",
"lodash": "^4.17.4",
"mongodb": "^2.2.25",
Expand Down
8 changes: 4 additions & 4 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as _ from 'lodash';
import * as semver from 'semver';
import * as express from 'express';
import { normalizeUri } from 'jsonref';
import { Schema } from 'jsonpolice';
import { Schema, DynamicSchema } from 'jsonpolice';
import { Router, RouterOptions, RequestHandler, Request, Response, NextFunction } from 'express';
import { Eredita } from 'eredita';
import debug, { Logger } from './debug';
Expand Down Expand Up @@ -227,17 +227,17 @@ export class API implements Swagger {
return this;
}

registerSchema(id: string, schema: Swagger.Schema | Schema) {
registerSchema(id: string, schema: Swagger.Schema | DynamicSchema) {
if (!this[__schemas]) {
this[__schemas] = {};
this.registerTag(_.cloneDeep(__default_schema_tag));
this.registerOperation('/schemas/{id}', 'get', _.cloneDeep(__default_schema_operation));
}

let _schema: Swagger.FullSchema;
if (schema instanceof Schema) {
if (schema instanceof DynamicSchema) {
_schema = {};
Schema.attach(_schema, schema as Schema);
Schema.attach(_schema, schema as DynamicSchema);
} else {
_schema = schema as Swagger.FullSchema;
}
Expand Down
14 changes: 2 additions & 12 deletions test/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var chai = require('chai')
, pem = require('pem')
, express = require('express')
, Schema = require('jsonpolice').Schema
, DynamicSchema = require('jsonpolice').DynamicSchema
, Scopes = require('../dist/scopes').Scopes
, API = require('../dist/api').API
, Resource = require('../dist/resource').Resource
Expand Down Expand Up @@ -197,21 +198,10 @@ describe('API', function() {
const schema1 = { a: true, b: 2 };
const schema2 = { c: 'd', e: [] };

class TestSchema extends Schema {
constructor(scope, opts) {
super(scope, opts);
}
class TestSchema extends DynamicSchema {
async schema() {
return schema2;
}
async validate(data, path) {
return data;
}
init() {
}
default(data) {
return data;
}
}
let server;

Expand Down

0 comments on commit c3941b0

Please sign in to comment.