Skip to content

Commit

Permalink
feat: skip visited nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
cdimascio committed Jan 2, 2021
1 parent cf304c1 commit 08df2b4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/middlewares/parsers/schema.preprocessor.ts
Expand Up @@ -34,10 +34,12 @@ class Node<T, P> {
public readonly path: string[];
public readonly parent: P;
public readonly schema: T;
public readonly seen: boolean;
constructor(parent: P, schema: T, path: string[]) {
this.path = path;
this.parent = parent;
this.schema = schema;
this.seen = false;
}
}
type SchemaObjectNode = Node<SchemaObject, SchemaObject>;
Expand Down Expand Up @@ -170,12 +172,13 @@ export class SchemaPreprocessor {
private traverseSchemas(nodes: TopLevelSchemaNodes, visit) {
const recurse = (parent, node, opts: TraversalStates) => {
const schema = this.resolveSchema<SchemaObject>(node.schema);
if (!schema) {
if (node.seen || !schema) {
// if we can't dereference a path within the schema, skip preprocessing
// TODO handle refs like below during preprocessing
// #/paths/~1subscription/get/requestBody/content/application~1json/schema/properties/subscription
return;
}
node.seen = true;
// Save the original schema so we can check if it was a $ref
(<any>opts).req.originalSchema = node.schema;
(<any>opts).res.originalSchema = node.schema;
Expand Down

0 comments on commit 08df2b4

Please sign in to comment.