Skip to content

Commit 9cab493

Browse files
committed
Revert authentication changes from unused root Java/api.mustache template
1 parent 1e7267b commit 9cab493

File tree

1 file changed

+2
-138
lines changed
  • modules/openapi-generator/src/main/resources/Java

1 file changed

+2
-138
lines changed

modules/openapi-generator/src/main/resources/Java/api.mustache

Lines changed: 2 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,11 @@ import java.util.ArrayList;
1717
import java.util.HashMap;
1818
import java.util.List;
1919
import java.util.Map;
20-
{{#hasHttpBasicMethods}}
21-
import java.util.Base64;
22-
{{/hasHttpBasicMethods}}
2320

2421
{{>generatedAnnotation}}
2522
{{#operations}}
2623
public class {{classname}} {
2724
private ApiClient apiClient;
28-
{{#hasHttpBearerMethods}}
29-
private String bearerToken;
30-
{{/hasHttpBearerMethods}}
31-
{{#hasHttpBasicMethods}}
32-
private String username;
33-
private String password;
34-
{{/hasHttpBasicMethods}}
35-
{{#hasApiKeyMethods}}
36-
private String apiKey;
37-
private String apiKeyPrefix;
38-
{{/hasApiKeyMethods}}
39-
{{#hasOAuthMethods}}
40-
private String accessToken;
41-
{{/hasOAuthMethods}}
4225
4326
public {{classname}}() {
4427
this(Configuration.getDefaultApiClient());
@@ -56,120 +39,6 @@ public class {{classname}} {
5639
this.apiClient = apiClient;
5740
}
5841

59-
{{#hasHttpBearerMethods}}
60-
/**
61-
* Helper method to set access token for Bearer authentication.
62-
* @param bearerToken Bearer token
63-
* @return {{classname}}
64-
*/
65-
public {{classname}} setBearerToken(String bearerToken) {
66-
this.bearerToken = bearerToken;
67-
return this;
68-
}
69-
{{/hasHttpBearerMethods}}
70-
71-
{{#hasHttpBasicMethods}}
72-
/**
73-
* Helper method to set username for HTTP basic authentication.
74-
* @param username Username
75-
* @return {{classname}}
76-
*/
77-
public {{classname}} setUsername(String username) {
78-
this.username = username;
79-
return this;
80-
}
81-
82-
/**
83-
* Helper method to set password for HTTP basic authentication.
84-
* @param password Password
85-
* @return {{classname}}
86-
*/
87-
public {{classname}} setPassword(String password) {
88-
this.password = password;
89-
return this;
90-
}
91-
{{/hasHttpBasicMethods}}
92-
93-
{{#hasApiKeyMethods}}
94-
/**
95-
* Helper method to set API key value for API key authentication.
96-
* @param apiKey API key
97-
* @return {{classname}}
98-
*/
99-
public {{classname}} setApiKey(String apiKey) {
100-
this.apiKey = apiKey;
101-
return this;
102-
}
103-
104-
/**
105-
* Helper method to set API key prefix for API key authentication.
106-
* @param apiKeyPrefix API key prefix
107-
* @return {{classname}}
108-
*/
109-
public {{classname}} setApiKeyPrefix(String apiKeyPrefix) {
110-
this.apiKeyPrefix = apiKeyPrefix;
111-
return this;
112-
}
113-
{{/hasApiKeyMethods}}
114-
115-
{{#hasOAuthMethods}}
116-
/**
117-
* Helper method to set access token for OAuth2 authentication.
118-
* @param accessToken Access token
119-
* @return {{classname}}
120-
*/
121-
public {{classname}} setAccessToken(String accessToken) {
122-
this.accessToken = accessToken;
123-
return this;
124-
}
125-
{{/hasOAuthMethods}}
126-
127-
/**
128-
* Apply authentication settings directly to request headers.
129-
* This avoids modifying the shared ApiClient's authentication state.
130-
*/
131-
private void applyAuthToHeaders(Map<String, String> headerParams) {
132-
{{#hasHttpBearerMethods}}
133-
if (bearerToken != null) {
134-
headerParams.put("Authorization", "Bearer " + bearerToken);
135-
}
136-
{{/hasHttpBearerMethods}}
137-
{{#hasHttpBasicMethods}}
138-
if (username != null && password != null) {
139-
String credentials = java.util.Base64.getEncoder().encodeToString((username + ":" + password).getBytes());
140-
headerParams.put("Authorization", "Basic " + credentials);
141-
}
142-
{{/hasHttpBasicMethods}}
143-
{{#hasApiKeyMethods}}
144-
if (apiKey != null) {
145-
{{#authMethods}}{{#isApiKey}}{{#isKeyInHeader}}
146-
String keyValue = apiKeyPrefix != null ? apiKeyPrefix + " " + apiKey : apiKey;
147-
headerParams.put("{{keyParamName}}", keyValue);
148-
{{/isKeyInHeader}}{{/isApiKey}}{{/authMethods}}
149-
}
150-
{{/hasApiKeyMethods}}
151-
{{#hasOAuthMethods}}
152-
if (accessToken != null) {
153-
headerParams.put("Authorization", "Bearer " + accessToken);
154-
}
155-
{{/hasOAuthMethods}}
156-
}
157-
158-
/**
159-
* Apply authentication settings directly to query parameters.
160-
* This avoids modifying the shared ApiClient's authentication state.
161-
*/
162-
private void applyAuthToQueryParams(List<Pair> queryParams) {
163-
{{#hasApiKeyMethods}}
164-
if (apiKey != null) {
165-
{{#authMethods}}{{#isApiKey}}{{#isKeyInQuery}}
166-
String keyValue = apiKeyPrefix != null ? apiKeyPrefix + " " + apiKey : apiKey;
167-
queryParams.add(new Pair("{{keyParamName}}", keyValue));
168-
{{/isKeyInQuery}}{{/isApiKey}}{{/authMethods}}
169-
}
170-
{{/hasApiKeyMethods}}
171-
}
172-
17342
{{#operation}}
17443
/**
17544
* {{summary}}
@@ -227,10 +96,6 @@ public class {{classname}} {
22796
localVarFormParams.put("{{baseName}}", {{paramName}});
22897
{{/formParams}}
22998

230-
// Apply authentication directly to request parameters (no shared state modification)
231-
applyAuthToHeaders(localVarHeaderParams);
232-
applyAuthToQueryParams(localVarQueryParams);
233-
23499
final String[] localVarAccepts = {
235100
{{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}}
236101
};
@@ -241,9 +106,8 @@ public class {{classname}} {
241106
};
242107
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
243108

244-
// No authentication names needed - auth is applied directly above
245-
String[] localVarAuthNames = new String[] {};
246-
109+
String[] localVarAuthNames = new String[] { {{#authMethods}}"{{name}}"{{^-last}}, {{/-last}}{{/authMethods}} };
110+
247111
{{#returnType}}
248112
GenericType<{{{returnType}}}> localVarReturnType = new GenericType<{{{returnType}}}>() {};
249113
return apiClient.invokeAPI(localVarPath, "{{httpMethod}}", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType);

0 commit comments

Comments
 (0)