Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #13613
Closed
Open
Issue created Oct 06, 2022 by Administrator@rootContributor

[BUG] 6.2.0 : Swift API has multiple requiresAuthentication "true"-values when there are multiple securityDefinitions (truetruetruetrue)

Created by: kanduvisla

Description

I've updated openapi-generator from 6.0.0 to 6.2.0 and this adds a requiresAuthentication-property with the value true or false, but when there are multiple security definitions, the generated code becomes something like truetruetruetrue. Which - of course - causes a compilation error :-P

openapi-generator version

Version 6.2.0

OpenAPI declaration file content or url
{
  "swagger" : "2.0",
  "info" : {
    "description" : "Example",
    "version" : "v1",
    "title" : "Example",
    "termsOfService" : "None",
    "contact" : {
      "name" : "Foo",
      "url" : "https://www.example.com"
    }
  },
  "host" : "www.example.com",
  "basePath" : "/Example",
  "schemes" : [ "https" ],
  "produces" : [ "application/json" ],
  "security" : [ {
    "Ping + Oauth.OAuthImplicit" : [ "partner:read" ]
  }, {
    "Ping + Oauth.OAuthImplicit" : [ "partner:write" ]
  }, {
    "Ping + Oauth.OAuthAccessCode" : [ "partner:read" ]
  }, {
    "Ping + Oauth.OAuthAccessCode" : [ "partner:write" ]
  }, {
    "Ping + Oauth.OAuth (External)Implicit" : [ "openid" ]
  }, {
    "Ping + Oauth.OAuth (External)AccessCode" : [ "openid" ]
  } ],
  "paths" : {
    "/api/{country}/v1/accounts/{accountNumber}/split-amount" : {
      "put" : {
        "tags" : [ "Accounts" ],
        "operationId" : "Accounts_SplitAmount",
        "consumes" : [ "application/json" ],
        "produces" : [ "application/json" ],
        "parameters" : [ {
          "name" : "accountNumber",
          "in" : "path",
          "required" : true,
          "type" : "string"
        }, {
          "in" : "body",
          "name" : "input",
          "required" : true,
          "schema" : {
            "$ref" : "#/definitions/SplitAmountInput"
          }
        }, {
          "name" : "country",
          "in" : "path",
          "required" : true,
          "type" : "string",
          "default" : "nl"
        } ],
        "responses" : {
          "200" : {
            "description" : "OK"
          }
        }
      }
    }
  },
  "securityDefinitions" : {
    "Ping + Oauth.OAuthImplicit" : {
      "description" : "OAuth",
      "type" : "oauth2",
      "authorizationUrl" : "https://www.example.com/api/oauth/authorize",
      "flow" : "implicit",
      "scopes" : {
        "partner:read" : "",
        "partner:write" : ""
      }
    },
    "Ping + Oauth.OAuthAccessCode" : {
      "description" : "OAuth",
      "type" : "oauth2",
      "authorizationUrl" : "https://www.example.com/api/oauth/authorize",
      "tokenUrl" : "https://www.example.com/api/oauth/token",
      "flow" : "accessCode",
      "scopes" : {
        "partner:read" : "",
        "partner:write" : ""
      }
    },
    "Ping + Oauth.OAuth (External)AccessCode" : {
      "description" : "OAuth (External)",
      "type" : "oauth2",
      "authorizationUrl" : "https://www.example.com/api/oauth/authorize",
      "tokenUrl" : "https://www.example.com/api/oauth/token",
      "flow" : "accessCode",
      "scopes" : {
        "openid" : ""
      }
    },
    "Ping + Oauth.OAuth (External)Implicit" : {
      "description" : "OAuth (External)",
      "type" : "oauth2",
      "authorizationUrl" : "https://www.example.com/api/oauth/authorize",
      "flow" : "implicit",
      "scopes" : {
        "openid" : ""
      }
    }
  },
  "definitions" : {
    "SplitAmountInput" : {
      "type" : "object",
      "required" : [ "amount" ],
      "properties" : {
        "amount" : {
          "type" : "number",
          "format" : "decimal"
        }
      }
    }
  }
}
Generation Details

Just build it:

openapi-generator generate -i example.json -g swift5
Steps to reproduce

Look at the generated code of OpenAPIClient/Classes/OpenAPIs/APIs/AccountsAPI.swift and check the last line:

return localVariableRequestBuilder.init(
    method: "PUT", 
    URLString: (localVariableUrlComponents?.string ?? localVariableURLString), 
    parameters: localVariableParameters, 
    headers: localVariableHeaderParameters, 
    requiresAuthentication: truetruetruetrue       // Whut?
)

I don't think the compiler will be too kind to the mega-boolean truetruetruetrue :-D

It appears that this issue was introduced in https://github.com/OpenAPITools/openapi-generator/pull/13321

Assignee
Assign to
Time tracking