swagger-api / swagger-parser

Swagger Spec to Java POJOs
http://swagger.io
Apache License 2.0
773 stars 525 forks source link

Resolving schema array items refs #2108

Open cosmin-marginean opened 1 week ago

cosmin-marginean commented 1 week ago

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?