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

$refs inside additionalProperties are not converted from definitions to components/schema #821

Closed
2 tasks done
jldmn opened this issue Sep 24, 2024 · 0 comments
Closed
2 tasks done

Comments

@jldmn
Copy link
Contributor

jldmn commented Sep 24, 2024

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

5.0.0

Plugin version

9.0.0

Node.js version

20.17.0

Operating system

Windows

Operating system version (i.e. 20.04, 11.3, 10)

22H2

Description

When using $ref inside patternProperties the relative path is not adjusted to reference components/schema instead of definitions, thus resulting in a broken reference.

So this basic example:

server
  .addSchema({
    $id: 'FileVariant',
    title: 'FileVariant',
    type: 'object',
    properties: {
     ...
    }
  })
  .addSchema({
    $id: 'File',
    title: 'File',
    type: 'object',
    properties: {
      variants: {
        type: 'object',
        patternProperties: {
          '^[A-z0-9-]{1,50}$': {
            $ref: 'FileVariant#'
          }
        }
      }
    }
  })

results in this broken spec:

{
  "openapi": "3.0.0",
  "components": {
    "schemas": {
      "def-0": {
        "title": "FileVariant",
        "description": "",
        "type": "object",
        "properties": {
         
        },
        "additionalProperties": false
      },
      "def-1": {
        "title": "File",
        "type": "object",
        "properties": {
          "variants": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/definitions/def-0"
            }
          }
        },
        "required": [],
        "additionalProperties": false
      }
    }
  }
}

instead of the correct:

"additionalProperties": {
  "$ref": "#/components/schmemas/def-0"
}

Link to code that reproduces the bug

No response

Expected Behavior

The expected behavior would be to correctly reference other schemas trough $ref inside the patterProperties as described in the upper example.

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

No branches or pull requests

1 participant