swagger-api / swagger-api/swagger-client

Expose original OAS 3.1 $ref fields in resolver meta patches

Open
#4,201 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
2.7k
Forks
765
Avg merge
1d 1h
Merged PRs (30d)
6

Description

Content & configuration

Swagger/OpenAPI definition:

openapi: 3.1.0
info:
  title: Example
  version: 1.0.0
paths: {}
components:
  schemas:
    User:
      type: object
      properties:
        id:
          type: string

    UserList:
      type: object
      properties:
        users:
          type: array
          items:
            $ref: "#/components/schemas/User"

    UserListWithDescription:
      type: object
      properties:
        users:
          type: array
          items:
            $ref: "#/components/schemas/User"
            description: Users returned by this operation

Swagger-Client usage:

SwaggerClient.resolveSubtree(spec, ["components", "schemas", "UserList"])
Is your feature request related to a problem?

Swagger Client adds $$ref to resolved OAS 3.1 schemas, but $$ref does not tell consumers whether the original schema was only a $ref, or a $ref with sibling keywords.

That matters for renderers like Swagger UI. A plain ref can safely be shown as a reference to User, but this is different:

items:
  $ref: "#/components/schemas/User"
  description: Users returned by this operation

In OAS 3.1, sibling keywords are part of the schema. After resolution, both cases may still have $$ref, so downstream code cannot reliably tell them apart.

Describe the solution you'd like

Today, the resolved plain object only exposes $$ref as the ref-related meta patch:

{
  type: "object",
  properties: {
    id: { type: "string" }
  },
  $$ref: "https://swagger.io/#/components/schemas/User"
}

That output is the same shape whether the original schema was just:

$ref: "#/components/schemas/User"

or had sibling keywords:

$ref: "#/components/schemas/User"
description: Users returned by this operation

It would be helpful to also expose the original ref fields in the resolved plain object when allowMetaPatches is enabled.

For example:

{
  type: "object",
  properties: {
    id: { type: "string" }
  },
  $$ref: "https://swagger.io/#/components/schemas/User",
  $$refFields: {
    $ref: "#/components/schemas/User"
  }
}

And when the original schema had siblings:

{
  type: "object",
  description: "Users returned by this operation",
  properties: {
    id: { type: "string" }
  },
  $$ref: "https://swagger.io/#/components/schemas/User",
  $$refFields: {
    $ref: "#/components/schemas/User",
    description: "Users returned by this operation"
  }
}

The property name does not need to be $$refFields; any clear internal meta field would work.

Describe alternatives you've considered

Swagger UI can infer from $$ref, but that is not reliable enough for OAS 3.1.

Swagger UI can always use $$ref as a label hint, but that can be misleading when the original schema had siblings.

Additional context

The OAS 3.1 dereference strategy already keeps ref-fields as ApiDOM metadata internally. This request is to expose that information, or a small equivalent, through allowMetaPatches.

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 at SwaggerClient.resolveSubtree with allowMetaPatches enabled and trace the OAS 3.1 dereference strategy's existing ref-fields ApiDOM metadata. Expose the original $ref and sibling fields in a meta patch, then verify that plain refs and refs with a description produce distinct outputs like the examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
57/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.