Skip to content

[BUG][DART] Multiple security options are all being added instead of only one. #7057

@gmeral

Description

@gmeral

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

When multiple security options are listed, the openapi specs specifies that they should be options :

A declaration of which security mechanisms can be used for this operation. The list of values includes alternative security requirement objects that can be used. Only one of the security requirement objects need to be satisfied to authorize a request.

However the generated dart client function that adds security headers will attempt to add all of them instead of only one (see sample code below)

openapi-generator version

v 4.3.1

OpenAPI declaration file content or url

Here is the generated function responsible :

void _updateParamsForAuth(List<String> authNames, List<QueryParam> queryParams, Map<String, String> headerParams) {
    authNames.forEach((authName) {
      Authentication auth = _authentications[authName];
      if (auth == null) throw ArgumentError("Authentication undefined: " + authName);
      auth.applyToParams(queryParams, headerParams);
    });
  }

Here is the security object of the scheme in the spec

"security": [
          {
            "ApiKeyAuth": []
          },
          {
            "BearerAuth": []
          }
        ]
Command line used for generation

openapi-generator generate -v -i spec.json -g dart -o api-client/ --api-name-suffix myproject -c config.json

Steps to reproduce
  1. generate a dart client including a schema with multiple security options.
  2. try to make a related call with only one security option set (e.g only ApiKeyAuth)
  3. client throws an exception because "BearerAuth" is undefined
Suggest a fix

Provide an argument to select a preferred security options or when a valid authorization header is set, ignore the others.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions