Skip to content

Resolving schema array items refs #2108

Open
@cosmin-marginean

Description

@cosmin-marginean

I've been struggling to understand how resolving refs works and I've created a basic example to try and reproduce what I think should happen when setting resolve to true.

Below is the YAML spec

openapi: 3.0.3
components:
  schemas:
    Child:
      type: object
      properties:
        name:
          type: string
    Parent:
      type: object
      properties:
        children:
          type: array
          items:
            $ref: '#/components/schemas/Child'

The (Kotlin) code to parse this is as follows

    val parseOptions = ParseOptions()
    parseOptions.isResolve = true

    val parseResult = OpenAPIParser().readLocation("spec.yaml", null, parseOptions)
    val childrenProperty = parseResult.openAPI.components
        .schemas["Parent"]!!
        .properties["children"]!!
    println(childrenProperty.items.`$ref`)
    println(childrenProperty.items.type)

This prints out

#/components/schemas/Child
null

That is, $ref for the items in the children array is still a full reference (i.e. not dereferenced) and the type is null.

What should the outcome of resolving #/components/schemas/Child be in this case?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions