Skip to content

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

Open
@sonalys

Description

@sonalys

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions