openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG] Inconsistent $ref path resolution for parameters vs schemas from sibling files in subdirectories

Open adamzzza opened this issue 7 months ago • 1 comments

Bug Report Checklist

Description

When using openapi-generator-cli with a multi-file OpenAPI 3.0.3 specification, relative $ref paths to parameter components defined in a separate file (-parameters.yaml) are resolved differently than $ref paths to schema components defined in another separate file (-schemas.yaml), even when the referencing file (*-paths.yaml) and both referenced files are located in the same subdirectory.

Specifically, referencing a schema with ./sibling-schemas.yaml#/MySchema works, but referencing a parameter with ./sibling-parameters.yaml#/MyParameter fails. The parameter reference only works if the path is written as ../<subdir_name>/sibling-parameters.yaml#/MyParameter, as if the base for parameter $ref resolution is incorrectly set to the parent directory.

openapi-generator version

7.13.0

OpenAPI declaration file content or url
  1. openapi.yaml
openapi: 3.0.3
info:
  title: Ref Issue Demo
  version: 1.0.0
tags:
  - name: Orders
paths:
  /orders:
    $ref: './orders/orders-paths.yaml#/orders'
  1. orders/orders-parameters.yaml:
# orders/orders-parameters.yaml
TestParameter:
  name: testParam
  in: query
  schema:
    type: string
  1. orders/orders-schemas.yaml:
# orders/orders-schemas.yaml
QueryFilterSchema:
  type: string
  enum:
    - active
    - inactive
Order:
  type: object
  properties:
    id:
      type: string
  1. orders/orders-paths.yaml
orders:
  get:
    summary: List orders
    operationId: listOrders
    tags:
      - Orders
    parameters:
      - name: filterBy
        in: query
        schema:
          $ref: "./orders-schemas.yaml#/QueryFilterSchema" # This path (./) WORKS for schemas
      # Scenario 1: Expected path for parameter (FAILS)
      - $ref: "./orders-parameters.yaml#/TestParameter"
      # Scenario 2: Workaround path for parameter (WORKS)
      #- $ref: "../orders/orders-parameters.yaml#/TestParameter"
    responses:
      '200':
        description: A list of orders.
        content:
          application/json:
            schema:
              type: array
              items:
                $ref: "./orders-schemas.yaml#/Order"
Generation Details

Any generate command that processes this input

Workaround
  # Scenario 2: Workaround path for parameter (WORKS)
  #- $ref: "../orders/orders-parameters.yaml#/TestParameter"

adamzzza avatar May 16 '25 09:05 adamzzza

Same problem here, would the library authors accept a PR on this ?

LaSylv avatar Jun 09 '25 13:06 LaSylv