Bug Report Checklist
Description
When an OpenAPI spec defines multiple OAuth2 security schemes as alternatives at the global level, the cpp-qt-client generator emits the OAuth authentication code block once per scheme, causing C++ compilation errors due to variable redefinition.
For example, if the spec has:
security:
- oauth_realm_a: []
- oauth_realm_b: []
The generator loops over authMethods and emits the OAuth setup code twice in the same function scope, redeclaring variables like scope and token.
openapi-generator version
Tested on:
Both exhibit the same behavior.
OpenAPI declaration file content or url
Minimal reproducible example:
openapi: 3.0.4
info:
title: Test API
version: 1.0.0
servers:
- url: http://localhost:8080/api
security:
- oauth_primary: []
- oauth_secondary: []
paths:
/test:
get:
operationId: testEndpoint
responses:
"200":
description: OK
components:
securitySchemes:
oauth_primary:
type: oauth2
description: Primary OAuth server
flows:
authorizationCode:
authorizationUrl: http://localhost/auth/primary/authorize
tokenUrl: http://localhost/auth/primary/token
scopes: {}
oauth_secondary:
type: oauth2
description: Secondary OAuth server
flows:
authorizationCode:
authorizationUrl: http://localhost/auth/secondary/authorize
tokenUrl: http://localhost/auth/secondary/token
scopes: {}
Generation Details
openapi-generator-cli generate -g cpp-qt-client -i test-api.yaml -o generated/
Steps to reproduce
- Create the YAML file above
- Generate cpp-qt-client code
- Attempt to compile the generated code
Actual Output
The generated OAIDefaultApi.cpp contains duplicate code blocks:
void OAIDefaultApi::testEndpoint() {
// ... request setup ...
// First OAuth block (oauth_primary)
_OauthMethod = 2;
_implicitFlow.unlink();
_credentialFlow.unlink();
_passwordFlow.unlink();
_authFlow.link();
QStringList scope; // <-- First declaration
auto token = _authFlow.getToken(scope.join(" ")); // <-- First declaration
// ... more code ...
// Second OAuth block (oauth_secondary)
_OauthMethod = 2;
_implicitFlow.unlink();
_credentialFlow.unlink();
_passwordFlow.unlink();
_authFlow.link();
QStringList scope; // <-- ERROR: redefinition
auto token = _authFlow.getToken(scope.join(" ")); // <-- ERROR: redefinition
// ... more code ...
Compilation errors:
error C2086: 'QStringList scope': redefinition
error C2371: 'token': redefinition; different basic types
Expected Output
Only one OAuth code block should be generated. Since the security schemes are alternatives (OR logic), the client only needs to support one OAuth flow at runtime.
Related issues/PRs
Bug Report Checklist
Description
When an OpenAPI spec defines multiple OAuth2 security schemes as alternatives at the global level, the cpp-qt-client generator emits the OAuth authentication code block once per scheme, causing C++ compilation errors due to variable redefinition.
For example, if the spec has:
The generator loops over
authMethodsand emits the OAuth setup code twice in the same function scope, redeclaring variables likescopeandtoken.openapi-generator version
Tested on:
Both exhibit the same behavior.
OpenAPI declaration file content or url
Minimal reproducible example:
Generation Details
Steps to reproduce
Actual Output
The generated
OAIDefaultApi.cppcontains duplicate code blocks:Compilation errors:
Expected Output
Only one OAuth code block should be generated. Since the security schemes are alternatives (OR logic), the client only needs to support one OAuth flow at runtime.
Related issues/PRs