-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Register properly OpenApiConfigMapping at runtime #30055
Register properly OpenApiConfigMapping at runtime #30055
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My recommendation is to use StaticInitConfigBuilderBuildItem
RunTimeConfigBuilderBuildItem
, which allow you to register a custom io.quarkus.runtime.configuration.ConfigBuilder
, and gives you access to the current SmallRyeConfigBuilder
instance.
This is way more flexible since then you can register everything that you want and you don't need separate build steps for each type of registration. I intend to deprecate and remove the specific build steps and keep only these ones.
Hi @radcortez, thank you for your feedback. Unless I miss something obvious I don't see any services or dynamic data that are currently registered using a Or maybe within the context of this PR, I only move WDYT? |
The @BuildStep
void runtimeOnly(BuildProducer<RunTimeConfigBuilderBuildItem> runTimeConfigBuilder) {
runTimeConfigBuilder.produce(new RunTimeConfigBuilderBuildItem(RuntimeOnlyBuilder.class.getName()));
} and public class RuntimeOnlyBuilder implements ConfigBuilder {
@Override
public SmallRyeConfigBuilder configBuilder(final SmallRyeConfigBuilder builder) {
return return builder.withInterceptors(new OpenApiConfigMapping());
}
} |
This would be done directly in the openapi extension. If you have conditions to apply for the registration, these could be checked at the build step level. If you need to check something on runtime, then you can always register an interceptor factory instead and check it with the config context. |
That sounds a little bit cumbersome to create a new class for each service to register but ok, it is clear now, thx |
a1dbbbd
to
8368537
Compare
In practice, it is a nice approach, thx for sharing 🙏 |
8368537
to
f20bddc
Compare
"First-time contributors need a maintainer to approve running workflows.", I should not be a "first-time contributor", that's weird?! |
It is by extension. Remember you can write like: public class RuntimeOnlyBuilder implements ConfigBuilder {
@Override
public SmallRyeConfigBuilder configBuilder(final SmallRyeConfigBuilder builder) {
return return builder
.withSources(...)
.withMapping(...)
.withInterceptors(...);
}
} So you can customize everything related to the configuration for the extension. |
No idea... but it does show you as an author and contributor. Maybe some issue with GH? It is building now. |
We have build failures with this approach because all over the place in the code base we get the config thanks to Any ideas about how to workaround/fix this new problem? I'm wondering if my initial fix is not the best compromise? |
This comment has been minimized.
This comment has been minimized.
It seems like CI is not happy with the fix :) |
I had a look, and the issue is that the interceptor is relocating properties that are build only and runtime only, meaning that if you have the interceptor in deployment (as of now), it will only work for the build time properties. If you move it to runtime, it will work for runtime properties but will stop working for the build time properties. The relocate interceptor will need to be split into one that handles build time only and another that handles runtime only. |
TBH, I'm a bit lost with your comment, indeed according to my investigations, the test Could you please clarify a bit more what you have in mind? Any example to share? |
Correct, because some properties are build time only, so they are needed during Quarkus augmentation. I never added a way to register Config builds for the build phase because we never needed them before, so the only way to do it is by using the ServiceLoader. I recommend splitting the relocation rules, adding an interceptor relocator (deployment module) with the build time properties rules, and registering it with the ServiceLoader. Add another interceptor (runtime module) for the runtime properties rules and use the ConfigBuilder registration approach. |
f20bddc
to
2d4772c
Compare
FYI, the build fails because of "JDK 17 MacOS M1" |
Don't worry about that check, it's very flaky |
@radcortez Does my last commit match with what you had in mind? |
In this case, I believe the configuration relocate between |
It is already tested by https://github.com/quarkusio/quarkus/blob/main/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/ConfigMappingTest.java#L21 and https://github.com/quarkusio/quarkus/blob/main/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/OpenApiWithConfigTestCase.java#L21, and both tests pass so it seems to work properly, doesn't it? |
Ah, yes, and the interceptor is also applied to |
Motivation
While working on #29886, we realized that
OpenApiConfigMapping
was located in the deployment module instead of runtime which prevented the mapping to work.Modifications:
OpenApiConfigMapping
from deployment to runtimeOpenApiConfigMapping
usingConfigBuilder
instead of relying on theServiceLoader
for more flexibilityResult
The mapping defined in
OpenApiConfigMapping
is properly taken into account.cc @zakkak @radcortez