Skip to content

Commit 688105b

Browse files
committed
fix: cdimascio#626 op level params override path level
1 parent 5268177 commit 688105b

File tree

3 files changed

+69
-44
lines changed

3 files changed

+69
-44
lines changed

package-lock.json

Lines changed: 47 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/framework/index.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,22 @@ export class OpenAPIFramework {
8383
const absolutePath = path.resolve(origCwd, filePath);
8484
if (fs.existsSync(absolutePath)) {
8585
// Get document, or throw exception on error
86-
return $refParser.mode === 'dereference'
87-
? $RefParser.dereference(absolutePath)
88-
: $RefParser.bundle(absolutePath);
86+
const doc =
87+
$refParser.mode === 'dereference'
88+
? $RefParser.dereference(absolutePath)
89+
: $RefParser.bundle(absolutePath);
90+
return doc as Promise<OpenAPIV3.Document>;
8991
} else {
9092
throw new Error(
9193
`${this.loggingPrefix}spec could not be read at ${filePath}`,
9294
);
9395
}
9496
}
95-
return $refParser.mode === 'dereference'
96-
? $RefParser.dereference(filePath)
97-
: $RefParser.bundle(filePath);
97+
const doc =
98+
$refParser.mode === 'dereference'
99+
? $RefParser.dereference(filePath)
100+
: $RefParser.bundle(filePath);
101+
return doc as Promise<OpenAPIV3.Document>;
98102
}
99103

100104
private sortApiDocTags(apiDoc: OpenAPIV3.Document): void {

src/middlewares/parsers/schema.preprocessor.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,8 @@ export class SchemaPreprocessor {
331331
};
332332

333333
for (const option of options) {
334-
ancestor._discriminator.validators[option] = this.ajv.compile(
335-
newSchema,
336-
);
334+
ancestor._discriminator.validators[option] =
335+
this.ajv.compile(newSchema);
337336
}
338337
}
339338
//reset data
@@ -477,10 +476,18 @@ export class SchemaPreprocessor {
477476
if (v === parameters) return;
478477
v.parameters = v.parameters || [];
479478

479+
const match = (
480+
pathParam: OpenAPIV3.ReferenceObject | OpenAPIV3.ParameterObject,
481+
opParam: OpenAPIV3.ReferenceObject | OpenAPIV3.OperationObject,
482+
) =>
483+
// if name or ref exists and are equal
484+
(opParam['name'] && opParam['name'] === pathParam['name']) ||
485+
(opParam['$ref'] && opParam['$ref'] === pathParam['$ref']);
486+
480487
// Add Path level query param to list ONLY if there is not already an operation-level query param by the same name.
481488
for (const param of parameters) {
482-
if (!(v.parameters.some(vparam => vparam["name"] === param["name"]))){
483-
v.parameters.push(param);
489+
if (!v.parameters.some((vparam) => match(param, vparam))) {
490+
v.parameters.push(param);
484491
}
485492
}
486493
}

0 commit comments

Comments
 (0)