swagger-api / swagger-api/swagger-codegen

Swift3 Security Support

Open
#6,060 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/main/resources/swift3/api.mustache and inspect how authMethods is handled in the class open func and RequestBuilder definitions. Generate Swift3 output from the YAML example using the documented command, then compare the generated methods with the declared Bearer security requirement. Done means the generated methods provide a way to pass the required security headers.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
security, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.