express-openapi-validator: Referenced Responses with '../' not resolving correctly - I think
Describe the bug I am not sure if this is a bug. But I have a schema that has numerous includes:
index.yaml
....
 /v1/foo:
    $ref: './resources/foo/paths.yaml'
....
paths.yaml 
post:
...add the before
  requestBody:
    description: Details to create test
    content:
      application/json:
        schema:
          $ref: './models.yaml#/MyModel'
...add the rest
get:
...add the rest
models.yaml
MyModel:
  allOf:
    - $ref: "#/Test"
    - type: object
       properties:
         test:
           type: string
Having multiple operations in a file appears to produce an error. (I am going to investigate further.)
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
TypeError: Cannot read property 'content' of undefined
    at SchemaPreprocessor.extractResponseSchemaNodes (/~/project/node_modules/express-openapi-validator/dist/middlewares/parsers/schema.preprocessor.js:306:25)
    at SchemaPreprocessor.gatherSchemaNodesFromPaths (/~/project/node_modules/express-openapi-validator/dist/middlewares/parsers/schema.preprocessor.js:97:49)
    at SchemaPreprocessor.preProcess (/~/project/node_modules/express-openapi-validator/dist/middlewares/parsers/schema.preprocessor.js:56:24)
    at /~/project/node_modules/express-openapi-validator/dist/openapi.validator.js:81:95
Nope I extended the paths file to have 3 operations and the error resurfaced. — further update It actually looks like the resolution of the $ref pointer in the responses is not working. When I logged it,
{
  "401": { "$ref": "#/paths/~1v1~1tests/get/responses/401" }
}
My schema
responses:
    401:
      $ref: "../responses.yaml#/responses/UnauthorizedError"
— further update, I was able to continue developing by using refParser: dereference
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (5 by maintainers)
Let me get you a in-depth schema. I will have time later this week.