Skip to content

Commit

Permalink
Fix set invoker package for kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
altro3 committed Jul 16, 2024
1 parent b7a1048 commit 2a69135
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import static org.openapitools.codegen.CodegenConstants.API_PACKAGE;
import static org.openapitools.codegen.CodegenConstants.INVOKER_PACKAGE;
import static org.openapitools.codegen.CodegenConstants.MODEL_PACKAGE;
import static org.openapitools.codegen.CodegenConstants.PACKAGE_NAME;
import static org.openapitools.codegen.languages.KotlinClientCodegen.DATE_LIBRARY;
import static org.openapitools.codegen.utils.StringUtils.camelize;
import static org.openapitools.codegen.utils.StringUtils.underscore;
Expand Down Expand Up @@ -245,6 +246,7 @@ protected AbstractMicronautKotlinCodegen() {

// Set client options that will be presented to user
updateOption(INVOKER_PACKAGE, packageName);
updateOption(PACKAGE_NAME, packageName);
updateOption(CodegenConstants.ARTIFACT_ID, artifactId);
updateOption(CodegenConstants.API_PACKAGE, apiPackage);
updateOption(CodegenConstants.MODEL_PACKAGE, modelPackage);
Expand Down Expand Up @@ -391,8 +393,10 @@ public void setApiPackage(String apiPackage) {
updateOption(CodegenConstants.API_PACKAGE, apiPackage);
}

public void setInvokerPackage(String packageName) {
public void setPackageName(String packageName) {
super.setPackageName(packageName);
updateOption(INVOKER_PACKAGE, packageName);
updateOption(PACKAGE_NAME, packageName);
}

public void setPlural(boolean plural) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private void configureOptions() {
} else if (options.lang == GeneratorLanguage.KOTLIN && codeGenerator instanceof AbstractMicronautKotlinCodegen<?> kotlinCodeGen) {

if (options.invokerPackage != null) {
kotlinCodeGen.setInvokerPackage(options.invokerPackage);
kotlinCodeGen.setPackageName(options.invokerPackage);
}
if (options.artifactId != null) {
kotlinCodeGen.setArtifactId(options.artifactId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public class AuthorizationBinder implements AnnotatedClientRequestBinder<Authori
.getAnnotationValuesByType(Authorization.class);
if (CollectionUtils.isNotEmpty(annotations)) {
List<String> authorizationNames = new ArrayList<>();
var authorizationNames = new ArrayList<String>();
for (AnnotationValue<Authorization> annotation : annotations) {
annotation.get("name", String.class)
annotation.stringValue("name")
.filter(StringUtils::isNotEmpty)
.ifPresent(v -> authorizationNames.add(configurationName(v)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ open class AuthorizationBinder : AnnotatedClientRequestBinder<Authorization> {
if (annotations.isNotEmpty()) {
val authorizationNames = ArrayList<String>()
for (ann in annotations) {
ann.get("name", String::class.java)
.filter{ s -> !s.isNullOrEmpty()}
.ifPresent {v -> authorizationNames.add(configurationName(v))}
ann.stringValue("name")
.filter{ s -> !s.isNullOrEmpty() }
.ifPresent { v -> authorizationNames.add(configurationName(v)) }
}
request.setAttribute(AUTHORIZATION_NAMES, authorizationNames)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import io.micronaut.http.filter.ClientFilterChain
import io.micronaut.http.filter.HttpClientFilter
import io.micronaut.inject.qualifiers.Qualifiers
import io.micronaut.security.oauth2.client.clientcredentials.ClientCredentialsClient
import io.micronaut.security.oauth2.client.clientcredentials.ClientCredentialsConfiguration
import io.micronaut.security.oauth2.client.clientcredentials.propagation.ClientCredentialsHttpClientFilter
import io.micronaut.security.oauth2.client.clientcredentials.propagation.ClientCredentialsTokenPropagator
import io.micronaut.security.oauth2.configuration.OauthClientConfiguration
Expand All @@ -32,7 +31,7 @@ import {{javaxPackage}}.annotation.Generated
{{/generatedAnnotation}}
@Filter({{#configureAuthFilterPattern}}"{{authorizationFilterPattern}}"{{/configureAuthFilterPattern}}{{^configureAuthFilterPattern}}Filter.MATCH_ALL_PATTERN{{/configureAuthFilterPattern}})
open class AuthorizationFilter(
defaultTokenPropagator: ClientCredentialsTokenPropagator,
var defaultTokenPropagator: ClientCredentialsTokenPropagator?,
clientConfigurations: Stream<OauthClientConfiguration>,
configurableAuthorizations: Stream<ConfigurableAuthorization>,
private val beanContext: BeanContext,
Expand All @@ -46,12 +45,12 @@ open class AuthorizationFilter(
init {
clientConfigurationByName = clientConfigurations
.filter { obj: OauthClientConfiguration -> obj.isEnabled }
.collect(Collectors.toMap({ obj: OauthClientConfiguration -> obj.name }, { v: OauthClientConfiguration? -> v }))
.filter { it.isEnabled }
.collect(Collectors.toMap({ it.name }, { it }))
tokenPropagatorByName = HashMap()
clientCredentialsClientByName = HashMap()
authorizationsByName = configurableAuthorizations
.collect(Collectors.toMap({ obj: ConfigurableAuthorization -> obj.getName() }, { v: ConfigurableAuthorization? -> v }))
.collect(Collectors.toMap({ it.name }, { it }))
}

override fun doFilter(request: @NonNull MutableHttpRequest<*>, chain: @NonNull ClientFilterChain): Publisher<out HttpResponse<*>?> {
Expand Down Expand Up @@ -124,7 +123,7 @@ open class AuthorizationFilter(

protected fun getScope(oauthClient: @NonNull OauthClientConfiguration): @Nullable String? {
return oauthClient.clientCredentials
.flatMap { obj: ClientCredentialsConfiguration -> obj.scope }
.flatMap { it.scope }
.orElse(null)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import {{javaxPackage}}.annotation.Generated
{{/generatedAnnotation}}
@EachProperty("security.api-key-auth")
data class ApiKeyAuthConfiguration(
@Parameter val name: String,
@Parameter override val name: String,
@NonNull var location: AuthKeyLocation,
@NonNull var paramName: String,
@NonNull var apiKey: String
): ConfigurableAuthorization {
) : ConfigurableAuthorization {
override fun applyAuthorization(@NonNull request: MutableHttpRequest<*>) {
when (location) {
Expand All @@ -36,8 +36,6 @@ data class ApiKeyAuthConfiguration(
}
}

override fun getName() = name

enum class AuthKeyLocation {
HEADER,
QUERY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {{javaxPackage}}.annotation.Generated
{{/generatedAnnotation}}
interface ConfigurableAuthorization {
fun getName(): String
val name: String
fun applyAuthorization(@NonNull request: MutableHttpRequest<*>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ import {{javaxPackage}}.annotation.Generated
{{/generatedAnnotation}}
@EachProperty("security.basic-auth")
data class HttpBasicAuthConfiguration(
@Parameter val name: String,
@Parameter override val name: String,
@NonNull var username: String,
@NonNull var password: String
) : ConfigurableAuthorization {
override fun applyAuthorization(@NonNull request: MutableHttpRequest<*>) {
request.basicAuth(username, password)
}

override fun getName() = name
}

0 comments on commit 2a69135

Please sign in to comment.