ogen icon indicating copy to clipboard operation
ogen copied to clipboard

Default Response: Use interface for handler response when specifying a default response

Open sonalys opened this issue 10 months ago • 1 comments

Description

When using a default response:

 operationId: LedgerExpenseList
 responses:
        default:
          $ref: "#/components/responses/ErrorResponse"
        '200':
          description: Ok response

I want the generated code to use interface response

type LedgerExpenseListRes interface {
	ledgerExpenseListRes()
}

Currently what happens is

func (a *API) LedgerExpenseList(context.Context, handlers.LedgerExpenseListParams) (*handlers.LedgerExpenseListOK, error)

When implementing more explicit returns it turns into:

func (a *API) LedgerExpenseList(context.Context, handlers.LedgerExpenseListParams) (handlers.LedgerExpenseListRes, error)

The interface is only used when you specify at least 2 explicit responses and not generated when there is only the default and an ok response.

I can't properly specify a default error response and use it from the handler unless you use the interface for the signature. Of course, as is, the error will go to the error handler and I can still handle it there, but I really think it would be more readable and cleaner this way.

If needed, I can implement this feature. Thanks!

Version used: v1.12.0

sonalys avatar Apr 28 '25 17:04 sonalys

Looking back at it now, I would even consider this a bug, since the specification is allowing a default response type and the generated code is not allowing the developer to return said default response type.

sonalys avatar Aug 17 '25 08:08 sonalys