open-api icon indicating copy to clipboard operation
open-api copied to clipboard

$ref cannot refer to schema under the top-level `paths` section

Open IvanaGyro opened this issue 6 years ago • 1 comments

Framework: express

I want to reuse the schema defined with the specific content type. If I put the schema I want to reuse under the top-level components section, it works properly. However, $ref cannot work on the destination under the paths section.

apiDoc.yaml

openapi: 3.0.2
info:
  version: 1.0.0
  title: API Server
x-express-openapi-disable-response-validation-middleware: true
servers:
  - url: /api
paths:
  /list/post:
    post:
      summary: Get the list of the posts
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - page
              properties:
                page:
                  type: string
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/paths/~1list~1post/post/requestBody/content/application~1json/schema'
      responses: {}

The error message I got.

{
  "message": "can't resolve reference #/paths/~1list~1post/post/requestBody/content/application~1json/schema",
    "location": "body",
      "schema": {
    "$ref": "#/paths/~1list~1post/post/requestBody/content/application~1json/schema",
  },
}

/list/post.js

module.exports.post = (req, res, next) => {
  next();
};

IvanaGyro avatar Dec 11 '19 04:12 IvanaGyro

not sure how we'd support this. feel free to open a pr

jsdevel avatar Dec 11 '19 22:12 jsdevel