Skip to content

How to add authInfo to request with generated client #2584

@martinostvik

Description

@martinostvik

Generated Client does not include authInfo as second parameter

I want to include a bearer token as a Authentication header For each request I make with the generated go-swagger client.
Examples I've seen is doing something like this:

auth := httptransport.BearerToken(rawToken), nil
client.cart.CancelCart(params, auth)

Where the different methods takes authInfo of type runtime.ClientAuthInfoWriter as a second parameter like this:

type ClientService interface {
       CancelCart(params *CancelCartParams, authInfo runtime.ClientAuthInfoWriter) (*CancelCartOK, error)
}

However in my generated client it looks like this:

// ClientOption is the option for Client methods
type ClientOption func(*runtime.ClientOperation)
type ClientService interface {
      CancelCart(params *CancelCartParams, opts ...ClientOption) (*CancelCartOK, error)
}

Why don't I get authInfo as a second parameter?
Is it possible to achieve the same goal the way my client is generated?

Swagger specification

Client generated with a swagger specification of version 2.0

Environment

swagger version: 0.26.1
go version: 1.16.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions