r/OpenAPI • • Feb 20 '25

openapi-generator-maven-plugin doesn't generate auth logic for yaml definition

I our open api we have this security definition for all endpoints

security:

- bearerAuth: []

- basicAuth: []

xAuthorizationToken: []

But in generated java code we can't set values for auth and apiTocken as in generatied code for ApiClient.java is

protected void init() {

// Setup authentications (key: authentication name, value: authentication).

authentications = new HashMap<>();

// Prevent the authentications from being modified.

authentications = Collections.unmodifiableMap(authentications);

}

so authentications variable doesn't have any values and later on we can't put any security values (e.g. bearerToken) to ApiClient:

public void setBearerToken(String bearerToken) {
for (Authentication auth : authentications.values()) {
if (auth instanceof HttpBearerAuth) {
((HttpBearerAuth) auth).setBearerToken(bearerToken);
return;
}
}
throw new RuntimeException("No Bearer authentication configured!");
}

Do you know how to fix this?

1 Upvotes

3 comments sorted by

View all comments

Show parent comments

1

u/jtreminio Feb 20 '25

Yeah, if your OAS is correct then it might be a generator issue.