Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Referenced parameters broken in 3.12.0 (“$ref targets root is not found”) #503

Closed
tkalliom opened this issue May 19, 2021 · 3 comments
Closed
Labels

Comments

@tkalliom
Copy link

The following API specification with paths referencing parameter specifications in the components section, adapted from an example in the OpenAPI documentation, produces a The $ref targets root is not found error on dtsgenerator 3.12.0. The same specification was successfully processed on 3.11.0.

Specification:

openapi: 3.0.0
info:
  title: Referenced parameters example
  version: 0.0.1
  description: Based on https://swagger.io/docs/specification/describing-parameters#common-for-various-paths
components:
  parameters:
    offsetParam:
      in: query
      name: offset
      required: false
      schema:
        type: integer
        minimum: 0
      description: The number of items to skip before starting to collect the result set.
    limitParam:
      in: query
      name: limit
      required: false
      schema:
        type: integer
        minimum: 1
        maximum: 50
        default: 20
      description: The numbers of items to return.
paths:
  /users:
    get:
      summary: Gets a list of users.
      parameters:
        - $ref: '#/components/parameters/offsetParam'
        - $ref: '#/components/parameters/limitParam'
      responses:
        '200':
          description: OK

Error:

Error: The $ref targets root is not found: #/components/parameters/offsetParam
The $ref targets root is not found: #/components/parameters/limitParam
    at ReferenceResolver.resolve (/tmp/dtsgenerator-parameters/node_modules/dtsgenerator/dist/core/referenceResolver.js:77:19)
    at DtsGenerator.generate (/tmp/dtsgenerator-parameters/node_modules/dtsgenerator/dist/core/dtsGenerator.js:28:29)
    at async Object.dtsGenerator [as default] (/tmp/dtsgenerator-parameters/node_modules/dtsgenerator/dist/core/index.js:15:12)
    at async exec (/tmp/dtsgenerator-parameters/node_modules/dtsgenerator/dist/cli.js:111:20)
@horiuchi
Copy link
Owner

@tkalliom Thank you for your report!

I think this cause is the same as this issue #471
I'm working on fixing it now, so please wait a little longer.

@horiuchi horiuchi added the bug label May 19, 2021
@horiuchi
Copy link
Owner

Fixed by #504
And released by v3.12.1

@zzzbra
Copy link

zzzbra commented Jan 29, 2023

Still seeing this issue with what appear to be valid JSON pointer paths.

I've installed dtsgenerator@^3.16.2.

Target of reference is shown here:

      "put": {
        "tags": [
          "user"
        ],
        "summary": "Update existing user profile",
        "operationId": "updateUserProfile",
        "requestBody": {
          "description": "User profile object to be updated",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UserProfile"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "User profile updated",
            "content": {}
          },
          "401": {
            "description": "API key is missing or invalid",
            "headers": {
              "WWW_Authenticate": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "description": "User profile not found",
            "content": {}
          },
          "405": {
            "description": "Validation exception",
            "content": {}
          }
        },
        "x-swagger-router-controller": "User"
      },

And it's referenced like so throughout (following if from definition of POST for same path):

 "responses": {
          "201": {
            "description": "User profile created",
            "content": {}
          },
          "401": {
            "$ref": "#/paths/~1user~1profile/put/responses/401"
          },
          "405": {
            "description": "Invalid input",
            "content": {}
          }
        },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants