Skip to content

TransformSiblingRefs is not applied to subschema $ref siblings (properties, items, parameter/body schemas, etc.) #568

@jhump

Description

@jhump

TransformSiblingRefs correctly rewrites a top-level component schema declared as {$ref: ..., <siblings>} into an equivalent allOf, matching OpenAPI 3.1 / JSON Schema 2020-12 semantics. However, the same shape declared in a subschema (under properties, items, additionalProperties, an allOf/anyOf/oneOf member, a parameter schema, a request/response body schema, etc.) is not transformed.

The siblings are silently dropped: the resulting *SchemaProxy reports IsReference() == true and Schema() returns only the resolved target's shape with no record of the sibling keywords.

This is a meaningful gap because property-level (and other subschema) $ref+siblings are common, such as to mark a property, whose schema comes from a $ref, as deprecated.

Here's an example spec that doesn't get transformed correctly

openapi: 3.1.0
info:
  title: SiblingRefRepro
  version: 1.0.0
components:
  schemas:
    Name:
      type: string
    TopLevel:
      $ref: '#/components/schemas/Name'
      deprecated: true
    Container:
      type: object
      properties:
        foo:
          $ref: '#/components/schemas/Name'
          deprecated: true

In the above example, the TopLevel schema is processed correctly, but the schema for the foo property of Container does not.

Top-level component schemas go through low/base.SchemaProxy.Build(), which checks idx.GetConfig().TransformSiblingRefs and runs SiblingRefTransformer on the YAML node before the proxy's value node is set.

But subschema locations (object properties, items, allOf members, parameter/body schemas, etc.) take a different path:

The end result is that TransformSiblingRefs is effectively a top-level-component-only feature, despite OpenAPI 3.1 / JSON Schema 2020-12 allowing $ref with siblings anywhere a schema appears.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions