Skip to content

Commit

Permalink
Fix using discriminators. (#510)
Browse files Browse the repository at this point in the history
If an object's reference has already been resolved, or if the object is
not a reference, the code will abort with an error like:

node_modules/express-openapi-validator/dist/middlewares/parsers/schema.preprocessor.js:366
        return ref.split('/components/schemas/')[1];
                   ^
TypeError: Cannot read property 'split' of undefined
    at SchemaPreprocessor.getKeyFromRef (node_modules/express-openapi-validator/dist/middlewares/parsers/schema.preprocessor.js:366:20)
    at node_modules/express-openapi-validator/dist/middlewares/parsers/schema.preprocessor.js:194:34
    at Array.flatMap (<anonymous>)
  • Loading branch information
mat813 committed Jan 7, 2021
1 parent 20e2350 commit 590649a
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/middlewares/parsers/schema.preprocessor.ts
Expand Up @@ -264,6 +264,9 @@ export class SchemaPreprocessor {

if (xOf && schemaObj?.discriminator?.propertyName && !o.discriminator) {
const options = schemaObj[xOf].flatMap((refObject) => {
if (refObject['$ref'] === undefined) {
return [];
}
const keys = this.findKeys(
schemaObj.discriminator.mapping,
(value) => value === refObject['$ref'],
Expand Down

0 comments on commit 590649a

Please sign in to comment.