{"action":"closed","issue":{"url":"https://api.github.com/repos/go-swagger/go-swagger/issues/544","repository_url":"https://api.github.com/repos/go-swagger/go-swagger","labels_url":"https://api.github.com/repos/go-swagger/go-swagger/issues/544/labels{/name}","comments_url":"https://api.github.com/repos/go-swagger/go-swagger/issues/544/comments","events_url":"https://api.github.com/repos/go-swagger/go-swagger/issues/544/events","html_url":"https://github.com/go-swagger/go-swagger/issues/544","id":157289526,"number":544,"title":"Build failure when using principal flag.","user":{"login":"williambailey","id":1120702,"avatar_url":"https://avatars.githubusercontent.com/u/1120702?v=3","gravatar_id":"","url":"https://api.github.com/users/williambailey","html_url":"https://github.com/williambailey","followers_url":"https://api.github.com/users/williambailey/followers","following_url":"https://api.github.com/users/williambailey/following{/other_user}","gists_url":"https://api.github.com/users/williambailey/gists{/gist_id}","starred_url":"https://api.github.com/users/williambailey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/williambailey/subscriptions","organizations_url":"https://api.github.com/users/williambailey/orgs","repos_url":"https://api.github.com/users/williambailey/repos","events_url":"https://api.github.com/users/williambailey/events{/privacy}","received_events_url":"https://api.github.com/users/williambailey/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/go-swagger/go-swagger/labels/bug","name":"bug","color":"fc2929"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-05-27T20:58:19Z","updated_at":"2016-06-19T16:05:14Z","closed_at":"2016-06-19T16:05:14Z","body":"## Problem statement\r\n\r\nIf i try to use the `--principal` flag during server generation the resulting code fails to compile.\r\n\r\n`swagger version` returns `0.5.0-118-gfffb4b0`\r\n\r\n### Swagger specification\r\n\r\nThe specification needs to include a security definition. e.g.\r\n\r\n```yaml\r\nsecurityDefinitions:\r\n  bearer:\r\n    type: apiKey\r\n    name: Authorization\r\n    in: header\r\n```\r\n\r\n### Steps to reproduce\r\n\r\n```bash\r\nswagger generate server --principal=my.Principal\r\n```\r\n\r\n```bash\r\ngo build\r\n...\r\nmy_api.go:174: cannot use o.BearerAuth (type func(string) (*my.Principal, error))\r\nas type security.TokenAuthentication in argument to security.APIKeyAuth\r\n```\r\n\r\nTo resolve the issue all I had to do was alter 2 of the generated files.\r\n\r\n*example_api.go*\r\n```diff\r\n- BearerAuth func(string) (*my.Principal, error)\r\n+ BearerAuth func(string) (interface{}, error)\r\n```\r\n\r\n*configure_example.go*\r\n```diff\r\n- api.BearerAuth = func(token string) (*my.Principal, error) {\r\n+ api.BearerAuth = func(token string) (interface{}, error) {\r\n```\r\n\r\nI was then successfully able to `return &my.Principal{...}, nil` from `configure_example.go` and have it passed into the api handler with the correct type. \r\n\r\n*configure_example.go*\r\n```\r\napi.ExampleOpHandler = example.OpHandlerFunc(func(ctx context.Context, params example.OpGetParams, principal *my.Principal) middleware.Responder {\r\n    foo := principal.Foo\r\n    // ...\r\n}\r\n``` "}}
{"actor":{"display_login":"casualjim"}}