Skip to content

Commit 7df7ef6

Browse files
committed
fix(DynamicSchemas): Fixed handling of dynamic schemas
1 parent 1666717 commit 7df7ef6

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@
9999
"decamelize": "^1.2.0",
100100
"eredita": "^1.0.1",
101101
"express": "^4.15.2",
102-
"jsonpolice": "^5.2.0",
103-
"jsonref": "^3.5.2",
102+
"jsonpolice": "^6.0.0",
103+
"jsonref": "^4.0.0",
104104
"lodash": "^4.17.4",
105105
"mongodb": "^2.2.26",
106106
"request": "^2.81.0",

src/api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ export class API implements Swagger {
235235
}
236236

237237
let _schema: Swagger.FullSchema;
238-
if (schema instanceof DynamicSchema) {
238+
if (schema && typeof (<any>schema).validate === 'function') {
239239
_schema = {};
240240
Schema.attach(_schema, schema as DynamicSchema);
241241
} else {
@@ -346,7 +346,7 @@ export class API implements Swagger {
346346
r.get('/schemas/:id', (req: APIRequest, res: APIResponse, next: NextFunction) => {
347347
let s = this[__schemas][req.params.id];
348348
if (s) {
349-
Schema.get(s as Schema).schema().then(data => res.json(data));
349+
Schema.get(s).schema().then(data => res.json(data));
350350
} else {
351351
next();
352352
}

src/schema.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,11 @@ export class SchemaRegistry {
189189
return parseRefs(dataOrUri, this.opts);
190190
}
191191
async create(dataOrUri:any): Promise<Schema> {
192-
return createSchema(dataOrUri, this.opts);
192+
if (typeof dataOrUri === 'object' && Schema.get(dataOrUri)) {
193+
return Promise.resolve(Schema.get(dataOrUri));
194+
} else {
195+
return createSchema(dataOrUri, this.opts);
196+
}
193197
}
194198
register(id, schema: Swagger.FullSchema) {
195199
schema.id = normalizeUri(id);

0 commit comments

Comments
 (0)