cdimascio / express-openapi-validator

🦋 Auto-validates api requests, responses, and securities using ExpressJS and an OpenAPI 3.x specification
MIT License
920 stars 211 forks source link

Fixes for 881 - multiple specs w/validateRequests fail #903

Closed mzbik closed 9 months ago

mzbik commented 9 months ago

Problem: Multiple api installations cause installation of chained mung'd json implementations each is bound to a specific apiSpec in the surrounding ResponseValidator. requests are labelled with a specific apiSpec. One (or more) of the chained implementations will then ResponseValidator.validate against a mismatched ResponseValidator.

Solution is:

  1. OpenApiSpecLoader.load() decorates its returned Spec with a unique serial number
  2. OpenApiContext caches this serial number
  3. applyOpenMetadata stores this serial number in the OpenApiRequestMetadata in req.openapi
  4. ResponseValidator.constructor caches the serial number when it is created

And, to make it all work,

  1. ResponseValidator.validate inside the mung'd json, checks to see if the serial number in req.openapi.serial matches the serial number in the containing ResponseValidator instance.