OpenAPITools / OpenAPITools/openapi-generator

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

Open
#21,288 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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"

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the provided openapi.yaml and the orders/orders-paths.yaml, orders/orders-parameters.yaml, and orders/orders-schemas.yaml files using any generate command. Trace how the generator resolves the parameter and schema $ref values; done when both sibling paths resolve consistently from orders/orders-paths.yaml without the ../orders workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.