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

Reference resolver fails for external parameter definitions in paths section #374

Open
dani2819 opened this issue Feb 13, 2025 · 0 comments
Labels
requires investigation This needs to be looked at in more detail

Comments

@dani2819
Copy link

Description

The $ref resolution for external file references appears inconsistent when the reference is used directly in the paths section, compared to when it is indirectly used via components.

Working Example

base.yaml

openapi: 3.0.0
info:
  title: Example API
  version: 1.0.0

paths:
  "/test":
    post:
      description: Update script
      operationId: updateScript
      parameters:
        - $ref: '#/components/parameters/test'
      tags:
        - scripts
      responses:
        '200':
          description: OK

components:
  parameters:
    test:
      $ref: './components.yaml#/components/parameters/test'

components.yaml

components:
  parameters:
    test:
      name: test

Here, the reference in the components section resolves correctly from components.yaml.

Non-Working Example

base.yaml

openapi: 3.0.0
info:
  title: Example API
  version: 1.0.0

paths:
  "/test":
    post:
      description: Update script
      operationId: updateScript
      parameters:
        - $ref: './components.yaml#/components/parameters/test'
      tags:
        - scripts
      responses:
        '200':
          description: OK

Here, the $ref for parameters used directly in paths does not resolve successfully if it points to an external file (components.yaml).

Expected Behavior

The $ref in parameters under paths should resolve properly when pointing to an external file, just as it works when referenced indirectly via the components section.

Testing Code

This is the code I used to test parameters resolution:


package main

import (
    "fmt"
    "os"

    "github.com/pb33f/libopenapi"
    "github.com/pb33f/libopenapi/datamodel"
)

func main() {
    // Load the primary OpenAPI spec
    bytes, _ := os.ReadFile("./routes.yaml")
    
    // Build the OpenAPI document with configuration
    document, _ := libopenapi.NewDocumentWithConfiguration(bytes, &datamodel.DocumentConfiguration{
        AllowRemoteReferences: true,
        AllowFileReferences:   true,
        BasePath:              "./",
    })
    
    // Build the V3 OpenAPI Model
    docModel, _ := (document).BuildV3Model()
    fmt.Println(docModel)
    
    // Serialize the resolved document for export
    data, _ := document.Render()
    file, _ := os.Create("./output.yaml")
    file.Write(data)
    file.Close()
}

Environment:

libopenapi version: v0.21.2
Go version: go version go1.23.0

@dani2819 dani2819 changed the title Reference Resolver Fails for External Parameter Definitions in paths Section Reference resolver fails for external parameter definitions in paths section Feb 13, 2025
@daveshanley daveshanley added the requires investigation This needs to be looked at in more detail label Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
requires investigation This needs to be looked at in more detail
Projects
None yet
Development

No branches or pull requests

2 participants