feTS icon indicating copy to clipboard operation
feTS copied to clipboard

Inferred responses are not included in the openapi spec

Open hpx7 opened this issue 11 months ago • 1 comments

Describe the bug

The TypeBox example mentions

Response type will be automatically inferred from the handler's return type

But the OpenAPI spec that gets generated doesn't have the inferred responses

"responses": { "default": { "description": "" } }

To Reproduce Steps to reproduce the behavior:

import { createRouter, Response, Type } from 'fets'
 
const router = createRouter().route({
  path: '/user/:id',
  method: 'POST',
  schemas: {
    request: {
      headers: Type.Object({
        authorization: Type.String()
      }),
      params: Type.Object({
        id: Type.String({
          format: 'uuid'
        })
      })
    }
  },
  // Response type will be automatically inferred from the handler's return type
  handler: request => {
    if (request.params.id !== EXPECTED_UUID) {
      return Response.json(
        {
          message: 'User not found'
        },
        {
          status: 404
        }
      )
    }
    return Response.json({
      id: request.params.id,
      name: 'John Doe'
    })
  }
})

Expected behavior

The generate openapi.json has well typed responses

Environment:

  • OS:
  • package-name...:
  • NodeJS:

Additional context

hpx7 avatar Jan 25 '25 23:01 hpx7

Responses are not inferred automatically in typescript. You have to define them explicitly.

ardatan avatar Jan 25 '25 23:01 ardatan