swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.88k stars 6.03k forks source link

Swift3 Security Support #6060

Open wolfAle opened 7 years ago

wolfAle commented 7 years ago
Description

Looks like the swagger-codegen for Swift3 ignores the Security settings and doesn't add any chance to pass the headers to the methods.

Swagger-codegen version

2.3.0

Swagger declaration file content or url

Yaml:

securityDefinitions:
  Bearer:
    type: apiKey
    name: Authorization
    in: header
/api/users:
    get:
      tags:
        - user-resource
      summary: getAllUsers
      operationId: getAllUsersUsingGET
      [...]
      security:
        - Bearer: []

Generated methods:

open class func getAllUsersUsingGET(page: Int32? = nil, size: Int32? = nil, sort: [String]? = nil, completion: @escaping ((_ data: [UserDTO]?,_ error: Error?) -> Void)) 

open class func getAllUsersUsingGETWithRequestBuilder(page: Int32? = nil, size: Int32? = nil, sort: [String]? = nil) -> RequestBuilder<[UserDTO]> {
Command line used for generation

swagger-codegen generate -l swift3 -o destination/path -i ./swagger.yaml

Steps to reproduce
  1. Generate the swift3 code with a YAML file that contains settings for jtw security as source
  2. check the swift3 methods generated, it'd be not possible to pass the token
Suggest a fix/enhancement

I'm trying to fix this but I'm not sure about what files to touch first. My grasp is to edit src/main/resources/swift3/api.mustache and check for {{#authMethods}} inside the class open func definition. If there is any authMethod defined, than I can read some value and add them to headers. Is that right?

Thanks, Alessandro

wolfAle commented 7 years ago

Hi there,

any news about this?