Skip to content

Commit 5623da5

Browse files
fix schema replacement
1 parent 997940d commit 5623da5

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/middlewares/parsers/schema.preprocessor.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,15 @@ export class SchemaPreprocessor<
230230

231231
// Resolve reference object in parent, then process again with resolved schema
232232
// As every object (aka schema) is 'pass-by-reference', this will update the actual apiDoc.
233-
parent.object[node.path[-1]] = resolvedObject;
233+
const lastPathComponent = node.path[node.path.length - 1];
234+
if (isInteger(lastPathComponent)) {
235+
const arrayName = node.path[node.path.length - 2];
236+
const index = parseInt(lastPathComponent);
237+
parent.object[arrayName][index] = resolvedObject;
238+
} else {
239+
parent.object[lastPathComponent] = resolvedObject;
240+
}
241+
234242
node.object = resolvedObject;
235243

236244
return traverse(parent, node as VisitorNode<NodeType>, state);
@@ -968,3 +976,7 @@ function findKeys(
968976
function getKeyFromRef(ref: string) {
969977
return ref.split('/components/schemas/')[1];
970978
}
979+
980+
function isInteger(str: string): boolean {
981+
return /^\d+$/.test(str);
982+
}

0 commit comments

Comments
 (0)