Skip to content

Incorrect $ref for "referenced model"s #232

@mirismaili

Description

@mirismaili

Consider the following example:

import swagger from '@elysiajs/swagger'
import Elysia, {t} from 'elysia'

const app = new Elysia()
  .use(swagger())
  .model({score: t.Number()})
  .get('/scores', () => [5, 4, 9], {response: t.Array(t.Ref('score'))})

await app
  .handle(new Request('http://localhost/swagger/json'))
  .then(async (res) => console.log(res.status, JSON.stringify(await res.json(), null, 2)))

Then we'll see this output:

{
  "openapi": "3.0.3",
  "info": {
    "title": "Elysia Documentation",
    "description": "Development documentation",
    "version": "0.0.0"
  },
  "paths": {
    "/scores": {
      "get": {
        "responses": {
          "200": {
            "items": {
              "$ref": "score" // <<<---- THE BUG
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/score"
                  }
                }
              },
              "multipart/form-data": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/score"
                  }
                }
              },
              "text/plain": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/score"
                  }
                }
              }
            }
          }
        },
        "operationId": "getScores"
      }
    }
  },
  "components": {
    "schemas": {
      "score": {
        "type": "number",
        "$id": "#/components/schemas/score"
      }
    }
  }
}

"$ref": "score" is an invalid $ref.


Additionally, I don't know why items property exists there? It seems it's unnecessary and can be omitted:

        "responses": {
          "200": {
-            "items": {
-              "$ref": "score"
-            },
            "content": {
               // ...
            }

Versions:

"elysia": "1.3.20"
"@elysiajs/swagger": "1.3.1"

Bun v1.2.20

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