Skip to content

Add userParameterMode = CUSTOM for selecting a custom type for authentication in servers#2569

Merged
altro3 merged 4 commits intomicronaut-projects:6.19.xfrom
giovanniberti:custom-user-parameter
Feb 20, 2026
Merged

Add userParameterMode = CUSTOM for selecting a custom type for authentication in servers#2569
altro3 merged 4 commits intomicronaut-projects:6.19.xfrom
giovanniberti:custom-user-parameter

Conversation

@giovanniberti
Copy link
Copy Markdown
Contributor

Closes #2562

@cla-assistant
Copy link
Copy Markdown

cla-assistant Bot commented Feb 9, 2026

CLA assistant check
All committers have signed the CLA.

@altro3
Copy link
Copy Markdown
Collaborator

altro3 commented Feb 10, 2026

@giovanniberti need to sign CLA

@altro3 altro3 marked this pull request as ready for review February 10, 2026 16:56
@altro3 altro3 self-requested a review February 10, 2026 16:56
@altro3 altro3 added the type: improvement A minor improvement to an existing feature label Feb 11, 2026
@altro3
Copy link
Copy Markdown
Collaborator

altro3 commented Feb 13, 2026

@giovanniberti ping

@giovanniberti
Copy link
Copy Markdown
Contributor Author

Sorry for the delay! :)
Btw, after removing the FIXME I think the PR will be ready to be merged, I'll also probably write a follow-up PR to allow customizing the name of the generated auth parameter

@altro3
Copy link
Copy Markdown
Collaborator

altro3 commented Feb 16, 2026

Sorry for the delay! :) Btw, after removing the FIXME I think the PR will be ready to be merged, I'll also probably write a follow-up PR to allow customizing the name of the generated auth parameter

Ok! I'm ready to merge this PR. Waiting your fix

@giovanniberti
Copy link
Copy Markdown
Contributor Author

giovanniberti commented Feb 16, 2026

Added checks and tests for the combination of userParameterMode and userParameterClass, as soon as the pipeline goes green you can merge 🚀

@altro3
Copy link
Copy Markdown
Collaborator

altro3 commented Feb 17, 2026

@giovanniberti run gradle spotlessApply to fix this problem and commit again

изображение

@giovanniberti
Copy link
Copy Markdown
Contributor Author

Done

@altro3
Copy link
Copy Markdown
Collaborator

altro3 commented Feb 18, 2026

@giovanniberti you need to run build locally before commit.

изображение

Some tests failed:

KotlinMicronautServerCodegenTest.testEnumNullable()
JavaMicronautServerCodegenTest.testEnumNullable()

изображение

userParameterClass = (String) additionalProperties.get(OPT_USER_PARAMETER_CLASS);
var className = userParameterClass.substring(userParameterClass.lastIndexOf('.') + 1);
importMapping.put(className, userParameterClass);
} else if (additionalProperties.containsKey(OPT_USER_PARAMETER_CLASS)) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is your mistake: you need to check this parameter only when userModeOpt == CUSTOM

Copy link
Copy Markdown
Contributor Author

@giovanniberti giovanniberti Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the point of the check, we have four possible cases:

  • userParameterMode == CUSTOM
    • and userParameterClass not set -> user error, covered by the first check
    • and userParameterClass set -> ok
  • userParameterMode != CUSTOM
    • and userParameterClass not set -> ok
    • and userParameterClass set -> user error, covered by the else if

One parameter without the other is not a configuration that makes sense to support.

The problem at the implementation level was that additionalProperties.contains(OPT_USER_PARAMETER_CLASS) evaluates to true because there are other parts of the code that populate the map with that key and set null as the value if the user doesn't provide it.

Does it make sense to you?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, of course, I understand that we have four possible combinations.

But in my opinion, it would be easier to simply ignore the userParameterClass parameter if the mode is different from CUSTOM, rather than throwing an error. Because here you're already checking for the mode.

изображение

So, now you're checking the mode at startup, and then checking the mode every time you substitute the class.

Copy link
Copy Markdown
Collaborator

@altro3 altro3 Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main idea is that if a user switches the mode via a gradle plugin, so that his build doesn't break due to the fact that he has specified a parameter userParameterClass that is used only in CUSTOM mode, but simply silently ignore this parameter

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I don't like inferring the correct configuration via precedence rules, but if that's the convention in Gradle or specifically in this plugin I'll remove the extra check

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a small thing, in my opinion. That's okay too

@giovanniberti
Copy link
Copy Markdown
Contributor Author

giovanniberti commented Feb 18, 2026

you need to run build locally before commit

Weird, I did, something must have broken Gradle's config on my IDE 🤔

EDIT: I'm getting test failures (specifically a NullPointerException on :test-suite-server-generator-kotlin-kapt:generateOpenApi) on the unmodified 6.19.x branch (commit 51ae01d), I'll use the pipelines as the reference for green tests if you're ok with it

@giovanniberti giovanniberti marked this pull request as draft February 18, 2026 23:55
@giovanniberti
Copy link
Copy Markdown
Contributor Author

giovanniberti commented Feb 19, 2026

Given the open discussion and my current setup limitations I'm leaving this PR in draft for the moment until you're ok with it moving forward

@altro3 altro3 marked this pull request as ready for review February 19, 2026 07:36
@altro3 altro3 merged commit 5fe69c0 into micronaut-projects:6.19.x Feb 20, 2026
6 checks passed
@giovanniberti giovanniberti deleted the custom-user-parameter branch February 20, 2026 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: improvement A minor improvement to an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants