Skip to content

✨ Automatically use response status codes from OpenAPI spec #48

@rvfch

Description

@rvfch

Is your feature request related to a problem?

When creating the endpoint with status code different than 200, I should always explicitly define needed status code in the controller (e.g. res.status(201)).

What feature would you like to see?

It would be better to automatically use defined status codes from API spec

Example:

openapi: '3.0.3'
info:
  title: Node App API
  version: '0.0.1'

paths:
  /api/v1/someEndpoint
    get:
      operationId: someEndpoint
      summary: Do something
      responses:
        '201':
          description: Done
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SomeSchema'

Before:

export const someController = ctrl.createRestController({
  someEndpoint: async (_req, ctx, res) => {
    await someService.doSomething(ctx)
    res.status(201) // Otherwise it will return `200`
    return { foo: 'bar' }
  }

After:

export const someController = ctrl.createRestController({
  someEndpoint: async (_req, ctx, res) => {
    await someService.doSomething(ctx)
    return { foo: 'bar' } // Automatically return `201`
  }

What alternatives have you considered?

No response

Additional context

No response

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions