Go-swagger: Need help in successfully running swagger generate commands

Created on 14 Feb 2017  路  4Comments  路  Source: go-swagger/go-swagger

Problem statement

I am trying to generate server and client for go-swagger. (this is my first time using swagger).
And I have these packages:

  • github.com/go-openapi/runtime
  • github.com/tylerb/graceful
  • github.com/jessevdk/go-flags
  • golang.org/x/net/context

in my echo $GOPATH => /Users/argentum/dev/go. but when I run swagger generate server -A auth-service -f ./swagger.yml in /Users/argentum/dev/go/swagger-demo .
I get this:

Generation completed!

For this generation to compile you need to have some packages in your GOPATH:

  * github.com/go-openapi/runtime
  * github.com/tylerb/graceful
  * github.com/jessevdk/go-flags
  * golang.org/x/net/context

But I have these packages, I checked in $GOPATH/github.com/<package-names>

Swagger specification

Installed swagger with go get -u github.com/go-swagger/go-swagger/cmd/swagger when I do swagger version it shows dev

Steps to reproduce

Create a project diretory under $GOPATH.
make a swagger.yml

onsumes:
- application/json
info:
  description: Issues and validates access and refresh tokens and otp for two factor
    authentication
  title: Authentication service
  version: 1.0.0
produces:
- application/json
schemes:
- https
- http
swagger: "2.0"
securityDefinitions:
  key:
    type: apiKey
    in: header
    name: authorization
paths:
  /v1/customers/login:
    delete:
      tags: ["customer login"]
      responses:
        '200':
          description: ok
        '401':
          description: unauthorized
````

## Environment
swagger version: dev  
go version: 1.7.4 darwin/amd64
OS:   OSX SIERRA

Also it would be cool if you could say, how to do a DELETE/POST request which has headers:

Authorizartion: Bearer
X-Platform: Webapp
```

I know how to do the body.

Most helpful comment

The message you see actually means everything is OK, it only prints that as a reminder and a tip for when compilation doesn't work.

For bearer auth you want:

securityDefinitions:
  auth_token:
    type: oauth2
    authorizationUrl: http://dummyauth.io
    tokenUrl: http://dummytoken.io
    flow: accessCode
    scopes:
      all: all

security:
  - auth_token:
    - all

All 4 comments

The message you see actually means everything is OK, it only prints that as a reminder and a tip for when compilation doesn't work.

For bearer auth you want:

securityDefinitions:
  auth_token:
    type: oauth2
    authorizationUrl: http://dummyauth.io
    tokenUrl: http://dummytoken.io
    flow: accessCode
    scopes:
      all: all

security:
  - auth_token:
    - all

oh ok .. :D cool

@casualjim um, where did you get those securityDefinitions values. as in in the documentation or in the examples/authentication its not there, please guide me a bit into figuring out where can I refer to for future problems that are already solved :)

@argentum47, you can find all of that information in the official Swagger 2.0 / OpenAPI 2.0 documentation. For example your question is answered here: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#security-definitions-object

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexec picture alexec  路  3Comments

bobvanluijt picture bobvanluijt  路  3Comments

mpalomas picture mpalomas  路  5Comments

Ragnar-BY picture Ragnar-BY  路  3Comments

Ravenwater picture Ravenwater  路  3Comments