Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot add security and SecurityDefinitions in swagger:operation #2062

Open
aqsyonas opened this issue Sep 18, 2019 · 1 comment
Open

Cannot add security and SecurityDefinitions in swagger:operation #2062

aqsyonas opened this issue Sep 18, 2019 · 1 comment
Labels
generate spec Related to spec generation from code scanner

Comments

@aqsyonas
Copy link

aqsyonas commented Sep 18, 2019

Problem statement

I am trying to add Bearer authentication to swagger:operation like below. But, it is not working for swagger:operation but working fine for swagger:route and swagger:meta

Swagger specification

// swagger:operation PUT /user user UpdateUser
//
// Update an existing user
// ---
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: guid
//   in: query
//   example: 11111111-1111-1111-1111-111111111111
//   description: uuid of the user to update
//   required: true
//   type: string
// - name: area
//   in: body
//   description: area parameters
//   schema:
//     "$ref": "#/definitions/CreateUserStruct"
//   required: true
// Security:
// - bearer
//
// SecurityDefinitions:
// bearer:
//      type: apiKey
//      name: Authorization
//      in: header
// responses:
//   '201': body:UserCreateSuccessfulResponse
//   '400': body:BadRseponse

When i run below command

swagger generate spec -m -o ./swagger.json

It gives me below errors.

operation (UpdateUser): json: cannot unmarshal string into Go struct field OperationProps.security of type map[string][]string

But the same systanx works fine for swagger:meta and swagger:route.
Am I missing something for operation?

Steps to reproduce

Environment

swagger version: dev
go version: go version go1.12.4 windows/amd64

OS: Windows 10

@davidkuridza
Copy link

Swagger 2.0 defines the security as a list, see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#security-requirement-object for details. Changing the code to should resolve the problem:

security:
  - bearer: []

@fredbi fredbi added the generate spec Related to spec generation from code label Oct 1, 2019
@fredbi fredbi added the scanner label Dec 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generate spec Related to spec generation from code scanner
Projects
None yet
Development

No branches or pull requests

3 participants