elysiajs / elysia-swagger

A plugin for Elysia to auto-generate Swagger page
MIT License
90 stars 46 forks source link

Invalid parameters schema keywords location #102

Closed nxht closed 7 months ago

nxht commented 8 months ago

Based on

The schema keywords should go under schema key.

Example code:

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

const app = new Elysia()
  .use(swagger())
  .get('/', async () => 'hi', {
    query: t.Object({
      a: t.Optional(t.String({
        title: 'title',
        enum: ['a', 'b'],
        pattern: 'a|b',
        default: 'b',
        minLength: 1,
        maxLength: 10,
      })),
    }),
  })
  .listen(3000);

console.log(
  `🦊 Elysia is running at http://${app.server?.hostname}:${app.server?.port}`,
);

Current parameter json

{
  "parameters": [
    {
      "title": "title",
      "enum": [
        "a",
        "b"
      ],
      "pattern": "a|b",
      "default": "b",
      "minLength": 1,
      "maxLength": 10,
      "schema": {
        "type": "string"
      },
      "in": "query",
      "name": "a",
      "required": false
    }
  ]
}

Expected parameter json

{
  "parameters": [
    {
      "schema": {
        "title": "title",
        "enum": [
          "a",
          "b"
        ],
        "pattern": "a|b",
        "default": "b",
        "minLength": 1,
        "maxLength": 10,
        "type": "string"
      },
      "in": "query",
      "name": "a",
      "required": false
    }
  ]
}
nxht commented 8 months ago
rivulent commented 7 months ago

ETA on merging this PR? I tested in my application and found that it solved my pain points.

marclave commented 7 months ago

ETA on merging this PR? I tested in my application and found that it solved my pain points.

merged! ✨